r104521 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r104520‎ | r104521 | r104522 >
Date:00:37, 29 November 2011
Author:brion
Status:ok (Comments)
Tags:miscextensions 
Comment:
Experimental option $wgMathUseMathJax to have Extension:Math load things via MathJax.

If enabled, by default loads MathJax from a CDN and forces all equations through MathJax when JavaScript is available -- the image or source form gets used only as <noscript> fallback.

This has a couple of problems for us:
* if scripts are missing -- such as when viewed via MobileFrontend -- you end up with no math at all, as the <script type="math/tex"> bits get ignored but the <noscript> still hides the images.
* while MathJax is loading things, blank spots on the page may appear and stuff jumps around
* if loading new text in via ajax, it doesn't trigger there

Also using some fairly default config, no idea how appropriate it is. Hoping to get some insight from Nageh who's done some of the MathJax work on Wikipedia so far - <https://en.wikipedia.org/wiki/User_talk:Nageh#MathJax_integration_into_stock_MediaWiki&gt;
Modified paths:
  • /trunk/extensions/Math/Math.hooks.php (modified) (history)
  • /trunk/extensions/Math/Math.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Math/Math.php
@@ -81,7 +81,23 @@
8282 */
8383 $wgMathDirectory = false;
8484
 85+/**
 86+ * Experimental option to use MathJax library to do client-side math rendering
 87+ * when JavaScript is available. In supporting browsers this makes nice output
 88+ * that's scalable for zooming, printing, and high-resolution displays.
 89+ *
 90+ * Not guaranteed to be stable at this time.
 91+ */
 92+$wgMathUseMathJax = false;
8593
 94+/**
 95+ * Use of MathJax's CDN is governed by terms of service
 96+ * <http://www.mathjax.org/download/mathjax-cdn-terms-of-service/>
 97+ *
 98+ * If you don't like them, install your own copy to load.
 99+ */
 100+$wgMathJaxUrl = 'http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML';
 101+
86102 ////////// end of config settings.
87103
88104 $wgDefaultUserOptions['math'] = MW_MATH_PNG;
Index: trunk/extensions/Math/Math.hooks.php
@@ -42,11 +42,20 @@
4343 * @return
4444 */
4545 static function mathTagHook( $content, $attributes, $parser ) {
46 - global $wgContLang;
 46+ global $wgContLang, $wgUseMathJax;
4747 $renderedMath = MathRenderer::renderMath(
4848 $content, $attributes, $parser->getOptions()
4949 );
50 - return $wgContLang->armourMath( $renderedMath );
 50+
 51+ if ( $wgUseMathJax ) {
 52+ self::addMathJax( $parser );
 53+ $output = Html::rawElement('noscript', null, $renderedMath ) .
 54+ Html::element( 'script', array( 'type' => 'math/tex' ), $content );
 55+ } else {
 56+ $output = $renderedMath;
 57+ }
 58+
 59+ return $wgContLang->armourMath( $output );
5160 }
5261
5362 /**
@@ -146,4 +155,12 @@
147156 $wgMathPath = '/images/math';
148157 return true;
149158 }
 159+
 160+ static function addMathJax( $parser ) {
 161+ global $wgMathJaxUrl;
 162+ //$script = Html::element( 'script', array( 'type' => 'text/x-mathjax-config' ), $config );
 163+ $html = Html::element( 'script', array( 'src' => $wgMathJaxUrl ) );
 164+
 165+ $parser->getOutput()->addHeadItem( $html, 'mathjax' );
 166+ }
150167 }

Comments

#Comment by P858snake (talk | contribs)   08:55, 29 November 2011
+$wgMathJaxUrl = '[http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML'; http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML';]

Hmm, Not sure I really like external loading of scripts (even if it is a experimental option)

#Comment by Catrope (talk | contribs)   08:59, 29 November 2011

I'm not sure whether this should be the default. We'd have to customize this on WMF due to privacy policy (tracking visitors) and security (3rd party JS can steal cookies and/or do other scary things), and I think many other installs will have the same concerns.

#Comment by Brion VIBBER (talk | contribs)   16:47, 29 November 2011

We'll certainly use our own copy for Wikimedia. Probably will end up bundling MathJax into the ext for convenience as the support matures. Feel free to commit it if you're in a hurry. :D

#Comment by P858snake (talk | contribs)   07:17, 6 February 2012

I would like to see something done about this before the branching (and subsequence release), Although this is a experimental feature disabled by default, People might be wanting to try this out without noticing the EXTERNAL js calls.

#Comment by P858snake (talk | contribs)   09:43, 6 February 2012

Looks like that was done in r105268

Status & tagging log