$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:
Moritz Schubotz (Physikerwelt) 2014-04-08 13:57:15 +00:00 committed by Physikerwelt
parent ec4b89854d
commit 58f913ecb0
6 changed files with 44 additions and 29 deletions

View File

@ -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;

View File

@ -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';

View File

@ -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:

View File

@ -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.

View File

@ -5,6 +5,10 @@
( function ( mw, $ ) {
'use strict';
if( ! mw.user.options.get( 'mathJax' ) ) {
return true;
}
if ( typeof mathJax === 'undefined' ) {
window.mathJax = {};
}

View File

@ -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 = '<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>';