Preprocessor: Use correct cache prefix for the subclass
authorKevin Israel <pleasestand@live.com>
Mon, 26 Oct 2015 01:29:47 +0000 (21:29 -0400)
committerKevin Israel <pleasestand@live.com>
Mon, 26 Oct 2015 01:29:47 +0000 (21:29 -0400)
Follows-up 1559be9f7aef, which caused "Preprocessor" to be used as the
cache prefix for all subclasses, by using late static binding to access
the constant. Though use of that feature has been discouraged[1], this
change is a straightforward bug fix, and any improvements can be made
separately.

[1]: https://www.mediawiki.org/wiki/Manual:Coding_conventions/PHP#Late_static_binding

Change-Id: Ib25e1908a6373f6675659a0906e12d4a38af014c

includes/parser/Preprocessor.php

index 30eab19..b1e49b2 100644 (file)
@@ -46,9 +46,11 @@ abstract class Preprocessor {
                }
 
                $key = wfMemcKey(
-                       defined( 'self::CACHE_PREFIX' ) ? self::CACHE_PREFIX : __CLASS__,
+                       // TODO: Once we require PHP 5.5, use static::class instead of
+                       // get_called_class() or get_class( $this ).
+                       defined( 'static::CACHE_PREFIX' ) ? static::CACHE_PREFIX : get_called_class(),
                        md5( $text ), $flags );
-               $value = sprintf( "%08d", self::CACHE_VERSION ) . $tree;
+               $value = sprintf( "%08d", static::CACHE_VERSION ) . $tree;
 
                $cache = ObjectCache::getInstance( $config->get( 'MainCacheType' ) );
                $cache->set( $key, $value, 86400 );
@@ -77,7 +79,9 @@ abstract class Preprocessor {
                $cache = ObjectCache::getInstance( $config->get( 'MainCacheType' ) );
 
                $key = wfMemcKey(
-                       defined( 'self::CACHE_PREFIX' ) ? self::CACHE_PREFIX : __CLASS__,
+                       // TODO: Once we require PHP 5.5, use static::class instead of
+                       // get_called_class() or get_class( $this ).
+                       defined( 'static::CACHE_PREFIX' ) ? static::CACHE_PREFIX : get_called_class(),
                        md5( $text ), $flags );
 
                $value = $cache->get( $key );
@@ -86,7 +90,7 @@ abstract class Preprocessor {
                }
 
                $version = intval( substr( $value, 0, 8 ) );
-               if ( $version !== self::CACHE_VERSION ) {
+               if ( $version !== static::CACHE_VERSION ) {
                        return false;
                }