Index: trunk/phase3/docs/hooks.txt |
— | — | @@ -1440,12 +1440,6 @@ |
1441 | 1441 | 'remove-self' => array( removable groups from self ) |
1442 | 1442 | ) |
1443 | 1443 | |
1444 | | -'UserRightsLogEntry': before a log entry is added by UserrightsPage::addLogEntry(). If you use this hook to add your own log entries, you can return false to prevent the usual log entry from being added |
1445 | | -$user: User or UserrightsProxy object |
1446 | | -$oldGroups: Array of groups the user was a member of before the change |
1447 | | -$newGroups: Array of groups the user is a member of after the change |
1448 | | -$reason: User-provided summary |
1449 | | - |
1450 | 1444 | 'UserRetrieveNewTalks': called when retrieving "You have new messages!" message(s) |
1451 | 1445 | $user: user retrieving new talks messages |
1452 | 1446 | $talks: array of new talks page(s) |
Index: trunk/phase3/includes/api/ApiUserrights.php |
— | — | @@ -42,17 +42,21 @@ |
43 | 43 | $params = $this->extractRequestParams(); |
44 | 44 | if(is_null($params['user'])) |
45 | 45 | $this->dieUsageMsg(array('missingparam', 'user')); |
46 | | - $user = User::newFromName($params['user']); |
47 | | - if($user->isAnon()) |
48 | | - $this->dieUsageMsg(array('nosuchuser', $params['user'])); |
49 | 46 | if(is_null($params['token'])) |
50 | 47 | $this->dieUsageMsg(array('missingparam', 'token')); |
| 48 | + |
| 49 | + $form = new UserrightsPage; |
| 50 | + $user = $form->fetchUser($params['user']); |
| 51 | + if($user instanceof WikiErrorMsg) |
| 52 | + $this->dieUsageMsg(array_merge( |
| 53 | + (array)$user->getMessageKey(), |
| 54 | + $user->getMessageArgs())); |
51 | 55 | if(!$wgUser->matchEditToken($params['token'], $user->getName())) |
52 | 56 | $this->dieUsageMsg(array('sessionfailure')); |
53 | 57 | |
54 | 58 | $r['user'] = $user->getName(); |
55 | 59 | list($r['added'], $r['removed']) = |
56 | | - UserrightsPage::doSaveUserGroups( |
| 60 | + $form->doSaveUserGroups( |
57 | 61 | $user, (array)$params['add'], |
58 | 62 | (array)$params['remove'], $params['reason']); |
59 | 63 | |
— | — | @@ -71,9 +75,7 @@ |
72 | 76 | |
73 | 77 | public function getAllowedParams() { |
74 | 78 | return array ( |
75 | | - 'user' => array( |
76 | | - ApiBase :: PARAM_TYPE => 'user' |
77 | | - ), |
| 79 | + 'user' => null, |
78 | 80 | 'add' => array( |
79 | 81 | ApiBase :: PARAM_TYPE => User::getAllGroups(), |
80 | 82 | ApiBase :: PARAM_ISMULTI => true |
Index: trunk/phase3/includes/specials/SpecialUserrights.php |
— | — | @@ -134,7 +134,8 @@ |
135 | 135 | global $wgRequest, $wgUser, $wgGroupsAddToSelf, $wgGroupsRemoveFromSelf; |
136 | 136 | |
137 | 137 | $user = $this->fetchUser( $username ); |
138 | | - if( !$user ) { |
| 138 | + if( $user instanceof WikiErrorMsg ) { |
| 139 | + $wgOut->addWikiMsgArray($user->getMessageKey(), $user->getMessageArgs()); |
139 | 140 | return; |
140 | 141 | } |
141 | 142 | |
— | — | @@ -153,7 +154,7 @@ |
154 | 155 | $removegroup[] = $group; |
155 | 156 | } |
156 | 157 | } |
157 | | - self::doSaveUserGroups( $user, $addgroup, $removegroup, $reason ); |
| 158 | + $this->doSaveUserGroups( $user, $addgroup, $removegroup, $reason ); |
158 | 159 | } |
159 | 160 | |
160 | 161 | /** |
— | — | @@ -165,7 +166,7 @@ |
166 | 167 | * @param $reason String: reason for group change |
167 | 168 | * @return Array: Tuple of added, then removed groups |
168 | 169 | */ |
169 | | - static function doSaveUserGroups( $user, $add, $remove, $reason = '' ) { |
| 170 | + function doSaveUserGroups( $user, $add, $remove, $reason = '' ) { |
170 | 171 | global $wgUser; |
171 | 172 | |
172 | 173 | // Validate input set... |
— | — | @@ -206,7 +207,7 @@ |
207 | 208 | wfRunHooks( 'UserRights', array( &$user, $add, $remove ) ); |
208 | 209 | |
209 | 210 | if( $newGroups != $oldGroups ) { |
210 | | - self::addLogEntry( $user, $oldGroups, $newGroups, $reason ); |
| 211 | + $this->addLogEntry( $user, $oldGroups, $newGroups, $reason ); |
211 | 212 | } |
212 | 213 | return array( $add, $remove ); |
213 | 214 | } |
— | — | @@ -215,22 +216,15 @@ |
216 | 217 | /** |
217 | 218 | * Add a rights log entry for an action. |
218 | 219 | */ |
219 | | - static function addLogEntry( $user, $oldGroups, $newGroups, $reason ) { |
220 | | - // Just overriding addLogEntry in a subclass would be cleaner, |
221 | | - // but that requires PHP 5.3 (late static bindings) |
222 | | - if( !wfRunHooks( 'UserRightsLogEntry', array( $user, $oldGroups, |
223 | | - $newGroups, $reason ) ) ) { |
224 | | - return; |
225 | | - } |
226 | | - |
| 220 | + function addLogEntry( $user, $oldGroups, $newGroups, $reason ) { |
227 | 221 | $log = new LogPage( 'rights' ); |
228 | 222 | |
229 | 223 | $log->addEntry( 'rights', |
230 | 224 | $user->getUserPage(), |
231 | 225 | $reason, |
232 | 226 | array( |
233 | | - self::makeGroupNameListForLog( $oldGroups ), |
234 | | - self::makeGroupNameListForLog( $newGroups ) |
| 227 | + $this->makeGroupNameListForLog( $oldGroups ), |
| 228 | + $this->makeGroupNameListForLog( $newGroups ) |
235 | 229 | ) |
236 | 230 | ); |
237 | 231 | } |
— | — | @@ -243,7 +237,8 @@ |
244 | 238 | global $wgOut; |
245 | 239 | |
246 | 240 | $user = $this->fetchUser( $username ); |
247 | | - if( !$user ) { |
| 241 | + if( $user instanceof WikiErrorMsg ) { |
| 242 | + $wgOut->addWikiMsgArray($user->getMessageKey(), $user->getMessageArgs()); |
248 | 243 | return; |
249 | 244 | } |
250 | 245 | |
— | — | @@ -261,10 +256,10 @@ |
262 | 257 | * return a user (or proxy) object for manipulating it. |
263 | 258 | * |
264 | 259 | * Side effects: error output for invalid access |
265 | | - * @return mixed User, UserRightsProxy, or null |
| 260 | + * @return mixed User, UserRightsProxy, or WikiErrorMsg |
266 | 261 | */ |
267 | 262 | function fetchUser( $username ) { |
268 | | - global $wgOut, $wgUser, $wgUserrightsInterwikiDelimiter; |
| 263 | + global $wgUser, $wgUserrightsInterwikiDelimiter; |
269 | 264 | |
270 | 265 | $parts = explode( $wgUserrightsInterwikiDelimiter, $username ); |
271 | 266 | if( count( $parts ) < 2 ) { |
— | — | @@ -274,18 +269,15 @@ |
275 | 270 | list( $name, $database ) = array_map( 'trim', $parts ); |
276 | 271 | |
277 | 272 | if( !$wgUser->isAllowed( 'userrights-interwiki' ) ) { |
278 | | - $wgOut->addWikiMsg( 'userrights-no-interwiki' ); |
279 | | - return null; |
| 273 | + return new WikiErrorMsg( 'userrights-no-interwiki' ); |
280 | 274 | } |
281 | 275 | if( !UserRightsProxy::validDatabase( $database ) ) { |
282 | | - $wgOut->addWikiMsg( 'userrights-nodatabase', $database ); |
283 | | - return null; |
| 276 | + return new WikiErrorMsg( 'userrights-nodatabase', $database ); |
284 | 277 | } |
285 | 278 | } |
286 | 279 | |
287 | 280 | if( $name == '' ) { |
288 | | - $wgOut->addWikiMsg( 'nouserspecified' ); |
289 | | - return false; |
| 281 | + return new WikiErrorMsg( 'nouserspecified' ); |
290 | 282 | } |
291 | 283 | |
292 | 284 | if( $name{0} == '#' ) { |
— | — | @@ -300,8 +292,7 @@ |
301 | 293 | } |
302 | 294 | |
303 | 295 | if( !$name ) { |
304 | | - $wgOut->addWikiMsg( 'noname' ); |
305 | | - return null; |
| 296 | + return new WikiErrorMsg( 'noname' ); |
306 | 297 | } |
307 | 298 | } |
308 | 299 | |
— | — | @@ -312,14 +303,13 @@ |
313 | 304 | } |
314 | 305 | |
315 | 306 | if( !$user || $user->isAnon() ) { |
316 | | - $wgOut->addWikiMsg( 'nosuchusershort', $username ); |
317 | | - return null; |
| 307 | + return new WikiErrorMsg( 'nosuchusershort', $username ); |
318 | 308 | } |
319 | 309 | |
320 | 310 | return $user; |
321 | 311 | } |
322 | 312 | |
323 | | - static function makeGroupNameList( $ids ) { |
| 313 | + function makeGroupNameList( $ids ) { |
324 | 314 | if( empty( $ids ) ) { |
325 | 315 | return wfMsgForContent( 'rightsnone' ); |
326 | 316 | } else { |
— | — | @@ -327,11 +317,11 @@ |
328 | 318 | } |
329 | 319 | } |
330 | 320 | |
331 | | - static function makeGroupNameListForLog( $ids ) { |
| 321 | + function makeGroupNameListForLog( $ids ) { |
332 | 322 | if( empty( $ids ) ) { |
333 | 323 | return ''; |
334 | 324 | } else { |
335 | | - return self::makeGroupNameList( $ids ); |
| 325 | + return $this->makeGroupNameList( $ids ); |
336 | 326 | } |
337 | 327 | } |
338 | 328 | |