From ca32f08966f1b51fcb19460f0996bb0c4048e6fe Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Sat, 3 Dec 2011 13:29:22 +0100 Subject: Update to MediaWiki 1.18.0 * also update ArchLinux skin to chagnes in MonoBook * Use only css to hide our menu bar when printing --- includes/Skin.php | 1783 +++++++++++++++-------------------------------------- 1 file changed, 483 insertions(+), 1300 deletions(-) (limited to 'includes/Skin.php') diff --git a/includes/Skin.php b/includes/Skin.php index 01b3b4fe..a713660c 100644 --- a/includes/Skin.php +++ b/includes/Skin.php @@ -15,23 +15,10 @@ if ( !defined( 'MEDIAWIKI' ) ) { * * @ingroup Skins */ -class Skin extends Linker { - /**#@+ - * @private - */ - var $mWatchLinkNum = 0; // Appended to end of watch link id's - // How many search boxes have we made? Avoid duplicate id's. - protected $searchboxes = ''; - /**#@-*/ - protected $mRevisionId; // The revision ID we're looking at, null if not applicable. +abstract class Skin extends ContextSource { protected $skinname = 'standard'; - // @todo Fixme: should be protected :-\ - var $mTitle = null; - - /** Constructor, call parent constructor */ - function __construct() { - parent::__construct(); - } + protected $mRelevantTitle = null; + protected $mRelevantUser = null; /** * Fetch the set of available skins. @@ -41,7 +28,7 @@ class Skin extends Linker { global $wgValidSkinNames; static $skinsInitialised = false; - if ( !$skinsInitialised ) { + if ( !$skinsInitialised || !count( $wgValidSkinNames ) ) { # 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 @@ -123,7 +110,7 @@ class Skin extends Linker { if ( isset( $skinNames[$key] ) ) { return $key; - } else if ( isset( $skinNames[$wgDefaultSkin] ) ) { + } elseif ( isset( $skinNames[$wgDefaultSkin] ) ) { return $wgDefaultSkin; } else { return 'vector'; @@ -142,27 +129,31 @@ class Skin extends Linker { $skinNames = Skin::getSkinNames(); $skinName = $skinNames[$key]; - $className = 'Skin' . ucfirst( $key ); + $className = "Skin{$skinName}"; # Grab the skin class and initialise it. - if ( !class_exists( $className ) ) { - // Preload base classes to work around APC/PHP5 bug - $deps = "{$wgStyleDirectory}/{$skinName}.deps.php"; + if ( !MWInit::classExists( $className ) ) { - if ( file_exists( $deps ) ) { - include_once( $deps ); + 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" ); } - require_once( "{$wgStyleDirectory}/{$skinName}.php" ); # Check if we got if not failback to default skin - if ( !class_exists( $className ) ) { + 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'; - require_once( "{$wgStyleDirectory}/Vector.php" ); + if ( !defined( 'MW_COMPILED' ) ) { + require_once( "{$wgStyleDirectory}/Vector.php" ); + } } } $skin = new $className; @@ -179,60 +170,11 @@ class Skin extends Linker { return $this->skinname; } - function qbSetting() { - global $wgOut, $wgUser; - - if ( $wgOut->isQuickbarSuppressed() ) { - return 0; - } - - $q = $wgUser->getOption( 'quickbar', 0 ); - - return $q; - } - function initPage( OutputPage $out ) { - global $wgFavicon, $wgAppleTouchIcon, $wgEnableAPI; - wfProfileIn( __METHOD__ ); - # Generally the order of the favicon and apple-touch-icon links - # should not matter, but Konqueror (3.5.9 at least) incorrectly - # uses whichever one appears later in the HTML source. Make sure - # apple-touch-icon is specified first to avoid this. - if ( false !== $wgAppleTouchIcon ) { - $out->addLink( array( 'rel' => 'apple-touch-icon', 'href' => $wgAppleTouchIcon ) ); - } - - if ( false !== $wgFavicon ) { - $out->addLink( array( 'rel' => 'shortcut icon', 'href' => $wgFavicon ) ); - } - - # OpenSearch description link - $out->addLink( array( - 'rel' => 'search', - 'type' => 'application/opensearchdescription+xml', - 'href' => wfScript( 'opensearch_desc' ), - 'title' => wfMsgForContent( 'opensearch-desc' ), - ) ); - - if ( $wgEnableAPI ) { - # Real Simple Discovery link, provides auto-discovery information - # for the MediaWiki API (and potentially additional custom API - # support such as WordPress or Twitter-compatible APIs for a - # blogging extension, etc) - $out->addLink( array( - 'rel' => 'EditURI', - 'type' => 'application/rsd+xml', - 'href' => wfExpandUrl( wfAppendQuery( wfScript( 'api' ), array( 'action' => 'rsd' ) ) ), - ) ); - } - - $this->addMetadataLinks( $out ); - - $this->mRevisionId = $out->mRevisionId; - $this->preloadExistence(); + $this->setMembers(); wfProfileOut( __METHOD__ ); } @@ -241,18 +183,18 @@ class Skin extends Linker { * Preload the existence of three commonly-requested pages in a single query */ function preloadExistence() { - global $wgUser; + $user = $this->getUser(); // User/talk link - $titles = array( $wgUser->getUserPage(), $wgUser->getTalkPage() ); + $titles = array( $user->getUserPage(), $user->getTalkPage() ); // Other tab link - if ( $this->mTitle->getNamespace() == NS_SPECIAL ) { + if ( $this->getTitle()->getNamespace() == NS_SPECIAL ) { // nothing - } elseif ( $this->mTitle->isTalkPage() ) { - $titles[] = $this->mTitle->getSubjectPage(); + } elseif ( $this->getTitle()->isTalkPage() ) { + $titles[] = $this->getTitle()->getSubjectPage(); } else { - $titles[] = $this->mTitle->getTalkPage(); + $titles[] = $this->getTitle()->getTalkPage(); } $lb = new LinkBatch( $titles ); @@ -261,147 +203,100 @@ class Skin extends Linker { } /** - * Adds metadata links below to the HTML output. - *
    - *
  1. Creative Commons - *
    See http://wiki.creativecommons.org/Extend_Metadata. - *
  2. - *
  3. Dublin Core
  4. - *
  5. Use hreflang to specify canonical and alternate links - *
    See http://www.google.com/support/webmasters/bin/answer.py?answer=189077 - *
  6. - *
  7. Copyright
  8. - *
      - * - * @param $out Object: instance of OutputPage + * Set some local variables */ - function addMetadataLinks( OutputPage $out ) { - global $wgEnableDublinCoreRdf, $wgEnableCreativeCommonsRdf; - global $wgDisableLangConversion, $wgCanonicalLanguageLinks, $wgContLang; - global $wgRightsPage, $wgRightsUrl; - - if ( $out->isArticleRelated() ) { - # note: buggy CC software only reads first "meta" link - if ( $wgEnableCreativeCommonsRdf ) { - $out->addMetadataLink( array( - 'title' => 'Creative Commons', - 'type' => 'application/rdf+xml', - 'href' => $this->mTitle->getLocalURL( 'action=creativecommons' ) ) - ); - } - - if ( $wgEnableDublinCoreRdf ) { - $out->addMetadataLink( array( - 'title' => 'Dublin Core', - 'type' => 'application/rdf+xml', - 'href' => $this->mTitle->getLocalURL( 'action=dublincore' ) ) - ); - } - } - - if ( !$wgDisableLangConversion && $wgCanonicalLanguageLinks - && $wgContLang->hasVariants() ) { - - $urlvar = $wgContLang->getURLVariant(); - - if ( !$urlvar ) { - $variants = $wgContLang->getVariants(); - foreach ( $variants as $_v ) { - $out->addLink( array( - 'rel' => 'alternate', - 'hreflang' => $_v, - 'href' => $this->mTitle->getLocalURL( '', $_v ) ) - ); - } - } else { - $out->addLink( array( - 'rel' => 'canonical', - 'href' => $this->mTitle->getFullURL() ) - ); - } - } - - $copyright = ''; - if ( $wgRightsPage ) { - $copy = Title::newFromText( $wgRightsPage ); - - if ( $copy ) { - $copyright = $copy->getLocalURL(); - } - } - - if ( !$copyright && $wgRightsUrl ) { - $copyright = $wgRightsUrl; - } + protected function setMembers() { + $this->userpage = $this->getUser()->getUserPage()->getPrefixedText(); + } - if ( $copyright ) { - $out->addLink( array( - 'rel' => 'copyright', - 'href' => $copyright ) - ); - } + /** + * Get the current revision ID + * + * @return Integer + */ + public function getRevisionId() { + return $this->getOutput()->getRevisionId(); } /** - * Set some local variables + * Whether the revision displayed is the latest revision of the page + * + * @return Boolean */ - protected function setMembers() { - global $wgUser; - $this->mUser = $wgUser; - $this->userpage = $wgUser->getUserPage()->getPrefixedText(); - $this->usercss = false; + public function isRevisionCurrent() { + $revID = $this->getRevisionId(); + return $revID == 0 || $revID == $this->getTitle()->getLatestRevID(); } /** - * Set the title + * Set the "relevant" title + * @see self::getRelevantTitle() * @param $t Title object to use */ - public function setTitle( $t ) { - $this->mTitle = $t; + public function setRelevantTitle( $t ) { + $this->mRelevantTitle = $t; } - /** Get the title */ - public function getTitle() { - return $this->mTitle; + /** + * 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(); } /** - * Outputs the HTML generated by other functions. - * @param $out Object: instance of OutputPage + * Set the "relevant" user + * @see self::getRelevantUser() + * @param $u User object to use */ - function outputPage( OutputPage $out ) { - global $wgDebugComments; - wfProfileIn( __METHOD__ ); - - $this->setMembers(); - $this->initPage( $out ); - - // See self::afterContentHook() for documentation - $afterContent = $this->afterContentHook(); - - $out->out( $out->headElement( $this ) ); + public function setRelevantUser( $u ) { + $this->mRelevantUser = $u; + } - if ( $wgDebugComments ) { - $out->out( "\n" ); + /** + * 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; } - - $out->out( $this->beforeContent() ); - - $out->out( $out->mBodytext . "\n" ); - - $out->out( $this->afterContent() ); - - $out->out( $afterContent ); - - $out->out( $this->bottomScripts( $out ) ); - - $out->out( wfReportTime() ); - - $out->out( "\n" ); - wfProfileOut( __METHOD__ ); + 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( @@ -409,50 +304,7 @@ class Skin extends Linker { ); } else { return ''; - } - } - - /** - * Make a