Set up MathJax as a selectable option in math preferences

This commit is contained in:
Brion Vibber 2012-03-05 20:34:29 +00:00
parent a4c39f94a6
commit 2af7057b05
Notes: Brion Vibber 2012-03-05 20:34:29 +00:00
4 changed files with 17 additions and 17 deletions

View file

@ -44,7 +44,7 @@ class MathRenderer {
}
function setOutputMode( $mode ) {
$validModes = array( MW_MATH_PNG, MW_MATH_SOURCE );
$validModes = array( MW_MATH_PNG, MW_MATH_SOURCE, MW_MATH_MATHJAX );
if ( in_array( $mode, $validModes ) ) {
$this->mode = $mode;
} else {
@ -57,7 +57,7 @@ class MathRenderer {
global $wgTmpDirectory;
global $wgTexvc, $wgMathCheckFiles, $wgTexvcBackgroundColor;
if( $this->mode == MW_MATH_SOURCE ) {
if( $this->mode == MW_MATH_SOURCE || $this->mode == MW_MATH_MATHJAX ) {
# No need to render or parse anything more!
# New lines are replaced with spaces, which avoids confusing our parser (bugs 23190, 22818)
return ('<span class="tex" dir="ltr">$ ' . str_replace( "\n", " ", htmlspecialchars( $this->tex ) ) . ' $</span>');

View file

@ -46,9 +46,9 @@ class MathHooks {
$renderedMath = MathRenderer::renderMath(
$content, $attributes, $parser->getOptions()
);
if ( $wgUseMathJax ) {
self::addMathJax( $parser );
if ( $wgUseMathJax && $parser->getOptions()->getMath() == MW_MATH_MATHJAX ) {
$parser->getOutput()->addModules( array( 'ext.math.mathjax.enabler' ) );
}
$output = $renderedMath;
@ -78,10 +78,17 @@ class MathHooks {
* @return array of strings
*/
private static function getMathNames() {
return array(
$names = array(
MW_MATH_PNG => 'mw_math_png',
MW_MATH_SOURCE => 'mw_math_source'
MW_MATH_SOURCE => 'mw_math_source',
);
global $wgUseMathJax;
if( $wgUseMathJax ) {
$names[MW_MATH_MATHJAX] = 'mw_math_mathjax';
}
return $names;
}
/**
@ -152,13 +159,4 @@ class MathHooks {
$wgMathPath = '/images/math';
return true;
}
static function addMathJax( $parser ) {
global $wgMathJaxUrl;
//$script = Html::element( 'script', array( 'type' => 'text/x-mathjax-config' ), $config );
$html = Html::element( 'script', array( 'src' => $wgMathJaxUrl ) );
//$parser->getOutput()->addHeadItem( $html, 'mathjax' );
$parser->getOutput()->addModules( array( 'ext.math.mathjax.enabler' ) );
}
}

View file

@ -21,6 +21,7 @@ $messages['en'] = array(
// Math options
'mw_math_png' => 'Always render PNG',
'mw_math_source' => 'Leave it as TeX (for text browsers)',
'mw_math_mathjax' => 'MathJax (experimental; best for most browsers)',
// Math errors
'math_failure' => 'Failed to parse',

View file

@ -36,6 +36,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
/**@}*/
/** For back-compat */
@ -88,7 +89,7 @@ $wgMathDirectory = false;
*
* Not guaranteed to be stable at this time.
*/
$wgMathUseMathJax = false;
$wgUseMathJax = false;
/**
* Use of MathJax's CDN is governed by terms of service