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-cologneblue, skinname-monobook, skinname-modern, skinname-vector $messages[] = "skinname-$skinKey"; } return $messages; } /** * Fetch the list of user-selectable 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; $allowedSkins = self::getSkinNames(); foreach ( $wgSkipSkins as $skip ) { unset( $allowedSkins[$skip] ); } return $allowedSkins; } /** * 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 string $key '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, 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 string $key '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 ( !class_exists( $className ) ) { require_once "{$wgStyleDirectory}/{$skinName}.php"; # Check if we got if not fallback to default skin 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. wfDebug( "Skin class does not exist: $className\n" ); $className = 'SkinVector'; 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__ ); } /** * Defines the ResourceLoader modules that should be added to the skin * It is recommended that skins wishing to override call parent::getDefaultModules() * and substitute out any modules they wish to change by using a key to look them up * @return Array of modules with helper keys for easy overriding */ public function getDefaultModules() { global $wgIncludeLegacyJavaScript, $wgPreloadJavaScriptMwUtil, $wgUseAjax, $wgAjaxWatch, $wgEnableAPI, $wgEnableWriteAPI; $out = $this->getOutput(); $user = $out->getUser(); $modules = array( // modules that enhance the page content in some way 'content' => array( 'mediawiki.page.ready', ), // modules that exist for legacy reasons 'legacy' => array(), // modules relating to search functionality 'search' => array(), // modules relating to functionality relating to watching an article 'watch' => array(), // modules which relate to the current users preferences 'user' => array(), ); if ( $wgIncludeLegacyJavaScript ) { $modules['legacy'][] = 'mediawiki.legacy.wikibits'; } if ( $wgPreloadJavaScriptMwUtil ) { $modules['legacy'][] = 'mediawiki.util'; } // Add various resources if required if ( $wgUseAjax ) { $modules['legacy'][] = 'mediawiki.legacy.ajax'; if ( $wgEnableAPI ) { if ( $wgEnableWriteAPI && $wgAjaxWatch && $user->isLoggedIn() && $user->isAllowed( 'writeapi' ) ) { $modules['watch'][] = 'mediawiki.page.watch.ajax'; } if ( !$user->getOption( 'disablesuggest', false ) ) { $modules['search'][] = 'mediawiki.searchSuggest'; } } } if ( $user->getBoolOption( 'editsectiononrightclick' ) ) { $modules['user'][] = 'mediawiki.action.view.rightClickEdit'; } // Crazy edit-on-double-click stuff if ( $out->isArticle() && $user->getOption( 'editondblclick' ) ) { $modules['user'][] = 'mediawiki.action.view.dblClickEdit'; } return $modules; } /** * 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->hasSubjectNamespace( NS_USER ) ) { $rootUser = $title->getRootText(); 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 "