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 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 == '' ) { // 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' ) ) { // Preload base classes to work around APC/PHP5 bug $deps = "{$wgStyleDirectory}/{$skinName}.deps.php"; if ( file_exists( $deps ) ) { include_once( $deps ); } 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; return $skin; } /** @return string path to the skin stylesheet */ function getStylesheet() { return 'common/wikistandard.css'; } /** @return string skin name */ public function getSkinName() { return $this->skinname; } function initPage( OutputPage $out ) { wfProfileIn( __METHOD__ ); $this->preloadExistence(); $this->setMembers(); 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()->getNamespace() == NS_SPECIAL ) { // nothing } elseif ( $this->getTitle()->isTalkPage() ) { $titles[] = $this->getTitle()->getSubjectPage(); } else { $titles[] = $this->getTitle()->getTalkPage(); } $lb = new LinkBatch( $titles ); $lb->setCaller( __METHOD__ ); $lb->execute(); } /** * Set some local variables */ protected function setMembers() { $this->userpage = $this->getUser()->getUserPage()->getPrefixedText(); } /** * 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->isLoggedIn() ) { $this->mRelevantUser = $user; } } return $this->mRelevantUser; } return null; } /** * Outputs the HTML generated by other functions. * @param $out OutputPage */ abstract function outputPage( OutputPage $out ); static function makeVariablesScript( $data ) { if ( $data ) { return Html::inlineScript( ResourceLoader::makeLoaderConditionalScript( ResourceLoader::makeConfigSetScript( $data ) ) ); } else { return ''; } } /** * To make it harder for someone to slip a user a fake * user-JavaScript or user-CSS preview, a random token * is associated with the login session. If it's not * passed back with the preview request, we won't render * the code. * * @param $action String: 'edit', 'submit' etc. * @return bool */ public function userCanPreview( $action ) { if ( $action != 'submit' ) { return false; } if ( !$this->getRequest()->wasPosted() ) { return false; } if ( !$this->getTitle()->userCanEditCssSubpage() ) { return false; } if ( !$this->getTitle()->userCanEditJsSubpage() ) { return false; } return $this->getUser()->matchEditToken( $this->getRequest()->getVal( 'wpEditToken' ) ); } /** * Generated JavaScript action=raw&gen=js * This used to load MediaWiki:Common.js and the skin-specific style * before the ResourceLoader. * * @deprecated since 1.18 Use the ResourceLoader instead. This may be removed at some * point. * @param $skinName String: If set, overrides the skin name * @return String */ public function generateUserJs( $skinName = null ) { return ''; } /** * Generate user stylesheet for action=raw&gen=css * * @deprecated since 1.18 Use the ResourceLoader instead. This may be removed at some * point. * @return String */ public function generateUserStylesheet() { return ''; } /** * @private * @todo document * @param $out OutputPage */ function setupUserCss( OutputPage $out ) { global $wgUseSiteCss, $wgAllowUserCss, $wgAllowUserCssPrefs; wfProfileIn( __METHOD__ ); $this->setupSkinUserCss( $out ); // Add any extension CSS foreach ( $out->getExtStyle() as $url ) { $out->addStyle( $url ); } // Per-site custom styles if ( $wgUseSiteCss ) { $out->addModuleStyles( array( 'site', 'noscript' ) ); if( $this->getUser()->isLoggedIn() ){ $out->addModuleStyles( 'user.groups' ); } } // Per-user custom styles if ( $wgAllowUserCss ) { if ( $this->getTitle()->isCssSubpage() && $this->userCanPreview( $this->getRequest()->getVal( 'action' ) ) ) { // @todo FIXME: Properly escape the cdata! $out->addInlineStyle( $this->getRequest()->getText( 'wpTextbox1' ) ); } else { $out->addModuleStyles( 'user' ); } } // Per-user preference styles if ( $wgAllowUserCssPrefs ) { $out->addModuleStyles( 'user.options' ); } wfProfileOut( __METHOD__ ); } /** * Make a