Continue with r85240; Move getSkin from User to RequestContext, do it without globals...
authorDaniel Friesen <dantman@users.mediawiki.org>
Sun, 3 Apr 2011 12:46:36 +0000 (12:46 +0000)
committerDaniel Friesen <dantman@users.mediawiki.org>
Sun, 3 Apr 2011 12:46:36 +0000 (12:46 +0000)
includes/OutputPage.php
includes/RequestContext.php
includes/Skin.php
includes/SkinTemplate.php
includes/User.php

index 60057b5..1d82155 100644 (file)
@@ -552,7 +552,7 @@ class OutputPage {
         * @return Boolean: true iff cache-ok headers was sent.
         */
        public function checkLastModified( $timestamp ) {
-               global $wgCachePages, $wgCacheEpoch, $wgRequest;
+               global $wgCachePages, $wgCacheEpoch;
 
                if ( !$timestamp || $timestamp == '19700101000000' ) {
                        wfDebug( __METHOD__ . ": CACHE DISABLED, NO TIMESTAMP\n" );
@@ -619,7 +619,7 @@ class OutputPage {
                # Give a 304 response code and disable body output
                wfDebug( __METHOD__ . ": NOT MODIFIED, $info\n", false );
                ini_set( 'zlib.output_compression', 0 );
-               $wgRequest->response()->header( "HTTP/1.1 304 Not Modified" );
+               $this->getRequest()->response()->header( "HTTP/1.1 304 Not Modified" );
                $this->sendCacheControl();
                $this->disable();
 
@@ -773,6 +773,16 @@ class OutputPage {
                return $this->mContext;
        }
 
+       /**
+        * Get the WebRequest being used for this instance
+        *
+        * @return WebRequest
+        * @since 1.18
+        */
+       public function getRequest() {
+               return $this->getContext()->getRequest();
+       }
+
        /**
         * Set the Title object to use
         *
@@ -1546,9 +1556,9 @@ class OutputPage {
         * @return Boolean
         */
        function uncacheableBecauseRequestVars() {
-               global $wgRequest;
-               return $wgRequest->getText( 'useskin', false ) === false
-                       && $wgRequest->getText( 'uselang', false ) === false;
+               $request = $this->getRequest();
+               return $request->getText( 'useskin', false ) === false
+                       && $request->getText( 'uselang', false ) === false;
        }
 
        /**
@@ -1558,8 +1568,7 @@ class OutputPage {
         * @return Boolean
         */
        function haveCacheVaryCookies() {
-               global $wgRequest;
-               $cookieHeader = $wgRequest->getHeader( 'cookie' );
+               $cookieHeader = $this->getRequest()->getHeader( 'cookie' );
                if ( $cookieHeader === false ) {
                        return false;
                }
@@ -1632,8 +1641,8 @@ class OutputPage {
         *   /w/index.php?title=Main_page&variant=zh-cn should never be served.
         */
        function addAcceptLanguage() {
-               global $wgRequest, $wgContLang;
-               if( !$wgRequest->getCheck( 'variant' ) && $wgContLang->hasVariants() ) {
+               global $wgContLang;
+               if( !$this->getRequest()->getCheck( 'variant' ) && $wgContLang->hasVariants() ) {
                        $variants = $wgContLang->getVariants();
                        $aloption = array();
                        foreach ( $variants as $variant ) {
@@ -1696,9 +1705,9 @@ class OutputPage {
         * Send cache control HTTP headers
         */
        public function sendCacheControl() {
-               global $wgUseSquid, $wgUseESI, $wgUseETag, $wgSquidMaxage, $wgRequest, $wgUseXVO;
+               global $wgUseSquid, $wgUseESI, $wgUseETag, $wgSquidMaxage, $wgUseXVO;
 
-               $response = $wgRequest->response();
+               $response = $this->getRequest()->response();
                if ( $wgUseETag && $this->mETag ) {
                        $response->header( "ETag: $this->mETag" );
                }
@@ -1824,7 +1833,7 @@ class OutputPage {
         * the object, let's actually output it:
         */
        public function output() {
-               global $wgOutputEncoding, $wgRequest;
+               global $wgOutputEncoding;
                global $wgLanguageCode, $wgDebugRedirects, $wgMimeType;
 
                if( $this->mDoNothing ) {
@@ -1833,7 +1842,7 @@ class OutputPage {
 
                wfProfileIn( __METHOD__ );
 
-               $response = $wgRequest->response();
+               $response = $this->getRequest()->response();
 
                if ( $this->mRedirect != '' ) {
                        # Standards require redirect URLs to be absolute
@@ -1924,7 +1933,7 @@ class OutputPage {
         * @return nothing
         */
        function blockedPage( $return = true ) {
-               global $wgContLang, $wgLang;
+               global $wgContLang;
 
                $this->setPageTitle( wfMsg( 'blockedtitle' ) );
                $this->setRobotPolicy( 'noindex,nofollow' );
@@ -1935,7 +1944,7 @@ class OutputPage {
                if( $reason == '' ) {
                        $reason = wfMsg( 'blockednoreason' );
                }
-               $blockTimestamp = $wgLang->timeanddate(
+               $blockTimestamp = $this->getContext()->getLang()->timeanddate(
                        wfTimestamp( TS_MW, $this->getUser()->mBlock->mTimestamp ), true
                );
                $ip = wfGetIP();
@@ -1944,7 +1953,7 @@ class OutputPage {
 
                $blockid = $this->getUser()->mBlock->getId();
 
-               $blockExpiry = $wgLang->formatExpiry( $this->getUser()->mBlock->mExpiry );
+               $blockExpiry = $this->getContext()->getLang()->formatExpiry( $this->getUser()->mBlock->mExpiry );
 
                if ( $this->getUser()->mBlock->mAuto ) {
                        $msg = 'autoblockedtext';
@@ -2034,8 +2043,6 @@ class OutputPage {
         * @param $permission String: key required
         */
        public function permissionRequired( $permission ) {
-               global $wgLang;
-
                $this->setPageTitle( wfMsg( 'badaccess' ) );
                $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
                $this->setRobotPolicy( 'noindex,nofollow' );
@@ -2047,7 +2054,7 @@ class OutputPage {
                if( $groups ) {
                        $this->addWikiMsg(
                                'badaccess-groups',
-                               $wgLang->commaList( $groups ),
+                               $this->getContext()->getLang()->commaList( $groups ),
                                count( $groups )
                        );
                } else {
@@ -2279,14 +2286,12 @@ class OutputPage {
         * @param $returntoquery String: query string for the return to link
         */
        public function returnToMain( $unused = null, $returnto = null, $returntoquery = null ) {
-               global $wgRequest;
-
                if ( $returnto == null ) {
-                       $returnto = $wgRequest->getText( 'returnto' );
+                       $returnto = $this->getRequest()->getText( 'returnto' );
                }
 
                if ( $returntoquery == null ) {
-                       $returntoquery = $wgRequest->getText( 'returntoquery' );
+                       $returntoquery = $this->getRequest()->getText( 'returntoquery' );
                }
 
                if ( $returnto === '' ) {
@@ -2313,7 +2318,6 @@ class OutputPage {
        public function headElement( Skin $sk, $includeStyle = true ) {
                global $wgOutputEncoding, $wgMimeType;
                global $wgUseTrackbacks, $wgHtml5;
-               global $wgRequest, $wgLang;
 
                if ( $sk->commonPrintStylesheet() ) {
                        $this->addModuleStyles( 'mediawiki.legacy.wikiprintable' );
@@ -2353,7 +2357,7 @@ class OutputPage {
                $bodyAttrs = array();
 
                # Crazy edit-on-double-click stuff
-               $action = $wgRequest->getVal( 'action', 'view' );
+               $action = $this->getRequest()->getVal( 'action', 'view' );
 
                if (
                        $this->getTitle()->getNamespace() != NS_SPECIAL &&
@@ -2368,7 +2372,7 @@ class OutputPage {
                $dir = wfUILang()->getDir();
                $bodyAttrs['class'] = "mediawiki $dir";
 
-               if ( $wgLang->capitalizeAllNouns() ) {
+               if ( $this->getContext()->getLang()->capitalizeAllNouns() ) {
                        # A <body> class is probably not the best way to do this . . .
                        $bodyAttrs['class'] .= ' capitalize-all-nouns';
                }
@@ -2437,13 +2441,13 @@ class OutputPage {
         * @return string html <script> and <style> tags
         */
        protected function makeResourceLoaderLink( Skin $skin, $modules, $only, $useESI = false ) {
-               global $wgLang, $wgLoadScript, $wgResourceLoaderUseESI,
-                       $wgResourceLoaderInlinePrivateModules, $wgRequest;
+               global $wgLoadScript, $wgResourceLoaderUseESI,
+                       $wgResourceLoaderInlinePrivateModules;
                // Lazy-load ResourceLoader
                // TODO: Should this be a static function of ResourceLoader instead?
                // TODO: Divide off modules starting with "user", and add the user parameter to them
                $baseQuery = array(
-                       'lang' => $wgLang->getCode(),
+                       'lang' => $this->getContext()->getLang()->getCode(),
                        'debug' => ResourceLoader::inDebugMode() ? 'true' : 'false',
                        'skin' => $skin->getSkinName(),
                        'only' => $only,
@@ -2452,7 +2456,7 @@ class OutputPage {
                if ( $this->isPrintable() ) {
                        $baseQuery['printable'] = 1;
                }
-               if ( $wgRequest->getBool( 'handheld' ) ) {
+               if ( $this->getRequest()->getBool( 'handheld' ) ) {
                        $baseQuery['handheld'] = 1;
                }
 
@@ -2589,7 +2593,7 @@ class OutputPage {
         * @return String: HTML fragment
         */
        function getHeadScripts( Skin $sk ) {
-               global $wgRequest, $wgUseSiteJs, $wgAllowUserJs;
+               global $wgUseSiteJs, $wgAllowUserJs;
 
                // Startup - this will immediately load jquery and mediawiki modules
                $scripts = $this->makeResourceLoaderLink( $sk, 'startup', ResourceLoaderModule::TYPE_SCRIPTS, true );
@@ -2626,10 +2630,10 @@ class OutputPage {
 
                // Add user JS if enabled
                if ( $wgAllowUserJs && $this->getUser()->isLoggedIn() ) {
-                       $action = $wgRequest->getVal( 'action', 'view' );
+                       $action = $this->getRequest()->getVal( 'action', 'view' );
                        if( $this->getTitle() && $this->getTitle()->isJsSubpage() && $sk->userCanPreview( $action ) ) {
                                # XXX: additional security check/prompt?
-                               $scripts .= Html::inlineScript( "\n" . $wgRequest->getText( 'wpTextbox1' ) . "\n" ) . "\n";
+                               $scripts .= Html::inlineScript( "\n" . $this->getRequest()->getText( 'wpTextbox1' ) . "\n" ) . "\n";
                        } else {
                                # FIXME: this means that User:Me/Common.js doesn't load when previewing
                                # User:Me/Vector.js, and vice versa (bug26283)
@@ -2650,7 +2654,7 @@ class OutputPage {
         * have to be purged on configuration changes.
         */
        protected function getJSVars() {
-               global $wgRequest, $wgUseAjax, $wgEnableMWSuggest, $wgContLang;
+               global $wgUseAjax, $wgEnableMWSuggest, $wgContLang;
 
                $title = $this->getTitle();
                $ns = $title->getNamespace();
@@ -2671,7 +2675,7 @@ class OutputPage {
                        'wgCurRevisionId' => $title->getLatestRevID(),
                        'wgArticleId' => $title->getArticleId(),
                        'wgIsArticle' => $this->isArticle(),
-                       'wgAction' => $wgRequest->getText( 'action', 'view' ),
+                       'wgAction' => $this->getRequest()->getText( 'action', 'view' ),
                        'wgUserName' => $this->getUser()->isAnon() ? null : $this->getUser()->getName(),
                        'wgUserGroups' => $this->getUser()->getEffectiveGroups(),
                        'wgCategories' => $this->getCategories(),
@@ -3094,7 +3098,7 @@ class OutputPage {
         * @return String: modified value of the "media" attribute
         */
        public static function transformCssMedia( $media ) {
-               global $wgRequest, $wgHandheldForIPhone;
+               global $wgHandheldForIPhone;
 
                // Switch in on-screen display for media testing
                $switches = array(
@@ -3102,7 +3106,7 @@ class OutputPage {
                        'handheld' => 'handheld',
                );
                foreach( $switches as $switch => $targetMedia ) {
-                       if( $wgRequest->getBool( $switch ) ) {
+                       if( $this->getRequest()->getBool( $switch ) ) {
                                if( $media == $targetMedia ) {
                                        $media = '';
                                } elseif( $media == 'screen' ) {
@@ -3153,13 +3157,13 @@ class OutputPage {
         * @param $lag Integer: slave lag
         */
        public function showLagWarning( $lag ) {
-               global $wgSlaveLagWarning, $wgSlaveLagCritical, $wgLang;
+               global $wgSlaveLagWarning, $wgSlaveLagCritical;
                if( $lag >= $wgSlaveLagWarning ) {
                        $message = $lag < $wgSlaveLagCritical
                                ? 'lag-warn-normal'
                                : 'lag-warn-high';
                        $wrap = Html::rawElement( 'div', array( 'class' => "mw-{$message}" ), "\n$1\n" );
-                       $this->wrapWikiMsg( "$wrap\n", array( $message, $wgLang->formatNum( $lag ) ) );
+                       $this->wrapWikiMsg( "$wrap\n", array( $message, $this->getContext()->getLang()->formatNum( $lag ) ) );
                }
        }
 
index 0f1488e..503f9b8 100644 (file)
@@ -130,9 +130,25 @@ class RequestContext {
         * @return Skin
         */
        public function getSkin() {
-               // For now we'll just proxy to the user. In the future a saner location for
-               // organizing what skin to use may be chosen
-               return $this->getUser()->getSkin();
+               if ( !isset($this->skin) ) {
+                       wfProfileIn( __METHOD__ . '-createskin' );
+                       
+                       global $wgHiddenPrefs;
+                       if( !in_array( 'skin', $wgHiddenPrefs ) ) {
+                               # get the user skin
+                               $userSkin = $this->getUser()->getOption( 'skin' );
+                               $userSkin = $this->getRequest()->getVal( 'useskin', $userSkin );
+                       } else {
+                               # if we're not allowing users to override, then use the default
+                               global $wgDefaultSkin;
+                               $userSkin = $wgDefaultSkin;
+                       }
+
+                       $this->skin = Skin::newFromKey( $userSkin );
+                       $this->skin->setContext( $this );
+                       wfProfileOut( __METHOD__ . '-createskin' );
+               }
+               return $this->skin;
        }
 
        /** Helpful methods **/
index a7bad90..3146eb8 100644 (file)
@@ -23,11 +23,6 @@ abstract class Skin {
        /**#@-*/
        protected $mRevisionId; // The revision ID we're looking at, null if not applicable.
        protected $skinname = 'standard';
-       /**
-        * todo Fixme: should be protected :-\
-        * @var Title
-        */
-       var $mTitle = null;
        protected $mRelevantTitle = null;
        protected $mRelevantUser = null;
 
@@ -191,18 +186,18 @@ abstract class Skin {
         * Preload the existence of three commonly-requested pages in a single query
         */
        function preloadExistence() {
-               global $wgUser;
-
+               $user = $this->getContext()->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 );
@@ -214,9 +209,7 @@ abstract class Skin {
         * Set some local variables
         */
        protected function setMembers() {
-               global $wgUser;
-               $this->mUser = $wgUser;
-               $this->userpage = $wgUser->getUserPage()->getPrefixedText();
+               $this->userpage = $this->getContext()->getUser()->getUserPage()->getPrefixedText();
                $this->usercss = false;
        }
 
@@ -226,15 +219,29 @@ abstract class Skin {
         * @return Boolean
         */
        public function isRevisionCurrent() {
-               return $this->mRevisionId == 0 || $this->mRevisionId == $this->mTitle->getLatestRevID();
+               return $this->mRevisionId == 0 || $this->mRevisionId == $this->getTitle()->getLatestRevID();
        }
 
        /**
-        * Set the title
-        * @param $t Title object to use
+        * Set the RequestContext used in this instance
+        *
+        * @param RequestContext $context
+        */
+       public function setContext( RequestContext $context ) {
+               $this->mContext = $context;
+       }
+
+       /**
+        * Get the RequestContext used in this instance
+        *
+        * @return RequestContext
         */
-       public function setTitle( $t ) {
-               $this->mTitle = $t;
+       public function getContext() {
+               if ( !isset($this->mContext) ) {
+                       wfDebug( __METHOD__ . " called and \$mContext is null. Using RequestContext::getMain(); for sanity\n" );
+                       $this->mContext = RequestContext::getMain();
+               }
+               return $this->mContext;
        }
 
        /** Get the title
@@ -242,7 +249,7 @@ abstract class Skin {
         * @return Title
         */
        public function getTitle() {
-               return $this->mTitle;
+               return $this->getContext()->getTitle();
        }
 
        /**
@@ -266,7 +273,7 @@ abstract class Skin {
                if ( isset($this->mRelevantTitle) ) {
                        return $this->mRelevantTitle;
                }
-               return $this->mTitle;
+               return $this->getTitle();
        }
 
        /**
@@ -363,23 +370,21 @@ abstract class Skin {
         * @return bool
         */
        public function userCanPreview( $action ) {
-               global $wgRequest, $wgUser;
-
                if ( $action != 'submit' ) {
                        return false;
                }
-               if ( !$wgRequest->wasPosted() ) {
+               if ( !$this->getContext()->getRequest()->wasPosted() ) {
                        return false;
                }
-               if ( !$this->mTitle->userCanEditCssSubpage() ) {
+               if ( !$this->getTitle()->userCanEditCssSubpage() ) {
                        return false;
                }
-               if ( !$this->mTitle->userCanEditJsSubpage() ) {
+               if ( !$this->getTitle()->userCanEditJsSubpage() ) {
                        return false;
                }
 
-               return $wgUser->matchEditToken(
-                       $wgRequest->getVal( 'wpEditToken' ) );
+               return $this->getContext()->getUser()->matchEditToken(
+                       $this->getContext()->getRequest()->getVal( 'wpEditToken' ) );
        }
 
        /**
@@ -428,7 +433,6 @@ abstract class Skin {
         * @private
         */
        function setupUserCss( OutputPage $out ) {
-               global $wgRequest, $wgUser;
                global $wgUseSiteCss, $wgAllowUserCss, $wgAllowUserCssPrefs;
 
                wfProfileIn( __METHOD__ );
@@ -442,16 +446,16 @@ abstract class Skin {
                // Per-site custom styles
                if ( $wgUseSiteCss ) {
                        $out->addModuleStyles( array( 'site', 'noscript' ) );
-                       if( $wgUser->isLoggedIn() ){
+                       if( $this->getContext()->getUser()->isLoggedIn() ){
                                $out->addModuleStyles( 'user.groups' );
                        }
                }
 
                // Per-user custom styles
                if ( $wgAllowUserCss ) {
-                       if ( $this->mTitle->isCssSubpage() && $this->userCanPreview( $wgRequest->getVal( 'action' ) ) ) {
+                       if ( $this->getTitle()->isCssSubpage() && $this->userCanPreview( $this->getContext()->getRequest()->getVal( 'action' ) ) ) {
                                // @FIXME: properly escape the cdata!
-                               $out->addInlineStyle( $wgRequest->getText( 'wpTextbox1' ) );
+                               $out->addInlineStyle( $this->getContext()->getRequest()->getText( 'wpTextbox1' ) );
                        } else {
                                $out->addModuleStyles( 'user' );
                        }
@@ -533,13 +537,7 @@ abstract class Skin {
         * The format without an explicit $out argument is deprecated
         */
        function getCategoryLinks( OutputPage $out=null ) {
-               global $wgUseCategoryBrowser, $wgContLang, $wgUser;
-
-               if ( is_null( $out ) ) {
-                       // Backwards compatibility for when there was no $out arg
-                       global $wgOut;
-                       $out = $wgOut;
-               }
+               global $wgUseCategoryBrowser, $wgContLang;
 
                if ( count( $out->mCategoryLinks ) == 0 ) {
                        return '';
@@ -569,9 +567,9 @@ abstract class Skin {
 
                # Hidden categories
                if ( isset( $allCats['hidden'] ) ) {
-                       if ( $wgUser->getBoolOption( 'showhiddencats' ) ) {
+                       if ( $this->getContext()->getUser()->getBoolOption( 'showhiddencats' ) ) {
                                $class = 'mw-hidden-cats-user-shown';
-                       } elseif ( $this->mTitle->getNamespace() == NS_CATEGORY ) {
+                       } elseif ( $this->getTitle()->getNamespace() == NS_CATEGORY ) {
                                $class = 'mw-hidden-cats-ns-shown';
                        } else {
                                $class = 'mw-hidden-cats-hidden';
@@ -589,7 +587,7 @@ abstract class Skin {
                        $s .= '<br /><hr />';
 
                        # get a big array of the parents tree
-                       $parenttree = $this->mTitle->getParentCategoryTree();
+                       $parenttree = $this->getTitle()->getParentCategoryTree();
                        # Skin object passed by reference cause it can not be
                        # accessed under the method subfunction drawCategoryBrowser
                        $tempout = explode( "\n", $this->drawCategoryBrowser( $parenttree, $this ) );
@@ -634,22 +632,15 @@ abstract class Skin {
         * the ->getCategories( $out ) form with whatout OutputPage is on hand
         */
        function getCategories( OutputPage $out=null ) {
-               if ( is_null( $out ) ) {
-                       // Backwards compatibility for when there was no $out arg
-                       global $wgOut;
-                       $out = $wgOut;
-               }
 
                $catlinks = $this->getCategoryLinks( $out );
 
                $classes = 'catlinks';
 
-               global $wgUser;
-
                // Check what we're showing
                $allCats = $out->getCategoryLinks();
-               $showHidden = $wgUser->getBoolOption( 'showhiddencats' ) ||
-                                               $this->mTitle->getNamespace() == NS_CATEGORY;
+               $showHidden = $this->getContext()->getUser()->getBoolOption( 'showhiddencats' ) ||
+                                               $this->getTitle()->getNamespace() == NS_CATEGORY;
 
                if ( empty( $allCats['normal'] ) && !( !empty( $allCats['hidden'] ) && $showHidden ) ) {
                        $classes .= ' catlinks-allhidden';
@@ -774,21 +765,19 @@ abstract class Skin {
 
        /** @return string Retrievied from HTML text */
        function printSource() {
-               $url = htmlspecialchars( $this->mTitle->getFullURL() );
+               $url = htmlspecialchars( $this->getTitle()->getFullURL() );
                return wfMsg( 'retrievedfrom', '<a href="' . $url . '">' . $url . '</a>' );
        }
 
        function getUndeleteLink() {
-               global $wgUser, $wgLang, $wgRequest;
-
-               $action = $wgRequest->getVal( 'action', 'view' );
+               $action = $this->getContext()->getRequest()->getVal( 'action', 'view' );
 
-               if ( $wgUser->isAllowed( 'deletedhistory' ) &&
-                       ( $this->mTitle->getArticleId() == 0 || $action == 'history' ) ) {
-                       $n = $this->mTitle->isDeleted();
+               if ( $this->getContext()->getUser()->isAllowed( 'deletedhistory' ) &&
+                       ( $this->getTitle()->getArticleId() == 0 || $action == 'history' ) ) {
+                       $n = $this->getTitle()->isDeleted();
 
                        if ( $n ) {
-                               if ( $wgUser->isAllowed( 'undelete' ) ) {
+                               if ( $this->getContext()->getUser()->isAllowed( 'undelete' ) ) {
                                        $msg = 'thisisdeleted';
                                } else {
                                        $msg = 'viewdeleted';
@@ -797,8 +786,8 @@ abstract class Skin {
                                return wfMsg(
                                        $msg,
                                        $this->link(
-                                               SpecialPage::getTitleFor( 'Undelete', $this->mTitle->getPrefixedDBkey() ),
-                                               wfMsgExt( 'restorelink', array( 'parsemag', 'escape' ), $wgLang->formatNum( $n ) ),
+                                               SpecialPage::getTitleFor( 'Undelete', $this->getTitle()->getPrefixedDBkey() ),
+                                               wfMsgExt( 'restorelink', array( 'parsemag', 'escape' ), $this->getContext()->getLang()->formatNum( $n ) ),
                                                array(),
                                                array(),
                                                array( 'known', 'noclasses' )
@@ -814,12 +803,7 @@ abstract class Skin {
         * The format without an explicit $out argument is deprecated
         */
        function subPageSubtitle( OutputPage $out=null ) {
-               if ( is_null( $out ) ) {
-                       // Backwards compatibility for when there was no $out arg
-                       global $wgOut;
-                       $out = $wgOut;
-               }
-
+               $out = $this->getContext()->getOutput();
                $subpages = '';
 
                if ( !wfRunHooks( 'SkinSubPageSubtitle', array( &$subpages, $this, $out ) ) ) {
@@ -827,7 +811,7 @@ abstract class Skin {
                }
 
                if ( $out->isArticle() && MWNamespace::hasSubpages( $out->getTitle()->getNamespace() ) ) {
-                       $ptext = $this->mTitle->getPrefixedText();
+                       $ptext = $this->getTitle()->getPrefixedText();
                        if ( preg_match( '/\//', $ptext ) ) {
                                $links = explode( '/', $ptext );
                                array_pop( $links );
@@ -888,10 +872,10 @@ abstract class Skin {
        }
 
        function getCopyright( $type = 'detect' ) {
-               global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgRequest;
+               global $wgRightsPage, $wgRightsUrl, $wgRightsText;
 
                if ( $type == 'detect' ) {
-                       $diff = $wgRequest->getVal( 'diff' );
+                       $diff = $this->getContext()->getRequest()->getVal( 'diff' );
 
                        if ( is_null( $diff ) && !$this->isRevisionCurrent() && wfMsgForContent( 'history_copyright' ) !== '-' ) {
                                $type = 'history';
@@ -923,7 +907,7 @@ abstract class Skin {
                // Allow for site and per-namespace customization of copyright notice.
                $forContent = true;
 
-               wfRunHooks( 'SkinCopyrightFooter', array( $this->mTitle, $type, &$msg, &$link, &$forContent ) );
+               wfRunHooks( 'SkinCopyrightFooter', array( $this->getTitle(), $type, &$msg, &$link, &$forContent ) );
 
                if ( $forContent ) {
                        $out .= wfMsgForContent( $msg, $link );
@@ -980,17 +964,15 @@ abstract class Skin {
         * @return String
         */
        protected function lastModified( $article ) {
-               global $wgLang;
-
                if ( !$this->isRevisionCurrent() ) {
-                       $timestamp = Revision::getTimestampFromId( $this->mTitle, $this->mRevisionId );
+                       $timestamp = Revision::getTimestampFromId( $this->getTitle(), $this->mRevisionId );
                } else {
                        $timestamp = $article->getTimestamp();
                }
 
                if ( $timestamp ) {
-                       $d = $wgLang->date( $timestamp, true );
-                       $t = $wgLang->time( $timestamp, true );
+                       $d = $this->getContext()->getLang()->date( $timestamp, true );
+                       $t = $this->getContext()->getLang()->time( $timestamp, true );
                        $s = ' ' . wfMsg( 'lastmodifiedat', $d, $t );
                } else {
                        $s = '';
@@ -1116,9 +1098,8 @@ abstract class Skin {
        }
 
        function showEmailUser( $id ) {
-               global $wgUser;
                $targetUser = User::newFromId( $id );
-               return $wgUser->canSendEmail() && # the sending user must have a confirmed email address
+               return $this->getContext()->getUser()->canSendEmail() && # the sending user must have a confirmed email address
                        $targetUser->canReceiveEmail(); # the target user must have a confirmed email address and allow emails from users
        }
 
@@ -1238,10 +1219,9 @@ abstract class Skin {
         */
        function buildSidebar() {
                global $parserMemc, $wgEnableSidebarCache, $wgSidebarCacheExpiry;
-               global $wgLang;
                wfProfileIn( __METHOD__ );
 
-               $key = wfMemcKey( 'sidebar', $wgLang->getCode() );
+               $key = wfMemcKey( 'sidebar', $this->getContext()->getLang()->getCode() );
 
                if ( $wgEnableSidebarCache ) {
                        $cachedsidebar = $parserMemc->get( $key );
@@ -1301,7 +1281,7 @@ abstract class Skin {
                                $line = trim( $line, '* ' );
 
                                if ( strpos( $line, '|' ) !== false ) { // sanity check
-                                       $line = MessageCache::singleton()->transform( $line, false, null, $this->mTitle );
+                                       $line = MessageCache::singleton()->transform( $line, false, null, $this->getTitle() );
                                        $line = array_map( 'trim', explode( '|', $line, 2 ) );
                                        $link = wfMsgForContent( $line[0] );
 
@@ -1346,7 +1326,7 @@ abstract class Skin {
                                        $options = new ParserOptions();
                                        $options->setEditSection( false );
                                        $options->setInterfaceMessage( true );
-                                       $wikiBar[$heading] = $wgParser->parse( wfMsgForContentNoTrans( $line ) , $this->mTitle, $options )->getText();
+                                       $wikiBar[$heading] = $wgParser->parse( wfMsgForContentNoTrans( $line ) , $this->getTitle(), $options )->getText();
                                } else {
                                        continue;
                                }
@@ -1375,18 +1355,11 @@ abstract class Skin {
        /**
         * Gets new talk page messages for the current user.
         * @return MediaWiki message or if no new talk page messages, nothing
-        * The format without an explicit $out argument is deprecated
         */
-       function getNewtalks( OutputPage $out=null ) {
-               global $wgUser;
-
-               if ( is_null( $out ) ) {
-                       // Backwards compatibility for when there was no $out arg
-                       global $wgOut;
-                       $out = $wgOut;
-               }
+       function getNewtalks() {
+               $out = $this->getContext()->getOutput();
 
-               $newtalks = $wgUser->getNewMessageLinks();
+               $newtalks = $this->getContext()->getUser()->getNewMessageLinks();
                $ntl = '';
 
                if ( count( $newtalks ) == 1 && $newtalks[0]['wiki'] === wfWikiID() ) {
@@ -1444,7 +1417,7 @@ abstract class Skin {
         * @return String: HTML fragment
         */
        private function getCachedNotice( $name ) {
-               global $wgOut, $wgRenderHashAppend, $parserMemc;
+               global $wgRenderHashAppend, $parserMemc;
 
                wfProfileIn( __METHOD__ );
 
@@ -1481,14 +1454,9 @@ abstract class Skin {
                }
 
                if ( $needParse ) {
-                       if( is_object( $wgOut ) ) {
-                               $parsed = $wgOut->parse( $notice );
-                               $parserMemc->set( $key, array( 'html' => $parsed, 'hash' => md5( $notice ) ), 600 );
-                               $notice = $parsed;
-                       } else {
-                               wfDebug( 'Skin::getCachedNotice called for ' . $name . ' with no $wgOut available' . "\n" );
-                               $notice = '';
-                       }
+                       $parsed = $this->getContext()->getOutput()->parse( $notice );
+                       $parserMemc->set( $key, array( 'html' => $parsed, 'hash' => md5( $notice ) ), 600 );
+                       $notice = $parsed;
                }
 
                $notice = '<div id="localNotice">' .$notice . '</div>';
@@ -1504,7 +1472,7 @@ abstract class Skin {
        function getNamespaceNotice() {
                wfProfileIn( __METHOD__ );
 
-               $key = 'namespacenotice-' . $this->mTitle->getNsText();
+               $key = 'namespacenotice-' . $this->getTitle()->getNsText();
                $namespaceNotice = $this->getCachedNotice( $key );
                if ( $namespaceNotice && substr( $namespaceNotice, 0, 7 ) != '<p>&lt;' ) {
                        $namespaceNotice = '<div id="namespacebanner">' . $namespaceNotice . '</div>';
@@ -1522,13 +1490,11 @@ abstract class Skin {
         * @return String: HTML fragment
         */
        function getSiteNotice() {
-               global $wgUser;
-
                wfProfileIn( __METHOD__ );
                $siteNotice = '';
 
                if ( wfRunHooks( 'SiteNoticeBefore', array( &$siteNotice, $this ) ) ) {
-                       if ( is_object( $wgUser ) && $wgUser->isLoggedIn() ) {
+                       if ( is_object( $this->getContext()->getUser() ) && $this->getContext()->getUser()->isLoggedIn() ) {
                                $siteNotice = $this->getCachedNotice( 'sitenotice' );
                        } else {
                                $anonNotice = $this->getCachedNotice( 'anonnotice' );
index 7a91b37..3b39abe 100644 (file)
@@ -158,8 +158,8 @@ class SkinTemplate extends Skin {
                wfProfileOut( __METHOD__ . '-init' );
 
                wfProfileIn( __METHOD__ . '-stuff' );
-               $this->thispage = $this->mTitle->getPrefixedDBkey();
-               $this->thisurl = $this->mTitle->getPrefixedURL();
+               $this->thispage = $this->getTitle()->getPrefixedDBkey();
+               $this->thisurl = $this->getTitle()->getPrefixedURL();
                $query = array();
                if ( !$wgRequest->wasPosted() ) {
                        $query = $wgRequest->getValues();
@@ -169,7 +169,7 @@ class SkinTemplate extends Skin {
                }
                $this->thisquery = wfUrlencode( wfArrayToCGI( $query ) );
                $this->loggedin = $wgUser->isLoggedIn();
-               $this->iscontent = ( $this->mTitle->getNamespace() != NS_SPECIAL );
+               $this->iscontent = ( $this->getTitle()->getNamespace() != NS_SPECIAL );
                $this->iseditable = ( $this->iscontent and !( $action == 'edit' or $action == 'submit' ) );
                $this->username = $wgUser->getName();
 
@@ -181,7 +181,7 @@ class SkinTemplate extends Skin {
                        $this->userpageUrlDetails = self::makeKnownUrlDetails( $this->userpage );
                }
 
-               $this->titletxt = $this->mTitle->getPrefixedText();
+               $this->titletxt = $this->getTitle()->getPrefixedText();
                wfProfileOut( __METHOD__ . '-stuff' );
 
                wfProfileIn( __METHOD__ . '-stuff-head' );
@@ -230,19 +230,19 @@ class SkinTemplate extends Skin {
                $tpl->set( 'title', $out->getPageTitle() );
                $tpl->set( 'pagetitle', $out->getHTMLTitle() );
                $tpl->set( 'displaytitle', $out->mPageLinkTitle );
-               $tpl->set( 'pageclass', $this->getPageClasses( $this->mTitle ) );
+               $tpl->set( 'pageclass', $this->getPageClasses( $this->getTitle() ) );
                $tpl->set( 'skinnameclass', ( 'skin-' . Sanitizer::escapeClass( $this->getSkinName() ) ) );
 
-               $nsname = MWNamespace::exists( $this->mTitle->getNamespace() ) ?
-                                       MWNamespace::getCanonicalName( $this->mTitle->getNamespace() ) :
-                                       $this->mTitle->getNsText();
+               $nsname = MWNamespace::exists( $this->getTitle()->getNamespace() ) ?
+                                       MWNamespace::getCanonicalName( $this->getTitle()->getNamespace() ) :
+                                       $this->getTitle()->getNsText();
 
                $tpl->set( 'nscanonical', $nsname );
-               $tpl->set( 'nsnumber', $this->mTitle->getNamespace() );
-               $tpl->set( 'titleprefixeddbkey', $this->mTitle->getPrefixedDBKey() );
-               $tpl->set( 'titletext', $this->mTitle->getText() );
-               $tpl->set( 'articleid', $this->mTitle->getArticleId() );
-               $tpl->set( 'currevisionid', $this->mTitle->getLatestRevID() );
+               $tpl->set( 'nsnumber', $this->getTitle()->getNamespace() );
+               $tpl->set( 'titleprefixeddbkey', $this->getTitle()->getPrefixedDBKey() );
+               $tpl->set( 'titletext', $this->getTitle()->getText() );
+               $tpl->set( 'articleid', $this->getTitle()->getArticleId() );
+               $tpl->set( 'currevisionid', $this->getTitle()->getLatestRevID() );
 
                $tpl->set( 'isarticle', $out->isArticle() );
 
@@ -284,12 +284,12 @@ class SkinTemplate extends Skin {
                $tpl->set( 'printable', $out->isPrintable() );
                $tpl->set( 'handheld', $wgRequest->getBool( 'handheld' ) );
                $tpl->setRef( 'loggedin', $this->loggedin );
-               $tpl->set( 'notspecialpage', $this->mTitle->getNamespace() != NS_SPECIAL );
+               $tpl->set( 'notspecialpage', $this->getTitle()->getNamespace() != NS_SPECIAL );
                /* XXX currently unused, might get useful later
-               $tpl->set( 'editable', ( $this->mTitle->getNamespace() != NS_SPECIAL ) );
-               $tpl->set( 'exists', $this->mTitle->getArticleID() != 0 );
-               $tpl->set( 'watch', $this->mTitle->userIsWatching() ? 'unwatch' : 'watch' );
-               $tpl->set( 'protect', count( $this->mTitle->isProtected() ) ? 'unprotect' : 'protect' );
+               $tpl->set( 'editable', ( $this->getTitle()->getNamespace() != NS_SPECIAL ) );
+               $tpl->set( 'exists', $this->getTitle()->getArticleID() != 0 );
+               $tpl->set( 'watch', $this->getTitle()->userIsWatching() ? 'unwatch' : 'watch' );
+               $tpl->set( 'protect', count( $this->getTitle()->isProtected() ) ? 'unprotect' : 'protect' );
                $tpl->set( 'helppage', wfMsg( 'helppage' ) );
                */
                $tpl->set( 'searchaction', $this->escapeSearchLink() );
@@ -328,7 +328,7 @@ class SkinTemplate extends Skin {
 
                        // The content of SpecialPages should be presented in the
                        // user's language. Content of regular pages should not be touched.
-                       if( $this->mTitle->isSpecialPage() ) {
+                       if( $this->getTitle()->isSpecialPage() ) {
                                $tpl->set( 'specialpageattributes', $attrs );
                        }
                }
@@ -342,9 +342,9 @@ class SkinTemplate extends Skin {
                $tpl->setRef( 'skin', $this );
                $tpl->set( 'logo', $this->logoText() );
                if ( $out->isArticle() && ( !isset( $oldid ) || isset( $diff ) ) &&
-                       $this->mTitle->exists() )
+                       $this->getTitle()->exists() )
                {
-                       $article = new Article( $this->mTitle, 0 );
+                       $article = new Article( $this->getTitle(), 0 );
                        if ( !$wgDisableCounters ) {
                                $viewcount = $wgLang->formatNum( $article->getCount() );
                                if ( $viewcount ) {
@@ -360,7 +360,7 @@ class SkinTemplate extends Skin {
                                $dbr = wfGetDB( DB_SLAVE );
                                $res = $dbr->select( 'watchlist',
                                        array( 'COUNT(*) AS n' ),
-                                       array( 'wl_title' => $dbr->strencode( $this->mTitle->getDBkey() ), 'wl_namespace' => $this->mTitle->getNamespace() ),
+                                       array( 'wl_title' => $dbr->strencode( $this->getTitle()->getDBkey() ), 'wl_namespace' => $this->getTitle()->getNamespace() ),
                                        __METHOD__
                                );
                                $x = $dbr->fetchObject( $res );
@@ -796,7 +796,7 @@ class SkinTemplate extends Skin {
                wfProfileIn( __METHOD__ );
                
                $title = $this->getRelevantTitle(); // Display tabs for the relevant title rather than always the title itself
-               $onPage = $title->equals($this->mTitle);
+               $onPage = $title->equals($this->getTitle());
                
                $content_navigation = array(
                        'namespaces' => array(),
@@ -935,7 +935,7 @@ class SkinTemplate extends Skin {
                                if ( $title->quickUserCan( 'move' ) ) {
                                        $moveTitle = SpecialPage::getTitleFor( 'Movepage', $title->getPrefixedDBkey() );
                                        $content_navigation['actions']['move'] = array(
-                                               'class' => $this->mTitle->isSpecial( 'Movepage' ) ? 'selected' : false,
+                                               'class' => $this->getTitle()->isSpecial( 'Movepage' ) ? 'selected' : false,
                                                'text' => wfMessageFallback( "$skname-action-move", 'move' )->text(),
                                                'href' => $moveTitle->getLocalURL()
                                        );
@@ -958,7 +958,7 @@ class SkinTemplate extends Skin {
                                                // If the user can't undelete but can view deleted history show them a "View .. deleted" tab instead
                                                $msgKey = $wgUser->isAllowed( 'undelete' ) ? 'undelete' : 'viewdeleted';
                                                $content_navigation['actions']['undelete'] = array(
-                                                       'class' => $this->mTitle->isSpecial( 'Undelete' ) ? 'selected' : false,
+                                                       'class' => $this->getTitle()->isSpecial( 'Undelete' ) ? 'selected' : false,
                                                        'text' => wfMessageFallback( "$skname-action-$msgKey", "{$msgKey}_short" )
                                                                ->params( $wgLang->formatNum( $n ) )->text(),
                                                        'href' => $undelTitle->getLocalURL( array( 'target' => $title->getPrefixedDBkey() ) )
@@ -1157,7 +1157,7 @@ class SkinTemplate extends Skin {
                        if ( !$out->isPrintable() ) {
                                $nav_urls['print'] = array(
                                        'text' => wfMsg( 'printableversion' ),
-                                       'href' => $this->mTitle->getLocalURL( $wgRequest->appendQueryValue( 'printable', 'yes', true ) )
+                                       'href' => $this->getTitle()->getLocalURL( $wgRequest->appendQueryValue( 'printable', 'yes', true ) )
                                );
                        }
 
@@ -1174,12 +1174,12 @@ class SkinTemplate extends Skin {
                        wfRunHooks( 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink', array( &$this, &$nav_urls, &$revid, &$revid ) );
                }
 
-               if( $this->mTitle->getNamespace() != NS_SPECIAL ) {
+               if( $this->getTitle()->getNamespace() != NS_SPECIAL ) {
                        $wlhTitle = SpecialPage::getTitleFor( 'Whatlinkshere', $this->thispage );
                        $nav_urls['whatlinkshere'] = array(
                                'href' => $wlhTitle->getLocalUrl()
                        );
-                       if( $this->mTitle->getArticleId() ) {
+                       if( $this->getTitle()->getArticleId() ) {
                                $rclTitle = SpecialPage::getTitleFor( 'Recentchangeslinked', $this->thispage );
                                $nav_urls['recentchangeslinked'] = array(
                                        'href' => $rclTitle->getLocalUrl()
@@ -1249,7 +1249,7 @@ class SkinTemplate extends Skin {
         * @private
         */
        function getNameSpaceKey() {
-               return $this->mTitle->getNamespaceKey();
+               return $this->getTitle()->getNamespaceKey();
        }
 
        /**
@@ -1263,7 +1263,7 @@ class SkinTemplate extends Skin {
                $action = $wgRequest->getVal( 'action', 'view' );
 
                if( $allowUserJs && $this->loggedin ) {
-                       if( $this->mTitle->isJsSubpage() and $this->userCanPreview( $action ) ) {
+                       if( $this->getTitle()->isJsSubpage() and $this->userCanPreview( $action ) ) {
                                # XXX: additional security check/prompt?
                                $this->userjsprev = '/*<![CDATA[*/ ' . $wgRequest->getText( 'wpTextbox1' ) . ' /*]]>*/';
                        } else {
index 631babc..968a830 100644 (file)
@@ -2295,46 +2295,13 @@ class User {
        }
 
        /**
-        * Get the current skin, loading it if required, and setting a title
-        * @param $t Title: the title to use in the skin
+        * Get the current skin, loading it if required
         * @return Skin The current skin
         * @todo: FIXME : need to check the old failback system [AV]
+        * @deprecated Use ->getSkin() in the most relevant outputting context you have
         */
-       function getSkin( $t = null ) {
-               if( !$this->mSkin ) {
-                       global $wgOut;
-                       $this->mSkin = $this->createSkinObject();
-                       $this->mSkin->setTitle( $wgOut->getTitle() );
-               }
-               if ( $t && ( !$this->mSkin->getTitle() || !$t->equals( $this->mSkin->getTitle() ) ) ) {
-                       $skin = $this->createSkinObject();
-                       $skin->setTitle( $t );
-                       return $skin;
-               } else {
-                       return $this->mSkin;
-               }
-       }
-
-       // Creates a Skin object, for getSkin()
-       private function createSkinObject() {
-               wfProfileIn( __METHOD__ );
-
-               global $wgHiddenPrefs;
-               if( !in_array( 'skin', $wgHiddenPrefs ) ) {
-                       global $wgRequest;
-                       # get the user skin
-                       $userSkin = $this->getOption( 'skin' );
-                       $userSkin = $wgRequest->getVal( 'useskin', $userSkin );
-               } else {
-                       # if we're not allowing users to override, then use the default
-                       global $wgDefaultSkin;
-                       $userSkin = $wgDefaultSkin;
-               }
-
-               $skin = Skin::newFromKey( $userSkin );
-               wfProfileOut( __METHOD__ );
-
-               return $skin;
+       function getSkin() {
+               return RequestContext::getMain()->getSkin();
        }
 
        /**