r85226 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r85225‎ | r85226 | r85227 >
Date:03:59, 3 April 2011
Author:dantman
Status:resolved (Comments)
Tags:
Comment:
Start better utalizing OutputPage as the focal point for things related to the output of the page. Like getTitle use $out->get{User,Skin} instead of $wgUser and $wgUser->getSkin() for things where the user or skin is being used for output generation back to $out instead of using globals with bad structure.
Modified paths:
  • /trunk/phase3/includes/Article.php (modified) (history)
  • /trunk/phase3/includes/OutputPage.php (modified) (history)
  • /trunk/phase3/includes/SpecialPage.php (modified) (history)
  • /trunk/phase3/includes/api/ApiParse.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Article.php
@@ -1580,7 +1580,7 @@
15811581 * Builds trackback links for article display if $wgUseTrackbacks is set to true
15821582 */
15831583 public function addTrackbacks() {
1584 - global $wgOut, $wgUser;
 1584+ global $wgOut;
15851585
15861586 $dbr = wfGetDB( DB_SLAVE );
15871587 $tbs = $dbr->select( 'trackbacks',
@@ -1598,9 +1598,9 @@
15991599 foreach ( $tbs as $o ) {
16001600 $rmvtxt = "";
16011601
1602 - if ( $wgUser->isAllowed( 'trackback' ) ) {
 1602+ if ( $wgOut->getUser()->isAllowed( 'trackback' ) ) {
16031603 $delurl = $this->mTitle->getFullURL( "action=deletetrackback&tbid=" .
1604 - $o->tb_id . "&token=" . urlencode( $wgUser->editToken() ) );
 1604+ $o->tb_id . "&token=" . urlencode( $wgOut->getUser()->editToken() ) );
16051605 $rmvtxt = wfMsg( 'trackbackremove', htmlspecialchars( $delurl ) );
16061606 }
16071607
@@ -1620,15 +1620,15 @@
16211621 * Removes trackback record for current article from trackbacks table
16221622 */
16231623 public function deletetrackback() {
1624 - global $wgUser, $wgRequest, $wgOut;
 1624+ global $wgRequest, $wgOut;
16251625
1626 - if ( !$wgUser->matchEditToken( $wgRequest->getVal( 'token' ) ) ) {
 1626+ if ( !$wgOut->getUser()->matchEditToken( $wgRequest->getVal( 'token' ) ) ) {
16271627 $wgOut->addWikiMsg( 'sessionfailure' );
16281628
16291629 return;
16301630 }
16311631
1632 - $permission_errors = $this->mTitle->getUserPermissionsErrors( 'delete', $wgUser );
 1632+ $permission_errors = $this->mTitle->getUserPermissionsErrors( 'delete', $wgOut->getUser() );
16331633
16341634 if ( count( $permission_errors ) ) {
16351635 $wgOut->showPermissionsErrorPage( $permission_errors );
@@ -1658,9 +1658,9 @@
16591659 * Handle action=purge
16601660 */
16611661 public function purge() {
1662 - global $wgUser, $wgRequest, $wgOut;
 1662+ global $wgRequest, $wgOut;
16631663
1664 - if ( $wgUser->isAllowed( 'purge' ) || $wgRequest->wasPosted() ) {
 1664+ if ( $wgOut->getUser()->isAllowed( 'purge' ) || $wgRequest->wasPosted() ) {
16651665 //FIXME: shouldn't this be in doPurge()?
16661666 if ( wfRunHooks( 'ArticlePurge', array( &$this ) ) ) {
16671667 $this->doPurge();
@@ -2273,14 +2273,14 @@
22742274 * Mark this particular edit/page as patrolled
22752275 */
22762276 public function markpatrolled() {
2277 - global $wgOut, $wgUser, $wgRequest;
 2277+ global $wgOut, $wgRequest;
22782278
22792279 $wgOut->setRobotPolicy( 'noindex,nofollow' );
22802280
22812281 # If we haven't been given an rc_id value, we can't do anything
22822282 $rcid = (int) $wgRequest->getVal( 'rcid' );
22832283
2284 - if ( !$wgUser->matchEditToken( $wgRequest->getVal( 'token' ), $rcid ) ) {
 2284+ if ( !$wgOut->getUser()->matchEditToken( $wgRequest->getVal( 'token' ), $rcid ) ) {
22852285 $wgOut->showErrorPage( 'sessionfailure-title', 'sessionfailure' );
22862286 return;
22872287 }
@@ -2333,9 +2333,9 @@
23342334 * User-interface handler for the "watch" action
23352335 */
23362336 public function watch() {
2337 - global $wgUser, $wgOut;
 2337+ global $wgOut;
23382338
2339 - if ( $wgUser->isAnon() ) {
 2339+ if ( $wgOut->getUser()->isAnon() ) {
23402340 $wgOut->showErrorPage( 'watchnologin', 'watchnologintext' );
23412341 return;
23422342 }
@@ -2380,9 +2380,9 @@
23812381 * User interface handler for the "unwatch" action.
23822382 */
23832383 public function unwatch() {
2384 - global $wgUser, $wgOut;
 2384+ global $wgOut;
23852385
2386 - if ( $wgUser->isAnon() ) {
 2386+ if ( $wgOut->getUser()->isAnon() ) {
23872387 $wgOut->showErrorPage( 'watchnologin', 'watchnologintext' );
23882388 return;
23892389 }
@@ -2742,10 +2742,10 @@
27432743 * UI entry point for page deletion
27442744 */
27452745 public function delete() {
2746 - global $wgUser, $wgOut, $wgRequest;
 2746+ global $wgOut, $wgRequest;
27472747
27482748 $confirm = $wgRequest->wasPosted() &&
2749 - $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) );
 2749+ $wgOut->getUser()->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) );
27502750
27512751 $this->DeleteReasonList = $wgRequest->getText( 'wpDeleteReasonList', 'other' );
27522752 $this->DeleteReason = $wgRequest->getText( 'wpReason' );
@@ -2760,7 +2760,7 @@
27612761 }
27622762
27632763 # Flag to hide all contents of the archived revisions
2764 - $suppress = $wgRequest->getVal( 'wpSuppress' ) && $wgUser->isAllowed( 'suppressrevision' );
 2764+ $suppress = $wgRequest->getVal( 'wpSuppress' ) && $wgOut->getUser()->isAllowed( 'suppressrevision' );
27652765
27662766 # This code desperately needs to be totally rewritten
27672767
@@ -2772,7 +2772,7 @@
27732773 }
27742774
27752775 # Check permissions
2776 - $permission_errors = $this->mTitle->getUserPermissionsErrors( 'delete', $wgUser );
 2776+ $permission_errors = $this->mTitle->getUserPermissionsErrors( 'delete', $wgOut->getUser() );
27772777
27782778 if ( count( $permission_errors ) > 0 ) {
27792779 $wgOut->showPermissionsErrorPage( $permission_errors );
@@ -2818,7 +2818,7 @@
28192819 if ( $confirm ) {
28202820 $this->doDelete( $reason, $suppress );
28212821
2822 - if ( $wgRequest->getCheck( 'wpWatch' ) && $wgUser->isLoggedIn() ) {
 2822+ if ( $wgRequest->getCheck( 'wpWatch' ) && $wgOut->getUser()->isLoggedIn() ) {
28232823 $this->doWatch();
28242824 } elseif ( $this->mTitle->userIsWatching() ) {
28252825 $this->doUnwatch();
@@ -2837,7 +2837,7 @@
28382838 if ( $hasHistory && !$confirm ) {
28392839 global $wgLang;
28402840
2841 - $skin = $wgUser->getSkin();
 2841+ $skin = $wgOut->getSkin();
28422842 $revisions = $this->estimateRevisionCount();
28432843 //FIXME: lego
28442844 $wgOut->addHTML( '<strong class="mw-delete-warning-revisions">' .
@@ -2944,18 +2944,18 @@
29452945 * @param $reason String: prefilled reason
29462946 */
29472947 public function confirmDelete( $reason ) {
2948 - global $wgOut, $wgUser;
 2948+ global $wgOut;
29492949
29502950 wfDebug( "Article::confirmDelete\n" );
29512951
2952 - $deleteBackLink = $wgUser->getSkin()->linkKnown( $this->mTitle );
 2952+ $deleteBackLink = $wgOut->getSkin()->linkKnown( $this->mTitle );
29532953 $wgOut->setSubtitle( wfMsgHtml( 'delete-backlink', $deleteBackLink ) );
29542954 $wgOut->setRobotPolicy( 'noindex,nofollow' );
29552955 $wgOut->addWikiMsg( 'confirmdeletetext' );
29562956
29572957 wfRunHooks( 'ArticleConfirmDelete', array( $this, $wgOut, &$reason ) );
29582958
2959 - if ( $wgUser->isAllowed( 'suppressrevision' ) ) {
 2959+ if ( $wgOut->getUser()->isAllowed( 'suppressrevision' ) ) {
29602960 $suppress = "<tr id=\"wpDeleteSuppressRow\">
29612961 <td></td>
29622962 <td class='mw-input'><strong>" .
@@ -2966,7 +2966,7 @@
29672967 } else {
29682968 $suppress = '';
29692969 }
2970 - $checkWatch = $wgUser->getBoolOption( 'watchdeletion' ) || $this->mTitle->userIsWatching();
 2970+ $checkWatch = $wgOut->getUser()->getBoolOption( 'watchdeletion' ) || $this->mTitle->userIsWatching();
29712971
29722972 $form = Xml::openElement( 'form', array( 'method' => 'post',
29732973 'action' => $this->mTitle->getLocalURL( 'action=delete' ), 'id' => 'deleteconfirm' ) ) .
@@ -2999,7 +2999,7 @@
30003000 </tr>";
30013001
30023002 # Disallow watching if user is not logged in
3003 - if ( $wgUser->isLoggedIn() ) {
 3003+ if ( $wgOut->getUser()->isLoggedIn() ) {
30043004 $form .= "
30053005 <tr>
30063006 <td></td>
@@ -3021,11 +3021,11 @@
30223022 </tr>" .
30233023 Xml::closeElement( 'table' ) .
30243024 Xml::closeElement( 'fieldset' ) .
3025 - Html::hidden( 'wpEditToken', $wgUser->editToken() ) .
 3025+ Html::hidden( 'wpEditToken', $wgOut->getUser()->editToken() ) .
30263026 Xml::closeElement( 'form' );
30273027
3028 - if ( $wgUser->isAllowed( 'editinterface' ) ) {
3029 - $skin = $wgUser->getSkin();
 3028+ if ( $wgOut->getUser()->isAllowed( 'editinterface' ) ) {
 3029+ $skin = $wgOut->getSkin();
30303030 $title = Title::makeTitle( NS_MEDIAWIKI, 'Deletereason-dropdown' );
30313031 $link = $skin->link(
30323032 $title,
Index: trunk/phase3/includes/OutputPage.php
@@ -193,6 +193,9 @@
194194 /// Stores a Title object (of the current page).
195195 protected $mTitle = null;
196196
 197+ /// Stores a User object (the one the page is being rendered for)
 198+ protected $mUser = null;
 199+
197200 /**
198201 * An array of stylesheet filenames (relative from skins path), with options
199202 * for CSS media, IE conditions, and RTL/LTR direction.
@@ -549,7 +552,7 @@
550553 * @return Boolean: true iff cache-ok headers was sent.
551554 */
552555 public function checkLastModified( $timestamp ) {
553 - global $wgCachePages, $wgCacheEpoch, $wgUser, $wgRequest;
 556+ global $wgCachePages, $wgCacheEpoch, $wgRequest;
554557
555558 if ( !$timestamp || $timestamp == '19700101000000' ) {
556559 wfDebug( __METHOD__ . ": CACHE DISABLED, NO TIMESTAMP\n" );
@@ -559,7 +562,7 @@
560563 wfDebug( __METHOD__ . ": CACHE DISABLED\n", false );
561564 return false;
562565 }
563 - if( $wgUser->getOption( 'nocache' ) ) {
 566+ if( $this->getUser()->getOption( 'nocache' ) ) {
564567 wfDebug( __METHOD__ . ": USER DISABLED CACHE\n", false );
565568 return false;
566569 }
@@ -567,7 +570,7 @@
568571 $timestamp = wfTimestamp( TS_MW, $timestamp );
569572 $modifiedTimes = array(
570573 'page' => $timestamp,
571 - 'user' => $wgUser->getTouched(),
 574+ 'user' => $this->getUser()->getTouched(),
572575 'epoch' => $wgCacheEpoch
573576 );
574577 wfRunHooks( 'OutputPageCheckLastModified', array( &$modifiedTimes ) );
@@ -773,6 +776,40 @@
774777 }
775778
776779 /**
 780+ * Set the User object to use
 781+ *
 782+ * @param $u User object
 783+ */
 784+ public function setUser( $u ) {
 785+ $this->mUser = $u;
 786+ }
 787+
 788+ /**
 789+ * Get the User object used in this instance
 790+ *
 791+ * @return User
 792+ */
 793+ public function getUser() {
 794+ if ( !isset($this->mUser) ) {
 795+ wfDebug( __METHOD__ . " called and \$mUser is null. Return \$wgUser for sanity\n" );
 796+ global $wgUser;
 797+ return $wgUser;
 798+ }
 799+ return $this->mUser;
 800+ }
 801+
 802+ /**
 803+ * Get the Skin object used to render this instance
 804+ *
 805+ * @return Skin
 806+ */
 807+ public function getSkin() {
 808+ // For now we'll just proxy to the user. In the future a saner location for
 809+ // organizing what skin to use may be chosen
 810+ return $this->getUser()->getSkin();
 811+ }
 812+
 813+ /**
777814 * Replace the subtile with $str
778815 *
779816 * @param $str String: new value of the subtitle
@@ -1009,7 +1046,7 @@
10101047 * @param $categories Array mapping category name => sort key
10111048 */
10121049 public function addCategoryLinks( $categories ) {
1013 - global $wgUser, $wgContLang;
 1050+ global $wgContLang;
10141051
10151052 if ( !is_array( $categories ) || count( $categories ) == 0 ) {
10161053 return;
@@ -1048,7 +1085,6 @@
10491086
10501087 # Add the remaining categories to the skin
10511088 if ( wfRunHooks( 'OutputPageMakeCategoryLinks', array( &$this, $categories, &$this->mCategoryLinks ) ) ) {
1052 - $sk = $wgUser->getSkin();
10531089 foreach ( $categories as $category => $type ) {
10541090 $origcategory = $category;
10551091 $title = Title::makeTitleSafe( NS_CATEGORY, $category );
@@ -1060,7 +1096,7 @@
10611097 }
10621098 $text = $wgContLang->convertHtml( $title->getText() );
10631099 $this->mCategories[] = $title->getText();
1064 - $this->mCategoryLinks[$type][] = $sk->link( $title, $text );
 1100+ $this->mCategoryLinks[$type][] = $this->getSkin()->link( $title, $text );
10651101 }
10661102 }
10671103 }
@@ -1768,7 +1804,7 @@
17691805 * the object, let's actually output it:
17701806 */
17711807 public function output() {
1772 - global $wgUser, $wgOutputEncoding, $wgRequest;
 1808+ global $wgOutputEncoding, $wgRequest;
17731809 global $wgLanguageCode, $wgDebugRedirects, $wgMimeType;
17741810
17751811 if( $this->mDoNothing ) {
@@ -1826,7 +1862,7 @@
18271863 } else {
18281864 $this->addDefaultModules();
18291865
1830 - $sk = $wgUser->getSkin( $this->getTitle() );
 1866+ $sk = $this->getSkin( $this->getTitle() );
18311867
18321868 // Hook that allows last minute changes to the output page, e.g.
18331869 // adding of CSS or Javascript by extensions.
@@ -1868,29 +1904,29 @@
18691905 * @return nothing
18701906 */
18711907 function blockedPage( $return = true ) {
1872 - global $wgUser, $wgContLang, $wgLang;
 1908+ global $wgContLang, $wgLang;
18731909
18741910 $this->setPageTitle( wfMsg( 'blockedtitle' ) );
18751911 $this->setRobotPolicy( 'noindex,nofollow' );
18761912 $this->setArticleRelated( false );
18771913
1878 - $name = $wgUser->blockedBy();
1879 - $reason = $wgUser->blockedFor();
 1914+ $name = $this->getUser()->blockedBy();
 1915+ $reason = $this->getUser()->blockedFor();
18801916 if( $reason == '' ) {
18811917 $reason = wfMsg( 'blockednoreason' );
18821918 }
18831919 $blockTimestamp = $wgLang->timeanddate(
1884 - wfTimestamp( TS_MW, $wgUser->mBlock->mTimestamp ), true
 1920+ wfTimestamp( TS_MW, $this->getUser()->mBlock->mTimestamp ), true
18851921 );
18861922 $ip = wfGetIP();
18871923
18881924 $link = '[[' . $wgContLang->getNsText( NS_USER ) . ":{$name}|{$name}]]";
18891925
1890 - $blockid = $wgUser->mBlock->getId();
 1926+ $blockid = $this->getUser()->mBlock->getId();
18911927
1892 - $blockExpiry = $wgLang->formatExpiry( $wgUser->mBlock->mExpiry );
 1928+ $blockExpiry = $wgLang->formatExpiry( $this->getUser()->mBlock->mExpiry );
18931929
1894 - if ( $wgUser->mBlock->mAuto ) {
 1930+ if ( $this->getUser()->mBlock->mAuto ) {
18951931 $msg = 'autoblockedtext';
18961932 } else {
18971933 $msg = 'blockedtext';
@@ -1898,7 +1934,7 @@
18991935
19001936 /* $ip returns who *is* being blocked, $intended contains who was meant to be blocked.
19011937 * This could be a username, an IP range, or a single IP. */
1902 - $intended = $wgUser->mBlock->getTarget();
 1938+ $intended = $this->getUser()->mBlock->getTarget();
19031939
19041940 $this->addWikiMsg(
19051941 $msg, $link, $reason, $ip, $name, $blockid, $blockExpiry,
@@ -2004,22 +2040,18 @@
20052041 * Produce the stock "please login to use the wiki" page
20062042 */
20072043 public function loginToUse() {
2008 - global $wgUser;
2009 -
2010 - if( $wgUser->isLoggedIn() ) {
 2044+ if( $this->getUser()->isLoggedIn() ) {
20112045 $this->permissionRequired( 'read' );
20122046 return;
20132047 }
20142048
2015 - $skin = $wgUser->getSkin();
2016 -
20172049 $this->setPageTitle( wfMsg( 'loginreqtitle' ) );
20182050 $this->setHtmlTitle( wfMsg( 'errorpagetitle' ) );
20192051 $this->setRobotPolicy( 'noindex,nofollow' );
20202052 $this->setArticleRelated( false );
20212053
20222054 $loginTitle = SpecialPage::getTitleFor( 'Userlogin' );
2023 - $loginLink = $skin->link(
 2055+ $loginLink = $this->getSkin()->link(
20242056 $loginTitle,
20252057 wfMsgHtml( 'loginreqlink' ),
20262058 array(),
@@ -2095,9 +2127,6 @@
20962128 * @param $action String: action that was denied or null if unknown
20972129 */
20982130 public function readOnlyPage( $source = null, $protected = false, $reasons = array(), $action = null ) {
2099 - global $wgUser;
2100 - $skin = $wgUser->getSkin();
2101 -
21022131 $this->setRobotPolicy( 'noindex,nofollow' );
21032132 $this->setArticleRelated( false );
21042133
@@ -2112,7 +2141,7 @@
21132142 if( $source ) {
21142143 $this->setPageTitle( wfMsg( 'viewsource' ) );
21152144 $this->setSubtitle(
2116 - wfMsg( 'viewsourcefor', $skin->linkKnown( $this->getTitle() ) )
 2145+ wfMsg( 'viewsourcefor', $this->getSkin()->linkKnown( $this->getTitle() ) )
21172146 );
21182147 } else {
21192148 $this->setPageTitle( wfMsg( 'badaccess' ) );
@@ -2132,14 +2161,14 @@
21332162 $params = array(
21342163 'id' => 'wpTextbox1',
21352164 'name' => 'wpTextbox1',
2136 - 'cols' => $wgUser->getOption( 'cols' ),
2137 - 'rows' => $wgUser->getOption( 'rows' ),
 2165+ 'cols' => $this->getUser()->getOption( 'cols' ),
 2166+ 'rows' => $this->getUser()->getOption( 'rows' ),
21382167 'readonly' => 'readonly'
21392168 );
21402169 $this->addHTML( Html::element( 'textarea', $params, $source ) );
21412170
21422171 // Show templates used by this article
2143 - $skin = $wgUser->getSkin();
 2172+ $skin = $this->getSkin();
21442173 $article = new Article( $this->getTitle() );
21452174 $this->addHTML( "<div class='templatesUsed'>
21462175 {$skin->formatTemplates( $article->getUsedTemplates() )}
@@ -2213,11 +2242,10 @@
22142243 * @param $text String text of the link (input is not escaped)
22152244 */
22162245 public function addReturnTo( $title, $query = array(), $text = null ) {
2217 - global $wgUser;
22182246 $this->addLink( array( 'rel' => 'next', 'href' => $title->getFullURL() ) );
22192247 $link = wfMsgHtml(
22202248 'returnto',
2221 - $wgUser->getSkin()->link( $title, $text, array(), $query )
 2249+ $this->getSkin()->link( $title, $text, array(), $query )
22222250 );
22232251 $this->addHTML( "<p id=\"mw-returnto\">{$link}</p>\n" );
22242252 }
@@ -2265,7 +2293,7 @@
22662294 public function headElement( Skin $sk, $includeStyle = true ) {
22672295 global $wgOutputEncoding, $wgMimeType;
22682296 global $wgUseTrackbacks, $wgHtml5;
2269 - global $wgUser, $wgRequest, $wgLang;
 2297+ global $wgRequest, $wgLang;
22702298
22712299 if ( $sk->commonPrintStylesheet() ) {
22722300 $this->addModuleStyles( 'mediawiki.legacy.wikiprintable' );
@@ -2310,7 +2338,7 @@
23112339 if (
23122340 $this->getTitle()->getNamespace() != NS_SPECIAL &&
23132341 in_array( $action, array( 'view', 'purge' ) ) &&
2314 - $wgUser->getOption( 'editondblclick' )
 2342+ $this->getUser()->getOption( 'editondblclick' )
23152343 )
23162344 {
23172345 $bodyAttrs['ondblclick'] = "document.location = '" . Xml::escapeJsString( $this->getTitle()->getEditURL() ) . "'";
@@ -2339,7 +2367,7 @@
23402368 * Add the default ResourceLoader modules to this object
23412369 */
23422370 private function addDefaultModules() {
2343 - global $wgUser, $wgIncludeLegacyJavaScript,
 2371+ global $wgIncludeLegacyJavaScript,
23442372 $wgUseAjax, $wgAjaxWatch, $wgEnableMWSuggest;
23452373
23462374 // Add base resources
@@ -2354,16 +2382,16 @@
23552383
23562384 wfRunHooks( 'AjaxAddScript', array( &$this ) );
23572385
2358 - if( $wgAjaxWatch && $wgUser->isLoggedIn() ) {
 2386+ if( $wgAjaxWatch && $this->getUser()->isLoggedIn() ) {
23592387 $this->addModules( 'mediawiki.action.watch.ajax' );
23602388 }
23612389
2362 - if ( $wgEnableMWSuggest && !$wgUser->getOption( 'disablesuggest', false ) ) {
 2390+ if ( $wgEnableMWSuggest && !$this->getUser()->getOption( 'disablesuggest', false ) ) {
23632391 $this->addModules( 'mediawiki.legacy.mwsuggest' );
23642392 }
23652393 }
23662394
2367 - if( $wgUser->getBoolOption( 'editsectiononrightclick' ) ) {
 2395+ if( $this->getUser()->getBoolOption( 'editsectiononrightclick' ) ) {
23682396 $this->addModules( 'mediawiki.action.view.rightClickEdit' );
23692397 }
23702398 }
@@ -2389,7 +2417,7 @@
23902418 * @return string html <script> and <style> tags
23912419 */
23922420 protected function makeResourceLoaderLink( Skin $skin, $modules, $only, $useESI = false ) {
2393 - global $wgUser, $wgLang, $wgLoadScript, $wgResourceLoaderUseESI,
 2421+ global $wgLang, $wgLoadScript, $wgResourceLoaderUseESI,
23942422 $wgResourceLoaderInlinePrivateModules, $wgRequest;
23952423 // Lazy-load ResourceLoader
23962424 // TODO: Should this be a static function of ResourceLoader instead?
@@ -2454,8 +2482,8 @@
24552483 foreach ( $groups as $group => $modules ) {
24562484 $query = $baseQuery;
24572485 // Special handling for user-specific groups
2458 - if ( ( $group === 'user' || $group === 'private' ) && $wgUser->isLoggedIn() ) {
2459 - $query['user'] = $wgUser->getName();
 2486+ if ( ( $group === 'user' || $group === 'private' ) && $this->getUser()->isLoggedIn() ) {
 2487+ $query['user'] = $this->getUser()->getName();
24602488 }
24612489
24622490 // Create a fake request based on the one we are about to make so modules return
@@ -2541,7 +2569,7 @@
25422570 * @return String: HTML fragment
25432571 */
25442572 function getHeadScripts( Skin $sk ) {
2545 - global $wgUser, $wgRequest, $wgUseSiteJs, $wgAllowUserJs;
 2573+ global $wgRequest, $wgUseSiteJs, $wgAllowUserJs;
25462574
25472575 // Startup - this will immediately load jquery and mediawiki modules
25482576 $scripts = $this->makeResourceLoaderLink( $sk, 'startup', ResourceLoaderModule::TYPE_SCRIPTS, true );
@@ -2571,13 +2599,13 @@
25722600 // Add site JS if enabled
25732601 if ( $wgUseSiteJs ) {
25742602 $scripts .= $this->makeResourceLoaderLink( $sk, 'site', ResourceLoaderModule::TYPE_SCRIPTS );
2575 - if( $wgUser->isLoggedIn() ){
 2603+ if( $this->getUser()->isLoggedIn() ){
25762604 $userScripts[] = 'user.groups';
25772605 }
25782606 }
25792607
25802608 // Add user JS if enabled
2581 - if ( $wgAllowUserJs && $wgUser->isLoggedIn() ) {
 2609+ if ( $wgAllowUserJs && $this->getUser()->isLoggedIn() ) {
25822610 $action = $wgRequest->getVal( 'action', 'view' );
25832611 if( $this->mTitle && $this->mTitle->isJsSubpage() && $sk->userCanPreview( $action ) ) {
25842612 # XXX: additional security check/prompt?
@@ -2602,7 +2630,7 @@
26032631 * have to be purged on configuration changes.
26042632 */
26052633 protected function getJSVars() {
2606 - global $wgUser, $wgRequest, $wgUseAjax, $wgEnableMWSuggest, $wgContLang;
 2634+ global $wgRequest, $wgUseAjax, $wgEnableMWSuggest, $wgContLang;
26072635
26082636 $title = $this->getTitle();
26092637 $ns = $title->getNamespace();
@@ -2624,8 +2652,8 @@
26252653 'wgArticleId' => $title->getArticleId(),
26262654 'wgIsArticle' => $this->isArticle(),
26272655 'wgAction' => $wgRequest->getText( 'action', 'view' ),
2628 - 'wgUserName' => $wgUser->isAnon() ? null : $wgUser->getName(),
2629 - 'wgUserGroups' => $wgUser->getEffectiveGroups(),
 2656+ 'wgUserName' => $this->getUser()->isAnon() ? null : $this->getUser()->getName(),
 2657+ 'wgUserGroups' => $this->getUser()->getEffectiveGroups(),
26302658 'wgCategories' => $this->getCategories(),
26312659 'wgBreakFrames' => $this->getFrameOptions() == 'DENY',
26322660 );
@@ -2635,8 +2663,8 @@
26362664 foreach ( $title->getRestrictionTypes() as $type ) {
26372665 $vars['wgRestriction' . ucfirst( $type )] = $title->getRestrictions( $type );
26382666 }
2639 - if ( $wgUseAjax && $wgEnableMWSuggest && !$wgUser->getOption( 'disablesuggest', false ) ) {
2640 - $vars['wgSearchNamespaces'] = SearchEngine::userNamespaces( $wgUser );
 2667+ if ( $wgUseAjax && $wgEnableMWSuggest && !$this->getUser()->getOption( 'disablesuggest', false ) ) {
 2668+ $vars['wgSearchNamespaces'] = SearchEngine::userNamespaces( $this->getUser() );
26412669 }
26422670
26432671 // Allow extensions to add their custom variables to the global JS variables
Index: trunk/phase3/includes/api/ApiParse.php
@@ -252,6 +252,7 @@
253253
254254 if ( isset( $prop['headitems'] ) || isset( $prop['headhtml'] ) ) {
255255 $out = new OutputPage;
 256+ $out->setUser( $wgUser );
256257 $out->addParserOutputNoText( $p_result );
257258 $userSkin = $wgUser->getSkin();
258259
Index: trunk/phase3/includes/SpecialPage.php
@@ -619,12 +619,13 @@
620620 * @return String: HTML fragment
621621 */
622622 static function capturePath( &$title ) {
623 - global $wgOut, $wgTitle;
 623+ global $wgOut, $wgTitle, $wgUser;
624624
625625 $oldTitle = $wgTitle;
626626 $oldOut = $wgOut;
627627 $wgOut = new OutputPage;
628628 $wgOut->setTitle( $title );
 629+ $wgOut->setUser( $wgUser ); # for now, there may be a better idea in the future
629630
630631 $ret = SpecialPage::executePath( $title, true );
631632 if ( $ret === true ) {

Sign-offs

UserFlagDate
Nikerabbitinspected15:12, 3 April 2011
Nikerabbittested15:12, 3 April 2011

Follow-up revisions

RevisionCommit summaryAuthorDate
r85234Follow-up r85226, r85227: add @since annotationsnikerabbit08:33, 3 April 2011
r90933Follow-up r85226: use getContext()->getUser() instead of $wgOut->getUser()aaron03:51, 28 June 2011

Comments

#Comment by IAlex (talk | contribs)   06:26, 3 April 2011

I like the fact to less rely on global objects, but I would much prefer centralising all this stuff in a "context" object as described in Requests for comment/Context object.

#Comment by Dantman (talk | contribs)   06:38, 3 April 2011

Hmmm... ok, that is a good idea. Though after a look over that I think this api is fine enough for now. Even after we move to something like that special pages will probably still use $this->get{Output,Skin,User}() helpers since the shortcuts are cleaner to use. So even when move to a context object SpecialPage will have the same api, we just have to make some unnoticeable backend changes. OutputPage will probably have a context object of it's own and likewise have some helper proxy methods. So I think this should be fine for now, it's a step closer to that context api and not incompatible with it.

Status & tagging log