OutputPage: Move hardcoded default modules to Skin::getDefaultModules
[lhc/web/wiklou.git] / includes / skins / Skin.php
index 85bd09a..2cd28b4 100644 (file)
@@ -149,20 +149,30 @@ abstract class Skin extends ContextSource {
         * Defines the ResourceLoader modules that should be added to the skin
         * It is recommended that skins wishing to override call parent::getDefaultModules()
         * and substitute out any modules they wish to change by using a key to look them up
+        *
+        * For style modules, use setupSkinUserCss() instead.
+        *
         * @return array Array of modules with helper keys for easy overriding
         */
        public function getDefaultModules() {
                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',
                        ],
-                       // modules that exist for legacy reasons
-                       'legacy' => ResourceLoaderStartUpModule::getLegacyModules(),
                        // modules relating to search functionality
                        'search' => [],
                        // modules relating to functionality relating to watching an article
@@ -171,6 +181,21 @@ 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';
+               }
+
+               // Preload jquery.makeCollapsible for mediawiki.page.ready
+               if ( strpos( $out->getHTML(), 'mw-collapsible' ) !== false ) {
+                       $modules['content'][] = 'jquery.makeCollapsible';
+               }
+
                // Add various resources if required
                if ( $wgUseAjax && $wgEnableAPI ) {
                        if ( $wgEnableWriteAPI && $user->isLoggedIn()
@@ -433,6 +458,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
         */
@@ -906,7 +940,10 @@ abstract class Skin extends ContextSource {
                                $html = htmlspecialchars( $icon["alt"] );
                        }
                        if ( $url ) {
-                               $html = Html::rawElement( 'a', [ "href" => $url ], $html );
+                               global $wgExternalLinkTarget;
+                               $html = Html::rawElement( 'a',
+                                       [ "href" => $url, "target" => $wgExternalLinkTarget ],
+                                       $html );
                        }
                }
                return $html;
@@ -1035,7 +1072,7 @@ abstract class Skin extends ContextSource {
                global $wgStylePath, $wgStyleVersion;
 
                if ( $this->stylename === null ) {
-                       $class = get_class( $this );
+                       $class = static::class;
                        throw new MWException( "$class::\$stylename must be set to use getSkinStylePath()" );
                }