Index: trunk/phase3/tests/phpunit/includes/upload/UploadFromUrlTest.php |
— | — | @@ -20,7 +20,7 @@ |
21 | 21 | } |
22 | 22 | } |
23 | 23 | |
24 | | - protected function doApiRequest( $params, $unused = null, $appendModule = false ) { |
| 24 | + protected function doApiRequest( $params, $unused = null, $appendModule = false, $user = null ) { |
25 | 25 | $sessionId = session_id(); |
26 | 26 | session_write_close(); |
27 | 27 | |
Index: trunk/phase3/tests/phpunit/includes/api/ApiUploadTest.php |
— | — | @@ -79,14 +79,11 @@ |
80 | 80 | * @depends testLogin |
81 | 81 | */ |
82 | 82 | public function testUploadMissingParams( $session ) { |
83 | | - global $wgUser; |
84 | | - $wgUser = self::$users['uploader']->user; |
85 | | - |
86 | 83 | $exception = false; |
87 | 84 | try { |
88 | 85 | $this->doApiRequestWithToken( array( |
89 | 86 | 'action' => 'upload', |
90 | | - ), $session ); |
| 87 | + ), $session, self::$users['uploader']->user ); |
91 | 88 | } catch ( UsageException $e ) { |
92 | 89 | $exception = true; |
93 | 90 | $this->assertEquals( "One of the parameters filekey, file, url, statuskey is required", |
— | — | @@ -100,9 +97,6 @@ |
101 | 98 | * @depends testLogin |
102 | 99 | */ |
103 | 100 | public function testUpload( $session ) { |
104 | | - global $wgUser; |
105 | | - $wgUser = self::$users['uploader']->user; |
106 | | - |
107 | 101 | $extension = 'png'; |
108 | 102 | $mimeType = 'image/png'; |
109 | 103 | |
— | — | @@ -136,7 +130,8 @@ |
137 | 131 | |
138 | 132 | $exception = false; |
139 | 133 | try { |
140 | | - list( $result, , ) = $this->doApiRequestWithToken( $params, $session ); |
| 134 | + list( $result, , ) = $this->doApiRequestWithToken( $params, $session, |
| 135 | + self::$users['uploader']->user ); |
141 | 136 | } catch ( UsageException $e ) { |
142 | 137 | $exception = true; |
143 | 138 | } |
— | — | @@ -156,9 +151,6 @@ |
157 | 152 | * @depends testLogin |
158 | 153 | */ |
159 | 154 | public function testUploadZeroLength( $session ) { |
160 | | - global $wgUser; |
161 | | - $wgUser = self::$users['uploader']->user; |
162 | | - |
163 | 155 | $mimeType = 'image/png'; |
164 | 156 | |
165 | 157 | $filePath = tempnam( wfTempDir(), "" ); |
— | — | @@ -180,7 +172,7 @@ |
181 | 173 | |
182 | 174 | $exception = false; |
183 | 175 | try { |
184 | | - $this->doApiRequestWithToken( $params, $session ); |
| 176 | + $this->doApiRequestWithToken( $params, $session, self::$users['uploader']->user ); |
185 | 177 | } catch ( UsageException $e ) { |
186 | 178 | $this->assertContains( 'The file you submitted was empty', $e->getMessage() ); |
187 | 179 | $exception = true; |
— | — | @@ -197,9 +189,6 @@ |
198 | 190 | * @depends testLogin |
199 | 191 | */ |
200 | 192 | public function testUploadSameFileName( $session ) { |
201 | | - global $wgUser; |
202 | | - $wgUser = self::$users['uploader']->user; |
203 | | - |
204 | 193 | $extension = 'png'; |
205 | 194 | $mimeType = 'image/png'; |
206 | 195 | |
— | — | @@ -234,7 +223,8 @@ |
235 | 224 | |
236 | 225 | $exception = false; |
237 | 226 | try { |
238 | | - list( $result, , $session ) = $this->doApiRequestWithToken( $params, $session ); |
| 227 | + list( $result, , $session ) = $this->doApiRequestWithToken( $params, $session, |
| 228 | + self::$users['uploader']->user ); |
239 | 229 | } catch ( UsageException $e ) { |
240 | 230 | $exception = true; |
241 | 231 | } |
— | — | @@ -250,7 +240,8 @@ |
251 | 241 | |
252 | 242 | $exception = false; |
253 | 243 | try { |
254 | | - list( $result, , ) = $this->doApiRequestWithToken( $params, $session ); |
| 244 | + list( $result, , ) = $this->doApiRequestWithToken( $params, $session, |
| 245 | + self::$users['uploader']->user ); |
255 | 246 | } catch ( UsageException $e ) { |
256 | 247 | $exception = true; |
257 | 248 | } |
— | — | @@ -271,9 +262,6 @@ |
272 | 263 | * @depends testLogin |
273 | 264 | */ |
274 | 265 | public function testUploadSameContent( $session ) { |
275 | | - global $wgUser; |
276 | | - $wgUser = self::$users['uploader']->user; |
277 | | - |
278 | 266 | $extension = 'png'; |
279 | 267 | $mimeType = 'image/png'; |
280 | 268 | |
— | — | @@ -309,7 +297,8 @@ |
310 | 298 | |
311 | 299 | $exception = false; |
312 | 300 | try { |
313 | | - list( $result, $request, $session ) = $this->doApiRequestWithToken( $params, $session ); |
| 301 | + list( $result, $request, $session ) = $this->doApiRequestWithToken( $params, $session, |
| 302 | + self::$users['uploader']->user ); |
314 | 303 | } catch ( UsageException $e ) { |
315 | 304 | $exception = true; |
316 | 305 | } |
— | — | @@ -334,7 +323,8 @@ |
335 | 324 | |
336 | 325 | $exception = false; |
337 | 326 | try { |
338 | | - list( $result, $request, $session ) = $this->doApiRequestWithToken( $params, $session ); |
| 327 | + list( $result, $request, $session ) = $this->doApiRequestWithToken( $params, $session, |
| 328 | + self::$users['uploader']->user ); |
339 | 329 | } catch ( UsageException $e ) { |
340 | 330 | $exception = true; |
341 | 331 | } |
— | — | @@ -356,7 +346,7 @@ |
357 | 347 | */ |
358 | 348 | public function testUploadStash( $session ) { |
359 | 349 | global $wgUser; |
360 | | - $wgUser = self::$users['uploader']->user; |
| 350 | + $wgUser = self::$users['uploader']->user; // @todo FIXME: still used somewhere |
361 | 351 | |
362 | 352 | $extension = 'png'; |
363 | 353 | $mimeType = 'image/png'; |
— | — | @@ -391,7 +381,8 @@ |
392 | 382 | |
393 | 383 | $exception = false; |
394 | 384 | try { |
395 | | - list( $result, $request, $session ) = $this->doApiRequestWithToken( $params, $session ); |
| 385 | + list( $result, $request, $session ) = $this->doApiRequestWithToken( $params, $session, |
| 386 | + self::$users['uploader']->user ); |
396 | 387 | } catch ( UsageException $e ) { |
397 | 388 | $exception = true; |
398 | 389 | } |
— | — | @@ -419,7 +410,8 @@ |
420 | 411 | $this->clearFakeUploads(); |
421 | 412 | $exception = false; |
422 | 413 | try { |
423 | | - list( $result, $request, $session ) = $this->doApiRequestWithToken( $params, $session ); |
| 414 | + list( $result, $request, $session ) = $this->doApiRequestWithToken( $params, $session, |
| 415 | + self::$users['uploader']->user ); |
424 | 416 | } catch ( UsageException $e ) { |
425 | 417 | $exception = true; |
426 | 418 | } |
Index: trunk/phase3/tests/phpunit/includes/api/ApiBlockTest.php |
— | — | @@ -47,7 +47,7 @@ |
48 | 48 | 'action' => 'block', |
49 | 49 | 'user' => 'UTApiBlockee', |
50 | 50 | 'reason' => 'Some reason', |
51 | | - 'token' => $pageinfo['blocktoken'] ), $data ); |
| 51 | + 'token' => $pageinfo['blocktoken'] ), $data, false, self::$users['sysop']->user ); |
52 | 52 | |
53 | 53 | $block = Block::newFromTarget('UTApiBlockee'); |
54 | 54 | |
Index: trunk/phase3/tests/phpunit/includes/api/ApiTestCase.php |
— | — | @@ -43,12 +43,12 @@ |
44 | 44 | |
45 | 45 | } |
46 | 46 | |
47 | | - protected function doApiRequest( $params, $session = null, $appendModule = false ) { |
| 47 | + protected function doApiRequest( $params, $session = null, $appendModule = false, $user = null ) { |
48 | 48 | if ( is_null( $session ) ) { |
49 | 49 | $session = array(); |
50 | 50 | } |
51 | 51 | |
52 | | - $context = $this->apiContext->newTestContext( $params, $session ); |
| 52 | + $context = $this->apiContext->newTestContext( $params, $session, $user ); |
53 | 53 | $module = new ApiMain( $context, true ); |
54 | 54 | $module->execute(); |
55 | 55 | |
— | — | @@ -71,13 +71,13 @@ |
72 | 72 | * @param $params: key-value API params |
73 | 73 | * @param $session: session array |
74 | 74 | */ |
75 | | - protected function doApiRequestWithToken( $params, $session ) { |
| 75 | + protected function doApiRequestWithToken( $params, $session, $user = null ) { |
76 | 76 | if ( $session['wsToken'] ) { |
77 | 77 | // add edit token to fake session |
78 | 78 | $session['wsEditToken'] = $session['wsToken']; |
79 | 79 | // add token to request parameters |
80 | 80 | $params['token'] = md5( $session['wsToken'] ) . User::EDIT_TOKEN_SUFFIX; |
81 | | - return $this->doApiRequest( $params, $session ); |
| 81 | + return $this->doApiRequest( $params, $session, false, $user ); |
82 | 82 | } else { |
83 | 83 | throw new Exception( "request data not in right format" ); |
84 | 84 | } |
— | — | @@ -102,12 +102,11 @@ |
103 | 103 | } |
104 | 104 | |
105 | 105 | protected function getTokenList( $user ) { |
106 | | - $GLOBALS['wgUser'] = $user->user; |
107 | 106 | $data = $this->doApiRequest( array( |
108 | 107 | 'action' => 'query', |
109 | 108 | 'titles' => 'Main Page', |
110 | 109 | 'intoken' => 'edit|delete|protect|move|block|unblock', |
111 | | - 'prop' => 'info' ) ); |
| 110 | + 'prop' => 'info' ), false, $user->user ); |
112 | 111 | return $data; |
113 | 112 | } |
114 | 113 | } |
— | — | @@ -156,11 +155,15 @@ |
157 | 156 | * |
158 | 157 | * @param $params Array key-value API params |
159 | 158 | * @param $session Array session data |
| 159 | + * @param $user User or null |
160 | 160 | * @return DerivativeContext |
161 | 161 | */ |
162 | | - public function newTestContext( $params, $session ) { |
| 162 | + public function newTestContext( $params, $session, $user = null ) { |
163 | 163 | $context = new DerivativeContext( $this ); |
164 | 164 | $context->setRequest( new FauxRequest( $params, true, $session ) ); |
| 165 | + if ( $user !== null ) { |
| 166 | + $context->setUser( $user ); |
| 167 | + } |
165 | 168 | return $context; |
166 | 169 | } |
167 | 170 | } |
Index: trunk/phase3/includes/api/ApiLogin.php |
— | — | @@ -74,15 +74,16 @@ |
75 | 75 | $context->setRequest( $req );*/ |
76 | 76 | $loginForm = new LoginForm(); |
77 | 77 | $loginForm->setContext( $context ); |
78 | | - $user = $this->getUser(); |
79 | 78 | |
80 | 79 | global $wgCookiePrefix, $wgPasswordAttemptThrottle; |
81 | 80 | |
82 | 81 | $authRes = $loginForm->authenticateUserData(); |
83 | 82 | switch ( $authRes ) { |
84 | 83 | case LoginForm::SUCCESS: |
| 84 | + $user = $context->getUser(); |
| 85 | + $this->getContext()->setUser( $user ); |
85 | 86 | $user->setOption( 'rememberpassword', 1 ); |
86 | | - $user->setCookies( $this->getMain()->getRequest() ); |
| 87 | + $user->setCookies( $this->getRequest() ); |
87 | 88 | |
88 | 89 | // Run hooks. |
89 | 90 | // @todo FIXME: Split back and frontend from this hook. |
Index: trunk/phase3/includes/api/ApiBase.php |
— | — | @@ -74,7 +74,7 @@ |
75 | 75 | $this->mModulePrefix = $modulePrefix; |
76 | 76 | |
77 | 77 | if ( !$this->isMain() ) { |
78 | | - $this->setContext( $this->mMainModule ); |
| 78 | + $this->setContext( $mainModule->getContext() ); |
79 | 79 | } |
80 | 80 | } |
81 | 81 | |