Let Skin extend ContextSource instead of reinventing the wheel
authorAlexandre Emsenhuber <ialex@users.mediawiki.org>
Mon, 18 Jul 2011 20:52:22 +0000 (20:52 +0000)
committerAlexandre Emsenhuber <ialex@users.mediawiki.org>
Mon, 18 Jul 2011 20:52:22 +0000 (20:52 +0000)
includes/Skin.php

index 3dc7a3c..c7558e9 100644 (file)
@@ -15,7 +15,7 @@ if ( !defined( 'MEDIAWIKI' ) ) {
  *
  * @ingroup Skins
  */
-abstract class Skin {
+abstract class Skin extends ContextSource {
        protected $skinname = 'standard';
        protected $mRelevantTitle = null;
        protected $mRelevantUser = null;
@@ -183,7 +183,7 @@ abstract class Skin {
         * Preload the existence of three commonly-requested pages in a single query
         */
        function preloadExistence() {
-               $user = $this->getContext()->getUser();
+               $user = $this->getUser();
 
                // User/talk link
                $titles = array( $user->getUserPage(), $user->getTalkPage() );
@@ -206,45 +206,7 @@ abstract class Skin {
         * Set some local variables
         */
        protected function setMembers() {
-               $this->userpage = $this->getContext()->getUser()->getUserPage()->getPrefixedText();
-       }
-
-       /**
-        * 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 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
-        *
-        * @return Title
-        */
-       public function getTitle() {
-               return $this->getContext()->getTitle();
-       }
-
-       /** Get the user
-        *
-        * @return User
-        */
-       public function getUser() {
-               return $this->getContext()->getUser();
+               $this->userpage = $this->getUser()->getUserPage()->getPrefixedText();
        }
 
        /**
@@ -253,7 +215,7 @@ abstract class Skin {
         * @return Integer
         */
        public function getRevisionId() {
-               return $this->getContext()->getOutput()->getRevisionId();
+               return $this->getOutput()->getRevisionId();
        }
 
        /**
@@ -359,7 +321,7 @@ abstract class Skin {
                if ( $action != 'submit' ) {
                        return false;
                }
-               if ( !$this->getContext()->getRequest()->wasPosted() ) {
+               if ( !$this->getRequest()->wasPosted() ) {
                        return false;
                }
                if ( !$this->getTitle()->userCanEditCssSubpage() ) {
@@ -369,8 +331,8 @@ abstract class Skin {
                        return false;
                }
 
-               return $this->getContext()->getUser()->matchEditToken(
-                       $this->getContext()->getRequest()->getVal( 'wpEditToken' ) );
+               return $this->getUser()->matchEditToken(
+                       $this->getRequest()->getVal( 'wpEditToken' ) );
        }
 
        /**
@@ -417,16 +379,16 @@ abstract class Skin {
                // Per-site custom styles
                if ( $wgUseSiteCss ) {
                        $out->addModuleStyles( array( 'site', 'noscript' ) );
-                       if( $this->getContext()->getUser()->isLoggedIn() ){
+                       if( $this->getUser()->isLoggedIn() ){
                                $out->addModuleStyles( 'user.groups' );
                        }
                }
 
                // Per-user custom styles
                if ( $wgAllowUserCss ) {
-                       if ( $this->getTitle()->isCssSubpage() && $this->userCanPreview( $this->getContext()->getRequest()->getVal( 'action' ) ) ) {
+                       if ( $this->getTitle()->isCssSubpage() && $this->userCanPreview( $this->getRequest()->getVal( 'action' ) ) ) {
                                // @todo FIXME: Properly escape the cdata!
-                               $out->addInlineStyle( $this->getContext()->getRequest()->getText( 'wpTextbox1' ) );
+                               $out->addInlineStyle( $this->getRequest()->getText( 'wpTextbox1' ) );
                        } else {
                                $out->addModuleStyles( 'user' );
                        }
@@ -460,7 +422,7 @@ abstract class Skin {
        /**
         * Add skin specific stylesheets
         * Calling this method with an $out of anything but the same OutputPage
-        * inside ->getContext()->getOutput() is deprecated. The $out arg is kept
+        * inside ->getOutput() is deprecated. The $out arg is kept
         * for compatibility purposes with skins.
         * @param $out OutputPage
         * @delete
@@ -524,7 +486,7 @@ abstract class Skin {
        function getCategoryLinks() {
                global $wgUseCategoryBrowser;
 
-               $out = $this->getContext()->getOutput();
+               $out = $this->getOutput();
 
                if ( count( $out->mCategoryLinks ) == 0 ) {
                        return '';
@@ -548,7 +510,7 @@ abstract class Skin {
 
                # Hidden categories
                if ( isset( $allCats['hidden'] ) ) {
-                       if ( $this->getContext()->getUser()->getBoolOption( 'showhiddencats' ) ) {
+                       if ( $this->getUser()->getBoolOption( 'showhiddencats' ) ) {
                                $class = 'mw-hidden-cats-user-shown';
                        } elseif ( $this->getTitle()->getNamespace() == NS_CATEGORY ) {
                                $class = 'mw-hidden-cats-ns-shown';
@@ -608,7 +570,7 @@ abstract class Skin {
        }
 
        function getCategories() {
-               $out = $this->getContext()->getOutput();
+               $out = $this->getOutput();
 
                $catlinks = $this->getCategoryLinks();
 
@@ -616,7 +578,7 @@ abstract class Skin {
 
                // Check what we're showing
                $allCats = $out->getCategoryLinks();
-               $showHidden = $this->getContext()->getUser()->getBoolOption( 'showhiddencats' ) ||
+               $showHidden = $this->getUser()->getBoolOption( 'showhiddencats' ) ||
                                                $this->getTitle()->getNamespace() == NS_CATEGORY;
 
                if ( empty( $allCats['normal'] ) && !( !empty( $allCats['hidden'] ) && $showHidden ) ) {
@@ -670,7 +632,7 @@ abstract class Skin {
                global $wgShowDebug;
 
                if ( $wgShowDebug ) {
-                       $listInternals = $this->formatDebugHTML( $this->getContext()->getOutput()->mDebugtext );
+                       $listInternals = $this->formatDebugHTML( $this->getOutput()->mDebugtext );
                        return "\n<hr />\n<strong>Debug data:</strong><ul id=\"mw-debug-html\">" .
                                $listInternals . "</ul>\n";
                }
@@ -750,16 +712,16 @@ abstract class Skin {
        }
 
        function getUndeleteLink() {
-               $action = $this->getContext()->getRequest()->getVal( 'action', 'view' );
+               $action = $this->getRequest()->getVal( 'action', 'view' );
 
-               if ( $this->getContext()->getUser()->isAllowed( 'deletedhistory' ) &&
+               if ( $this->getUser()->isAllowed( 'deletedhistory' ) &&
                        ( $this->getTitle()->getArticleId() == 0 || $action == 'history' ) ) {
 
-                       $includeSuppressed = $this->getContext()->getUser()->isAllowed( 'suppressrevision' );
+                       $includeSuppressed = $this->getUser()->isAllowed( 'suppressrevision' );
                        $n = $this->getTitle()->isDeleted( $includeSuppressed );
 
                        if ( $n ) {
-                               if ( $this->getContext()->getUser()->isAllowed( 'undelete' ) ) {
+                               if ( $this->getUser()->isAllowed( 'undelete' ) ) {
                                        $msg = 'thisisdeleted';
                                } else {
                                        $msg = 'viewdeleted';
@@ -769,7 +731,7 @@ abstract class Skin {
                                        $msg,
                                        Linker::link(
                                                SpecialPage::getTitleFor( 'Undelete', $this->getTitle()->getPrefixedDBkey() ),
-                                               wfMsgExt( 'restorelink', array( 'parsemag', 'escape' ), $this->getContext()->getLang()->formatNum( $n ) ),
+                                               wfMsgExt( 'restorelink', array( 'parsemag', 'escape' ), $this->getLang()->formatNum( $n ) ),
                                                array(),
                                                array(),
                                                array( 'known', 'noclasses' )
@@ -782,7 +744,7 @@ abstract class Skin {
        }
 
        function subPageSubtitle() {
-               $out = $this->getContext()->getOutput();
+               $out = $this->getOutput();
                $subpages = '';
 
                if ( !wfRunHooks( 'SkinSubPageSubtitle', array( &$subpages, $this, $out ) ) ) {
@@ -855,7 +817,7 @@ abstract class Skin {
                global $wgRightsPage, $wgRightsUrl, $wgRightsText;
 
                if ( $type == 'detect' ) {
-                       $diff = $this->getContext()->getRequest()->getVal( 'diff' );
+                       $diff = $this->getRequest()->getVal( 'diff' );
 
                        if ( is_null( $diff ) && !$this->isRevisionCurrent() && wfMsgForContent( 'history_copyright' ) !== '-' ) {
                                $type = 'history';
@@ -951,8 +913,8 @@ abstract class Skin {
                }
 
                if ( $timestamp ) {
-                       $d = $this->getContext()->getLang()->date( $timestamp, true );
-                       $t = $this->getContext()->getLang()->time( $timestamp, true );
+                       $d = $this->getLang()->date( $timestamp, true );
+                       $t = $this->getLang()->time( $timestamp, true );
                        $s = ' ' . wfMsg( 'lastmodifiedat', $d, $t );
                } else {
                        $s = '';
@@ -1083,7 +1045,7 @@ abstract class Skin {
 
        function showEmailUser( $id ) {
                $targetUser = User::newFromId( $id );
-               return $this->getContext()->getUser()->canSendEmail() && # the sending user must have a confirmed email address
+               return $this->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
        }
 
@@ -1210,7 +1172,7 @@ abstract class Skin {
                global $parserMemc, $wgEnableSidebarCache, $wgSidebarCacheExpiry;
                wfProfileIn( __METHOD__ );
 
-               $key = wfMemcKey( 'sidebar', $this->getContext()->getLang()->getCode() );
+               $key = wfMemcKey( 'sidebar', $this->getLang()->getCode() );
 
                if ( $wgEnableSidebarCache ) {
                        $cachedsidebar = $parserMemc->get( $key );
@@ -1372,9 +1334,9 @@ abstract class Skin {
         * @return MediaWiki message or if no new talk page messages, nothing
         */
        function getNewtalks() {
-               $out = $this->getContext()->getOutput();
+               $out = $this->getOutput();
 
-               $newtalks = $this->getContext()->getUser()->getNewMessageLinks();
+               $newtalks = $this->getUser()->getNewMessageLinks();
                $ntl = '';
 
                if ( count( $newtalks ) == 1 && $newtalks[0]['wiki'] === wfWikiID() ) {
@@ -1469,7 +1431,7 @@ abstract class Skin {
                }
 
                if ( $needParse ) {
-                       $parsed = $this->getContext()->getOutput()->parse( $notice );
+                       $parsed = $this->getOutput()->parse( $notice );
                        $parserMemc->set( $key, array( 'html' => $parsed, 'hash' => md5( $notice ) ), 600 );
                        $notice = $parsed;
                }
@@ -1510,7 +1472,7 @@ abstract class Skin {
                $siteNotice = '';
 
                if ( wfRunHooks( 'SiteNoticeBefore', array( &$siteNotice, $this ) ) ) {
-                       if ( is_object( $this->getContext()->getUser() ) && $this->getContext()->getUser()->isLoggedIn() ) {
+                       if ( is_object( $this->getUser() ) && $this->getUser()->isLoggedIn() ) {
                                $siteNotice = $this->getCachedNotice( 'sitenotice' );
                        } else {
                                $anonNotice = $this->getCachedNotice( 'anonnotice' );