X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fskins%2FSkinFactory.php;h=cc993aaf9b50eebd09f2677ad67d90c175f1228d;hb=088f0ab09174df62127623da09d1f7d091783ba7;hp=fb40857740381704188606dd6856f7378eb65432;hpb=38d59dd21347dc5167fbef94a0558f6bbdcd4195;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/skins/SkinFactory.php b/includes/skins/SkinFactory.php index fb40857740..cc993aaf9b 100644 --- a/includes/skins/SkinFactory.php +++ b/includes/skins/SkinFactory.php @@ -21,6 +21,8 @@ * @file */ +use MediaWiki\MediaWikiServices; + /** * Factory class to create Skin objects * @@ -32,33 +34,21 @@ class SkinFactory { * Map of name => callback * @var array */ - private $factoryFunctions = array(); + private $factoryFunctions = []; /** * Map of name => fallback human-readable name, used when the 'skinname-' 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(); + private $displayNames = []; /** - * @var SkinFactory + * @deprecated in 1.27 + * @return SkinFactory */ - private static $self; - public static function getDefaultInstance() { - if ( !self::$self ) { - self::$self = new self; - } - - return self::$self; + return MediaWikiServices::getInstance()->getSkinFactory(); } /** @@ -82,66 +72,6 @@ class SkinFactory { $this->displayNames[$name] = $displayName; } - /** - * @return array - */ - private function getLegacySkinNames() { - static $skinsInitialised = false; - - 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 - # - wfProfileIn( __METHOD__ . '-init' ); - - global $wgStyleDirectory; - - $skinDir = dir( $wgStyleDirectory ); - - if ( $skinDir !== false && $skinDir !== null ) { - # while code from www.php.net - while ( false !== ( $file = $skinDir->read() ) ) { - // Skip non-PHP files, hidden files, and '.dep' includes - $matches = array(); - - 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." - ); - $this->legacySkins[strtolower( $aSkin )] = $aSkin; - } - } - $skinDir->close(); - } - $skinsInitialised = true; - wfProfileOut( __METHOD__ . '-init' ); - } - return $this->legacySkins; - - } - /** * Returns an associative array of: * skin name => human readable name @@ -149,43 +79,7 @@ class SkinFactory { * @return array */ public function getSkinNames() { - return array_merge( - $this->getLegacySkinNames(), - $this->displayNames - ); - } - - /** - * Get a legacy skin which uses the autodiscovery mechanism. - * - * @param string $name - * @return Skin|bool False if the skin couldn't be constructed - */ - private function getLegacySkin( $name ) { - $skinNames = $this->getLegacySkinNames(); - if ( !isset( $skinNames[$name] ) ) { - return false; - } - $skinName = $skinNames[$name]; - $className = "Skin{$skinName}"; - - # Grab the skin class and initialise it. - if ( !class_exists( $className ) ) { - global $wgStyleDirectory; - require_once "{$wgStyleDirectory}/{$skinName}.php"; - - # Check if we got it - if ( !class_exists( $className ) ) { - # DO NOT die if the class isn't found. This breaks maintenance - # scripts and can cause a user account to be unrecoverable - # except by SQL manipulation if a previously valid skin name - # is no longer valid. - return false; - } - } - $skin = new $className( $name ); - return $skin; - + return $this->displayNames; } /** @@ -197,11 +91,6 @@ class SkinFactory { */ public function makeSkin( $name ) { if ( !isset( $this->factoryFunctions[$name] ) ) { - // Check the legacy autodiscovery method of skin loading - $legacy = $this->getLegacySkin( $name ); - if ( $legacy ) { - return $legacy; - } throw new SkinException( "No registered builder available for $name." ); } $skin = call_user_func( $this->factoryFunctions[$name], $name );