read() ) ) { // Skip non-PHP files, hidden files, and '.dep' includes $matches = array(); if ( preg_match( '/^([^.]*)\.php$/', $file, $matches ) ) { $aSkin = $matches[1]; $wgValidSkinNames[strtolower( $aSkin )] = $aSkin; } } $skinDir->close(); $skinsInitialised = true; wfProfileOut( __METHOD__ . '-init' ); } return $wgValidSkinNames; } /** * Fetch the skinname messages for available skins. * @return array of strings */ static function getSkinNameMessages() { $messages = array(); foreach( self::getSkinNames() as $skinKey => $skinName ) { $messages[] = "skinname-$skinKey"; } return $messages; } /** * Fetch the list of usable skins in regards to $wgSkipSkins. * Useful for Special:Preferences and other places where you * only want to show skins users _can_ use. * @return array of strings */ public static function getUsableSkins() { global $wgSkipSkins; $usableSkins = self::getSkinNames(); foreach ( $wgSkipSkins as $skip ) { unset( $usableSkins[$skip] ); } return $usableSkins; } /** * 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 old 'Classic' skin if that's broken). * @param $key String: 'monobook', 'standard', etc. * @return string */ static function normalizeKey( $key ) { global $wgDefaultSkin; $skinNames = Skin::getSkinNames(); if ( $key == '' || $key == 'default' ) { // Don't return the default immediately; // in a misconfiguration we need to fall back. $key = $wgDefaultSkin; } if ( isset( $skinNames[$key] ) ) { return $key; } // Older versions of the software used a numeric setting // in the user preferences. $fallback = array( 0 => $wgDefaultSkin, 1 => 'nostalgia', 2 => 'cologneblue' ); if ( isset( $fallback[$key] ) ) { $key = $fallback[$key]; } if ( isset( $skinNames[$key] ) ) { return $key; } elseif ( isset( $skinNames[$wgDefaultSkin] ) ) { return $wgDefaultSkin; } else { return 'vector'; } } /** * Factory method for loading a skin of a given type * @param $key String: 'monobook', 'standard', etc. * @return Skin */ static function &newFromKey( $key ) { global $wgStyleDirectory; $key = Skin::normalizeKey( $key ); $skinNames = Skin::getSkinNames(); $skinName = $skinNames[$key]; $className = "Skin{$skinName}"; # Grab the skin class and initialise it. if ( !MWInit::classExists( $className ) ) { if ( !defined( 'MW_COMPILED' ) ) { require_once( "{$wgStyleDirectory}/{$skinName}.php" ); } # Check if we got if not failback to default skin if ( !MWInit::classExists( $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. wfDebug( "Skin class does not exist: $className\n" ); $className = 'SkinVector'; if ( !defined( 'MW_COMPILED' ) ) { require_once( "{$wgStyleDirectory}/Vector.php" ); } } } $skin = new $className( $key ); return $skin; } /** @return string skin name */ public function getSkinName() { return $this->skinname; } /** * @param $out OutputPage */ function initPage( OutputPage $out ) { wfProfileIn( __METHOD__ ); $this->preloadExistence(); wfProfileOut( __METHOD__ ); } /** * Preload the existence of three commonly-requested pages in a single query */ function preloadExistence() { $user = $this->getUser(); // User/talk link $titles = array( $user->getUserPage(), $user->getTalkPage() ); // Other tab link if ( $this->getTitle()->isSpecialPage() ) { // nothing } elseif ( $this->getTitle()->isTalkPage() ) { $titles[] = $this->getTitle()->getSubjectPage(); } else { $titles[] = $this->getTitle()->getTalkPage(); } $lb = new LinkBatch( $titles ); $lb->setCaller( __METHOD__ ); $lb->execute(); } /** * Get the current revision ID * * @return Integer */ public function getRevisionId() { return $this->getOutput()->getRevisionId(); } /** * Whether the revision displayed is the latest revision of the page * * @return Boolean */ public function isRevisionCurrent() { $revID = $this->getRevisionId(); return $revID == 0 || $revID == $this->getTitle()->getLatestRevID(); } /** * Set the "relevant" title * @see self::getRelevantTitle() * @param $t Title object to use */ public function setRelevantTitle( $t ) { $this->mRelevantTitle = $t; } /** * Return the "relevant" title. * A "relevant" title is not necessarily the actual title of the page. * Special pages like Special:MovePage use set the page they are acting on * as their "relevant" title, this allows the skin system to display things * such as content tabs which belong to to that page instead of displaying * a basic special page tab which has almost no meaning. * * @return Title */ public function getRelevantTitle() { if ( isset($this->mRelevantTitle) ) { return $this->mRelevantTitle; } return $this->getTitle(); } /** * Set the "relevant" user * @see self::getRelevantUser() * @param $u User object to use */ public function setRelevantUser( $u ) { $this->mRelevantUser = $u; } /** * Return the "relevant" user. * A "relevant" user is similar to a relevant title. Special pages like * Special:Contributions mark the user which they are relevant to so that * things like the toolbox can display the information they usually are only * able to display on a user's userpage and talkpage. * @return User */ public function getRelevantUser() { if ( isset($this->mRelevantUser) ) { return $this->mRelevantUser; } $title = $this->getRelevantTitle(); if( $title->getNamespace() == NS_USER || $title->getNamespace() == NS_USER_TALK ) { $rootUser = strtok( $title->getText(), '/' ); if ( User::isIP( $rootUser ) ) { $this->mRelevantUser = User::newFromName( $rootUser, false ); } else { $user = User::newFromName( $rootUser, false ); if ( $user && $user->isLoggedIn() ) { $this->mRelevantUser = $user; } } return $this->mRelevantUser; } return null; } /** * Outputs the HTML generated by other functions. * @param $out OutputPage */ abstract function outputPage( OutputPage $out = null ); /** * @param $data array * @return string */ static function makeVariablesScript( $data ) { if ( $data ) { return Html::inlineScript( ResourceLoader::makeLoaderConditionalScript( ResourceLoader::makeConfigSetScript( $data ) ) ); } else { return ''; } } /** * Make a "