From 2af7057b0576a2ceddb0275ecc4c078c4b5ef06f Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Mon, 5 Mar 2012 20:34:29 +0000 Subject: [PATCH] Set up MathJax as a selectable option in math preferences --- Math.body.php | 4 ++-- Math.hooks.php | 26 ++++++++++++-------------- Math.i18n.php | 1 + Math.php | 3 ++- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/Math.body.php b/Math.body.php index f4d2481..156fee0 100644 --- a/Math.body.php +++ b/Math.body.php @@ -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 ('$ ' . str_replace( "\n", " ", htmlspecialchars( $this->tex ) ) . ' $'); diff --git a/Math.hooks.php b/Math.hooks.php index a56828e..ad86265 100644 --- a/Math.hooks.php +++ b/Math.hooks.php @@ -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' ) ); - } } diff --git a/Math.i18n.php b/Math.i18n.php index 13f8430..3dcad35 100644 --- a/Math.i18n.php +++ b/Math.i18n.php @@ -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', diff --git a/Math.php b/Math.php index 355ed53..03475b3 100644 --- a/Math.php +++ b/Math.php @@ -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