[MediaWiki-commits] [Gerrit] Remove call to deprecated ParserOptions::getMath - change (mediawiki...Math)

2014-01-29 Thread Physikerwelt (Code Review)
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 

[MediaWiki-commits] [Gerrit] Remove call to deprecated ParserOptions::getMath - change (mediawiki...Math)

2014-01-02 Thread Physikerwelt (Code Review)
Physikerwelt has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/104991


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.

Change-Id: Ifa847b61264f8d640c9886fd374eb3d6cf482c0c
---
M Math.hooks.php
1 file changed, 18 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Math 
refs/changes/91/104991/1

diff --git a/Math.hooks.php b/Math.hooks.php
index 3c26d1f..6ba9d65 100644
--- a/Math.hooks.php
+++ b/Math.hooks.php
@@ -7,6 +7,21 @@
  */
 
 class MathHooks {
+
+   /*
+* Generate a user dependet hash cache key.
+* The hash key depends on the rendering mode.
+* @param $confstr The to-be-hashed key string that is being 
constructed
+*/
+   public static function onPageRenderingHash( $confstr ) {
+   global $wgUser, $wgMathJax;
+   //TODO: If there is a better was to get the $user user that.
+   $user = $wgUser;
+   $confstr .= ! . $user-getOption('math');
+   wfDebugLog('Math', 'New cache key'.$confstr);
+   return true;
+   }
+   /**
/**
 * Set up $wgMathPath and $wgMathDirectory globals if they're not 
already
 * set.
@@ -43,11 +58,12 @@
 */
static function mathTagHook( $content, $attributes, $parser ) {
global $wgContLang, $wgUseMathJax;
-   if ( trim( $content )  ===  ) { // bug 8372
+   if ( trim( $content ) ===  ) { // bug 8372
return ;
}
wfProfileIn( __METHOD__ );
-   $mode = $parser-getOptions()-getMath();
+   $mode = (int) $parser-getUser()-getOption('math');
+   $parser-getOptions()-addExtraKey($mode);
$renderer = MathRenderer::getRenderer(
$content, $attributes, $mode
);

-- 
To view, visit https://gerrit.wikimedia.org/r/104991
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ifa847b61264f8d640c9886fd374eb3d6cf482c0c
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Math
Gerrit-Branch: master
Gerrit-Owner: Physikerwelt w...@physikerwelt.de

___
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits