https://www.mediawiki.org/wiki/Special:Code/MediaWiki/113079
Revision: 113079
Author: brion
Date: 2012-03-05 20:34:29 +0000 (Mon, 05 Mar 2012)
Log Message:
-----------
Set up MathJax as a selectable option in math preferences
Modified Paths:
--------------
trunk/extensions/Math/Math.body.php
trunk/extensions/Math/Math.hooks.php
trunk/extensions/Math/Math.i18n.php
trunk/extensions/Math/Math.php
Modified: trunk/extensions/Math/Math.body.php
===================================================================
--- trunk/extensions/Math/Math.body.php 2012-03-05 20:21:59 UTC (rev 113078)
+++ trunk/extensions/Math/Math.body.php 2012-03-05 20:34:29 UTC (rev 113079)
@@ -44,7 +44,7 @@
}
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 @@
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>');
Modified: trunk/extensions/Math/Math.hooks.php
===================================================================
--- trunk/extensions/Math/Math.hooks.php 2012-03-05 20:21:59 UTC (rev
113078)
+++ trunk/extensions/Math/Math.hooks.php 2012-03-05 20:34:29 UTC (rev
113079)
@@ -46,9 +46,9 @@
$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 @@
* @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 @@
$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' ) );
- }
}
Modified: trunk/extensions/Math/Math.i18n.php
===================================================================
--- trunk/extensions/Math/Math.i18n.php 2012-03-05 20:21:59 UTC (rev 113078)
+++ trunk/extensions/Math/Math.i18n.php 2012-03-05 20:34:29 UTC (rev 113079)
@@ -21,6 +21,7 @@
// 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',
Modified: trunk/extensions/Math/Math.php
===================================================================
--- trunk/extensions/Math/Math.php 2012-03-05 20:21:59 UTC (rev 113078)
+++ trunk/extensions/Math/Math.php 2012-03-05 20:34:29 UTC (rev 113079)
@@ -36,6 +36,7 @@
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 @@
*
* Not guaranteed to be stable at this time.
*/
-$wgMathUseMathJax = false;
+$wgUseMathJax = false;
/**
* Use of MathJax's CDN is governed by terms of service
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs