SpecialJavaScriptTest: Use Config instead of globals
[lhc/web/wiklou.git] / includes / Skin.php
index 06f39b1..fd737c0 100644 (file)
@@ -36,6 +36,12 @@ abstract class Skin extends ContextSource {
        protected $mRelevantTitle = null;
        protected $mRelevantUser = null;
 
+       /**
+        * @var string Stylesheets set to use. Subdirectory in skins/ where various stylesheets are
+        *   located. Only needs to be set if you intend to use the getSkinStylePath() method.
+        */
+       public $stylename = null;
+
        /**
         * Fetch the set of available skins.
         * @return array Associative array of strings
@@ -63,6 +69,29 @@ abstract class Skin extends ContextSource {
 
                                        if ( preg_match( '/^([^.]*)\.php$/', $file, $matches ) ) {
                                                $aSkin = $matches[1];
+
+                                               // Explicitly disallow loading core skins via the autodiscovery mechanism.
+                                               //
+                                               // They should be loaded already (in a non-autodicovery way), but old files might still
+                                               // exist on the server because our MW version upgrade process is widely documented as
+                                               // requiring just copying over all files, without removing old ones.
+                                               //
+                                               // This is one of the reasons we should have never used autodiscovery in the first
+                                               // place. This hack can be safely removed when autodiscovery is gone.
+                                               if ( in_array( $aSkin, array( 'CologneBlue', 'Modern', 'MonoBook', 'Vector' ) ) ) {
+                                                       wfLogWarning(
+                                                               "An old copy of the $aSkin skin was found in your skins/ directory. " .
+                                                               "You should remove it to avoid problems in the future." .
+                                                               "See https://www.mediawiki.org/wiki/Manual:Skin_autodiscovery for details."
+                                                       );
+                                                       continue;
+                                               }
+
+                                               wfLogWarning(
+                                                       "A skin using autodiscovery mechanism, $aSkin, was found in your skins/ directory. " .
+                                                       "The mechanism will be removed in MediaWiki 1.25 and the skin will no longer be recognized. " .
+                                                       "See https://www.mediawiki.org/wiki/Manual:Skin_autodiscovery for information how to fix this."
+                                               );
                                                $wgValidSkinNames[strtolower( $aSkin )] = $aSkin;
                                        }
                                }
@@ -81,7 +110,6 @@ abstract class Skin extends ContextSource {
        static function getSkinNameMessages() {
                $messages = array();
                foreach ( self::getSkinNames() as $skinKey => $skinName ) {
-                       // Messages: skinname-vector, skinname-monobook
                        $messages[] = "skinname-$skinKey";
                }
                return $messages;
@@ -117,20 +145,28 @@ abstract class Skin extends ContextSource {
 
        /**
         * Normalize a skin preference value to a form that can be loaded.
-        * If a skin can't be found, it will fall back to the configured
-        * default, or the hardcoded default if that's broken.
+        *
+        * If a skin can't be found, it will fall back to the configured default ($wgDefaultSkin), or the
+        * hardcoded default ($wgFallbackSkin) if the default skin is unavailable too.
+        *
         * @param string $key 'monobook', 'vector', etc.
         * @return string
         */
        static function normalizeKey( $key ) {
-               global $wgDefaultSkin;
+               global $wgDefaultSkin, $wgFallbackSkin;
 
                $skinNames = Skin::getSkinNames();
 
+               // Make keys lowercase for case-insensitive matching.
+               $skinNames = array_change_key_case( $skinNames, CASE_LOWER );
+               $key = strtolower( $key );
+               $defaultSkin = strtolower( $wgDefaultSkin );
+               $fallbackSkin = strtolower( $wgFallbackSkin );
+
                if ( $key == '' || $key == 'default' ) {
                        // Don't return the default immediately;
                        // in a misconfiguration we need to fall back.
-                       $key = $wgDefaultSkin;
+                       $key = $defaultSkin;
                }
 
                if ( isset( $skinNames[$key] ) ) {
@@ -140,7 +176,7 @@ abstract class Skin extends ContextSource {
                // Older versions of the software used a numeric setting
                // in the user preferences.
                $fallback = array(
-                       0 => $wgDefaultSkin,
+                       0 => $defaultSkin,
                        2 => 'cologneblue'
                );
 
@@ -150,10 +186,10 @@ abstract class Skin extends ContextSource {
 
                if ( isset( $skinNames[$key] ) ) {
                        return $key;
-               } elseif ( isset( $skinNames[$wgDefaultSkin] ) ) {
-                       return $wgDefaultSkin;
+               } elseif ( isset( $skinNames[$defaultSkin] ) ) {
+                       return $defaultSkin;
                } else {
-                       return 'vector';
+                       return $fallbackSkin;
                }
        }
 
@@ -163,7 +199,7 @@ abstract class Skin extends ContextSource {
         * @return Skin
         */
        static function &newFromKey( $key ) {
-               global $wgStyleDirectory;
+               global $wgStyleDirectory, $wgFallbackSkin;
 
                $key = Skin::normalizeKey( $key );
 
@@ -183,8 +219,9 @@ abstract class Skin extends ContextSource {
                                # except by SQL manipulation if a previously valid skin name
                                # is no longer valid.
                                wfDebug( "Skin class does not exist: $className\n" );
-                               $className = 'SkinVector';
-                               require_once "{$wgStyleDirectory}/Vector.php";
+
+                               $fallback = $skinNames[ Skin::normalizeKey( $wgFallbackSkin ) ];
+                               $className = "Skin{$fallback}";
                        }
                }
                $skin = new $className( $key );
@@ -394,21 +431,6 @@ abstract class Skin extends ContextSource {
                }
        }
 
-       /**
-        * Make a "<script>" tag containing global variables
-        *
-        * @deprecated since 1.19
-        * @param mixed $unused
-        * @return string HTML fragment
-        */
-       public static function makeGlobalVariablesScript( $unused ) {
-               global $wgOut;
-
-               wfDeprecated( __METHOD__, '1.19' );
-
-               return self::makeVariablesScript( $wgOut->getJSVars() );
-       }
-
        /**
         * Get the query to generate a dynamic stylesheet
         *
@@ -798,7 +820,7 @@ abstract class Skin extends ContextSource {
         * @return string
         */
        function getCopyright( $type = 'detect' ) {
-               global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgContLang;
+               global $wgRightsPage, $wgRightsUrl, $wgRightsText;
 
                if ( $type == 'detect' ) {
                        if ( !$this->isRevisionCurrent()
@@ -848,7 +870,7 @@ abstract class Skin extends ContextSource {
 
                $out = '';
 
-               if ( isset( $wgCopyrightIcon ) && $wgCopyrightIcon ) {
+               if ( $wgCopyrightIcon ) {
                        $out = $wgCopyrightIcon;
                } elseif ( $wgRightsIcon ) {
                        $icon = htmlspecialchars( $wgRightsIcon );
@@ -974,8 +996,8 @@ abstract class Skin extends ContextSource {
 
        /**
         * Returns an HTML link for use in the footer
-        * @param string $desc i18n message key for the link text
-        * @param string $page i18n message key for the page to link to
+        * @param string $desc The i18n message key for the link text
+        * @param string $page The i18n message key for the page to link to
         * @return string HTML anchor
         */
        public function footerLink( $desc, $page ) {
@@ -1070,11 +1092,20 @@ abstract class Skin extends ContextSource {
         * Return a fully resolved style path url to images or styles stored in the current skins's folder.
         * This method returns a url resolved using the configured skin style path
         * and includes the style version inside of the url.
+        *
+        * Requires $stylename to be set, otherwise throws MWException.
+        *
         * @param string $name The name or path of a skin resource file
         * @return string The fully resolved style path url including styleversion
         */
        function getSkinStylePath( $name ) {
                global $wgStylePath, $wgStyleVersion;
+
+               if ( $this->stylename === null ) {
+                       $class = get_class( $this );
+                       throw new MWException( "$class::\$stylename must be set to use getSkinStylePath()" );
+               }
+
                return "$wgStylePath/{$this->stylename}/$name?$wgStyleVersion";
        }