Jackmcbarn has uploaded a new change for review. https://gerrit.wikimedia.org/r/161892
Change subject: Revert "Completely remove skin autodiscovery" ...................................................................... Revert "Completely remove skin autodiscovery" 1.24 was un-branched. This reverts commit 5b11fa414670cd84887a18b2c35797f2451b97d5. Change-Id: Ie57a7c862907eae596952493c1b9b2bc5011d500 --- M RELEASE-NOTES-1.25 M docs/skin.txt M includes/skins/SkinFactory.php 3 files changed, 137 insertions(+), 22 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core refs/changes/92/161892/1 diff --git a/RELEASE-NOTES-1.25 b/RELEASE-NOTES-1.25 index 3f91520..a6e0a73 100644 --- a/RELEASE-NOTES-1.25 +++ b/RELEASE-NOTES-1.25 @@ -23,9 +23,6 @@ changes to languages because of Bugzilla reports. === Other changes in 1.25 === -* The skin autodiscovery mechanism, deprecated in MediaWiki 1.23, has been - removed. See https://www.mediawiki.org/wiki/Manual:Skin_autodiscovery for - migration guide for creators and users of custom skins that relied on it. == Compatibility == diff --git a/docs/skin.txt b/docs/skin.txt index e998ebd..58f77cf 100644 --- a/docs/skin.txt +++ b/docs/skin.txt @@ -53,30 +53,40 @@ These can also be customised on a per-user basis, by editing [[User:<name>/vector.css]], [[User:<name>/vector.js]], etc. +This feature has led to a wide variety of "user styles" becoming available: -== Custom skins == +https://www.mediawiki.org/wiki/Manual:Gallery_of_user_styles -Several custom skins are available as of 2014. +If you want a different look for your wiki, that gallery is a good place to start. -https://www.mediawiki.org/wiki/Category:All_skins +== Drop-in custom skins == -Installing a skin requires adding its files in a subdirectory under skins/ and -adding an appropriate require_once line to LocalSettings.php, similarly to how -extensions are installed. +If you put a file in MediaWiki's skins directory, ending in .php, the name of +the file will automatically be added as a skin name, and the file will be +expected to contain a class called Skin<name> with the skin class. You can then +make that skin the default by adding to LocalSettings.php: -You can then make that skin the default by adding: - $wgDefaultSkin = '<name>'; +$wgDefaultSkin = '<name>'; -Or disable it entirely by removing the require_once line. (User settings will -not be lost if it's reenabled later.) +You can also disable dropped-in or core skins using: -See https://www.mediawiki.org/wiki/Manual:Skinning for more information on -writing new skins. +$wgSkipSkins[] = '<name>'; +This technique is used by the more ambitious MediaWiki site operators, to +create complex custom skins for their wikis. It should be preferred over +editing the core Monobook skin directly. -Until MediaWiki 1.25 it used to be possible to just put a <name>.php file in -MediaWiki's skins/ directory, which would be loaded and expected to contain the -Skin<name> class. This way has always been discouraged because of its limitations -(inability to add localisation messages, ResourceLoader modules, etc.) and -awkwardness in managing such skins. For information on migrating skins using -this old method, see <https://www.mediawiki.org/wiki/Manual:Skin_autodiscovery>. +See https://www.mediawiki.org/wiki/Manual:Skinning for more information. + +== Extension skins == + +It is now possible (since MediaWiki 1.12) to write a skin as a standard +MediaWiki extension, enabled via LocalSettings.php. This is done by adding +it to $wgValidSkinNames, for example: + +$wgValidSkinNames['mycoolskin'] = 'MyCoolSkin'; + +and then registering a class in $wgAutoloadClasses called SkinMycoolSkin, which +derives from Skin. This technique is apparently not yet used (as of 2008) +outside the DumpHTML extension. + diff --git a/includes/skins/SkinFactory.php b/includes/skins/SkinFactory.php index ffbe629..fb40857 100644 --- a/includes/skins/SkinFactory.php +++ b/includes/skins/SkinFactory.php @@ -40,6 +40,13 @@ * @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 @@ -76,13 +83,109 @@ } /** + * @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 * * @return array */ public function getSkinNames() { - return $this->displayNames; + 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; + } /** @@ -94,6 +197,11 @@ */ 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 ); -- To view, visit https://gerrit.wikimedia.org/r/161892 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ie57a7c862907eae596952493c1b9b2bc5011d500 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/core Gerrit-Branch: master Gerrit-Owner: Jackmcbarn <jackmcb...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits