Index: trunk/phase3/includes/api/ApiBase.php |
— | — | @@ -599,6 +599,8 @@ |
600 | 600 | 'badipaddress' => array('code' => 'invalidip', 'info' => "Invalid IP address specified"), |
601 | 601 | 'ipb_expiry_invalid' => array('code' => 'invalidexpiry', 'info' => "Invalid expiry time"), |
602 | 602 | 'ipb_already_blocked' => array('code' => 'alreadyblocked', 'info' => "The user you tried to block was already blocked"), |
| 603 | + 'ipb_blocked_as_range' => array('code' => 'blockedasrange', 'info' => "IP address ``\$1'' was blocked as part of range ``\$2''. You can't unblock the IP invidually, but you can unblock the range as a whole."), |
| 604 | + 'ipb_cant_unblock' => array('code' => 'cantunblock', 'info' => "The block you specified was not found. It may have been unblocked already"), |
603 | 605 | |
604 | 606 | // API-specific messages |
605 | 607 | 'missingparam' => array('code' => 'no$1', 'info' => "The \$1 parameter must be set"), |
— | — | @@ -611,6 +613,9 @@ |
612 | 614 | 'cantblock' => array('code' => 'cantblock', 'info' => "You don't have permission to block users"), |
613 | 615 | 'canthide' => array('code' => 'canthide', 'info' => "You don't have permission to hide user names from the block log"), |
614 | 616 | 'cantblock-email' => array('code' => 'cantblock-email', 'info' => "You don't have permission to block users from sending e-mail through the wiki"), |
| 617 | + 'unblock-notarget' => array('code' => 'notarget', 'info' => "Either the id or the user parameter must be set"), |
| 618 | + 'unblock-idanduser' => array('code' => 'idanduser', 'info' => "The id and user parameters can\'t be used together"), |
| 619 | + 'cantunblock' => array('code' => 'permissiondenied', 'info' => "You don't have permission to unblock users"), |
615 | 620 | ); |
616 | 621 | |
617 | 622 | /** |
Index: trunk/phase3/includes/api/ApiUnblock.php |
— | — | @@ -41,7 +41,7 @@ |
42 | 42 | |
43 | 43 | /** |
44 | 44 | * Unblocks the specified user or provides the reason the unblock failed. |
45 | | - */ |
| 45 | + */ |
46 | 46 | public function execute() { |
47 | 47 | global $wgUser; |
48 | 48 | $this->getMain()->requestWriteMode(); |
— | — | @@ -55,42 +55,28 @@ |
56 | 56 | } |
57 | 57 | |
58 | 58 | if(is_null($params['id']) && is_null($params['user'])) |
59 | | - $this->dieUsage('Either the id or the user parameter must be set', 'notarget'); |
| 59 | + $this->dieUsageMsg(array('unblock-notarget')); |
60 | 60 | if(!is_null($params['id']) && !is_null($params['user'])) |
61 | | - $this->dieUsage('The id and user parameters can\'t be used together', 'idanduser'); |
| 61 | + $this->dieUsageMsg(array('unblock-idanduser')); |
62 | 62 | if(is_null($params['token'])) |
63 | | - $this->dieUsage('The token parameter must be set', 'notoken'); |
| 63 | + $this->dieUsageMsg(array('missingparam', 'token')); |
64 | 64 | if(!$wgUser->matchEditToken($params['token'])) |
65 | | - $this->dieUsage('Invalid token', 'badtoken'); |
| 65 | + $this->dieUsageMsg(array('sessionfailure')); |
66 | 66 | if(!$wgUser->isAllowed('block')) |
67 | | - $this->dieUsage('You don\'t have permission to unblock users', 'permissiondenied'); |
| 67 | + $this->dieUsageMsg(array('cantunblock')); |
68 | 68 | if(wfReadOnly()) |
69 | | - $this->dieUsage('The wiki is in read-only mode', 'readonly'); |
| 69 | + $this->dieUsageMsg(array('readonlytext')); |
70 | 70 | |
71 | 71 | $id = $params['id']; |
72 | 72 | $user = $params['user']; |
73 | | - $reason = $params['reason']; |
| 73 | + $reason = (is_null($params['reason']) ? '' : $params['reason']); |
74 | 74 | $dbw = wfGetDb(DB_MASTER); |
75 | 75 | $dbw->begin(); |
76 | | - $retval = IPUnblockForm::doUnblock(&$id, &$user, &$reason, &$range); |
| 76 | + $retval = IPUnblockForm::doUnblock($id, $user, $reason, $range); |
| 77 | + if(!empty($retval)) |
| 78 | + $this->dieUsageMsg($retval); |
77 | 79 | |
78 | | - switch($retval) |
79 | | - { |
80 | | - case IPUnblockForm::UNBLOCK_SUCCESS: |
81 | | - break; // We'll deal with that later |
82 | | - case IPUnblockForm::UNBLOCK_NO_SUCH_ID: |
83 | | - $this->dieUsage("There is no block with ID ``$id''", 'nosuchid'); |
84 | | - case IPUnblockForm::UNBLOCK_USER_NOT_BLOCKED: |
85 | | - $this->dieUsage("User ``$user'' is not blocked", 'notblocked'); |
86 | | - case IPUnblockForm::UNBLOCK_BLOCKED_AS_RANGE: |
87 | | - $this->dieUsage("IP address ``$user'' was blocked as part of range ``$range''. You can't unblock the IP invidually, but you can unblock the range as a whole.", 'blockedasrange'); |
88 | | - case IPUnblockForm::UNBLOCK_UNKNOWNERR: |
89 | | - $this->dieUsage("Unknown error", 'unknownerr'); |
90 | | - default: |
91 | | - $this->dieDebug(__METHOD__, "IPBlockForm::doBlock() returned an unknown error ($retval)"); |
92 | | - } |
93 | 80 | $dbw->commit(); |
94 | | - |
95 | 81 | $res['id'] = $id; |
96 | 82 | $res['user'] = $user; |
97 | 83 | $res['reason'] = $reason; |
Index: trunk/phase3/includes/SpecialIpblocklist.php |
— | — | @@ -150,7 +150,7 @@ |
151 | 151 | * Backend code for unblocking. doSubmit() wraps around this. |
152 | 152 | * $range is only used when UNBLOCK_BLOCKED_AS_RANGE is returned, in which |
153 | 153 | * case it contains the range $ip is part of. |
154 | | - * Returns one of UNBLOCK_* |
| 154 | + * @return array array(message key, parameters) on failure, empty array on success |
155 | 155 | */ |
156 | 156 | |
157 | 157 | static function doUnblock(&$id, &$ip, &$reason, &$range = null) |
— | — | @@ -158,7 +158,7 @@ |
159 | 159 | if ( $id ) { |
160 | 160 | $block = Block::newFromID( $id ); |
161 | 161 | if ( !$block ) { |
162 | | - return self::UNBLOCK_NO_SUCH_ID; |
| 162 | + return array('ipb_cant_unblock', htmlspecialchars($id)); |
163 | 163 | } |
164 | 164 | $ip = $block->getRedactedName(); |
165 | 165 | } else { |
— | — | @@ -168,19 +168,20 @@ |
169 | 169 | $id = substr( $ip, 1 ); |
170 | 170 | $block = Block::newFromID( $id ); |
171 | 171 | if( !$block ) { |
172 | | - return self::UNBLOCK_NO_SUCH_ID; |
| 172 | + return array('ipb_cant_unblock', htmlspecialchars($id)); |
173 | 173 | } |
| 174 | + $ip = $block->getRedactedName(); |
174 | 175 | } else { |
175 | 176 | $block = Block::newFromDB( $ip ); |
176 | 177 | if ( !$block ) { |
177 | | - return self::UNBLOCK_USER_NOT_BLOCKED; |
| 178 | + return array('ipb_cant_unblock', htmlspecialchars($id)); |
178 | 179 | } |
179 | 180 | if( $block->mRangeStart != $block->mRangeEnd |
180 | 181 | && !strstr( $ip, "/" ) ) { |
181 | 182 | /* If the specified IP is a single address, and the block is |
182 | 183 | * a range block, don't unblock the range. */ |
183 | 184 | $range = $block->mAddress; |
184 | | - return self::UNBLOCK_BLOCKED_AS_RANGE; |
| 185 | + return array('ipb_blocked_as_range', $ip, $range); |
185 | 186 | } |
186 | 187 | } |
187 | 188 | } |
— | — | @@ -189,31 +190,28 @@ |
190 | 191 | |
191 | 192 | # Delete block |
192 | 193 | if ( !$block->delete() ) { |
193 | | - return self::UNBLOCK_UNKNOWNERR; |
| 194 | + return array('ipb_cant_unblock', htmlspecialchars($id)); |
194 | 195 | } |
195 | 196 | |
196 | 197 | # Make log entry |
197 | 198 | $log = new LogPage( 'block' ); |
198 | 199 | $log->addEntry( 'unblock', Title::makeTitle( NS_USER, $ip ), $reason ); |
199 | | - return self::UNBLOCK_SUCCESS; |
| 200 | + return array(); |
200 | 201 | } |
201 | 202 | |
202 | 203 | function doSubmit() { |
203 | 204 | global $wgOut; |
204 | 205 | $retval = self::doUnblock($this->id, $this->ip, $this->reason, $range); |
205 | | - if($retval == self::UNBLOCK_SUCCESS) { |
206 | | - # Report to the user |
207 | | - $titleObj = SpecialPage::getTitleFor( "Ipblocklist" ); |
208 | | - $success = $titleObj->getFullURL( "action=success&successip=" . urlencode( $this->ip ) ); |
209 | | - $wgOut->redirect( $success ); |
210 | | - } else if($retval == self::UNBLOCK_BLOCKED_AS_RANGE) { |
211 | | - $this->showForm( wfMsg( 'ipb_blocked_as_range', $this->ip, $range ) ); |
212 | | - } else { // UI code doesn't distinguish between errors much. Maybe it should |
213 | | - if ( !$this->ip && $this->id ) { |
214 | | - $this->ip = '#' . $this->id; |
215 | | - } |
216 | | - $this->showForm( wfMsg( 'ipb_cant_unblock', htmlspecialchars( $this->id ) ) ); |
| 206 | + if(!empty($retval)) |
| 207 | + { |
| 208 | + $key = array_shift($retval); |
| 209 | + $this->showForm(wfMsgReal($key, $retval)); |
| 210 | + return; |
217 | 211 | } |
| 212 | + # Report to the user |
| 213 | + $titleObj = SpecialPage::getTitleFor( "Ipblocklist" ); |
| 214 | + $success = $titleObj->getFullURL( "action=success&successip=" . urlencode( $this->ip ) ); |
| 215 | + $wgOut->redirect( $success ); |
218 | 216 | } |
219 | 217 | |
220 | 218 | function showList( $msg ) { |