From e02bea0f8b28d7e93e6e9de14b91cf218614966f Mon Sep 17 00:00:00 2001 From: Alex Monk Date: Mon, 23 Apr 2012 00:42:38 +0100 Subject: [PATCH] Done a bit of deglobalisation. Change-Id: Id6e5e18b7bcaecd042528fdb37774a64e439e907 --- includes/Article.php | 313 ++++++++++++++---------------- includes/api/ApiParse.php | 10 +- includes/api/ApiQueryUserInfo.php | 4 +- 3 files changed, 153 insertions(+), 174 deletions(-) diff --git a/includes/Article.php b/includes/Article.php index 393f770bf7..67e1c873bb 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -191,8 +191,6 @@ class Article extends Page { * @return string Return the text of this revision */ public function getContent() { - global $wgUser; - wfProfileIn( __METHOD__ ); if ( $this->mPage->getID() === 0 ) { @@ -204,7 +202,7 @@ class Article extends Page { $text = ''; } } else { - $text = wfMsgExt( $wgUser->isLoggedIn() ? 'noarticletext' : 'noarticletextanon', 'parsemag' ); + $text = wfMsgExt( $this->getContext()->getUser()->isLoggedIn() ? 'noarticletext' : 'noarticletextanon', 'parsemag' ); } wfProfileOut( __METHOD__ ); @@ -235,11 +233,10 @@ class Article extends Page { * @return int The old id for the request */ public function getOldIDFromRequest() { - global $wgRequest; - $this->mRedirectUrl = false; - $oldid = $wgRequest->getIntOrNull( 'oldid' ); + $request = $this->getContext()->getRequest(); + $oldid = $request->getIntOrNull( 'oldid' ); if ( $oldid === null ) { return 0; @@ -262,7 +259,7 @@ class Article extends Page { } } - if ( $wgRequest->getVal( 'direction' ) == 'next' ) { + if ( $request->getVal( 'direction' ) == 'next' ) { $nextid = $this->getTitle()->getNextRevisionID( $oldid ); if ( $nextid ) { $oldid = $nextid; @@ -270,7 +267,7 @@ class Article extends Page { } else { $this->mRedirectUrl = $this->getTitle()->getFullURL( 'redirect=no' ); } - } elseif ( $wgRequest->getVal( 'direction' ) == 'prev' ) { + } elseif ( $request->getVal( 'direction' ) == 'prev' ) { $previd = $this->getTitle()->getPreviousRevisionID( $oldid ); if ( $previd ) { $oldid = $previd; @@ -404,8 +401,7 @@ class Article extends Page { * page of the given title. */ public function view() { - global $wgUser, $wgOut, $wgRequest, $wgParser; - global $wgUseFileCache, $wgUseETag, $wgDebugToolbar; + global $wgParser, $wgUseFileCache, $wgUseETag, $wgDebugToolbar; wfProfileIn( __METHOD__ ); @@ -415,17 +411,19 @@ class Article extends Page { # the first call of this method even if $oldid is used way below. $oldid = $this->getOldID(); + $user = $this->getContext()->getUser(); # Another whitelist check in case getOldID() is altering the title - $permErrors = $this->getTitle()->getUserPermissionsErrors( 'read', $wgUser ); + $permErrors = $this->getTitle()->getUserPermissionsErrors( 'read', $user ); if ( count( $permErrors ) ) { wfDebug( __METHOD__ . ": denied on secondary read check\n" ); wfProfileOut( __METHOD__ ); throw new PermissionsError( 'read', $permErrors ); } + $outputPage = $this->getContext()->getOutput(); # getOldID() may as well want us to redirect somewhere else if ( $this->mRedirectUrl ) { - $wgOut->redirect( $this->mRedirectUrl ); + $outputPage->redirect( $this->mRedirectUrl ); wfDebug( __METHOD__ . ": redirecting due to oldid\n" ); wfProfileOut( __METHOD__ ); @@ -433,7 +431,7 @@ class Article extends Page { } # If we got diff in the query, we want to see a diff page instead of the article. - if ( $wgRequest->getCheck( 'diff' ) ) { + if ( $this->getContext()->getRequest()->getCheck( 'diff' ) ) { wfDebug( __METHOD__ . ": showing diff page\n" ); $this->showDiffPage(); wfProfileOut( __METHOD__ ); @@ -442,17 +440,17 @@ class Article extends Page { } # Set page title (may be overridden by DISPLAYTITLE) - $wgOut->setPageTitle( $this->getTitle()->getPrefixedText() ); + $outputPage->setPageTitle( $this->getTitle()->getPrefixedText() ); - $wgOut->setArticleFlag( true ); + $outputPage->setArticleFlag( true ); # Allow frames by default - $wgOut->allowClickjacking(); + $outputPage->allowClickjacking(); $parserCache = ParserCache::singleton(); $parserOptions = $this->getParserOptions(); # Render printable version, use printable version cache - if ( $wgOut->isPrintable() ) { + if ( $outputPage->isPrintable() ) { $parserOptions->setIsPrintable( true ); $parserOptions->setEditSection( false ); } elseif ( !$this->isCurrent() || !$this->getTitle()->quickUserCan( 'edit' ) ) { @@ -462,11 +460,11 @@ class Article extends Page { # Try client and file cache if ( !$wgDebugToolbar && $oldid === 0 && $this->mPage->checkTouched() ) { if ( $wgUseETag ) { - $wgOut->setETag( $parserCache->getETag( $this, $parserOptions ) ); + $outputPage->setETag( $parserCache->getETag( $this, $parserOptions ) ); } # Is it client cached? - if ( $wgOut->checkLastModified( $this->mPage->getTouched() ) ) { + if ( $outputPage->checkLastModified( $this->mPage->getTouched() ) ) { wfDebug( __METHOD__ . ": done 304\n" ); wfProfileOut( __METHOD__ ); @@ -475,8 +473,8 @@ class Article extends Page { } elseif ( $wgUseFileCache && $this->tryFileCache() ) { wfDebug( __METHOD__ . ": done file cache\n" ); # tell wgOut that output is taken care of - $wgOut->disable(); - $this->mPage->doViewUpdates( $wgUser ); + $outputPage->disable(); + $this->mPage->doViewUpdates( $user ); wfProfileOut( __METHOD__ ); return; @@ -486,7 +484,7 @@ class Article extends Page { # Should the parser cache be used? $useParserCache = $this->mPage->isParserCacheUsed( $parserOptions, $oldid ); wfDebug( 'Article::view using parser cache: ' . ( $useParserCache ? 'yes' : 'no' ) . "\n" ); - if ( $wgUser->getStubThreshold() ) { + if ( $user->getStubThreshold() ) { wfIncrStats( 'pcache_miss_stub' ); } @@ -524,14 +522,14 @@ class Article extends Page { } else { wfDebug( __METHOD__ . ": showing parser cache contents\n" ); } - $wgOut->addParserOutput( $this->mParserOutput ); + $outputPage->addParserOutput( $this->mParserOutput ); # Ensure that UI elements requiring revision ID have # the correct version information. - $wgOut->setRevisionId( $this->mPage->getLatest() ); + $outputPage->setRevisionId( $this->mPage->getLatest() ); # Preload timestamp to avoid a DB hit $cachedTimestamp = $this->mParserOutput->getTimestamp(); if ( $cachedTimestamp !== null ) { - $wgOut->setRevisionTimestamp( $cachedTimestamp ); + $outputPage->setRevisionTimestamp( $cachedTimestamp ); $this->mPage->setTimestamp( $cachedTimestamp ); } $outputDone = true; @@ -555,16 +553,16 @@ class Article extends Page { # Ensure that UI elements requiring revision ID have # the correct version information. - $wgOut->setRevisionId( $this->getRevIdFetched() ); + $outputPage->setRevisionId( $this->getRevIdFetched() ); # Preload timestamp to avoid a DB hit - $wgOut->setRevisionTimestamp( $this->getTimestamp() ); + $outputPage->setRevisionTimestamp( $this->getTimestamp() ); # Pages containing custom CSS or JavaScript get special treatment if ( $this->getTitle()->isCssOrJsPage() || $this->getTitle()->isCssJsSubpage() ) { wfDebug( __METHOD__ . ": showing CSS/JS source\n" ); $this->showCssOrJsPage(); $outputDone = true; - } elseif( !wfRunHooks( 'ArticleViewCustom', array( $this->mContent, $this->getTitle(), $wgOut ) ) ) { + } elseif( !wfRunHooks( 'ArticleViewCustom', array( $this->mContent, $this->getTitle(), $outputPage ) ) ) { # Allow extensions do their own custom view for certain pages $outputDone = true; } else { @@ -573,10 +571,10 @@ class Article extends Page { if ( $rt ) { wfDebug( __METHOD__ . ": showing redirect=no page\n" ); # Viewing a redirect page (e.g. with parameter redirect=no) - $wgOut->addHTML( $this->viewRedirect( $rt ) ); + $outputPage->addHTML( $this->viewRedirect( $rt ) ); # Parse just to get categories, displaytitle, etc. $this->mParserOutput = $wgParser->parse( $text, $this->getTitle(), $parserOptions ); - $wgOut->addParserOutputNoText( $this->mParserOutput ); + $outputPage->addParserOutputNoText( $this->mParserOutput ); $outputDone = true; } } @@ -591,12 +589,12 @@ class Article extends Page { if ( !$poolArticleView->execute() ) { $error = $poolArticleView->getError(); if ( $error ) { - $wgOut->clearHTML(); // for release() errors - $wgOut->enableClientCache( false ); - $wgOut->setRobotPolicy( 'noindex,nofollow' ); + $outputPage->clearHTML(); // for release() errors + $outputPage->enableClientCache( false ); + $outputPage->setRobotPolicy( 'noindex,nofollow' ); $errortext = $error->getWikiText( false, 'view-pool-error' ); - $wgOut->addWikiText( '
' . $errortext . '
' ); + $outputPage->addWikiText( '
' . $errortext . '
' ); } # Connection or timeout error wfProfileOut( __METHOD__ ); @@ -604,12 +602,12 @@ class Article extends Page { } $this->mParserOutput = $poolArticleView->getParserOutput(); - $wgOut->addParserOutput( $this->mParserOutput ); + $outputPage->addParserOutput( $this->mParserOutput ); # Don't cache a dirty ParserOutput object if ( $poolArticleView->getIsDirty() ) { - $wgOut->setSquidMaxage( 0 ); - $wgOut->addHTML( "\n" ); + $outputPage->setSquidMaxage( 0 ); + $outputPage->addHTML( "\n" ); } $outputDone = true; @@ -638,17 +636,17 @@ class Article extends Page { if ( $this->getTitle()->isMainPage() ) { $msg = wfMessage( 'pagetitle-view-mainpage' )->inContentLanguage(); if ( !$msg->isDisabled() ) { - $wgOut->setHTMLTitle( $msg->title( $this->getTitle() )->text() ); + $outputPage->setHTMLTitle( $msg->title( $this->getTitle() )->text() ); } } # Check for any __NOINDEX__ tags on the page using $pOutput $policy = $this->getRobotPolicy( 'view', $pOutput ); - $wgOut->setIndexPolicy( $policy['index'] ); - $wgOut->setFollowPolicy( $policy['follow'] ); + $outputPage->setIndexPolicy( $policy['index'] ); + $outputPage->setFollowPolicy( $policy['follow'] ); $this->showViewFooter(); - $this->mPage->doViewUpdates( $wgUser ); + $this->mPage->doViewUpdates( $user ); wfProfileOut( __METHOD__ ); } @@ -658,11 +656,10 @@ class Article extends Page { * @param $pOutput ParserOutput */ public function adjustDisplayTitle( ParserOutput $pOutput ) { - global $wgOut; # Adjust the title if it was set by displaytitle, -{T|}- or language conversion $titleText = $pOutput->getTitleText(); if ( strval( $titleText ) !== '' ) { - $wgOut->setPageTitle( $titleText ); + $this->getContext()->getOutput()->setPageTitle( $titleText ); } } @@ -671,13 +668,13 @@ class Article extends Page { * Article::view() only, other callers should use the DifferenceEngine class. */ public function showDiffPage() { - global $wgRequest, $wgUser; - - $diff = $wgRequest->getVal( 'diff' ); - $rcid = $wgRequest->getVal( 'rcid' ); - $diffOnly = $wgRequest->getBool( 'diffonly', $wgUser->getOption( 'diffonly' ) ); - $purge = $wgRequest->getVal( 'action' ) == 'purge'; - $unhide = $wgRequest->getInt( 'unhide' ) == 1; + $request = $this->getContext()->getRequest(); + $user = $this->getContext()->getUser(); + $diff = $request->getVal( 'diff' ); + $rcid = $request->getVal( 'rcid' ); + $diffOnly = $request->getBool( 'diffonly', $user->getOption( 'diffonly' ) ); + $purge = $request->getVal( 'action' ) == 'purge'; + $unhide = $request->getInt( 'unhide' ) == 1; $oldid = $this->getOldID(); $de = new DifferenceEngine( $this->getContext(), $oldid, $diff, $rcid, $purge, $unhide ); @@ -687,7 +684,7 @@ class Article extends Page { if ( $diff == 0 || $diff == $this->mPage->getLatest() ) { # Run view updates for current revision only - $this->mPage->doViewUpdates( $wgUser ); + $this->mPage->doViewUpdates( $user ); } } @@ -699,22 +696,21 @@ class Article extends Page { * page views. */ protected function showCssOrJsPage() { - global $wgOut; - $dir = $this->getContext()->getLanguage()->getDir(); $lang = $this->getContext()->getLanguage()->getCode(); - $wgOut->wrapWikiMsg( "
\n$1\n
", + $outputPage = $this->getContext()->getOutput(); + $outputPage->wrapWikiMsg( "
\n$1\n
", 'clearyourcache' ); // Give hooks a chance to customise the output - if ( wfRunHooks( 'ShowRawCssJs', array( $this->mContent, $this->getTitle(), $wgOut ) ) ) { + if ( wfRunHooks( 'ShowRawCssJs', array( $this->mContent, $this->getTitle(), $outputPage ) ) ) { // Wrap the whole lot in a
 and don't parse
 			$m = array();
 			preg_match( '!\.(css|js)$!u', $this->getTitle()->getText(), $m );
-			$wgOut->addHTML( "
\n" );
-			$wgOut->addHTML( htmlspecialchars( $this->mContent ) );
-			$wgOut->addHTML( "\n
\n" ); + $outputPage->addHTML( "
\n" );
+			$outputPage->addHTML( htmlspecialchars( $this->mContent ) );
+			$outputPage->addHTML( "\n
\n" ); } } @@ -726,8 +722,7 @@ class Article extends Page { * TODO: actions other than 'view' */ public function getRobotPolicy( $action, $pOutput ) { - global $wgOut, $wgArticleRobotPolicies, $wgNamespaceRobotPolicies; - global $wgDefaultRobotPolicy, $wgRequest; + global $wgArticleRobotPolicies, $wgNamespaceRobotPolicies, $wgDefaultRobotPolicy; $ns = $this->getTitle()->getNamespace(); @@ -749,13 +744,13 @@ class Article extends Page { 'index' => 'noindex', 'follow' => 'nofollow' ); - } elseif ( $wgOut->isPrintable() ) { + } elseif ( $this->getContext()->getOutput()->isPrintable() ) { # Discourage indexing of printable versions, but encourage following return array( 'index' => 'noindex', 'follow' => 'follow' ); - } elseif ( $wgRequest->getInt( 'curid' ) ) { + } elseif ( $this->getContext()->getRequest()->getInt( 'curid' ) ) { # For ?curid=x urls, disallow indexing return array( 'index' => 'noindex', @@ -824,15 +819,16 @@ class Article extends Page { /** * If this request is a redirect view, send "redirected from" subtitle to - * $wgOut. Returns true if the header was needed, false if this is not a - * redirect view. Handles both local and remote redirects. + * the output. Returns true if the header was needed, false if this is not + * a redirect view. Handles both local and remote redirects. * * @return boolean */ public function showRedirectedFromHeader() { - global $wgOut, $wgRequest, $wgRedirectSources; + global $wgRedirectSources; + $outputPage = $this->getContext()->getOutput(); - $rdfrom = $wgRequest->getVal( 'rdfrom' ); + $rdfrom = $this->getContext()->getRequest()->getVal( 'rdfrom' ); if ( isset( $this->mRedirectedFrom ) ) { // This is an internally redirected page view. @@ -845,21 +841,21 @@ class Article extends Page { array( 'redirect' => 'no' ) ); - $wgOut->addSubtitle( wfMessage( 'redirectedfrom' )->rawParams( $redir ) ); + $outputPage->addSubtitle( wfMessage( 'redirectedfrom' )->rawParams( $redir ) ); // Set the fragment if one was specified in the redirect if ( strval( $this->getTitle()->getFragment() ) != '' ) { $fragment = Xml::escapeJsString( $this->getTitle()->getFragmentForURL() ); - $wgOut->addInlineScript( "redirectToFragment(\"$fragment\");" ); + $outputPage->addInlineScript( "redirectToFragment(\"$fragment\");" ); } // Add a tag - $wgOut->addLink( array( 'rel' => 'canonical', + $outputPage->addLink( array( 'rel' => 'canonical', 'href' => $this->getTitle()->getLocalURL() ) ); - // Tell $wgOut the user arrived at this article through a redirect - $wgOut->setRedirectedFrom( $this->mRedirectedFrom ); + // Tell the output object that the user arrived at this article through a redirect + $outputPage->setRedirectedFrom( $this->mRedirectedFrom ); return true; } @@ -868,7 +864,7 @@ class Article extends Page { // If it was reported from a trusted site, supply a backlink. if ( $wgRedirectSources && preg_match( $wgRedirectSources, $rdfrom ) ) { $redir = Linker::makeExternalLink( $rdfrom, $rdfrom ); - $wgOut->addSubtitle( wfMessage( 'redirectedfrom' )->rawParams( $redir ) ); + $outputPage->addSubtitle( wfMessage( 'redirectedfrom' )->rawParams( $redir ) ); return true; } @@ -882,11 +878,9 @@ class Article extends Page { * [[MediaWiki:Talkpagetext]]. For Article::view(). */ public function showNamespaceHeader() { - global $wgOut; - if ( $this->getTitle()->isTalkPage() ) { if ( !wfMessage( 'talkpageheader' )->isDisabled() ) { - $wgOut->wrapWikiMsg( "
\n$1\n
", array( 'talkpageheader' ) ); + $this->getContext()->getOutput()->wrapWikiMsg( "
\n$1\n
", array( 'talkpageheader' ) ); } } } @@ -895,11 +889,9 @@ class Article extends Page { * Show the footer section of an ordinary page view */ public function showViewFooter() { - global $wgOut; - # check if we're displaying a [[User talk:x.x.x.x]] anonymous talk page if ( $this->getTitle()->getNamespace() == NS_USER_TALK && IP::isValid( $this->getTitle()->getText() ) ) { - $wgOut->addWikiMsg( 'anontalkpagetext' ); + $this->getContext()->getOutput()->addWikiMsg( 'anontalkpagetext' ); } # If we have been passed an &rcid= parameter, we want to give the user a @@ -916,18 +908,18 @@ class Article extends Page { * desired, does nothing. */ public function showPatrolFooter() { - global $wgOut, $wgRequest, $wgUser; - - $rcid = $wgRequest->getVal( 'rcid' ); + $request = $this->getContext()->getRequest(); + $outputPage = $this->getContext()->getOutput(); + $rcid = $request->getVal( 'rcid' ); if ( !$rcid || !$this->getTitle()->quickUserCan( 'patrol' ) ) { return; } - $token = $wgUser->getEditToken( $rcid ); - $wgOut->preventClickjacking(); + $token = $request->getUser()->getEditToken( $rcid ); + $outputPage->preventClickjacking(); - $wgOut->addHTML( + $outputPage->addHTML( "