Index: trunk/phase3/includes/SpecialBlockip.php |
— | — | @@ -282,17 +282,10 @@ |
283 | 283 | } |
284 | 284 | } |
285 | 285 | |
286 | | - const BLOCK_SUCCESS = 0; // Success |
287 | | - const BLOCK_RANGE_INVALID = 1; // Invalid IP range |
288 | | - const BLOCK_RANGE_DISABLED = 2; // Sysops can't block ranges |
289 | | - const BLOCK_NONEXISTENT_USER = 3; // No such user |
290 | | - const BLOCK_IP_INVALID = 4; // Invalid IP address |
291 | | - const BLOCK_EXPIRY_INVALID = 5; // Invalid expiry time |
292 | | - const BLOCK_ALREADY_BLOCKED = 6; // User is already blocked |
293 | 286 | /** |
294 | 287 | * Backend block code. |
295 | 288 | * $userID and $expiry will be filled accordingly |
296 | | - * Returns one of the BLOCK_* constants |
| 289 | + * @return array(message key, arguments) on failure, empty array on success |
297 | 290 | */ |
298 | 291 | function doBlock(&$userId = null, &$expiry = null) |
299 | 292 | { |
— | — | @@ -313,23 +306,23 @@ |
314 | 307 | # IPv4 |
315 | 308 | if ( $wgSysopRangeBans ) { |
316 | 309 | if ( !IP::isIPv4( $this->BlockAddress ) || $matches[2] < 16 || $matches[2] > 32 ) { |
317 | | - return self::BLOCK_RANGE_INVALID; |
| 310 | + return array('ip_range_invalid'); |
318 | 311 | } |
319 | 312 | $this->BlockAddress = Block::normaliseRange( $this->BlockAddress ); |
320 | 313 | } else { |
321 | 314 | # Range block illegal |
322 | | - return self::BLOCK_RANGE_DISABLED; |
| 315 | + return array('range_block_disabled'); |
323 | 316 | } |
324 | 317 | } else if ( preg_match( "/^($rxIP6)\\/(\\d{1,3})$/", $this->BlockAddress, $matches ) ) { |
325 | 318 | # IPv6 |
326 | 319 | if ( $wgSysopRangeBans ) { |
327 | 320 | if ( !IP::isIPv6( $this->BlockAddress ) || $matches[2] < 64 || $matches[2] > 128 ) { |
328 | | - return self::BLOCK_RANGE_INVALID; |
| 321 | + return array('ip_range_invalid'); |
329 | 322 | } |
330 | 323 | $this->BlockAddress = Block::normaliseRange( $this->BlockAddress ); |
331 | 324 | } else { |
332 | 325 | # Range block illegal |
333 | | - return self::BLOCK_RANGE_DISABLED; |
| 326 | + return array('range_block_disabled'); |
334 | 327 | } |
335 | 328 | } else { |
336 | 329 | # Username block |
— | — | @@ -337,13 +330,12 @@ |
338 | 331 | $user = User::newFromName( $this->BlockAddress ); |
339 | 332 | if( !is_null( $user ) && $user->getID() ) { |
340 | 333 | # Use canonical name |
341 | | - $this->BlockAddress = $user->getName(); |
342 | 334 | $userId = $user->getID(); |
343 | 335 | } else { |
344 | | - return self::BLOCK_NONEXISTENT_USER; |
| 336 | + return array('nosuchusershort', htmlspecialchars($user->getName())); |
345 | 337 | } |
346 | 338 | } else { |
347 | | - return self::BLOCK_IP_INVALID; |
| 339 | + return array('badipaddress'); |
348 | 340 | } |
349 | 341 | } |
350 | 342 | } |
— | — | @@ -361,7 +353,7 @@ |
362 | 354 | $expirestr = $this->BlockOther; |
363 | 355 | |
364 | 356 | if (strlen($expirestr) == 0) { |
365 | | - return self::BLOCK_EXPIRY_INVALID; |
| 357 | + return array('ipb_expiry_invalid'); |
366 | 358 | } |
367 | 359 | |
368 | 360 | if ( $expirestr == 'infinite' || $expirestr == 'indefinite' ) { |
— | — | @@ -371,7 +363,7 @@ |
372 | 364 | $expiry = strtotime( $expirestr ); |
373 | 365 | |
374 | 366 | if ( $expiry < 0 || $expiry === false ) { |
375 | | - return self::BLOCK_EXPIRY_INVALID; |
| 367 | + return array('ipb_expiry_invalid'); |
376 | 368 | } |
377 | 369 | |
378 | 370 | $expiry = wfTimestamp( TS_MW, $expiry ); |
— | — | @@ -387,7 +379,7 @@ |
388 | 380 | if (wfRunHooks('BlockIp', array(&$block, &$wgUser))) { |
389 | 381 | |
390 | 382 | if ( !$block->insert() ) { |
391 | | - return self::BLOCK_ALREADY_BLOCKED; |
| 383 | + return array('ipb_already_blocked', htmlspecialchars($this->BlockAddress)); |
392 | 384 | } |
393 | 385 | |
394 | 386 | wfRunHooks('BlockIpComplete', array($block, $wgUser)); |
— | — | @@ -404,8 +396,10 @@ |
405 | 397 | $reasonstr, $logParams ); |
406 | 398 | |
407 | 399 | # Report to the user |
408 | | - return self::BLOCK_SUCCESS; |
| 400 | + return array(); |
409 | 401 | } |
| 402 | + else |
| 403 | + return array('hookaborted'); |
410 | 404 | } |
411 | 405 | |
412 | 406 | /** |
— | — | @@ -416,34 +410,14 @@ |
417 | 411 | { |
418 | 412 | global $wgOut; |
419 | 413 | $retval = $this->doBlock(); |
420 | | - switch($retval) |
421 | | - { |
422 | | - case self::BLOCK_RANGE_INVALID: |
423 | | - $this->showForm( wfMsg( 'ip_range_invalid' ) ); |
424 | | - return; |
425 | | - case self::BLOCK_RANGE_DISABLED: |
426 | | - $this->showForm( wfMsg( 'range_block_disabled' ) ); |
427 | | - return; |
428 | | - case self::BLOCK_NONEXISTENT_USER: |
429 | | - $this->showForm( wfMsg( 'nosuchusershort', htmlspecialchars( $this->BlockAddress ) ) ); |
430 | | - return; |
431 | | - case self::BLOCK_IP_INVALID: |
432 | | - $this->showForm( wfMsg( 'badipaddress' ) ); |
433 | | - return; |
434 | | - case self::BLOCK_EXPIRY_INVALID: |
435 | | - $this->showForm( wfMsg( 'ipb_expiry_invalid' ) ); |
436 | | - return; |
437 | | - case self::BLOCK_ALREADY_BLOCKED: |
438 | | - $this->showForm( wfMsg( 'ipb_already_blocked', htmlspecialchars( $this->BlockAddress ) ) ); |
439 | | - return; |
440 | | - case self::BLOCK_SUCCESS: |
441 | | - $titleObj = SpecialPage::getTitleFor( 'Blockip' ); |
442 | | - $wgOut->redirect( $titleObj->getFullURL( 'action=success&ip=' . |
443 | | - urlencode( $this->BlockAddress ) ) ); |
444 | | - return; |
445 | | - default: |
446 | | - throw new MWException( __METHOD__ . ": Unknown return value ``{$retval}''" ); |
| 414 | + if(empty($retval)) { |
| 415 | + $titleObj = SpecialPage::getTitleFor( 'Blockip' ); |
| 416 | + $wgOut->redirect( $titleObj->getFullURL( 'action=success&ip=' . |
| 417 | + urlencode( $this->BlockAddress ) ) ); |
| 418 | + return; |
447 | 419 | } |
| 420 | + $key = array_shift($retval); |
| 421 | + $this->showForm(wfMsgReal($key, $retval)); |
448 | 422 | } |
449 | 423 | |
450 | 424 | function showSuccess() { |
Index: trunk/phase3/includes/api/ApiBlock.php |
— | — | @@ -61,21 +61,23 @@ |
62 | 62 | } |
63 | 63 | |
64 | 64 | if(is_null($params['user'])) |
65 | | - $this->dieUsage('The user parameter must be set', 'nouser'); |
| 65 | + $this->dieUsageMsg(array('missingparam', 'user')); |
66 | 66 | if(is_null($params['token'])) |
67 | | - $this->dieUsage('The token parameter must be set', 'notoken'); |
| 67 | + $this->dieUsageMsg(array('missingparam', 'token')); |
68 | 68 | if(!$wgUser->matchEditToken($params['token'])) |
69 | | - $this->dieUsage('Invalid token', 'badtoken'); |
| 69 | + $this->dieUsageMsg(array('sessionfailure')); |
70 | 70 | if(!$wgUser->isAllowed('block')) |
71 | | - $this->dieUsage('You don\'t have permission to block users', 'permissiondenied'); |
| 71 | + $this->dieUsageMsg(array('cantblock')); |
72 | 72 | if($params['hidename'] && !$wgUser->isAllowed('hideuser')) |
73 | | - $this->dieUsage('You don\'t have permission to hide user names from the block log', 'nohide'); |
| 73 | + $this->dieUsageMsg(array('canthide')); |
| 74 | + if($params['noemail'] && !$wgUser->isAllowed('blockemail')) |
| 75 | + $this->dieUsageMsg(array('cantblock-email')); |
74 | 76 | if(wfReadOnly()) |
75 | | - $this->dieUsage('The wiki is in read-only mode', 'readonly'); |
| 77 | + $this->dieUsageMsg(array('readonlytext')); |
76 | 78 | |
77 | 79 | $form = new IPBlockForm(''); |
78 | 80 | $form->BlockAddress = $params['user']; |
79 | | - $form->BlockReason = $params['reason']; |
| 81 | + $form->BlockReason = (is_null($params['reason']) ? '' : $params['reason']); |
80 | 82 | $form->BlockReasonList = 'other'; |
81 | 83 | $form->BlockExpiry = ($params['expiry'] == 'never' ? 'infinite' : $params['expiry']); |
82 | 84 | $form->BlockOther = ''; |
— | — | @@ -88,27 +90,11 @@ |
89 | 91 | $dbw = wfGetDb(DB_MASTER); |
90 | 92 | $dbw->begin(); |
91 | 93 | $retval = $form->doBlock($userID, $expiry); |
92 | | - switch($retval) |
93 | | - { |
94 | | - case IPBlockForm::BLOCK_SUCCESS: |
95 | | - break; // We'll deal with that later |
96 | | - case IPBlockForm::BLOCK_RANGE_INVALID: |
97 | | - $this->dieUsage("Invalid IP range ``{$params['user']}''", 'invalidrange'); |
98 | | - case IPBlockForm::BLOCK_RANGE_DISABLED: |
99 | | - $this->dieUsage('Blocking IP ranges has been disabled', 'rangedisabled'); |
100 | | - case IPBlockForm::BLOCK_NONEXISTENT_USER: |
101 | | - $this->dieUsage("User ``{$params['user']}'' doesn't exist", 'nosuchuser'); |
102 | | - case IPBlockForm::BLOCK_IP_INVALID: |
103 | | - $this->dieUsage("Invaild IP address ``{$params['user']}''", 'invalidip'); |
104 | | - case IPBlockForm::BLOCK_EXPIRY_INVALID: |
105 | | - $this->dieUsage("Invalid expiry time ``{$params['expiry']}''", 'invalidexpiry'); |
106 | | - case IPBlockForm::BLOCK_ALREADY_BLOCKED: |
107 | | - $this->dieUsage("User ``{$params['user']}'' is already blocked", 'alreadyblocked'); |
108 | | - default: |
109 | | - $this->dieDebug(__METHOD__, "IPBlockForm::doBlock() returned an unknown error ($retval)"); |
110 | | - } |
| 94 | + if(!empty($retval)) |
| 95 | + // We don't care about multiple errors, just report one of them |
| 96 | + $this->dieUsageMsg($retval); |
| 97 | + |
111 | 98 | $dbw->commit(); |
112 | | - |
113 | 99 | $res['user'] = $params['user']; |
114 | 100 | $res['userID'] = $userID; |
115 | 101 | $res['expiry'] = ($expiry == Block::infinity() ? 'infinite' : $expiry); |
— | — | @@ -152,7 +138,7 @@ |
153 | 139 | 'anononly' => 'Block anonymous users only (i.e. disable anonymous edits for this IP)', |
154 | 140 | 'nocreate' => 'Prevent account creation', |
155 | 141 | 'autoblock' => 'Automatically block the last used IP address, and any subsequent IP addresses they try to login from', |
156 | | - 'noemail' => 'Prevent user from sending e-mail through the wiki', |
| 142 | + 'noemail' => 'Prevent user from sending e-mail through the wiki. (Requires the "blockemail" right.)', |
157 | 143 | 'hidename' => 'Hide the username from the block log. (Requires the "hideuser" right.)' |
158 | 144 | ); |
159 | 145 | } |
Index: trunk/phase3/includes/api/ApiBase.php |
— | — | @@ -593,6 +593,12 @@ |
594 | 594 | 'cantmove-titleprotected' => array('code' => 'protectedtitle', 'info' => "The destination article has been protected from creation"), |
595 | 595 | // 'badarticleerror' => shouldn't happen |
596 | 596 | // 'badtitletext' => shouldn't happen |
| 597 | + 'ip_range_invalid' => array('code' => 'invalidrange', 'info' => "Invalid IP range"), |
| 598 | + 'range_block_disabled' => array('code' => 'rangedisabled', 'info' => "Blocking IP ranges has been disabled"), |
| 599 | + 'nosuchusershort' => array('code' => 'nosuchuser', 'info' => "The user you specified doesn't exist"), |
| 600 | + 'badipaddress' => array('code' => 'invalidip', 'info' => "Invalid IP address specified"), |
| 601 | + 'ipb_expiry_invalid' => array('code' => 'invalidexpiry', 'info' => "Invalid expiry time"), |
| 602 | + 'ipb_already_blocked' => array('code' => 'alreadyblocked', 'info' => "The user you tried to block was already blocked"), |
597 | 603 | |
598 | 604 | // API-specific messages |
599 | 605 | 'missingparam' => array('code' => 'no$1', 'info' => "The \$1 parameter must be set"), |
— | — | @@ -602,6 +608,9 @@ |
603 | 609 | 'pastexpiry' => array('code' => 'pastexpiry', 'info' => "Expiry time is in the past"), |
604 | 610 | 'create-titleexists' => array('code' => 'create-titleexists', 'info' => "Existing titles can't be protected with 'create'"), |
605 | 611 | 'missingtitle-createonly' => array('code' => 'missingtitle-createonly', 'info' => "Missing titles can only be protected with 'create'"), |
| 612 | + 'cantblock' => array('code' => 'cantblock', 'info' => "You don't have permission to block users"), |
| 613 | + 'canthide' => array('code' => 'canthide', 'info' => "You don't have permission to hide user names from the block log"), |
| 614 | + 'cantblock-email' => array('code' => 'cantblock-email', 'info' => "You don't have permission to block users from sending e-mail through the wiki"), |
606 | 615 | ); |
607 | 616 | |
608 | 617 | /** |
Index: trunk/phase3/includes/SpecialIpblocklist.php |
— | — | @@ -200,7 +200,7 @@ |
201 | 201 | |
202 | 202 | function doSubmit() { |
203 | 203 | global $wgOut; |
204 | | - $retval = self::doUnblock(&$this->id, &$this->ip, &$this->reason, &$range); |
| 204 | + $retval = self::doUnblock($this->id, $this->ip, $this->reason, $range); |
205 | 205 | if($retval == self::UNBLOCK_SUCCESS) { |
206 | 206 | # Report to the user |
207 | 207 | $titleObj = SpecialPage::getTitleFor( "Ipblocklist" ); |