3 * Constructor for Special:Blockip page
6 * @subpackage SpecialPage
12 function wfSpecialBlockip( $par ) {
13 global $wgUser, $wgOut, $wgRequest;
15 if( !$wgUser->isAllowed( 'block' ) ) {
16 $wgOut->permissionRequired( 'block' );
20 $ipb = new IPBlockForm( $par );
22 $action = $wgRequest->getVal( 'action' );
23 if ( 'success' == $action ) {
25 } else if ( $wgRequest->wasPosted() && 'submit' == $action &&
26 $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) {
37 * @subpackage SpecialPage
40 var $BlockAddress, $BlockExpiry, $BlockReason;
42 function IPBlockForm( $par ) {
45 $this->BlockAddress
= $wgRequest->getVal( 'wpBlockAddress', $wgRequest->getVal( 'ip', $par ) );
46 $this->BlockReason
= $wgRequest->getText( 'wpBlockReason' );
47 $this->BlockExpiry
= $wgRequest->getVal( 'wpBlockExpiry', wfMsg('ipbotheroption') );
48 $this->BlockOther
= $wgRequest->getVal( 'wpBlockOther', '' );
49 $this->BlockAnonOnly
= $wgRequest->getBool( 'wpAnonOnly' );
51 # Unchecked checkboxes are not included in the form data at all, so having one
52 # that is true by default is a bit tricky
53 if ( $wgRequest->wasPosted() ) {
54 $this->BlockCreateAccount
= $wgRequest->getBool( 'wpCreateAccount', false );
56 $this->BlockCreateAccount
= $wgRequest->getBool( 'wpCreateAccount', true );
60 function showForm( $err ) {
61 global $wgOut, $wgUser, $wgSysopUserBans;
63 $wgOut->setPagetitle( wfMsg( 'blockip' ) );
64 $wgOut->addWikiText( wfMsg( 'blockiptext' ) );
66 if($wgSysopUserBans) {
67 $mIpaddress = wfMsgHtml( 'ipadressorusername' );
69 $mIpaddress = wfMsgHtml( 'ipaddress' );
71 $mIpbexpiry = wfMsgHtml( 'ipbexpiry' );
72 $mIpbother = wfMsgHtml( 'ipbother' );
73 $mIpbothertime = wfMsgHtml( 'ipbotheroption' );
74 $mIpbreason = wfMsgHtml( 'ipbreason' );
75 $mIpbsubmit = wfMsgHtml( 'ipbsubmit' );
76 $mIpbanononly = wfMsgHtml( 'ipbanononly' );
77 $mIpbcreateaccount = wfMsgHtml( 'ipbcreateaccount' );
78 $titleObj = Title
::makeTitle( NS_SPECIAL
, 'Blockip' );
79 $action = $titleObj->escapeLocalURL( "action=submit" );
82 $wgOut->setSubtitle( wfMsgHtml( 'formerror' ) );
83 $wgOut->addHTML( "<p class='error'>{$err}</p>\n" );
86 $scBlockAddress = htmlspecialchars( $this->BlockAddress
);
87 $scBlockExpiry = htmlspecialchars( $this->BlockExpiry
);
88 $scBlockReason = htmlspecialchars( $this->BlockReason
);
89 $scBlockOtherTime = htmlspecialchars( $this->BlockOther
);
90 $scBlockExpiryOptions = htmlspecialchars( wfMsgForContent( 'ipboptions' ) );
91 $anonOnlyChecked = $this->BlockAnonOnly ?
'checked' : '';
92 $createAccountChecked = $this->BlockCreateAccount ?
'checked' : '';
94 $showblockoptions = $scBlockExpiryOptions != '-';
95 if (!$showblockoptions)
96 $mIpbother = $mIpbexpiry;
98 $blockExpiryFormOptions = "<option value=\"other\">$mIpbothertime</option>";
99 foreach (explode(',', $scBlockExpiryOptions) as $option) {
100 if ( strpos($option, ":") === false ) $option = "$option:$option";
101 list($show, $value) = explode(":", $option);
102 $show = htmlspecialchars($show);
103 $value = htmlspecialchars($value);
105 if ($this->BlockExpiry
=== $value)
106 $selected = ' selected="selected"';
107 $blockExpiryFormOptions .= "<option value=\"$value\"$selected>$show</option>";
110 $token = htmlspecialchars( $wgUser->editToken() );
113 <form id=\"blockip\" method=\"post\" action=\"{$action}\">
116 <td align=\"right\">{$mIpaddress}:</td>
118 <input tabindex='1' type='text' size='40' name=\"wpBlockAddress\" value=\"{$scBlockAddress}\" />
122 if ($showblockoptions) {
124 <td align=\"right\">{$mIpbexpiry}:</td>
126 <select tabindex='2' id='wpBlockExpiry' name=\"wpBlockExpiry\" onchange=\"considerChangingExpiryFocus()\">
127 $blockExpiryFormOptions
134 <tr id='wpBlockOther'>
135 <td align=\"right\">{$mIpbother}:</td>
137 <input tabindex='3' type='text' size='40' name=\"wpBlockOther\" value=\"{$scBlockOtherTime}\" />
141 <td align=\"right\">{$mIpbreason}:</td>
143 <input tabindex='3' type='text' size='40' name=\"wpBlockReason\" value=\"{$scBlockReason}\" />
150 <input type='checkbox' name='wpAnonOnly' value='1' $anonOnlyChecked />
159 <input type='checkbox' name='wpCreateAccount' value='1' $createAccountChecked />
165 <td style='padding-top: 1em'> </td>
166 <td style='padding-top: 1em' align=\"left\">
167 <input tabindex='4' type='submit' name=\"wpBlock\" value=\"{$mIpbsubmit}\" />
171 <input type='hidden' name='wpEditToken' value=\"{$token}\" />
176 function doSubmit() {
177 global $wgOut, $wgUser, $wgSysopUserBans, $wgSysopRangeBans;
180 $this->BlockAddress
= trim( $this->BlockAddress
);
181 $rxIP = '\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}';
183 # Check for invalid specifications
184 if ( ! preg_match( "/^$rxIP$/", $this->BlockAddress
) ) {
185 if ( preg_match( "/^($rxIP)\\/(\\d{1,2})$/", $this->BlockAddress
, $matches ) ) {
186 if ( $wgSysopRangeBans ) {
187 if ( $matches[2] > 31 ||
$matches[2] < 16 ) {
188 $this->showForm( wfMsg( 'ip_range_invalid' ) );
191 $this->BlockAddress
= Block
::normaliseRange( $this->BlockAddress
);
193 # Range block illegal
194 $this->showForm( wfMsg( 'range_block_disabled' ) );
199 if ( $wgSysopUserBans ) {
200 $user = User
::newFromName( $this->BlockAddress
);
201 if ( $user->getID() ) {
203 $this->BlockAddress
= $user->getName();
205 $this->showForm( wfMsg( 'nosuchusershort', htmlspecialchars( $this->BlockAddress
) ) );
209 $this->showForm( wfMsg( 'badipaddress' ) );
215 $expirestr = $this->BlockExpiry
;
216 if( $expirestr == 'other' )
217 $expirestr = $this->BlockOther
;
219 if (strlen($expirestr) == 0) {
220 $this->showForm( wfMsg( 'ipb_expiry_invalid' ) );
224 if ( $expirestr == 'infinite' ||
$expirestr == 'indefinite' ) {
225 $expiry = Block
::infinity();
227 # Convert GNU-style date, on error returns -1 for PHP <5.1 and false for PHP >=5.1
228 $expiry = strtotime( $expirestr );
230 if ( $expiry < 0 ||
$expiry === false ) {
231 $this->showForm( wfMsg( 'ipb_expiry_invalid' ) );
235 $expiry = wfTimestamp( TS_MW
, $expiry );
239 # Note: for a user block, ipb_address is only for display purposes
241 $block = new Block( $this->BlockAddress
, $userId, $wgUser->getID(),
242 $this->BlockReason
, wfTimestampNow(), 0, $expiry, $this->BlockAnonOnly
,
243 $this->BlockCreateAccount
);
245 if (wfRunHooks('BlockIp', array(&$block, &$wgUser))) {
247 if ( !$block->insert() ) {
248 $this->showForm( wfMsg( 'ipb_already_blocked',
249 htmlspecialchars( $this->BlockAddress
) ) );
253 wfRunHooks('BlockIpComplete', array($block, $wgUser));
256 $log = new LogPage( 'block' );
257 $log->addEntry( 'block', Title
::makeTitle( NS_USER
, $this->BlockAddress
),
258 $this->BlockReason
, $expirestr );
261 $titleObj = Title
::makeTitle( NS_SPECIAL
, 'Blockip' );
262 $wgOut->redirect( $titleObj->getFullURL( 'action=success&ip=' .
263 urlencode( $this->BlockAddress
) ) );
267 function showSuccess() {
270 $wgOut->setPagetitle( wfMsg( 'blockip' ) );
271 $wgOut->setSubtitle( wfMsg( 'blockipsuccesssub' ) );
272 $text = wfMsg( 'blockipsuccesstext', $this->BlockAddress
);
273 $wgOut->addWikiText( $text );