$wgMathValidModes and orthogonal MathJax enabler
To adjust the selectable math rendering modes in user preferences $wgMathValidModes is introduced. * $wgUseLaTeXML becomes unnecessary use $wgMathValidModes[] = MW_MATH_LATEXML; to enable the LaTeXML rendering mode * add $wgMathValidModes[] = MW_MATH_MATHJAX; to enable MathJax Currently, MathJax is bound to the MW_MATH_SOURCE rendering mode. This change makes the base mode user configurable. That means before MathJax is loaded the png fallback image could be displayed. ATTENTION: This change modifies global variables as follows: * MW_MATH_MATHJAX is deprecated. Bug: 57981 Change-Id: Ibf705cb66754d04e4c7eafd1e98608b25d7dbb94
This commit is contained in:
parent
ec4b89854d
commit
58f913ecb0
@ -122,7 +122,7 @@ class MathHooks {
|
|||||||
|
|
||||||
$renderedMath = $renderer->render();
|
$renderedMath = $renderer->render();
|
||||||
|
|
||||||
if ( $wgUseMathJax && $mode == MW_MATH_MATHJAX ) {
|
if ( $wgUseMathJax ) {
|
||||||
$parser->getOutput()->addModules( array( 'ext.math.mathjax.enabler' ) );
|
$parser->getOutput()->addModules( array( 'ext.math.mathjax.enabler' ) );
|
||||||
}
|
}
|
||||||
$parser->getOutput()->addModuleStyles( array( 'ext.math.styles' ) );
|
$parser->getOutput()->addModuleStyles( array( 'ext.math.styles' ) );
|
||||||
@ -141,13 +141,20 @@ class MathHooks {
|
|||||||
* @return Boolean: true
|
* @return Boolean: true
|
||||||
*/
|
*/
|
||||||
static function onGetPreferences( $user, &$defaultPreferences ) {
|
static function onGetPreferences( $user, &$defaultPreferences ) {
|
||||||
|
global $wgUseMathJax;
|
||||||
$defaultPreferences['math'] = array(
|
$defaultPreferences['math'] = array(
|
||||||
'type' => 'radio',
|
'type' => 'radio',
|
||||||
'options' => array_flip( self::getMathNames() ),
|
'options' => array_flip( self::getMathNames() ),
|
||||||
'label' => ' ',
|
'label' => ' ',
|
||||||
'section' => 'rendering/math',
|
'section' => 'rendering/math',
|
||||||
);
|
);
|
||||||
|
if ( $wgUseMathJax ) {
|
||||||
|
$defaultPreferences['mathJax'] = array(
|
||||||
|
'type' => 'toggle',
|
||||||
|
'label-message' => 'mw_math_mathjax',
|
||||||
|
'section' => 'rendering/math',
|
||||||
|
);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -179,19 +186,17 @@ class MathHooks {
|
|||||||
* @return array of strings
|
* @return array of strings
|
||||||
*/
|
*/
|
||||||
private static function getMathNames() {
|
private static function getMathNames() {
|
||||||
global $wgUseMathJax, $wgUseLaTeXML;
|
global $wgMathValidModes;
|
||||||
|
$MathConstantNames = array(
|
||||||
$names = array(
|
MW_MATH_SOURCE => 'mw_math_source',
|
||||||
MW_MATH_PNG => wfMessage( 'mw_math_png' )->escaped(),
|
MW_MATH_PNG => 'mw_math_png',
|
||||||
MW_MATH_SOURCE => wfMessage( 'mw_math_source' )->escaped(),
|
MW_MATH_MATHML => 'mw_math_mathml',
|
||||||
|
MW_MATH_LATEXML => 'mw_math_latexml',
|
||||||
|
MW_MATH_MATHJAX => 'mw_math_mathjax'
|
||||||
);
|
);
|
||||||
|
$names = array();
|
||||||
if ( $wgUseMathJax ) {
|
foreach ( $wgMathValidModes as $mode ) {
|
||||||
$names[MW_MATH_MATHJAX] = wfMessage( 'mw_math_mathjax' )->escaped();
|
$names[$mode] = wfMessage( $MathConstantNames[$mode] )->escaped();
|
||||||
}
|
|
||||||
|
|
||||||
if ( $wgUseLaTeXML ) {
|
|
||||||
$names[MW_MATH_LATEXML] = wfMessage( 'mw_math_latexml' )->escaped();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $names;
|
return $names;
|
||||||
|
25
Math.php
25
Math.php
@ -37,7 +37,7 @@ define( 'MW_MATH_HTML', 2 ); /// @deprecated
|
|||||||
define( 'MW_MATH_SOURCE', 3 );
|
define( 'MW_MATH_SOURCE', 3 );
|
||||||
define( 'MW_MATH_MODERN', 4 ); /// @deprecated
|
define( 'MW_MATH_MODERN', 4 ); /// @deprecated
|
||||||
define( 'MW_MATH_MATHML', 5 ); /// @deprecated
|
define( 'MW_MATH_MATHML', 5 ); /// @deprecated
|
||||||
define( 'MW_MATH_MATHJAX', 6 ); /// new in 1.19/1.20
|
define( 'MW_MATH_MATHJAX', 6 ); /// @deprecated
|
||||||
define( 'MW_MATH_LATEXML', 7 ); /// new in 1.22
|
define( 'MW_MATH_LATEXML', 7 ); /// new in 1.22
|
||||||
/**@}*/
|
/**@}*/
|
||||||
|
|
||||||
@ -51,6 +51,15 @@ define( 'MW_MATHSTYLE_INLINE', 2 ); // small operators inline
|
|||||||
// but display the equation centered in a new line.
|
// but display the equation centered in a new line.
|
||||||
/**@}*/
|
/**@}*/
|
||||||
|
|
||||||
|
/**@var array defines the mode allowed on the server */
|
||||||
|
$wgMathValidModes = array( MW_MATH_PNG, MW_MATH_SOURCE );
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The default rendering mode for anonymous users.
|
||||||
|
* Valid options are defined in $wgMathValidModes.
|
||||||
|
*/
|
||||||
|
$wgDefaultUserOptions['math'] = MW_MATH_PNG;
|
||||||
|
|
||||||
/** Location of the texvc binary */
|
/** Location of the texvc binary */
|
||||||
$wgTexvc = __DIR__ . '/math/texvc';
|
$wgTexvc = __DIR__ . '/math/texvc';
|
||||||
/**
|
/**
|
||||||
@ -101,11 +110,10 @@ $wgMathFileBackend = false;
|
|||||||
$wgMathDirectory = false;
|
$wgMathDirectory = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Experimental option to use MathJax library to do client-side math rendering
|
* Enables the option to use MathJax library to do client-side math rendering
|
||||||
* when JavaScript is available. In supporting browsers this makes nice output
|
* when JavaScript is available. In supporting browsers this makes nice output
|
||||||
* that's scalable for zooming, printing, and high-resolution displays.
|
* that's scalable for zooming, printing, and high-resolution displays, even if
|
||||||
*
|
* the browsers do not support HTML5 (i.e. MathML).
|
||||||
* Not guaranteed to be stable at this time.
|
|
||||||
*
|
*
|
||||||
* @todo Rename to $wgMathJax
|
* @todo Rename to $wgMathJax
|
||||||
*/
|
*/
|
||||||
@ -126,11 +134,6 @@ $wgUseMathJax = false;
|
|||||||
*/
|
*/
|
||||||
$wgMathLaTeXMLUrl = 'http://latexml.mathweb.org/convert';
|
$wgMathLaTeXMLUrl = 'http://latexml.mathweb.org/convert';
|
||||||
|
|
||||||
/**
|
|
||||||
* Allows to use LaTeXML as renderer for mathematical equation.
|
|
||||||
*/
|
|
||||||
$wgUseLaTeXML = false;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The timeout for the HTTP-Request sent to the LaTeXML to render an equation,
|
* The timeout for the HTTP-Request sent to the LaTeXML to render an equation,
|
||||||
* in seconds.
|
* in seconds.
|
||||||
@ -153,8 +156,6 @@ $wgMathTexvcCheckExecutable = __DIR__ . '/texvccheck/texvccheck';
|
|||||||
$wgMathDisableTexFilter = false;
|
$wgMathDisableTexFilter = false;
|
||||||
////////// end of config settings.
|
////////// end of config settings.
|
||||||
|
|
||||||
$wgDefaultUserOptions['math'] = MW_MATH_PNG;
|
|
||||||
|
|
||||||
$wgExtensionFunctions[] = 'MathHooks::setup';
|
$wgExtensionFunctions[] = 'MathHooks::setup';
|
||||||
$wgHooks['ParserFirstCallInit'][] = 'MathHooks::onParserFirstCallInit';
|
$wgHooks['ParserFirstCallInit'][] = 'MathHooks::onParserFirstCallInit';
|
||||||
$wgHooks['GetBetaFeaturePreferences'][] = 'MathHooks::onGetBetaPreferences';
|
$wgHooks['GetBetaFeaturePreferences'][] = 'MathHooks::onGetBetaPreferences';
|
||||||
|
@ -85,7 +85,7 @@ abstract class MathRenderer {
|
|||||||
* @return MathRenderer appropriate renderer for mode
|
* @return MathRenderer appropriate renderer for mode
|
||||||
*/
|
*/
|
||||||
public static function getRenderer( $tex, $params = array(), $mode = MW_MATH_PNG ) {
|
public static function getRenderer( $tex, $params = array(), $mode = MW_MATH_PNG ) {
|
||||||
global $wgDefaultUserOptions;
|
global $wgDefaultUserOptions, $wgMathValidModes;
|
||||||
$mathStyle = null;
|
$mathStyle = null;
|
||||||
if ( isset( $params['display'] ) ) {
|
if ( isset( $params['display'] ) ) {
|
||||||
$layoutMode = $params['display'];
|
$layoutMode = $params['display'];
|
||||||
@ -107,9 +107,9 @@ abstract class MathRenderer {
|
|||||||
$tex = '{\textstyle ' . $tex . '}';
|
$tex = '{\textstyle ' . $tex . '}';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$validModes = array( MW_MATH_PNG, MW_MATH_SOURCE, MW_MATH_MATHJAX, MW_MATH_LATEXML );
|
if ( !in_array( $mode, $wgMathValidModes ) ) {
|
||||||
if ( !in_array( $mode, $validModes ) )
|
|
||||||
$mode = $wgDefaultUserOptions['math'];
|
$mode = $wgDefaultUserOptions['math'];
|
||||||
|
}
|
||||||
switch ( $mode ) {
|
switch ( $mode ) {
|
||||||
case MW_MATH_MATHJAX:
|
case MW_MATH_MATHJAX:
|
||||||
case MW_MATH_SOURCE:
|
case MW_MATH_SOURCE:
|
||||||
|
@ -8,3 +8,7 @@ production.
|
|||||||
=== Configuration changes in 2.0 ===
|
=== Configuration changes in 2.0 ===
|
||||||
* $wgLaTeXMLUrl was renamed to $wgMathLaTeXMLUrl
|
* $wgLaTeXMLUrl was renamed to $wgMathLaTeXMLUrl
|
||||||
* $wgLaTeXMLTimeout was renamed to $wgMathLaTeXMLTimeout
|
* $wgLaTeXMLTimeout was renamed to $wgMathLaTeXMLTimeout
|
||||||
|
* $wgMathValidModes is introduced:
|
||||||
|
It determines the selectable math rendering modes MW_MATH_(PNG|MATHML|...) in user preferences.
|
||||||
|
* $wgUseLaTeXML becomes unnecessary use $wgMathValidModes[] = MW_MATH_LATEXML;
|
||||||
|
to enable the LaTeXML rendering mode.
|
||||||
|
@ -5,6 +5,10 @@
|
|||||||
( function ( mw, $ ) {
|
( function ( mw, $ ) {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
if( ! mw.user.options.get( 'mathJax' ) ) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
if ( typeof mathJax === 'undefined' ) {
|
if ( typeof mathJax === 'undefined' ) {
|
||||||
window.mathJax = {};
|
window.mathJax = {};
|
||||||
}
|
}
|
||||||
|
@ -140,6 +140,7 @@ class MathLaTeXMLTest extends MediaWikiTestCase {
|
|||||||
*/
|
*/
|
||||||
public function testIntegration() {
|
public function testIntegration() {
|
||||||
$this->setMwGlobals( 'wgMathLaTeXMLTimeout', 20 );
|
$this->setMwGlobals( 'wgMathLaTeXMLTimeout', 20 );
|
||||||
|
$this->setMwGlobals( 'wgMathValidModes', array( MW_MATH_LATEXML ) );
|
||||||
$renderer = MathRenderer::getRenderer( "a+b", array(), MW_MATH_LATEXML );
|
$renderer = MathRenderer::getRenderer( "a+b", array(), MW_MATH_LATEXML );
|
||||||
$real = $renderer->render( true );
|
$real = $renderer->render( true );
|
||||||
$expected = '<span class="tex" dir="ltr" id="a_b"><math xmlns="http://www.w3.org/1998/Math/MathML" id="p1.1.m1" class="ltx_Math" alttext="{\displaystyle a+b}" display="inline" xml:id="p1.1.m1.1" xref="p1.1.m1.1.cmml"> <semantics xml:id="p1.1.m1.1a" xref="p1.1.m1.1.cmml"> <mrow xml:id="p1.1.m1.1.4" xref="p1.1.m1.1.4.cmml"> <mi xml:id="p1.1.m1.1.1" xref="p1.1.m1.1.1.cmml">a</mi> <mo xml:id="p1.1.m1.1.2" xref="p1.1.m1.1.2.cmml">+</mo> <mi xml:id="p1.1.m1.1.3" xref="p1.1.m1.1.3.cmml">b</mi> </mrow> <annotation-xml encoding="MathML-Content" xml:id="p1.1.m1.1.cmml" xref="p1.1.m1.1"> <apply xml:id="p1.1.m1.1.4.cmml" xref="p1.1.m1.1.4"> <plus xml:id="p1.1.m1.1.2.cmml" xref="p1.1.m1.1.2"/> <ci xml:id="p1.1.m1.1.1.cmml" xref="p1.1.m1.1.1">a</ci> <ci xml:id="p1.1.m1.1.3.cmml" xref="p1.1.m1.1.3">b</ci> </apply> </annotation-xml> <annotation encoding="application/x-tex" xml:id="p1.1.m1.1b" xref="p1.1.m1.1.cmml">{\displaystyle a+b}</annotation> </semantics> </math></span>';
|
$expected = '<span class="tex" dir="ltr" id="a_b"><math xmlns="http://www.w3.org/1998/Math/MathML" id="p1.1.m1" class="ltx_Math" alttext="{\displaystyle a+b}" display="inline" xml:id="p1.1.m1.1" xref="p1.1.m1.1.cmml"> <semantics xml:id="p1.1.m1.1a" xref="p1.1.m1.1.cmml"> <mrow xml:id="p1.1.m1.1.4" xref="p1.1.m1.1.4.cmml"> <mi xml:id="p1.1.m1.1.1" xref="p1.1.m1.1.1.cmml">a</mi> <mo xml:id="p1.1.m1.1.2" xref="p1.1.m1.1.2.cmml">+</mo> <mi xml:id="p1.1.m1.1.3" xref="p1.1.m1.1.3.cmml">b</mi> </mrow> <annotation-xml encoding="MathML-Content" xml:id="p1.1.m1.1.cmml" xref="p1.1.m1.1"> <apply xml:id="p1.1.m1.1.4.cmml" xref="p1.1.m1.1.4"> <plus xml:id="p1.1.m1.1.2.cmml" xref="p1.1.m1.1.2"/> <ci xml:id="p1.1.m1.1.1.cmml" xref="p1.1.m1.1.1">a</ci> <ci xml:id="p1.1.m1.1.3.cmml" xref="p1.1.m1.1.3">b</ci> </apply> </annotation-xml> <annotation encoding="application/x-tex" xml:id="p1.1.m1.1b" xref="p1.1.m1.1.cmml">{\displaystyle a+b}</annotation> </semantics> </math></span>';
|
||||||
|
Loading…
Reference in New Issue
Block a user