diff --git a/Math.hooks.php b/Math.hooks.php index bba5090..60eb2f0 100644 --- a/Math.hooks.php +++ b/Math.hooks.php @@ -122,7 +122,7 @@ class MathHooks { $renderedMath = $renderer->render(); - if ( $wgUseMathJax && $mode == MW_MATH_MATHJAX ) { + if ( $wgUseMathJax ) { $parser->getOutput()->addModules( array( 'ext.math.mathjax.enabler' ) ); } $parser->getOutput()->addModuleStyles( array( 'ext.math.styles' ) ); @@ -141,13 +141,20 @@ class MathHooks { * @return Boolean: true */ static function onGetPreferences( $user, &$defaultPreferences ) { + global $wgUseMathJax; $defaultPreferences['math'] = array( 'type' => 'radio', 'options' => array_flip( self::getMathNames() ), 'label' => ' ', 'section' => 'rendering/math', ); - + if ( $wgUseMathJax ) { + $defaultPreferences['mathJax'] = array( + 'type' => 'toggle', + 'label-message' => 'mw_math_mathjax', + 'section' => 'rendering/math', + ); + } return true; } @@ -179,19 +186,17 @@ class MathHooks { * @return array of strings */ private static function getMathNames() { - global $wgUseMathJax, $wgUseLaTeXML; - - $names = array( - MW_MATH_PNG => wfMessage( 'mw_math_png' )->escaped(), - MW_MATH_SOURCE => wfMessage( 'mw_math_source' )->escaped(), + global $wgMathValidModes; + $MathConstantNames = array( + MW_MATH_SOURCE => 'mw_math_source', + MW_MATH_PNG => 'mw_math_png', + MW_MATH_MATHML => 'mw_math_mathml', + MW_MATH_LATEXML => 'mw_math_latexml', + MW_MATH_MATHJAX => 'mw_math_mathjax' ); - - if ( $wgUseMathJax ) { - $names[MW_MATH_MATHJAX] = wfMessage( 'mw_math_mathjax' )->escaped(); - } - - if ( $wgUseLaTeXML ) { - $names[MW_MATH_LATEXML] = wfMessage( 'mw_math_latexml' )->escaped(); + $names = array(); + foreach ( $wgMathValidModes as $mode ) { + $names[$mode] = wfMessage( $MathConstantNames[$mode] )->escaped(); } return $names; diff --git a/Math.php b/Math.php index 9e18e13..6f94c5b 100644 --- a/Math.php +++ b/Math.php @@ -37,7 +37,7 @@ define( 'MW_MATH_HTML', 2 ); /// @deprecated define( 'MW_MATH_SOURCE', 3 ); define( 'MW_MATH_MODERN', 4 ); /// @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 /**@}*/ @@ -51,6 +51,15 @@ define( 'MW_MATHSTYLE_INLINE', 2 ); // small operators inline // 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 */ $wgTexvc = __DIR__ . '/math/texvc'; /** @@ -101,11 +110,10 @@ $wgMathFileBackend = 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 - * that's scalable for zooming, printing, and high-resolution displays. - * - * Not guaranteed to be stable at this time. + * that's scalable for zooming, printing, and high-resolution displays, even if + * the browsers do not support HTML5 (i.e. MathML). * * @todo Rename to $wgMathJax */ @@ -126,11 +134,6 @@ $wgUseMathJax = false; */ $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, * in seconds. @@ -153,8 +156,6 @@ $wgMathTexvcCheckExecutable = __DIR__ . '/texvccheck/texvccheck'; $wgMathDisableTexFilter = false; ////////// end of config settings. -$wgDefaultUserOptions['math'] = MW_MATH_PNG; - $wgExtensionFunctions[] = 'MathHooks::setup'; $wgHooks['ParserFirstCallInit'][] = 'MathHooks::onParserFirstCallInit'; $wgHooks['GetBetaFeaturePreferences'][] = 'MathHooks::onGetBetaPreferences'; diff --git a/MathRenderer.php b/MathRenderer.php index 23bb9ca..088c351 100644 --- a/MathRenderer.php +++ b/MathRenderer.php @@ -85,7 +85,7 @@ abstract class MathRenderer { * @return MathRenderer appropriate renderer for mode */ public static function getRenderer( $tex, $params = array(), $mode = MW_MATH_PNG ) { - global $wgDefaultUserOptions; + global $wgDefaultUserOptions, $wgMathValidModes; $mathStyle = null; if ( isset( $params['display'] ) ) { $layoutMode = $params['display']; @@ -107,9 +107,9 @@ abstract class MathRenderer { $tex = '{\textstyle ' . $tex . '}'; } } - $validModes = array( MW_MATH_PNG, MW_MATH_SOURCE, MW_MATH_MATHJAX, MW_MATH_LATEXML ); - if ( !in_array( $mode, $validModes ) ) + if ( !in_array( $mode, $wgMathValidModes ) ) { $mode = $wgDefaultUserOptions['math']; + } switch ( $mode ) { case MW_MATH_MATHJAX: case MW_MATH_SOURCE: diff --git a/RELEASE-NOTES-2.0 b/RELEASE-NOTES-2.0 index 86531e0..43bf86c 100644 --- a/RELEASE-NOTES-2.0 +++ b/RELEASE-NOTES-2.0 @@ -8,3 +8,7 @@ production. === Configuration changes in 2.0 === * $wgLaTeXMLUrl was renamed to $wgMathLaTeXMLUrl * $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. diff --git a/modules/ext.math.mathjax.enabler.js b/modules/ext.math.mathjax.enabler.js index 9a45a01..ec56d1e 100644 --- a/modules/ext.math.mathjax.enabler.js +++ b/modules/ext.math.mathjax.enabler.js @@ -5,6 +5,10 @@ ( function ( mw, $ ) { 'use strict'; + if( ! mw.user.options.get( 'mathJax' ) ) { + return true; + } + if ( typeof mathJax === 'undefined' ) { window.mathJax = {}; } diff --git a/tests/MathLaTeXMLTest.php b/tests/MathLaTeXMLTest.php index 1573232..2af6342 100644 --- a/tests/MathLaTeXMLTest.php +++ b/tests/MathLaTeXMLTest.php @@ -140,6 +140,7 @@ class MathLaTeXMLTest extends MediaWikiTestCase { */ public function testIntegration() { $this->setMwGlobals( 'wgMathLaTeXMLTimeout', 20 ); + $this->setMwGlobals( 'wgMathValidModes', array( MW_MATH_LATEXML ) ); $renderer = MathRenderer::getRenderer( "a+b", array(), MW_MATH_LATEXML ); $real = $renderer->render( true ); $expected = ' a + b a b {\displaystyle a+b} ';