Physikerwelt has submitted this change and it was merged.
Change subject: Remove call to deprecated ParserOptions::getMath
..
Remove call to deprecated ParserOptions::getMath
Since math has been moved from core to an extension
it should take care of the caching by its own.
Therefore, a call to the parserOptions::getMath is removed
and own caching logic is introduced, once getMath is removed
from core.
Bug: 14202
Change-Id: Ifa847b61264f8d640c9886fd374eb3d6cf482c0c
---
M Math.hooks.php
M Math.php
2 files changed, 94 insertions(+), 16 deletions(-)
Approvals:
Physikerwelt: Looks good to me, approved
diff --git a/Math.hooks.php b/Math.hooks.php
index 3a3147a..b9453a5 100644
--- a/Math.hooks.php
+++ b/Math.hooks.php
@@ -7,16 +7,65 @@
*/
class MathHooks {
+ const mathCacheKey = 'math=';
+
+ /*
+* Generate a user dependent hash cache key.
+* The hash key depends on the rendering mode.
+* @param $confstr The to-be-hashed key string that is being
constructed
+* @param User $user reference to the current user
+* @param array $forOptions userOptions used on that page
+*/
+ public static function onPageRenderingHash( $confstr, $user = false,
$forOptions = array() ) {
+ global $wgUser;
+
+ // To be independent of the MediaWiki core version,
+ // we check if the core caching logic for math is still
available.
+ if ( ! is_callable( 'ParserOptions::getMath' ) in_array(
'math', $forOptions) ) {
+ if ( $user === false ) {
+ $user = $wgUser;
+ }
+
+ $mathOption = $user-getOption( 'math' );
+ // Check if the key already contains the math option
part
+ if (
+ !preg_match(
+ '/(^|!)' . self::mathCacheKey .
$mathOption . '(!|$)/',
+ $confstr
+ )
+ ) {
+ // The math part of cache key starts with
math= followed by a star or a number for the math mode
+ // and the optional letter j that indicates if
clientside MathJax rendering is used.
+ if ( preg_match( '/(^|!)' .
self::mathCacheKey.'[*\d]m?(!|$)/', $confstr ) ) {
+ $confstr = preg_replace(
+ '/(^|!)' . self::mathCacheKey .
'[*\d]m?(!|$)/',
+ '\1' . self::mathCacheKey .
$mathOption . '\2',
+ $confstr
+ );
+ } else {
+ $confstr .= '!' . self::mathCacheKey .
$mathOption;
+ }
+
+ wfDebugLog( 'Math', New cache key: $confstr );
+ } else {
+ wfDebugLog( 'Math', Cache key found $confstr
);
+ }
+ }
+
+ return true;
+ }
+
/**
-* Set up $wgMathPath and $wgMathDirectory globals if they're not
already
-* set.
+* Set up $wgMathPath and $wgMathDirectory globals if they're not
already set.
*/
static function setup() {
- global $wgMathPath, $wgMathDirectory;
- global $wgUploadPath, $wgUploadDirectory;
+ global $wgMathPath, $wgMathDirectory,
+ $wgUploadPath, $wgUploadDirectory;
+
if ( $wgMathPath === false ) {
$wgMathPath = {$wgUploadPath}/math;
}
+
if ( $wgMathDirectory === false ) {
$wgMathDirectory = {$wgUploadDirectory}/math;
}
@@ -30,6 +79,7 @@
*/
static function onParserFirstCallInit( $parser ) {
$parser-setHook( 'math', array( 'MathHooks', 'mathTagHook' ) );
+
return true;
}
@@ -38,35 +88,48 @@
*
* @param $content (the LaTeX input)
* @param $attributes
-* @param $parser Parser
+* @param Parser $parser
* @return string
*/
static function mathTagHook( $content, $attributes, $parser ) {
- global $wgMathDisableTexFilter, $wgContLang, $wgUseMathJax;
- if ( trim( $content ) === ) { // bug 8372
- return ;
+ global $wgContLang, $wgUseMathJax, $wgMathDisableTexFilter;
+
+ if ( trim( $content ) === '' ) { // bug 8372
+ return '';
}
+
wfProfileIn( __METHOD__ );
- $mode