Switch the sidebar cache to using checkKeys
[lhc/web/wiklou.git] / includes / skins / Skin.php
index 167b49d..65a300a 100644 (file)
@@ -34,7 +34,11 @@ use MediaWiki\MediaWikiServices;
  * @ingroup Skins
  */
 abstract class Skin extends ContextSource {
+       /**
+        * @var string|null
+        */
        protected $skinname = null;
+
        protected $mRelevantTitle = null;
        protected $mRelevantUser = null;
 
@@ -134,7 +138,17 @@ abstract class Skin extends ContextSource {
        }
 
        /**
-        * @return string Skin name
+        * @since 1.31
+        * @param string|null $skinname
+        */
+       public function __construct( $skinname = null ) {
+               if ( is_string( $skinname ) ) {
+                       $this->skinname = $skinname;
+               }
+       }
+
+       /**
+        * @return string|null Skin name
         */
        public function getSkinName() {
                return $this->skinname;
@@ -753,15 +767,6 @@ abstract class Skin extends ContextSource {
                return $subpages;
        }
 
-       /**
-        * @deprecated since 1.27, feature removed
-        * @return bool Always false
-        */
-       function showIPinHeader() {
-               wfDeprecated( __METHOD__, '1.27' );
-               return false;
-       }
-
        /**
         * @return string
         */
@@ -897,7 +902,7 @@ abstract class Skin extends ContextSource {
                        $s = '';
                }
 
-               if ( wfGetLB()->getLaggedReplicaMode() ) {
+               if ( MediaWikiServices::getInstance()->getDBLoadBalancer()->getLaggedReplicaMode() ) {
                        $s .= ' <strong>' . $this->msg( 'laggedslavemode' )->parse() . '</strong>';
                }
 
@@ -1248,30 +1253,38 @@ abstract class Skin extends ContextSource {
         *
         * @return array
         */
-       function buildSidebar() {
+       public function buildSidebar() {
                global $wgEnableSidebarCache, $wgSidebarCacheExpiry;
 
-               $callback = function () {
+               $callback = function ( $old = null, &$ttl = null ) {
                        $bar = [];
                        $this->addToSidebar( $bar, 'sidebar' );
                        Hooks::run( 'SkinBuildSidebar', [ $this, &$bar ] );
+                       if ( MessageCache::singleton()->isDisabled() ) {
+                               $ttl = WANObjectCache::TTL_UNCACHEABLE; // bug T133069
+                       }
 
                        return $bar;
                };
 
-               if ( $wgEnableSidebarCache ) {
-                       $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
-                       $sidebar = $cache->getWithSetCallback(
-                               $cache->makeKey( 'sidebar', $this->getLanguage()->getCode() ),
-                               MessageCache::singleton()->isDisabled()
-                                       ? $cache::TTL_UNCACHEABLE // bug T133069
-                                       : $wgSidebarCacheExpiry,
+               $msgCache = MessageCache::singleton();
+               $wanCache = MediaWikiServices::getInstance()->getMainWANObjectCache();
+
+               $sidebar = $wgEnableSidebarCache
+                       ? $wanCache->getWithSetCallback(
+                               $wanCache->makeKey( 'sidebar', $this->getLanguage()->getCode() ),
+                               $wgSidebarCacheExpiry,
                                $callback,
-                               [ 'lockTSE' => 30 ]
-                       );
-               } else {
-                       $sidebar = $callback();
-               }
+                               [
+                                       'checkKeys' => [
+                                               // Unless there is both no exact $code override nor an i18n definition
+                                               // in the the software, the only MediaWiki page to check is for $code.
+                                               $msgCache->getCheckKey( $this->getLanguage()->getCode() )
+                                       ],
+                                       'lockTSE' => 30
+                               ]
+                       )
+                       : $callback();
 
                // Apply post-processing to the cached value
                Hooks::run( 'SidebarBeforeOutput', [ $this, &$sidebar ] );