Add SkinPreloadExistence hook
[lhc/web/wiklou.git] / includes / skins / SkinFactory.php
index 51aced9..fb40857 100644 (file)
@@ -34,10 +34,19 @@ class SkinFactory {
         */
        private $factoryFunctions = array();
        /**
-        * Map of name => human readable name
+        * Map of name => fallback human-readable name, used when the 'skinname-<skin>' message is not
+        * available
+        *
         * @var array
         */
        private $displayNames = array();
+       /**
+        * Map of name => class name without "Skin" prefix, for legacy skins using the autodiscovery
+        * mechanism
+        *
+        * @var array
+        */
+       private $legacySkins = array();
 
        /**
         * @var SkinFactory
@@ -53,11 +62,16 @@ class SkinFactory {
        }
 
        /**
-        * Register a new Skin factory function
-        * Will override if it's already registered
-        * @param string $name
-        * @param string $displayName
-        * @param callable $callback That takes the skin name as an argument
+        * Register a new Skin factory function.
+        *
+        * Will override if it's already registered.
+        *
+        * @param string $name Internal skin name. Should be all-lowercase (technically doesn't have
+        *     to be, but doing so would change the case of i18n message keys).
+        * @param string $displayName For backwards-compatibility with old skin loading system. This is
+        *     the text used as skin's human-readable name when the 'skinname-<skin>' message is not
+        *     available. It should be the same as the skin name provided in $wgExtensionCredits.
+        * @param callable $callback Callback that takes the skin name as an argument
         * @throws InvalidArgumentException If an invalid callback is provided
         */
        public function register( $name, $displayName, $callback ) {
@@ -72,10 +86,9 @@ class SkinFactory {
         * @return array
         */
        private function getLegacySkinNames() {
-               global $wgValidSkinNames;
                static $skinsInitialised = false;
 
-               if ( !$skinsInitialised || !count( $wgValidSkinNames ) ) {
+               if ( !$skinsInitialised || !count( $this->legacySkins ) ) {
                        # Get a list of available skins
                        # Build using the regular expression '^(.*).php$'
                        # Array keys are all lower case, array value keep the case used by filename
@@ -117,7 +130,7 @@ class SkinFactory {
                                                        "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;
+                                               $this->legacySkins[strtolower( $aSkin )] = $aSkin;
                                        }
                                }
                                $skinDir->close();
@@ -125,7 +138,7 @@ class SkinFactory {
                        $skinsInitialised = true;
                        wfProfileOut( __METHOD__ . '-init' );
                }
-               return $wgValidSkinNames;
+               return $this->legacySkins;
 
        }
 
@@ -143,11 +156,10 @@ class SkinFactory {
        }
 
        /**
-        * Get a legacy skin which uses $wgValidSkinNames
-        * or autoloading
+        * Get a legacy skin which uses the autodiscovery mechanism.
         *
         * @param string $name
-        * @return Skin|bool false if the skin couldn't be constructed
+        * @return Skin|bool False if the skin couldn't be constructed
         */
        private function getLegacySkin( $name ) {
                $skinNames = $this->getLegacySkinNames();
@@ -185,7 +197,7 @@ class SkinFactory {
         */
        public function makeSkin( $name ) {
                if ( !isset( $this->factoryFunctions[$name] ) ) {
-                       // Check the legacy method of skin loading
+                       // Check the legacy autodiscovery method of skin loading
                        $legacy = $this->getLegacySkin( $name );
                        if ( $legacy ) {
                                return $legacy;