Skin: Use WANObjectCache for sitenotice caching
[lhc/web/wiklou.git] / includes / skins / Skin.php
index 99658f2..3e8b3f2 100644 (file)
@@ -20,6 +20,8 @@
  * @file
  */
 
+use MediaWiki\MediaWikiServices;
+
 /**
  * @defgroup Skins Skins
  */
@@ -158,8 +160,17 @@ abstract class Skin extends ContextSource {
                global $wgUseAjax, $wgEnableAPI, $wgEnableWriteAPI;
 
                $out = $this->getOutput();
+               $config = $this->getConfig();
                $user = $out->getUser();
                $modules = [
+                       // modules not specific to any specific skin or page
+                       'core' => [
+                               // Enforce various default modules for all pages and all skins
+                               // Keep this list as small as possible
+                               'site',
+                               'mediawiki.page.startup',
+                               'mediawiki.user',
+                       ],
                        // modules that enhance the page content in some way
                        'content' => [
                                'mediawiki.page.ready',
@@ -172,6 +183,11 @@ abstract class Skin extends ContextSource {
                        'user' => [],
                ];
 
+               // Support for high-density display images if enabled
+               if ( $config->get( 'ResponsiveImages' ) ) {
+                       $modules['core'][] = 'mediawiki.hidpi';
+               }
+
                // Preload jquery.tablesorter for mediawiki.page.ready
                if ( strpos( $out->getHTML(), 'sortable' ) !== false ) {
                        $modules['content'][] = 'jquery.tablesorter';
@@ -182,6 +198,10 @@ abstract class Skin extends ContextSource {
                        $modules['content'][] = 'jquery.makeCollapsible';
                }
 
+               if ( $out->isTOCEnabled() ) {
+                       $modules['content'][] = 'mediawiki.toc';
+               }
+
                // Add various resources if required
                if ( $wgUseAjax && $wgEnableAPI ) {
                        if ( $wgEnableWriteAPI && $user->isLoggedIn()
@@ -444,6 +464,15 @@ abstract class Skin extends ContextSource {
                return $wgLogo;
        }
 
+       /**
+        * Whether the logo should be preloaded with an HTTP link header or not
+        * @since 1.29
+        * @return bool
+        */
+       public function shouldPreloadLogo() {
+               return false;
+       }
+
        /**
         * @return string HTML
         */
@@ -1232,7 +1261,7 @@ abstract class Skin extends ContextSource {
                };
 
                if ( $wgEnableSidebarCache ) {
-                       $cache = ObjectCache::getMainWANInstance();
+                       $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
                        $sidebar = $cache->getWithSetCallback(
                                $cache->makeKey( 'sidebar', $this->getLanguage()->getCode() ),
                                MessageCache::singleton()->isDisabled()
@@ -1458,7 +1487,7 @@ abstract class Skin extends ContextSource {
         *   should fall back to the next notice in its sequence
         */
        private function getCachedNotice( $name ) {
-               global $wgRenderHashAppend, $parserMemc, $wgContLang;
+               global $wgRenderHashAppend, $wgContLang;
 
                $needParse = false;
 
@@ -1479,28 +1508,27 @@ abstract class Skin extends ContextSource {
                        $notice = $msg->plain();
                }
 
-               // Use the extra hash appender to let eg SSL variants separately cache.
-               $key = wfMemcKey( $name . $wgRenderHashAppend );
-               $cachedNotice = $parserMemc->get( $key );
-               if ( is_array( $cachedNotice ) ) {
-                       if ( md5( $notice ) == $cachedNotice['hash'] ) {
-                               $notice = $cachedNotice['html'];
-                       } else {
-                               $needParse = true;
+               $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
+               $parsed = $cache->getWithSetCallback(
+                       // Use the extra hash appender to let eg SSL variants separately cache
+                       // Key is verified with md5 hash of unparsed wikitext
+                       $cache->makeKey( $name, $wgRenderHashAppend, md5( $notice ) ),
+                       // TTL in seconds
+                       600,
+                       function () use ( $notice ) {
+                               return $this->getOutput()->parse( $notice );
                        }
-               } else {
-                       $needParse = true;
-               }
-
-               if ( $needParse ) {
-                       $parsed = $this->getOutput()->parse( $notice );
-                       $parserMemc->set( $key, [ 'html' => $parsed, 'hash' => md5( $notice ) ], 600 );
-                       $notice = $parsed;
-               }
+               );
 
-               $notice = Html::rawElement( 'div', [ 'id' => 'localNotice',
-                       'lang' => $wgContLang->getHtmlCode(), 'dir' => $wgContLang->getDir() ], $notice );
-               return $notice;
+               return Html::rawElement(
+                       'div',
+                       [
+                               'id' => 'localNotice',
+                               'lang' => $wgContLang->getHtmlCode(),
+                               'dir' => $wgContLang->getDir()
+                       ],
+                       $parsed
+               );
        }
 
        /**