Index: trunk/phase3/includes/api/ApiMove.php |
— | — | @@ -46,8 +46,6 @@ |
47 | 47 | $this->requireOnlyOneParameter( $params, 'from', 'fromid' ); |
48 | 48 | if ( !isset( $params['to'] ) ) |
49 | 49 | $this->dieUsageMsg( array( 'missingparam', 'to' ) ); |
50 | | - if ( !$wgUser->matchEditToken( $params['token'] ) ) |
51 | | - $this->dieUsageMsg( array( 'sessionfailure' ) ); |
52 | 50 | |
53 | 51 | if ( isset( $params['from'] ) ) |
54 | 52 | { |
— | — | @@ -213,7 +211,6 @@ |
214 | 212 | public function getPossibleErrors() { |
215 | 213 | return array_merge( parent::getPossibleErrors(), array( |
216 | 214 | array( 'missingparam', 'to' ), |
217 | | - array( 'sessionfailure' ), |
218 | 215 | array( 'invalidtitle', 'from' ), |
219 | 216 | array( 'nosuchpageid', 'fromid' ), |
220 | 217 | array( 'notanarticle' ), |
— | — | @@ -222,8 +219,8 @@ |
223 | 220 | ) ); |
224 | 221 | } |
225 | 222 | |
226 | | - public function requiresToken() { |
227 | | - return true; |
| 223 | + public function getTokenSalt() { |
| 224 | + return null; |
228 | 225 | } |
229 | 226 | |
230 | 227 | protected function getExamples() { |
Index: trunk/phase3/includes/api/ApiProtect.php |
— | — | @@ -46,9 +46,6 @@ |
47 | 47 | if ( empty( $params['protections'] ) ) |
48 | 48 | $this->dieUsageMsg( array( 'missingparam', 'protections' ) ); |
49 | 49 | |
50 | | - if ( !$wgUser->matchEditToken( $params['token'] ) ) |
51 | | - $this->dieUsageMsg( array( 'sessionfailure' ) ); |
52 | | - |
53 | 50 | $titleObj = Title::newFromText( $params['title'] ); |
54 | 51 | if ( !$titleObj ) |
55 | 52 | $this->dieUsageMsg( array( 'invalidtitle', $params['title'] ) ); |
— | — | @@ -176,7 +173,6 @@ |
177 | 174 | return array_merge( parent::getPossibleErrors(), array( |
178 | 175 | array( 'missingparam', 'title' ), |
179 | 176 | array( 'missingparam', 'protections' ), |
180 | | - array( 'sessionfailure' ), |
181 | 177 | array( 'invalidtitle', 'title' ), |
182 | 178 | array( 'toofewexpiries', 'noofexpiries', 'noofprotections' ), |
183 | 179 | array( 'create-titleexists' ), |
— | — | @@ -188,8 +184,8 @@ |
189 | 185 | ) ); |
190 | 186 | } |
191 | 187 | |
192 | | - public function requiresToken() { |
193 | | - return true; |
| 188 | + public function getTokenSalt() { |
| 189 | + return null; |
194 | 190 | } |
195 | 191 | |
196 | 192 | protected function getExamples() { |
Index: trunk/phase3/includes/api/ApiRollback.php |
— | — | @@ -122,8 +122,8 @@ |
123 | 123 | ) ); |
124 | 124 | } |
125 | 125 | |
126 | | - public function requiresToken() { |
127 | | - return true; |
| 126 | + public function getTokenSalt() { |
| 127 | + return null; |
128 | 128 | } |
129 | 129 | |
130 | 130 | protected function getExamples() { |
Index: trunk/phase3/includes/api/ApiUserrights.php |
— | — | @@ -37,19 +37,11 @@ |
38 | 38 | } |
39 | 39 | |
40 | 40 | public function execute() { |
41 | | - global $wgUser; |
42 | 41 | $params = $this->extractRequestParams(); |
43 | | - if ( is_null( $params['user'] ) ) |
44 | | - $this->dieUsageMsg( array( 'missingparam', 'user' ) ); |
45 | | - |
| 42 | + |
| 43 | + //User already validated in call to getTokenSalt from Main |
46 | 44 | $form = new UserrightsPage; |
47 | 45 | $user = $form->fetchUser( $params['user'] ); |
48 | | - if ( $user instanceof WikiErrorMsg ) |
49 | | - $this->dieUsageMsg( array_merge( |
50 | | - (array)$user->getMessageKey(), $user->getMessageArgs() ) ); |
51 | | - |
52 | | - if ( !$wgUser->matchEditToken( $params['token'], $user->getName() ) ) |
53 | | - $this->dieUsageMsg( array( 'sessionfailure' ) ); |
54 | 46 | |
55 | 47 | $r['user'] = $user->getName(); |
56 | 48 | list( $r['added'], $r['removed'] ) = |
— | — | @@ -107,12 +99,21 @@ |
108 | 100 | public function getPossibleErrors() { |
109 | 101 | return array_merge( parent::getPossibleErrors(), array( |
110 | 102 | array( 'missingparam', 'user' ), |
111 | | - array( 'sessionfailure' ), |
112 | 103 | ) ); |
113 | 104 | } |
114 | 105 | |
115 | | - public function requiresToken() { |
116 | | - return true; |
| 106 | + public function getTokenSalt() { |
| 107 | + $params = $this->extractRequestParams(); |
| 108 | + if ( is_null( $params['user'] ) ) |
| 109 | + $this->dieUsageMsg( array( 'missingparam', 'user' ) ); |
| 110 | + |
| 111 | + $form = new UserrightsPage; |
| 112 | + $user = $form->fetchUser( $params['user'] ); |
| 113 | + if ( $user instanceof WikiErrorMsg ) |
| 114 | + $this->dieUsageMsg( array_merge( |
| 115 | + (array)$user->getMessageKey(), $user->getMessageArgs() ) ); |
| 116 | + |
| 117 | + return $user->getName(); |
117 | 118 | } |
118 | 119 | |
119 | 120 | protected function getExamples() { |
Index: trunk/phase3/includes/api/ApiDelete.php |
— | — | @@ -47,7 +47,8 @@ |
48 | 48 | * result object. |
49 | 49 | */ |
50 | 50 | public function execute() { |
51 | | - global $wgUser; |
| 51 | + global $wgUser; |
| 52 | + |
52 | 53 | $params = $this->extractRequestParams(); |
53 | 54 | |
54 | 55 | $this->requireOnlyOneParameter( $params, 'title', 'pageid' ); |
— | — | @@ -78,7 +79,7 @@ |
79 | 80 | |
80 | 81 | if ( count( $retval ) ) |
81 | 82 | $this->dieUsageMsg( reset( $retval ) ); // We don't care about multiple errors, just report one of them |
82 | | - |
| 83 | + |
83 | 84 | if ( $params['watch'] || $wgUser->getOption( 'watchdeletion' ) ) |
84 | 85 | $articleObj->doWatch(); |
85 | 86 | else if ( $params['unwatch'] ) |
— | — | @@ -95,10 +96,7 @@ |
96 | 97 | // Check permissions |
97 | 98 | $errors = $title->getUserPermissionsErrors( 'delete', $wgUser ); |
98 | 99 | if ( count( $errors ) > 0 ) return $errors; |
99 | | - |
100 | | - // Check token |
101 | | - if ( !$wgUser->matchEditToken( $token ) ) |
102 | | - return array( array( 'sessionfailure' ) ); |
| 100 | + |
103 | 101 | return array(); |
104 | 102 | } |
105 | 103 | |
— | — | @@ -219,8 +217,8 @@ |
220 | 218 | ) ); |
221 | 219 | } |
222 | 220 | |
223 | | - public function requiresToken() { |
224 | | - return true; |
| 221 | + public function getTokenSalt() { |
| 222 | + return null; |
225 | 223 | } |
226 | 224 | |
227 | 225 | protected function getExamples() { |
Index: trunk/phase3/includes/api/ApiImport.php |
— | — | @@ -44,8 +44,6 @@ |
45 | 45 | if ( !$wgUser->isAllowed( 'import' ) ) |
46 | 46 | $this->dieUsageMsg( array( 'cantimport' ) ); |
47 | 47 | $params = $this->extractRequestParams(); |
48 | | - if ( !$wgUser->matchEditToken( $params['token'] ) ) |
49 | | - $this->dieUsageMsg( array( 'sessionfailure' ) ); |
50 | 48 | |
51 | 49 | $source = null; |
52 | 50 | $isUpload = false; |
— | — | @@ -144,7 +142,6 @@ |
145 | 143 | public function getPossibleErrors() { |
146 | 144 | return array_merge( parent::getPossibleErrors(), array( |
147 | 145 | array( 'cantimport' ), |
148 | | - array( 'sessionfailure' ), |
149 | 146 | array( 'missingparam', 'interwikipage' ), |
150 | 147 | array( 'cantimport-upload' ), |
151 | 148 | array( 'import-unknownerror', 'source' ), |
— | — | @@ -152,8 +149,8 @@ |
153 | 150 | ) ); |
154 | 151 | } |
155 | 152 | |
156 | | - public function requiresToken() { |
157 | | - return true; |
| 153 | + public function getTokenSalt() { |
| 154 | + return null; |
158 | 155 | } |
159 | 156 | |
160 | 157 | protected function getExamples() { |
Index: trunk/phase3/includes/api/ApiEditPage.php |
— | — | @@ -53,9 +53,6 @@ |
54 | 54 | $params['undo'] == 0 ) |
55 | 55 | $this->dieUsageMsg( array( 'missingtext' ) ); |
56 | 56 | |
57 | | - if ( !$wgUser->matchEditToken( $params['token'] ) ) |
58 | | - $this->dieUsageMsg( array( 'sessionfailure' ) ); |
59 | | - |
60 | 57 | $titleObj = Title::newFromText( $params['title'] ); |
61 | 58 | if ( !$titleObj || $titleObj->isExternal() ) |
62 | 59 | $this->dieUsageMsg( array( 'invalidtitle', $params['title'] ) ); |
— | — | @@ -347,7 +344,6 @@ |
348 | 345 | return array_merge( parent::getPossibleErrors(), array( |
349 | 346 | array( 'missingparam', 'title' ), |
350 | 347 | array( 'missingtext' ), |
351 | | - array( 'sessionfailure' ), |
352 | 348 | array( 'invalidtitle', 'title' ), |
353 | 349 | array( 'createonly-exists' ), |
354 | 350 | array( 'nocreate-missing' ), |
— | — | @@ -463,8 +459,8 @@ |
464 | 460 | ); |
465 | 461 | } |
466 | 462 | |
467 | | - public function requiresToken() { |
468 | | - return true; |
| 463 | + public function getTokenSalt() { |
| 464 | + return null; |
469 | 465 | } |
470 | 466 | |
471 | 467 | protected function getExamples() { |
Index: trunk/phase3/includes/api/ApiUnblock.php |
— | — | @@ -57,8 +57,7 @@ |
58 | 58 | $this->dieUsageMsg( array( 'unblock-notarget' ) ); |
59 | 59 | if ( !is_null( $params['id'] ) && !is_null( $params['user'] ) ) |
60 | 60 | $this->dieUsageMsg( array( 'unblock-idanduser' ) ); |
61 | | - if ( !$wgUser->matchEditToken( $params['token'] ) ) |
62 | | - $this->dieUsageMsg( array( 'sessionfailure' ) ); |
| 61 | + |
63 | 62 | if ( !$wgUser->isAllowed( 'block' ) ) |
64 | 63 | $this->dieUsageMsg( array( 'cantunblock' ) ); |
65 | 64 | |
— | — | @@ -113,13 +112,12 @@ |
114 | 113 | return array_merge( parent::getPossibleErrors(), array( |
115 | 114 | array( 'unblock-notarget' ), |
116 | 115 | array( 'unblock-idanduser' ), |
117 | | - array( 'sessionfailure' ), |
118 | 116 | array( 'cantunblock' ), |
119 | 117 | ) ); |
120 | 118 | } |
121 | 119 | |
122 | | - public function requiresToken() { |
123 | | - return true; |
| 120 | + public function getTokenSalt() { |
| 121 | + return null; |
124 | 122 | } |
125 | 123 | |
126 | 124 | protected function getExamples() { |
Index: trunk/phase3/includes/api/ApiMain.php |
— | — | @@ -400,7 +400,7 @@ |
401 | 401 | $this->getResult()->addValue( null, 'requestid', $requestid ); |
402 | 402 | |
403 | 403 | $params = $this->extractRequestParams(); |
404 | | - |
| 404 | + |
405 | 405 | $this->mShowVersions = $params['version']; |
406 | 406 | $this->mAction = $params['action']; |
407 | 407 | |
— | — | @@ -412,9 +412,22 @@ |
413 | 413 | $module = new $this->mModules[$this->mAction] ( $this, $this->mAction ); |
414 | 414 | $this->mModule = $module; |
415 | 415 | |
| 416 | + $moduleParams = $module->extractRequestParams(); |
| 417 | + |
416 | 418 | //Die if token required, but not provided (unless there is a gettoken parameter) |
417 | | - if ( $module->requiresToken() && !isset( $params['token'] ) && isset( $params['gettoken'] ) ) |
418 | | - $this->dieUsageMsg( array( 'missingparam', 'token' ) ); |
| 419 | + $salt = $module->getTokenSalt(); |
| 420 | + if ( $salt != false ) |
| 421 | + { |
| 422 | + if ( !isset( $moduleParams['token'] ) && !isset( $moduleParams['gettoken'] ) ) { |
| 423 | + $this->dieUsageMsg( array( 'missingparam', 'token' ) ); |
| 424 | + } else { |
| 425 | + global $wgUser; |
| 426 | + if ( ( $salt != null /*&& !$wgUser->matchEditToken( $moduleParams['token'], $salt )*/ ) |
| 427 | + /*|| !$wgUser->matchEditToken( $moduleParams['token'] )*/ ) { |
| 428 | + $this->dieUsageMsg( array( 'sessionfailure' ) ); |
| 429 | + } |
| 430 | + } |
| 431 | + } |
419 | 432 | |
420 | 433 | if ( $module->shouldCheckMaxlag() && isset( $params['maxlag'] ) ) { |
421 | 434 | // Check for maxlag |
Index: trunk/phase3/includes/api/ApiEmailUser.php |
— | — | @@ -112,8 +112,8 @@ |
113 | 113 | ) ); |
114 | 114 | } |
115 | 115 | |
116 | | - public function requiresToken() { |
117 | | - return true; |
| 116 | + public function getTokenSalt() { |
| 117 | + return null; |
118 | 118 | } |
119 | 119 | |
120 | 120 | protected function getExamples() { |
Index: trunk/phase3/includes/api/ApiBlock.php |
— | — | @@ -61,8 +61,6 @@ |
62 | 62 | |
63 | 63 | if ( is_null( $params['user'] ) ) |
64 | 64 | $this->dieUsageMsg( array( 'missingparam', 'user' ) ); |
65 | | - if ( !$wgUser->matchEditToken( $params['token'] ) ) |
66 | | - $this->dieUsageMsg( array( 'sessionfailure' ) ); |
67 | 65 | if ( !$wgUser->isAllowed( 'block' ) ) |
68 | 66 | $this->dieUsageMsg( array( 'cantblock' ) ); |
69 | 67 | if ( $params['hidename'] && !$wgUser->isAllowed( 'hideuser' ) ) |
— | — | @@ -161,15 +159,14 @@ |
162 | 160 | public function getPossibleErrors() { |
163 | 161 | return array_merge( parent::getPossibleErrors(), array( |
164 | 162 | array( 'missingparam', 'user' ), |
165 | | - array( 'sessionfailure' ), |
166 | 163 | array( 'cantblock' ), |
167 | 164 | array( 'canthide' ), |
168 | 165 | array( 'cantblock-email' ), |
169 | 166 | ) ); |
170 | 167 | } |
171 | 168 | |
172 | | - public function requiresToken() { |
173 | | - return true; |
| 169 | + public function getTokenSalt() { |
| 170 | + return null; |
174 | 171 | } |
175 | 172 | |
176 | 173 | protected function getExamples() { |
Index: trunk/phase3/includes/api/ApiPatrol.php |
— | — | @@ -41,13 +41,10 @@ |
42 | 42 | * Patrols the article or provides the reason the patrol failed. |
43 | 43 | */ |
44 | 44 | public function execute() { |
45 | | - global $wgUser; |
46 | 45 | $params = $this->extractRequestParams(); |
47 | 46 | |
48 | 47 | if ( !isset( $params['rcid'] ) ) |
49 | 48 | $this->dieUsageMsg( array( 'missingparam', 'rcid' ) ); |
50 | | - if ( !$wgUser->matchEditToken( $params['token'] ) ) |
51 | | - $this->dieUsageMsg( array( 'sessionfailure' ) ); |
52 | 49 | |
53 | 50 | $rc = RecentChange::newFromID( $params['rcid'] ); |
54 | 51 | if ( !$rc instanceof RecentChange ) |
— | — | @@ -91,13 +88,12 @@ |
92 | 89 | public function getPossibleErrors() { |
93 | 90 | return array_merge( parent::getPossibleErrors(), array( |
94 | 91 | array( 'missingparam', 'rcid' ), |
95 | | - array( 'sessionfailure' ), |
96 | 92 | array( 'nosuchrcid', 'rcid' ), |
97 | 93 | ) ); |
98 | 94 | } |
99 | 95 | |
100 | | - public function requiresToken() { |
101 | | - return true; |
| 96 | + public function getTokenSalt() { |
| 97 | + return null; |
102 | 98 | } |
103 | 99 | |
104 | 100 | protected function getExamples() { |
Index: trunk/phase3/includes/api/ApiUndelete.php |
— | — | @@ -50,9 +50,6 @@ |
51 | 51 | if ( $wgUser->isBlocked() ) |
52 | 52 | $this->dieUsageMsg( array( 'blockedtext' ) ); |
53 | 53 | |
54 | | - if ( !$wgUser->matchEditToken( $params['token'] ) ) |
55 | | - $this->dieUsageMsg( array( 'sessionfailure' ) ); |
56 | | - |
57 | 54 | $titleObj = Title::newFromText( $params['title'] ); |
58 | 55 | if ( !$titleObj ) |
59 | 56 | $this->dieUsageMsg( array( 'invalidtitle', $params['title'] ) ); |
— | — | @@ -123,14 +120,13 @@ |
124 | 121 | array( 'missingparam', 'title' ), |
125 | 122 | array( 'permdenied-undelete' ), |
126 | 123 | array( 'blockedtext' ), |
127 | | - array( 'sessionfailure' ), |
128 | 124 | array( 'invalidtitle', 'title' ), |
129 | 125 | array( 'cannotundelete' ), |
130 | 126 | ) ); |
131 | 127 | } |
132 | 128 | |
133 | | - public function requiresToken() { |
134 | | - return true; |
| 129 | + public function getTokenSalt() { |
| 130 | + return null; |
135 | 131 | } |
136 | 132 | |
137 | 133 | protected function getExamples() { |
Index: trunk/phase3/includes/api/ApiBase.php |
— | — | @@ -970,10 +970,10 @@ |
971 | 971 | } |
972 | 972 | |
973 | 973 | /** |
974 | | - * Indicates whether this module needs a token to preform the request |
| 974 | + * Returns the token salt if there is one, null if the module doesn't require a salt, else false if the module doesn't need a token |
975 | 975 | * @returns bool |
976 | 976 | */ |
977 | | - public function requiresToken() { |
| 977 | + public function getTokenSalt() { |
978 | 978 | return false; |
979 | 979 | } |
980 | 980 | |
— | — | @@ -997,7 +997,7 @@ |
998 | 998 | $ret[] = array ( 'writedisabled' ); |
999 | 999 | } |
1000 | 1000 | |
1001 | | - if ( $this->requiresToken() ) { |
| 1001 | + if ( $this->getTokenSalt() != false ) { |
1002 | 1002 | $ret[] = array( 'missingparam', 'token' ); |
1003 | 1003 | } |
1004 | 1004 | |
Index: trunk/phase3/includes/api/ApiUpload.php |
— | — | @@ -47,10 +47,6 @@ |
48 | 48 | $this->mParams = $this->extractRequestParams(); |
49 | 49 | $request = $this->getMain()->getRequest(); |
50 | 50 | |
51 | | - // Do token checks: |
52 | | - if ( !$wgUser->matchEditToken( $this->mParams['token'] ) ) |
53 | | - $this->dieUsageMsg( array( 'sessionfailure' ) ); |
54 | | - |
55 | 51 | // Add the uploaded file to the params array |
56 | 52 | $this->mParams['file'] = $request->getFileName( 'file' ); |
57 | 53 | |
— | — | @@ -328,7 +324,6 @@ |
329 | 325 | public function getPossibleErrors() { |
330 | 326 | return array_merge( parent::getPossibleErrors(), array( |
331 | 327 | array( 'uploaddisabled' ), |
332 | | - array( 'sessionfailure' ), |
333 | 328 | array( 'invalid-session-key' ), |
334 | 329 | array( 'uploaddisabled' ), |
335 | 330 | array( 'badaccess-groups' ), |
— | — | @@ -347,8 +342,8 @@ |
348 | 343 | ) ); |
349 | 344 | } |
350 | 345 | |
351 | | - public function requiresToken() { |
352 | | - return true; |
| 346 | + public function getTokenSalt() { |
| 347 | + return null; |
353 | 348 | } |
354 | 349 | |
355 | 350 | protected function getExamples() { |