r100905 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r100904‎ | r100905 | r100906 >
Date:23:27, 26 October 2011
Author:johnduhart
Status:ok (Comments)
Tags:
Comment:
Adding context to the API

This will probably break something somewhere so when it does please yell at me on IRC and I'll fix it.
Modified paths:
  • /trunk/phase3/includes/api/ApiBase.php (modified) (history)
  • /trunk/phase3/includes/api/ApiBlock.php (modified) (history)
  • /trunk/phase3/includes/api/ApiEditPage.php (modified) (history)
  • /trunk/phase3/includes/api/ApiEmailUser.php (modified) (history)
  • /trunk/phase3/includes/api/ApiFileRevert.php (modified) (history)
  • /trunk/phase3/includes/api/ApiImport.php (modified) (history)
  • /trunk/phase3/includes/api/ApiLogin.php (modified) (history)
  • /trunk/phase3/includes/api/ApiLogout.php (modified) (history)
  • /trunk/phase3/includes/api/ApiMain.php (modified) (history)
  • /trunk/phase3/includes/api/ApiMove.php (modified) (history)
  • /trunk/phase3/includes/api/ApiParse.php (modified) (history)
  • /trunk/phase3/includes/api/ApiPatrol.php (modified) (history)
  • /trunk/phase3/includes/api/ApiProtect.php (modified) (history)
  • /trunk/phase3/includes/api/ApiPurge.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryBase.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryBlocks.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryDeletedrevs.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryFilearchive.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryInfo.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryQueryPage.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryRecentChanges.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryUserContributions.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryUserInfo.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryWatchlist.php (modified) (history)
  • /trunk/phase3/includes/api/ApiRollback.php (modified) (history)
  • /trunk/phase3/includes/api/ApiUnblock.php (modified) (history)
  • /trunk/phase3/includes/api/ApiUndelete.php (modified) (history)
  • /trunk/phase3/includes/api/ApiUpload.php (modified) (history)
  • /trunk/phase3/includes/api/ApiUserrights.php (modified) (history)
  • /trunk/phase3/includes/api/ApiWatch.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/api/ApiQueryRecentChanges.php
@@ -129,7 +129,7 @@
130130 * @param $resultPageSet ApiPageSet
131131 */
132132 public function run( $resultPageSet = null ) {
133 - global $wgUser;
 133+ $user = $this->getUser();
134134 /* Get the parameters of the request. */
135135 $params = $this->extractRequestParams();
136136
@@ -163,7 +163,7 @@
164164
165165 // Check permissions
166166 if ( isset( $show['patrolled'] ) || isset( $show['!patrolled'] ) ) {
167 - if ( !$wgUser->useRCPatrol() && !$wgUser->useNPPatrol() ) {
 167+ if ( !$user->useRCPatrol() && !$user->useNPPatrol() ) {
168168 $this->dieUsage( 'You need the patrol right to request the patrolled flag', 'permissiondenied' );
169169 }
170170 }
@@ -219,7 +219,7 @@
220220 /* Set up internal members based upon params. */
221221 $this->initProperties( $prop );
222222
223 - if ( $this->fld_patrolled && !$wgUser->useRCPatrol() && !$wgUser->useNPPatrol() ) {
 223+ if ( $this->fld_patrolled && !$user->useRCPatrol() && !$user->useNPPatrol() ) {
224224 $this->dieUsage( 'You need the patrol right to request the patrolled flag', 'permissiondenied' );
225225 }
226226
Index: trunk/phase3/includes/api/ApiWatch.php
@@ -41,8 +41,8 @@
4242 }
4343
4444 public function execute() {
45 - global $wgUser;
46 - if ( !$wgUser->isLoggedIn() ) {
 45+ $user = $this->getUser();
 46+ if ( !$user->isLoggedIn() ) {
4747 $this->dieUsage( 'You must be logged-in to have a watchlist', 'notloggedin' );
4848 }
4949
@@ -59,11 +59,11 @@
6060 if ( $params['unwatch'] ) {
6161 $res['unwatched'] = '';
6262 $res['message'] = wfMsgExt( 'removedwatchtext', array( 'parse' ), $title->getPrefixedText() );
63 - $success = UnwatchAction::doUnwatch( $title, $wgUser );
 63+ $success = UnwatchAction::doUnwatch( $title, $user );
6464 } else {
6565 $res['watched'] = '';
6666 $res['message'] = wfMsgExt( 'addedwatchtext', array( 'parse' ), $title->getPrefixedText() );
67 - $success = WatchAction::doWatch( $title, $wgUser );
 67+ $success = WatchAction::doWatch( $title, $user );
6868 }
6969 if ( !$success ) {
7070 $this->dieUsageMsg( 'hookaborted' );
Index: trunk/phase3/includes/api/ApiMove.php
@@ -40,7 +40,7 @@
4141 }
4242
4343 public function execute() {
44 - global $wgUser;
 44+ $user = $this->getUser();
4545 $params = $this->extractRequestParams();
4646 if ( is_null( $params['reason'] ) ) {
4747 $params['reason'] = '';
@@ -75,9 +75,9 @@
7676 && !RepoGroup::singleton()->getLocalRepo()->findFile( $toTitle )
7777 && wfFindFile( $toTitle ) )
7878 {
79 - if ( !$params['ignorewarnings'] && $wgUser->isAllowed( 'reupload-shared' ) ) {
 79+ if ( !$params['ignorewarnings'] && $user->isAllowed( 'reupload-shared' ) ) {
8080 $this->dieUsageMsg( 'sharedfile-exists' );
81 - } elseif ( !$wgUser->isAllowed( 'reupload-shared' ) ) {
 81+ } elseif ( !$user->isAllowed( 'reupload-shared' ) ) {
8282 $this->dieUsageMsg( 'cantoverwrite-sharedfile' );
8383 }
8484 }
@@ -89,7 +89,7 @@
9090 }
9191
9292 $r = array( 'from' => $fromTitle->getPrefixedText(), 'to' => $toTitle->getPrefixedText(), 'reason' => $params['reason'] );
93 - if ( !$params['noredirect'] || !$wgUser->isAllowed( 'suppressredirect' ) ) {
 93+ if ( !$params['noredirect'] || !$user->isAllowed( 'suppressredirect' ) ) {
9494 $r['redirectcreated'] = '';
9595 }
9696
Index: trunk/phase3/includes/api/ApiFileRevert.php
@@ -47,14 +47,12 @@
4848 }
4949
5050 public function execute() {
51 - global $wgUser;
52 -
5351 $this->params = $this->extractRequestParams();
5452 // Extract the file and archiveName from the request parameters
5553 $this->validateParameters();
5654
5755 // Check whether we're allowed to revert this file
58 - $this->checkPermissions( $wgUser );
 56+ $this->checkPermissions( $this->getUser() );
5957
6058 $sourceUrl = $this->file->getArchiveVirtualUrl( $this->archiveName );
6159 $status = $this->file->upload( $sourceUrl, $this->params['comment'], $this->params['comment'] );
Index: trunk/phase3/includes/api/ApiLogout.php
@@ -42,13 +42,13 @@
4343 }
4444
4545 public function execute() {
46 - global $wgUser;
47 - $oldName = $wgUser->getName();
48 - $wgUser->logout();
 46+ $user = $this->getUser();
 47+ $oldName = $user->getName();
 48+ $user->logout();
4949
5050 // Give extensions to do something after user logout
5151 $injected_html = '';
52 - wfRunHooks( 'UserLogoutComplete', array( &$wgUser, &$injected_html, $oldName ) );
 52+ wfRunHooks( 'UserLogoutComplete', array( &$user, &$injected_html, $oldName ) );
5353 }
5454
5555 public function isReadMode() {
Index: trunk/phase3/includes/api/ApiParse.php
@@ -62,7 +62,8 @@
6363
6464 // The parser needs $wgTitle to be set, apparently the
6565 // $title parameter in Parser::parse isn't enough *sigh*
66 - global $wgParser, $wgUser, $wgTitle, $wgLang;
 66+ // TODO: Does this still need $wgTitle?
 67+ global $wgParser, $wgTitle, $wgLang;
6768
6869 // Currently unnecessary, code to act as a safeguard against any change in current behaviour of uselang breaks
6970 $oldLang = null;
@@ -179,7 +180,7 @@
180181 }
181182
182183 if ( $params['pst'] || $params['onlypst'] ) {
183 - $this->pstText = $wgParser->preSaveTransform( $this->text, $titleObj, $wgUser, $popts );
 184+ $this->pstText = $wgParser->preSaveTransform( $this->text, $titleObj, $this->getUser(), $popts );
184185 }
185186 if ( $params['onlypst'] ) {
186187 // Build a result and bail out
Index: trunk/phase3/includes/api/ApiProtect.php
@@ -39,7 +39,7 @@
4040 }
4141
4242 public function execute() {
43 - global $wgUser, $wgRestrictionLevels;
 43+ global $wgRestrictionLevels;
4444 $params = $this->extractRequestParams();
4545
4646 $titleObj = Title::newFromText( $params['title'] );
@@ -47,7 +47,7 @@
4848 $this->dieUsageMsg( array( 'invalidtitle', $params['title'] ) );
4949 }
5050
51 - $errors = $titleObj->getUserPermissionsErrors( 'protect', $wgUser );
 51+ $errors = $titleObj->getUserPermissionsErrors( 'protect', $this->getUser() );
5252 if ( $errors ) {
5353 // We don't care about multiple errors, just report one of them
5454 $this->dieUsageMsg( reset( $errors ) );
Index: trunk/phase3/includes/api/ApiPurge.php
@@ -43,10 +43,10 @@
4444 * Purges the cache of a page
4545 */
4646 public function execute() {
47 - global $wgUser;
 47+ $user = $this->getUser();
4848 $params = $this->extractRequestParams();
49 - if ( !$wgUser->isAllowed( 'purge' ) && !$this->getMain()->isInternalMode() &&
50 - !$this->getMain()->getRequest()->wasPosted() ) {
 49+ if ( !$user->isAllowed( 'purge' ) && !$this->getMain()->isInternalMode() &&
 50+ !$this->getRequest()->wasPosted() ) {
5151 $this->dieUsageMsg( array( 'mustbeposted', $this->getModuleName() ) );
5252 }
5353
@@ -75,7 +75,7 @@
7676 $r['purged'] = '';
7777
7878 if( $forceLinkUpdate ) {
79 - if ( !$wgUser->pingLimiter() ) {
 79+ if ( !$user->pingLimiter() ) {
8080 global $wgParser, $wgEnableParserCache;
8181 $popts = new ParserOptions();
8282 $p_result = $wgParser->parse( $article->getContent(), $title, $popts );
Index: trunk/phase3/includes/api/ApiRollback.php
@@ -52,11 +52,11 @@
5353 $params = $this->extractRequestParams();
5454
5555 // User and title already validated in call to getTokenSalt from Main
56 - $titleObj = $this->getTitle();
 56+ $titleObj = $this->getRbTitle();
5757 $articleObj = new Article( $titleObj );
5858 $summary = ( isset( $params['summary'] ) ? $params['summary'] : '' );
5959 $details = array();
60 - $retval = $articleObj->doRollback( $this->getUser(), $summary, $params['token'], $params['markbot'], $details );
 60+ $retval = $articleObj->doRollback( $this->getRbUser(), $summary, $params['token'], $params['markbot'], $details );
6161
6262 if ( $retval ) {
6363 // We don't care about multiple errors, just report one of them
@@ -141,10 +141,10 @@
142142 }
143143
144144 public function getTokenSalt() {
145 - return array( $this->getTitle()->getPrefixedText(), $this->getUser() );
 145+ return array( $this->getRbTitle()->getPrefixedText(), $this->getRbUser() );
146146 }
147147
148 - private function getUser() {
 148+ private function getRbUser() {
149149 if ( $this->mUser !== null ) {
150150 return $this->mUser;
151151 }
@@ -165,7 +165,7 @@
166166 /**
167167 * @return Title
168168 */
169 - private function getTitle() {
 169+ private function getRbTitle() {
170170 if ( $this->mTitleObj !== null ) {
171171 return $this->mTitleObj;
172172 }
Index: trunk/phase3/includes/api/ApiQueryDeletedrevs.php
@@ -41,9 +41,9 @@
4242 }
4343
4444 public function execute() {
45 - global $wgUser;
 45+ $user = $this->getUser();
4646 // Before doing anything at all, let's check permissions
47 - if ( !$wgUser->isAllowed( 'deletedhistory' ) ) {
 47+ if ( !$user->isAllowed( 'deletedhistory' ) ) {
4848 $this->dieUsage( 'You don\'t have permission to view deleted revision information', 'permissiondenied' );
4949 }
5050
@@ -113,7 +113,7 @@
114114 $this->addWhere( 'ar_text_id = old_id' );
115115
116116 // This also means stricter restrictions
117 - if ( !$wgUser->isAllowed( 'undelete' ) ) {
 117+ if ( !$user->isAllowed( 'undelete' ) ) {
118118 $this->dieUsage( 'You don\'t have permission to view deleted revision content', 'permissiondenied' );
119119 }
120120 }
@@ -132,7 +132,7 @@
133133
134134 if ( $fld_token ) {
135135 // Undelete tokens are identical for all pages, so we cache one here
136 - $token = $wgUser->editToken( '', $this->getMain()->getRequest() );
 136+ $token = $user->editToken( '', $this->getMain()->getRequest() );
137137 }
138138
139139 $dir = $params['dir'];
Index: trunk/phase3/includes/api/ApiUserrights.php
@@ -44,7 +44,7 @@
4545 public function execute() {
4646 $params = $this->extractRequestParams();
4747
48 - $user = $this->getUser();
 48+ $user = $this->getUrUser();
4949
5050 $form = new UserrightsPage;
5151 $r['user'] = $user->getName();
@@ -62,7 +62,7 @@
6363 /**
6464 * @return User
6565 */
66 - private function getUser() {
 66+ private function getUrUser() {
6767 if ( $this->mUser !== null ) {
6868 return $this->mUser;
6969 }
@@ -130,7 +130,7 @@
131131 }
132132
133133 public function getTokenSalt() {
134 - return $this->getUser()->getName();
 134+ return $this->getUrUser()->getName();
135135 }
136136
137137 public function getExamples() {
Index: trunk/phase3/includes/api/ApiQueryBase.php
@@ -502,8 +502,7 @@
503503 * @return void
504504 */
505505 public function showHiddenUsersAddBlockInfo( $showBlockInfo ) {
506 - global $wgUser;
507 - $userCanViewHiddenUsers = $wgUser->isAllowed( 'hideuser' );
 506+ $userCanViewHiddenUsers = $this->getUser()->isAllowed( 'hideuser' );
508507
509508 if ( $showBlockInfo || !$userCanViewHiddenUsers ) {
510509 $this->addTables( 'ipblocks' );
Index: trunk/phase3/includes/api/ApiQueryBlocks.php
@@ -46,7 +46,7 @@
4747 }
4848
4949 public function execute() {
50 - global $wgUser, $wgContLang;
 50+ global $wgContLang;
5151
5252 $params = $this->extractRequestParams();
5353 $this->requireMaxOneParameter( $params, 'users', 'ip' );
@@ -136,7 +136,7 @@
137137 $this->addWhereIf( "ipb_range_end > ipb_range_start", isset( $show['range'] ) );
138138 }
139139
140 - if ( !$wgUser->isAllowed( 'hideuser' ) ) {
 140+ if ( !$this->getUser()->isAllowed( 'hideuser' ) ) {
141141 $this->addWhereFld( 'ipb_deleted', 0 );
142142 }
143143
Index: trunk/phase3/includes/api/ApiQueryFilearchive.php
@@ -43,9 +43,9 @@
4444 }
4545
4646 public function execute() {
47 - global $wgUser;
 47+ $user = $this->getUser();
4848 // Before doing anything at all, let's check permissions
49 - if ( !$wgUser->isAllowed( 'deletedhistory' ) ) {
 49+ if ( !$user->isAllowed( 'deletedhistory' ) ) {
5050 $this->dieUsage( 'You don\'t have permission to view deleted file information', 'permissiondenied' );
5151 }
5252
@@ -110,7 +110,7 @@
111111 }
112112 }
113113
114 - if ( !$wgUser->isAllowed( 'suppressrevision' ) ) {
 114+ if ( !$user->isAllowed( 'suppressrevision' ) ) {
115115 // Filter out revisions that the user is not allowed to see. There
116116 // is no way to indicate that we have skipped stuff because the
117117 // continuation parameter is fa_name
Index: trunk/phase3/includes/api/ApiImport.php
@@ -41,13 +41,12 @@
4242 }
4343
4444 public function execute() {
45 - global $wgUser;
46 -
 45+ $user = $this->getUser();
4746 $params = $this->extractRequestParams();
4847
4948 $isUpload = false;
5049 if ( isset( $params['interwikisource'] ) ) {
51 - if ( !$wgUser->isAllowed( 'import' ) ) {
 50+ if ( !$user->isAllowed( 'import' ) ) {
5251 $this->dieUsageMsg( 'cantimport' );
5352 }
5453 if ( !isset( $params['interwikipage'] ) ) {
@@ -61,7 +60,7 @@
6261 );
6362 } else {
6463 $isUpload = true;
65 - if ( !$wgUser->isAllowed( 'importupload' ) ) {
 64+ if ( !$user->isAllowed( 'importupload' ) ) {
6665 $this->dieUsageMsg( 'cantimport-upload' );
6766 }
6867 $source = ImportStreamSource::newFromUpload( 'xml' );
Index: trunk/phase3/includes/api/ApiEditPage.php
@@ -43,7 +43,7 @@
4444 }
4545
4646 public function execute() {
47 - global $wgUser;
 47+ $user = $this->getUser();
4848 $params = $this->extractRequestParams();
4949
5050 if ( is_null( $params['text'] ) && is_null( $params['appendtext'] ) &&
@@ -88,6 +88,7 @@
8989 }
9090
9191 // Some functions depend on $wgTitle == $ep->mTitle
 92+ // TODO: Make them not or check if they still do
9293 global $wgTitle;
9394 $wgTitle = $titleObj;
9495
@@ -99,9 +100,9 @@
100101 }
101102
102103 // Now let's check whether we're even allowed to do this
103 - $errors = $titleObj->getUserPermissionsErrors( 'edit', $wgUser );
 104+ $errors = $titleObj->getUserPermissionsErrors( 'edit', $user );
104105 if ( !$titleObj->exists() ) {
105 - $errors = array_merge( $errors, $titleObj->getUserPermissionsErrors( 'create', $wgUser ) );
 106+ $errors = array_merge( $errors, $titleObj->getUserPermissionsErrors( 'create', $user ) );
106107 }
107108 if ( count( $errors ) ) {
108109 $this->dieUsageMsg( $errors[0] );
@@ -207,7 +208,7 @@
208209 $reqArr['wpStarttime'] = wfTimestampNow(); // Fake wpStartime
209210 }
210211
211 - if ( $params['minor'] || ( !$params['notminor'] && $wgUser->getOption( 'minordefault' ) ) ) {
 212+ if ( $params['minor'] || ( !$params['notminor'] && $user->getOption( 'minordefault' ) ) ) {
212213 $reqArr['wpMinoredit'] = '';
213214 }
214215
@@ -270,7 +271,7 @@
271272 $oldRequest = $wgRequest;
272273 $wgRequest = $req;
273274
274 - $status = $ep->internalAttemptSave( $result, $wgUser->isAllowed( 'bot' ) && $params['bot'] );
 275+ $status = $ep->internalAttemptSave( $result, $user->isAllowed( 'bot' ) && $params['bot'] );
275276 $wgRequest = $oldRequest;
276277 global $wgMaxArticleSize;
277278
Index: trunk/phase3/includes/api/ApiUnblock.php
@@ -45,11 +45,11 @@
4646 * Unblocks the specified user or provides the reason the unblock failed.
4747 */
4848 public function execute() {
49 - global $wgUser;
 49+ $user = $this->getUser();
5050 $params = $this->extractRequestParams();
5151
5252 if ( $params['gettoken'] ) {
53 - $res['unblocktoken'] = $wgUser->editToken( '', $this->getMain()->getRequest() );
 53+ $res['unblocktoken'] = $user->editToken( '', $this->getMain()->getRequest() );
5454 $this->getResult()->addValue( null, $this->getModuleName(), $res );
5555 return;
5656 }
@@ -61,11 +61,11 @@
6262 $this->dieUsageMsg( 'unblock-idanduser' );
6363 }
6464
65 - if ( !$wgUser->isAllowed( 'block' ) ) {
 65+ if ( !$user->isAllowed( 'block' ) ) {
6666 $this->dieUsageMsg( 'cantunblock' );
6767 }
6868 # bug 15810: blocked admins should have limited access here
69 - if ( $wgUser->isBlocked() ) {
 69+ if ( $user->isBlocked() ) {
7070 $status = SpecialBlock::checkUnblockSelf( $params['user'] );
7171 if ( $status !== true ) {
7272 $this->dieUsageMsg( $status );
Index: trunk/phase3/includes/api/ApiLogin.php
@@ -68,29 +68,32 @@
6969 wfSetupSession();
7070 }
7171
72 - $context = $this->createContext();
 72+ $context = new DerivativeContext( $this->getContext() );
7373 $context->setRequest( $req );
 74+ /*$context = $this->createContext();
 75+ $context->setRequest( $req );*/
7476 $loginForm = new LoginForm();
7577 $loginForm->setContext( $context );
 78+ $user = $this->getUser();
7679
77 - global $wgCookiePrefix, $wgUser, $wgPasswordAttemptThrottle;
 80+ global $wgCookiePrefix, $wgPasswordAttemptThrottle;
7881
7982 $authRes = $loginForm->authenticateUserData();
8083 switch ( $authRes ) {
8184 case LoginForm::SUCCESS:
82 - $wgUser->setOption( 'rememberpassword', 1 );
83 - $wgUser->setCookies( $this->getMain()->getRequest() );
 85+ $user->setOption( 'rememberpassword', 1 );
 86+ $user->setCookies( $this->getMain()->getRequest() );
8487
8588 // Run hooks.
8689 // @todo FIXME: Split back and frontend from this hook.
8790 // @todo FIXME: This hook should be placed in the backend
8891 $injected_html = '';
89 - wfRunHooks( 'UserLoginComplete', array( &$wgUser, &$injected_html ) );
 92+ wfRunHooks( 'UserLoginComplete', array( &$user, &$injected_html ) );
9093
9194 $result['result'] = 'Success';
92 - $result['lguserid'] = intval( $wgUser->getId() );
93 - $result['lgusername'] = $wgUser->getName();
94 - $result['lgtoken'] = $wgUser->getToken();
 95+ $result['lguserid'] = intval( $user->getId() );
 96+ $result['lgusername'] = $user->getName();
 97+ $result['lgtoken'] = $user->getToken();
9598 $result['cookieprefix'] = $wgCookiePrefix;
9699 $result['sessionid'] = session_id();
97100 break;
Index: trunk/phase3/includes/api/ApiQueryUserInfo.php
@@ -55,47 +55,48 @@
5656 }
5757
5858 protected function getCurrentUserInfo() {
59 - global $wgUser, $wgRequest, $wgHiddenPrefs;
 59+ global $wgRequest, $wgHiddenPrefs;
 60+ $user = $this->getUser();
6061 $result = $this->getResult();
6162 $vals = array();
62 - $vals['id'] = intval( $wgUser->getId() );
63 - $vals['name'] = $wgUser->getName();
 63+ $vals['id'] = intval( $user->getId() );
 64+ $vals['name'] = $user->getName();
6465
65 - if ( $wgUser->isAnon() ) {
 66+ if ( $user->isAnon() ) {
6667 $vals['anon'] = '';
6768 }
6869
6970 if ( isset( $this->prop['blockinfo'] ) ) {
70 - if ( $wgUser->isBlocked() ) {
71 - $vals['blockedby'] = User::whoIs( $wgUser->blockedBy() );
72 - $vals['blockreason'] = $wgUser->blockedFor();
 71+ if ( $user->isBlocked() ) {
 72+ $vals['blockedby'] = User::whoIs( $user->blockedBy() );
 73+ $vals['blockreason'] = $user->blockedFor();
7374 }
7475 }
7576
76 - if ( isset( $this->prop['hasmsg'] ) && $wgUser->getNewtalk() ) {
 77+ if ( isset( $this->prop['hasmsg'] ) && $user->getNewtalk() ) {
7778 $vals['messages'] = '';
7879 }
7980
8081 if ( isset( $this->prop['groups'] ) ) {
81 - $autolist = ApiQueryUsers::getAutoGroups( $wgUser );
 82+ $autolist = ApiQueryUsers::getAutoGroups( $user );
8283
83 - $vals['groups'] = array_merge( $autolist, $wgUser->getGroups() );
 84+ $vals['groups'] = array_merge( $autolist, $user->getGroups() );
8485 $result->setIndexedTagName( $vals['groups'], 'g' ); // even if empty
8586 }
8687
8788 if ( isset( $this->prop['implicitgroups'] ) ) {
88 - $vals['implicitgroups'] = ApiQueryUsers::getAutoGroups( $wgUser );
 89+ $vals['implicitgroups'] = ApiQueryUsers::getAutoGroups( $user );
8990 $result->setIndexedTagName( $vals['implicitgroups'], 'g' ); // even if empty
9091 }
9192
9293 if ( isset( $this->prop['rights'] ) ) {
9394 // User::getRights() may return duplicate values, strip them
94 - $vals['rights'] = array_values( array_unique( $wgUser->getRights() ) );
 95+ $vals['rights'] = array_values( array_unique( $user->getRights() ) );
9596 $result->setIndexedTagName( $vals['rights'], 'r' ); // even if empty
9697 }
9798
9899 if ( isset( $this->prop['changeablegroups'] ) ) {
99 - $vals['changeablegroups'] = $wgUser->changeableGroups();
 100+ $vals['changeablegroups'] = $user->changeableGroups();
100101 $result->setIndexedTagName( $vals['changeablegroups']['add'], 'g' );
101102 $result->setIndexedTagName( $vals['changeablegroups']['remove'], 'g' );
102103 $result->setIndexedTagName( $vals['changeablegroups']['add-self'], 'g' );
@@ -103,17 +104,17 @@
104105 }
105106
106107 if ( isset( $this->prop['options'] ) ) {
107 - $vals['options'] = $wgUser->getOptions();
 108+ $vals['options'] = $user->getOptions();
108109 }
109110
110111 if ( isset( $this->prop['preferencestoken'] ) &&
111112 is_null( $this->getMain()->getRequest()->getVal( 'callback' ) )
112113 ) {
113 - $vals['preferencestoken'] = $wgUser->editToken( '', $this->getMain()->getRequest() );
 114+ $vals['preferencestoken'] = $user->editToken( '', $this->getMain()->getRequest() );
114115 }
115116
116117 if ( isset( $this->prop['editcount'] ) ) {
117 - $vals['editcount'] = intval( $wgUser->getEditCount() );
 118+ $vals['editcount'] = intval( $user->getEditCount() );
118119 }
119120
120121 if ( isset( $this->prop['ratelimits'] ) ) {
@@ -121,19 +122,19 @@
122123 }
123124
124125 if ( isset( $this->prop['realname'] ) && !in_array( 'realname', $wgHiddenPrefs ) ) {
125 - $vals['realname'] = $wgUser->getRealName();
 126+ $vals['realname'] = $user->getRealName();
126127 }
127128
128129 if ( isset( $this->prop['email'] ) ) {
129 - $vals['email'] = $wgUser->getEmail();
130 - $auth = $wgUser->getEmailAuthenticationTimestamp();
 130+ $vals['email'] = $user->getEmail();
 131+ $auth = $user->getEmailAuthenticationTimestamp();
131132 if ( !is_null( $auth ) ) {
132133 $vals['emailauthenticated'] = wfTimestamp( TS_ISO_8601, $auth );
133134 }
134135 }
135136
136137 if ( isset( $this->prop['registrationdate'] ) ) {
137 - $regDate = $wgUser->getRegistration();
 138+ $regDate = $user->getRegistration();
138139 if ( $regDate !== false ) {
139140 $vals['registrationdate'] = wfTimestamp( TS_ISO_8601, $regDate );
140141 }
@@ -154,25 +155,26 @@
155156 }
156157
157158 protected function getRateLimits() {
158 - global $wgUser, $wgRateLimits;
159 - if ( !$wgUser->isPingLimitable() ) {
 159+ global $wgRateLimits;
 160+ $user = $this->getUser();
 161+ if ( !$user->isPingLimitable() ) {
160162 return array(); // No limits
161163 }
162164
163165 // Find out which categories we belong to
164166 $categories = array();
165 - if ( $wgUser->isAnon() ) {
 167+ if ( $user->isAnon() ) {
166168 $categories[] = 'anon';
167169 } else {
168170 $categories[] = 'user';
169171 }
170 - if ( $wgUser->isNewbie() ) {
 172+ if ( $user->isNewbie() ) {
171173 $categories[] = 'ip';
172174 $categories[] = 'subnet';
173 - if ( !$wgUser->isAnon() )
 175+ if ( !$user->isAnon() )
174176 $categories[] = 'newbie';
175177 }
176 - $categories = array_merge( $categories, $wgUser->getGroups() );
 178+ $categories = array_merge( $categories, $user->getGroups() );
177179
178180 // Now get the actual limits
179181 $retval = array();
Index: trunk/phase3/includes/api/ApiMain.php
@@ -132,7 +132,7 @@
133133 private $mPrinter;
134134
135135 private $mModules, $mModuleNames, $mFormats, $mFormatNames;
136 - private $mResult, $mAction, $mShowVersions, $mEnableWrite, $mRequest;
 136+ private $mResult, $mAction, $mShowVersions, $mEnableWrite/*, $mRequest*/;
137137 private $mInternalMode, $mSquidMaxage, $mModule;
138138
139139 private $mCacheMode = 'private';
@@ -141,12 +141,23 @@
142142 /**
143143 * Constructs an instance of ApiMain that utilizes the module and format specified by $request.
144144 *
145 - * @param $request WebRequest - if this is an instance of FauxRequest, errors are thrown and no printing occurs
 145+ * @param $context IContextSource|WebRequest - if this is an instance of FauxRequest, errors are thrown and no printing occurs
146146 * @param $enableWrite bool should be set to true if the api may modify data
147147 */
148 - public function __construct( $request, $enableWrite = false ) {
149 - $this->mInternalMode = ( $request instanceof FauxRequest );
 148+ public function __construct( $context = null, $enableWrite = false ) {
 149+ if ( $context === null ) {
 150+ $context = RequestContext::getMain();
 151+ } elseif ( $context instanceof WebRequest ) {
 152+ // BC for pre-1.19
 153+ $request = $context;
 154+ $context = RequestContext::getMain();
 155+ $context->setRequest( $request );
 156+ }
 157+ // We set a derivative context so we can change stuff later
 158+ $this->setContext( new DerivativeContext( $context ) );
150159
 160+ $this->mInternalMode = ( $this->getRequest() instanceof FauxRequest );
 161+
151162 // Special handling for the main module: $parent === $this
152163 parent::__construct( $this, $this->mInternalMode ? 'main_int' : 'main' );
153164
@@ -156,11 +167,12 @@
157168 // Remove all modules other than login
158169 global $wgUser;
159170
160 - if ( $request->getVal( 'callback' ) !== null ) {
 171+ if ( $this->getRequest()->getVal( 'callback' ) !== null ) {
161172 // JSON callback allows cross-site reads.
162173 // For safety, strip user credentials.
163174 wfDebug( "API: stripping user credentials for JSON callback\n" );
164175 $wgUser = new User();
 176+ $this->getContext()->setUser( $wgUser );
165177 }
166178 }
167179
@@ -175,7 +187,7 @@
176188 $this->mShowVersions = false;
177189 $this->mEnableWrite = $enableWrite;
178190
179 - $this->mRequest = &$request;
 191+ //$this->mRequest = &$request;
180192
181193 $this->mSquidMaxage = - 1; // flag for executeActionWithErrorHandling()
182194 $this->mCommit = false;
@@ -193,9 +205,9 @@
194206 * Return the request object that contains client's request
195207 * @return WebRequest
196208 */
197 - public function getRequest() {
 209+ /*public function getRequest() {
198210 return $this->mRequest;
199 - }
 211+ }*/
200212
201213 /**
202214 * Get the ApiResult object associated with current request
@@ -596,8 +608,7 @@
597609 if ( !isset( $moduleParams['token'] ) ) {
598610 $this->dieUsageMsg( array( 'missingparam', 'token' ) );
599611 } else {
600 - global $wgUser;
601 - if ( !$wgUser->matchEditToken( $moduleParams['token'], $salt, $this->getRequest() ) ) {
 612+ if ( !$this->getUser()->matchEditToken( $moduleParams['token'], $salt, $this->getRequest() ) ) {
602613 $this->dieUsageMsg( 'sessionfailure' );
603614 }
604615 }
@@ -639,9 +650,9 @@
640651 * @param $module ApiBase An Api module
641652 */
642653 protected function checkExecutePermissions( $module ) {
643 - global $wgUser;
 654+ $user = $this->getUser();
644655 if ( $module->isReadMode() && !in_array( 'read', User::getGroupPermissions( array( '*' ) ), true ) &&
645 - !$wgUser->isAllowed( 'read' ) )
 656+ !$user->isAllowed( 'read' ) )
646657 {
647658 $this->dieUsageMsg( 'readrequired' );
648659 }
@@ -649,7 +660,7 @@
650661 if ( !$this->mEnableWrite ) {
651662 $this->dieUsageMsg( 'writedisabled' );
652663 }
653 - if ( !$wgUser->isAllowed( 'writeapi' ) ) {
 664+ if ( !$user->isAllowed( 'writeapi' ) ) {
654665 $this->dieUsageMsg( 'writerequired' );
655666 }
656667 if ( wfReadOnly() ) {
@@ -665,7 +676,7 @@
666677 */
667678 protected function setupExternalResponse( $module, $params ) {
668679 // Ignore mustBePosted() for internal calls
669 - if ( $module->mustBePosted() && !$this->mRequest->wasPosted() ) {
 680+ if ( $module->mustBePosted() && !$this->getRequest()->wasPosted() ) {
670681 $this->dieUsageMsg( array( 'mustbeposted', $this->mAction ) );
671682 }
672683
@@ -975,8 +986,7 @@
976987 */
977988 public function canApiHighLimits() {
978989 if ( !isset( $this->mCanApiHighLimits ) ) {
979 - global $wgUser;
980 - $this->mCanApiHighLimits = $wgUser->isAllowed( 'apihighlimits' );
 990+ $this->mCanApiHighLimits = $this->getUser()->isAllowed( 'apihighlimits' );
981991 }
982992
983993 return $this->mCanApiHighLimits;
Index: trunk/phase3/includes/api/ApiEmailUser.php
@@ -40,8 +40,6 @@
4141 }
4242
4343 public function execute() {
44 - global $wgUser;
45 -
4644 $params = $this->extractRequestParams();
4745
4846 // Validate target
@@ -51,7 +49,7 @@
5250 }
5351
5452 // Check permissions and errors
55 - $error = SpecialEmailUser::getPermissionsError( $wgUser, $params['token'] );
 53+ $error = SpecialEmailUser::getPermissionsError( $this->getUser(), $params['token'] );
5654 if ( $error ) {
5755 $this->dieUsageMsg( array( $error ) );
5856 }
Index: trunk/phase3/includes/api/ApiQueryQueryPage.php
@@ -75,12 +75,11 @@
7676 * @param $resultPageSet ApiPageSet
7777 */
7878 public function run( $resultPageSet = null ) {
79 - global $wgUser;
8079 $params = $this->extractRequestParams();
8180 $result = $this->getResult();
8281
8382 $qp = new $this->qpMap[$params['page']]();
84 - if ( !$qp->userCanExecute( $wgUser ) ) {
 83+ if ( !$qp->userCanExecute( $this->getUser() ) ) {
8584 $this->dieUsageMsg( 'specialpage-cantexecute' );
8685 }
8786
Index: trunk/phase3/includes/api/ApiQueryWatchlist.php
@@ -159,8 +159,8 @@
160160
161161 // Check permissions.
162162 if ( isset( $show['patrolled'] ) || isset( $show['!patrolled'] ) ) {
163 - global $wgUser;
164 - if ( !$wgUser->useRCPatrol() && !$wgUser->useNPPatrol() ) {
 163+ $user = $this->getUser();
 164+ if ( !$user->useRCPatrol() && !$user->useNPPatrol() ) {
165165 $this->dieUsage( 'You need the patrol right to request the patrolled flag', 'permissiondenied' );
166166 }
167167 }
Index: trunk/phase3/includes/api/ApiBlock.php
@@ -48,29 +48,29 @@
4949 * of success. If it fails, the result will specify the nature of the error.
5050 */
5151 public function execute() {
52 - global $wgUser;
 52+ $user = $this->getUser();
5353 $params = $this->extractRequestParams();
5454
5555 if ( $params['gettoken'] ) {
56 - $res['blocktoken'] = $wgUser->editToken( '', $this->getMain()->getRequest() );
 56+ $res['blocktoken'] = $user->editToken( '', $this->getMain()->getRequest() );
5757 $this->getResult()->addValue( null, $this->getModuleName(), $res );
5858 return;
5959 }
6060
61 - if ( !$wgUser->isAllowed( 'block' ) ) {
 61+ if ( !$user->isAllowed( 'block' ) ) {
6262 $this->dieUsageMsg( 'cantblock' );
6363 }
6464 # bug 15810: blocked admins should have limited access here
65 - if ( $wgUser->isBlocked() ) {
 65+ if ( $user->isBlocked() ) {
6666 $status = SpecialBlock::checkUnblockSelf( $params['user'] );
6767 if ( $status !== true ) {
6868 $this->dieUsageMsg( array( $status ) );
6969 }
7070 }
71 - if ( $params['hidename'] && !$wgUser->isAllowed( 'hideuser' ) ) {
 71+ if ( $params['hidename'] && !$user->isAllowed( 'hideuser' ) ) {
7272 $this->dieUsageMsg( 'canthide' );
7373 }
74 - if ( $params['noemail'] && !SpecialBlock::canBlockEmail( $wgUser ) ) {
 74+ if ( $params['noemail'] && !SpecialBlock::canBlockEmail( $user ) ) {
7575 $this->dieUsageMsg( 'cantblock-email' );
7676 }
7777
Index: trunk/phase3/includes/api/ApiPatrol.php
@@ -42,15 +42,13 @@
4343 * Patrols the article or provides the reason the patrol failed.
4444 */
4545 public function execute() {
46 - global $wgUser;
47 -
4846 $params = $this->extractRequestParams();
4947
5048 $rc = RecentChange::newFromID( $params['rcid'] );
5149 if ( !$rc instanceof RecentChange ) {
5250 $this->dieUsageMsg( array( 'nosuchrcid', $params['rcid'] ) );
5351 }
54 - $retval = $rc->doMarkPatrolled( $wgUser );
 52+ $retval = $rc->doMarkPatrolled( $this->getUser() );
5553
5654 if ( $retval ) {
5755 $this->dieUsageMsg( reset( $retval ) );
Index: trunk/phase3/includes/api/ApiUndelete.php
@@ -39,14 +39,13 @@
4040 }
4141
4242 public function execute() {
43 - global $wgUser;
4443 $params = $this->extractRequestParams();
4544
46 - if ( !$wgUser->isAllowed( 'undelete' ) ) {
 45+ if ( !$this->getUser()->isAllowed( 'undelete' ) ) {
4746 $this->dieUsageMsg( 'permdenied-undelete' );
4847 }
4948
50 - if ( $wgUser->isBlocked() ) {
 49+ if ( $this->getUser()->isBlocked() ) {
5150 $this->dieUsageMsg( 'blockedtext' );
5251 }
5352
@@ -74,7 +73,7 @@
7574
7675 if ( $retval[1] ) {
7776 wfRunHooks( 'FileUndeleteComplete',
78 - array( $titleObj, array(), $wgUser, $params['reason'] ) );
 77+ array( $titleObj, array(), $this->getUser(), $params['reason'] ) );
7978 }
8079
8180 $this->setWatch( $params['watchlist'], $titleObj );
Index: trunk/phase3/includes/api/ApiBase.php
@@ -39,7 +39,7 @@
4040 *
4141 * @ingroup API
4242 */
43 -abstract class ApiBase {
 43+abstract class ApiBase extends ContextSource {
4444
4545 // These constants allow modules to specify exactly how to treat incoming parameters.
4646
@@ -72,6 +72,10 @@
7373 $this->mMainModule = $mainModule;
7474 $this->mModuleName = $moduleName;
7575 $this->mModulePrefix = $modulePrefix;
 76+
 77+ if ( !$this->isMain() ) {
 78+ $this->setContext( $this->mMainModule );
 79+ }
7680 }
7781
7882 /*****************************************************************************
@@ -179,16 +183,11 @@
180184 * The object will have the WebRequest and the User object set to the ones
181185 * used in this instance.
182186 *
 187+ * @deprecated 1.19 use getContext to get the current context
183188 * @return RequestContext
184189 */
185190 public function createContext() {
186 - global $wgUser;
187 -
188 - $context = new RequestContext;
189 - $context->setRequest( $this->getMain()->getRequest() );
190 - $context->setUser( $wgUser ); /// @todo FIXME: we should store the User object
191 -
192 - return $context;
 191+ return $this->getContext();
193192 }
194193
195194 /**
@@ -674,7 +673,6 @@
675674
676675 $userWatching = $titleObj->userIsWatching();
677676
678 - global $wgUser;
679677 switch ( $watchlist ) {
680678 case 'watch':
681679 return true;
@@ -693,7 +691,7 @@
694692 ? 'watchdefault' : 'watchcreations';
695693 }
696694 # Watch the article based on the user preference
697 - return (bool)$wgUser->getOption( $userOption );
 695+ return (bool)$this->getUser()->getOption( $userOption );
698696
699697 case 'nochange':
700698 return $userWatching;
@@ -715,11 +713,11 @@
716714 return;
717715 }
718716
719 - global $wgUser;
 717+ $user = $this->getUser();
720718 if ( $value ) {
721 - WatchAction::doWatch( $titleObj, $wgUser );
 719+ WatchAction::doWatch( $titleObj, $user );
722720 } else {
723 - WatchAction::doUnwatch( $titleObj, $wgUser );
 721+ WatchAction::doUnwatch( $titleObj, $user );
724722 }
725723 }
726724
@@ -767,9 +765,9 @@
768766 ApiBase::dieDebug( __METHOD__, "Boolean param $encParamName's default is set to '$default'" );
769767 }
770768
771 - $value = $this->getMain()->getRequest()->getCheck( $encParamName );
 769+ $value = $this->getRequest()->getCheck( $encParamName );
772770 } else {
773 - $value = $this->getMain()->getRequest()->getVal( $encParamName, $default );
 771+ $value = $this->getRequest()->getVal( $encParamName, $default );
774772
775773 if ( isset( $value ) && $type == 'namespace' ) {
776774 $type = MWNamespace::getValidNamespaces();
@@ -1297,7 +1295,6 @@
12981296 * @return User
12991297 */
13001298 public function getWatchlistUser( $params ) {
1301 - global $wgUser;
13021299 if ( !is_null( $params['owner'] ) && !is_null( $params['token'] ) ) {
13031300 $user = User::newFromName( $params['owner'], false );
13041301 if ( !$user->getId() ) {
@@ -1308,10 +1305,10 @@
13091306 $this->dieUsage( 'Incorrect watchlist token provided -- please set a correct token in Special:Preferences', 'bad_wltoken' );
13101307 }
13111308 } else {
1312 - if ( !$wgUser->isLoggedIn() ) {
 1309+ if ( !$this->getUser()->isLoggedIn() ) {
13131310 $this->dieUsage( 'You must be logged-in to have a watchlist', 'notloggedin' );
13141311 }
1315 - $user = $wgUser;
 1312+ $user = $this->getUser();
13161313 }
13171314 return $user;
13181315 }
Index: trunk/phase3/includes/api/ApiQueryInfo.php
@@ -619,9 +619,9 @@
620620 * Get information about watched status and put it in $this->watched
621621 */
622622 private function getWatchedInfo() {
623 - global $wgUser;
 623+ $user = $this->getUser();
624624
625 - if ( $wgUser->isAnon() || count( $this->everything ) == 0 ) {
 625+ if ( $user->isAnon() || count( $this->everything ) == 0 ) {
626626 return;
627627 }
628628
@@ -635,7 +635,7 @@
636636 $this->addFields( array( 'wl_title', 'wl_namespace' ) );
637637 $this->addWhere( array(
638638 $lb->constructSet( 'wl', $db ),
639 - 'wl_user' => $wgUser->getID()
 639+ 'wl_user' => $user->getID()
640640 ) );
641641
642642 $res = $this->select( __METHOD__ );
Index: trunk/phase3/includes/api/ApiUpload.php
@@ -46,13 +46,13 @@
4747 }
4848
4949 public function execute() {
50 - global $wgUser;
51 -
5250 // Check whether upload is enabled
5351 if ( !UploadBase::isEnabled() ) {
5452 $this->dieUsageMsg( 'uploaddisabled' );
5553 }
5654
 55+ $user = $this->getUser();
 56+
5757 // Parameter handling
5858 $this->mParams = $this->extractRequestParams();
5959 $request = $this->getMain()->getRequest();
@@ -75,7 +75,7 @@
7676 }
7777
7878 // First check permission to upload
79 - $this->checkPermissions( $wgUser );
 79+ $this->checkPermissions( $user );
8080
8181 // Fetch the file
8282 $status = $this->mUpload->fetchFile();
@@ -100,7 +100,7 @@
101101 // (This check is irrelevant if stashing is already requested, since the errors
102102 // can always be fixed by changing the title)
103103 if ( ! $this->mParams['stash'] ) {
104 - $permErrors = $this->mUpload->verifyTitlePermissions( $wgUser );
 104+ $permErrors = $this->mUpload->verifyTitlePermissions( $user );
105105 if ( $permErrors !== true ) {
106106 $this->dieRecoverableError( $permErrors[0], 'filename' );
107107 }
@@ -254,17 +254,7 @@
255255 $this->dieUsageMsg( 'invalid-file-key' );
256256 }
257257
258 - if( class_exists( 'RequestContext' ) ) {
259 - // context allows access to the current user without creating new $wgUser references
260 - $context = $this->createContext();
261 - $this->mUpload = new UploadFromStash( $context->getUser() );
262 - } else {
263 - // this is here to maintain 1.17 compatibility, so these changes can
264 - // be merged into production
265 - // remove this after we've moved to 1.18
266 - global $wgUser;
267 - $this->mUpload = new UploadFromStash( $wgUser );
268 - }
 258+ $this->mUpload = new UploadFromStash( $this->getUser() );
269259
270260 $this->mUpload->initialize( $this->mParams['filekey'], $this->mParams['filename'] );
271261
@@ -440,8 +430,6 @@
441431 * @return array
442432 */
443433 protected function performUpload() {
444 - global $wgUser;
445 -
446434 // Use comment as initial page text by default
447435 if ( is_null( $this->mParams['text'] ) ) {
448436 $this->mParams['text'] = $this->mParams['comment'];
@@ -457,7 +445,7 @@
458446
459447 // No errors, no warnings: do the upload
460448 $status = $this->mUpload->performUpload( $this->mParams['comment'],
461 - $this->mParams['text'], $watch, $wgUser );
 449+ $this->mParams['text'], $watch, $this->getUser() );
462450
463451 if ( !$status->isGood() ) {
464452 $error = $status->getErrorsArray();
Index: trunk/phase3/includes/api/ApiQueryUserContributions.php
@@ -146,7 +146,7 @@
147147 // We're after the revision table, and the corresponding page
148148 // row for anything we retrieve. We may also need the
149149 // recentchanges row and/or tag summary row.
150 - global $wgUser;
 150+ $user = $this->getUser();
151151 $tables = array( 'page', 'revision' ); // Order may change
152152 $this->addWhere( 'page_id=rev_page' );
153153
@@ -167,7 +167,7 @@
168168 );
169169 }
170170
171 - if ( !$wgUser->isAllowed( 'hideuser' ) ) {
 171+ if ( !$user->isAllowed( 'hideuser' ) ) {
172172 $this->addWhere( $this->getDB()->bitAnd( 'rev_deleted', Revision::DELETED_USER ) . ' = 0' );
173173 }
174174 // We only want pages by the specified users.
@@ -216,7 +216,7 @@
217217
218218 if ( isset( $show['patrolled'] ) || isset( $show['!patrolled'] ) ||
219219 $this->fld_patrolled ) {
220 - if ( !$wgUser->useRCPatrol() && !$wgUser->useNPPatrol() ) {
 220+ if ( !$user->useRCPatrol() && !$user->useNPPatrol() ) {
221221 $this->dieUsage( 'You need the patrol right to request the patrolled flag', 'permissiondenied' );
222222 }
223223

Follow-up revisions

RevisionCommit summaryAuthorDate
r100906Followup 100905, fixing usages of getContext()johnduhart23:34, 26 October 2011
r100926Followup r100905, fixed the ApiTestsjohnduhart01:06, 27 October 2011
r100927Followup r100905, cleanup per CR and fixes the overriding of the main Request...johnduhart01:13, 27 October 2011
r101024Fix for r100905:...ialex18:46, 27 October 2011
r101051Followup r100905, disabling testGetRollbackToken because it reports as failed...johnduhart21:01, 27 October 2011
r101273Followup r100927 and r100905, when setting a FauxRequest use the NEW contextjohnduhart16:14, 29 October 2011

Comments

#Comment by Catrope (talk | contribs)   23:33, 26 October 2011
+               } elseif ( $context instanceof WebRequest ) {
+                       // BC for pre-1.19
+                       $request = $context;
+                       $context = RequestContext::getMain();
+                       $context->setRequest( $request );
+               }

This essentially sets the global context's request ("wgRequest") to whatever was passed into this constructor. That doesn't sound like a good idea. It should probably be done after creating the DerivativeContext instead.

There is some commented code and commenting out of code in your commit, please clean that up.

The architecture here (i.e. the changes to ApiMain and ApiBase) looks good to me otherwise. There's probably some oversight somewhere in the bazillion other changes, but I don't anticipate any fundamental problems.

#Comment by Hashar (talk | contribs)   16:08, 27 October 2011

Breaks the ApiUploadTests!

#Comment by RobLa-WMF (talk | contribs)   20:42, 27 October 2011

John assured me he is working on a fix for the tests now. Please revert or fix if this isn't the case by the time you're back up and about. Thanks!

#Comment by MaxSem (talk | contribs)   18:06, 27 October 2011

On some special pages:

MediaWiki internal error.

 Original exception: exception 'MWException' with message 'FauxRequest::getRequestURL() not implemented' in D:\Projects\MediaWiki branches\git\includes\WebRequest.php:1200
 Stack trace:
 #0 D:\Projects\MediaWiki branches\git\includes\WebRequest.php(1243): FauxRequest->notImplemented('FauxRequest::ge...')
 #1 D:\Projects\MediaWiki branches\git\includes\SkinTemplate.php(1006): FauxRequest->getRequestURL()
 #2 D:\Projects\MediaWiki branches\git\includes\SkinTemplate.php(465): SkinTemplate->buildContentNavigationUrls()
 #3 D:\Projects\MediaWiki branches\git\includes\OutputPage.php(1919): SkinTemplate->outputPage()
 #4 D:\Projects\MediaWiki branches\git\includes\Wiki.php(381): OutputPage->output()
 #5 D:\Projects\MediaWiki branches\git\includes\Wiki.php(601): MediaWiki->finalCleanup()
 #6 D:\Projects\MediaWiki branches\git\includes\Wiki.php(519): MediaWiki->main()
 #7 D:\Projects\MediaWiki branches\git\index.php(58): MediaWiki->run()
 #8 {main}

 Exception caught inside exception handler: exception 'MWException' with message 'FauxRequest::getRequestURL() not implemented' in D:\Projects\MediaWiki branches\git\includes\WebRequest.php:1200
 Stack trace:
 #0 D:\Projects\MediaWiki branches\git\includes\WebRequest.php(1243): FauxRequest->notImplemented('FauxRequest::ge...')
 #1 D:\Projects\MediaWiki branches\git\includes\SkinTemplate.php(1006): FauxRequest->getRequestURL()
 #2 D:\Projects\MediaWiki branches\git\includes\SkinTemplate.php(465): SkinTemplate->buildContentNavigationUrls()
 #3 D:\Projects\MediaWiki branches\git\includes\OutputPage.php(1919): SkinTemplate->outputPage()
 #4 D:\Projects\MediaWiki branches\git\includes\Exception.php(188): OutputPage->output()
 #5 D:\Projects\MediaWiki branches\git\includes\Exception.php(214): MWException->reportHTML()
 #6 D:\Projects\MediaWiki branches\git\includes\Exception.php(458): MWException->report()
 #7 D:\Projects\MediaWiki branches\git\includes\Exception.php(537): MWExceptionHandler::report(Object(MWException))
 #8 D:\Projects\MediaWiki branches\git\includes\Wiki.php(522): MWExceptionHandler::handle(Object(MWException))
 #9 D:\Projects\MediaWiki branches\git\index.php(58): MediaWiki->run()
 #10 {main}

#Comment by Johnduhart (talk | contribs)   20:44, 27 October 2011

That's really interesting, what SpecialPages are those

#Comment by MaxSem (talk | contribs)   20:42, 28 October 2011

Got it! The porblem was not in special pages, it was in

		} elseif ( $context instanceof WebRequest ) {
			// BC for pre-1.19
			$request = $context;
			$context = RequestContext::getMain();
		}

So if someone tries to create an ApiMain object for internal use, and pass it an instance of FauxRequest, old-style, they pollute global context with a request that will blow everything out of the sky later. That's wrong.

#Comment by Catrope (talk | contribs)   11:10, 29 October 2011

This was supposed to have been fixed in r100927, but was done wrong. I'll comment there.

#Comment by Catrope (talk | contribs)   20:36, 1 November 2011

Reported issues have been resolved, setting back to new.

#Comment by Catrope (talk | contribs)   16:03, 14 November 2011
+               // TODO: Does this still need $wgTitle?

I believe so. I don't think wfMsg() and friends have been fixed to no longer depend on $wgTitle yet, have they?

-                       $token = $wgUser->editToken( '', $this->getMain()->getRequest() );
+                       $token = $user->editToken( '', $this->getMain()->getRequest() );

Shouldn't this call $this->getRequest() directly?

-                       $vals['preferencestoken'] = $wgUser->editToken( '', $this->getMain()->getRequest() );
+                       $vals['preferencestoken'] = $user->editToken( '', $this->getMain()->getRequest() );

Same

OK otherwise. These comments are minor things, setting to OK.

Status & tagging log