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
45 function IPBlockForm( $par ) {
48 $this->BlockAddress
= $wgRequest->getVal( 'wpBlockAddress', $wgRequest->getVal( 'ip', $par ) );
49 $this->BlockReason
= $wgRequest->getText( 'wpBlockReason' );
50 $this->BlockExpiry
= $wgRequest->getVal( 'wpBlockExpiry', wfMsg('ipbotheroption') );
51 $this->BlockOther
= $wgRequest->getVal( 'wpBlockOther', '' );
54 function showForm( $err ) {
55 global $wgOut, $wgUser, $wgSysopUserBans;
57 $wgOut->setPagetitle( wfMsg( 'blockip' ) );
58 $wgOut->addWikiText( wfMsg( 'blockiptext' ) );
60 if($wgSysopUserBans) {
61 $mIpaddress = wfMsgHtml( 'ipadressorusername' );
63 $mIpaddress = wfMsgHtml( 'ipaddress' );
65 $mIpbexpiry = wfMsgHtml( 'ipbexpiry' );
66 $mIpbother = wfMsgHtml( 'ipbother' );
67 $mIpbothertime = wfMsgHtml( 'ipbotheroption' );
68 $mIpbreason = wfMsgHtml( 'ipbreason' );
69 $mIpbsubmit = wfMsgHtml( 'ipbsubmit' );
70 $titleObj = Title
::makeTitle( NS_SPECIAL
, 'Blockip' );
71 $action = $titleObj->escapeLocalURL( "action=submit" );
74 $wgOut->setSubtitle( wfMsgHtml( 'formerror' ) );
75 $wgOut->addHTML( "<p class='error'>{$err}</p>\n" );
78 $scBlockAddress = htmlspecialchars( $this->BlockAddress
);
79 $scBlockExpiry = htmlspecialchars( $this->BlockExpiry
);
80 $scBlockReason = htmlspecialchars( $this->BlockReason
);
81 $scBlockOtherTime = htmlspecialchars( $this->BlockOther
);
82 $scBlockExpiryOptions = htmlspecialchars( wfMsgForContent( 'ipboptions' ) );
84 $showblockoptions = $scBlockExpiryOptions != '-';
85 if (!$showblockoptions)
86 $mIpbother = $mIpbexpiry;
88 $blockExpiryFormOptions = "<option value=\"other\">$mIpbothertime</option>";
89 foreach (explode(',', $scBlockExpiryOptions) as $option) {
90 if ( strpos($option, ":") === false ) $option = "$option:$option";
91 list($show, $value) = explode(":", $option);
92 $show = htmlspecialchars($show);
93 $value = htmlspecialchars($value);
95 if ($this->BlockExpiry
=== $value)
96 $selected = ' selected="selected"';
97 $blockExpiryFormOptions .= "<option value=\"$value\"$selected>$show</option>";
100 $token = htmlspecialchars( $wgUser->editToken() );
103 <form id=\"blockip\" method=\"post\" action=\"{$action}\">
106 <td align=\"right\">{$mIpaddress}:</td>
108 <input tabindex='1' type='text' size='20' name=\"wpBlockAddress\" value=\"{$scBlockAddress}\" />
112 if ($showblockoptions) {
114 <td align=\"right\">{$mIpbexpiry}:</td>
116 <select tabindex='2' id='wpBlockExpiry' name=\"wpBlockExpiry\" onchange=\"considerChangingExpiryFocus()\">
117 $blockExpiryFormOptions
124 <tr id='wpBlockOther'>
125 <td align=\"right\">{$mIpbother}:</td>
127 <input tabindex='3' type='text' size='40' name=\"wpBlockOther\" value=\"{$scBlockOtherTime}\" />
131 <td align=\"right\">{$mIpbreason}:</td>
133 <input tabindex='3' type='text' size='40' name=\"wpBlockReason\" value=\"{$scBlockReason}\" />
139 <input tabindex='4' type='submit' name=\"wpBlock\" value=\"{$mIpbsubmit}\" />
143 <input type='hidden' name='wpEditToken' value=\"{$token}\" />
148 function doSubmit() {
149 global $wgOut, $wgUser, $wgSysopUserBans, $wgSysopRangeBans;
152 $this->BlockAddress
= trim( $this->BlockAddress
);
153 $rxIP = '\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}';
155 # Check for invalid specifications
156 if ( ! preg_match( "/^$rxIP$/", $this->BlockAddress
) ) {
157 if ( preg_match( "/^($rxIP)\\/(\\d{1,2})$/", $this->BlockAddress
, $matches ) ) {
158 if ( $wgSysopRangeBans ) {
159 if ( $matches[2] > 31 ||
$matches[2] < 16 ) {
160 $this->showForm( wfMsg( 'ip_range_invalid' ) );
163 $this->BlockAddress
= Block
::normaliseRange( $this->BlockAddress
);
165 # Range block illegal
166 $this->showForm( wfMsg( 'range_block_disabled' ) );
171 if ( $wgSysopUserBans ) {
172 $userId = User
::idFromName( $this->BlockAddress
);
173 if ( $userId == 0 ) {
174 $this->showForm( wfMsg( 'nosuchusershort', htmlspecialchars( $this->BlockAddress
) ) );
178 $this->showForm( wfMsg( 'badipaddress' ) );
184 $expirestr = $this->BlockExpiry
;
185 if( $expirestr == 'other' )
186 $expirestr = $this->BlockOther
;
188 if (strlen($expirestr) == 0) {
189 $this->showForm( wfMsg( 'ipb_expiry_invalid' ) );
193 if ( $expirestr == 'infinite' ||
$expirestr == 'indefinite' ) {
196 # Convert GNU-style date, on error returns -1 for PHP <5.1 and false for PHP >=5.1
197 $expiry = strtotime( $expirestr );
199 if ( $expiry < 0 ||
$expiry === false ) {
200 $this->showForm( wfMsg( 'ipb_expiry_invalid' ) );
204 $expiry = wfTimestamp( TS_MW
, $expiry );
209 # Note: for a user block, ipb_address is only for display purposes
211 $ban = new Block( $this->BlockAddress
, $userId, $wgUser->getID(),
212 $this->BlockReason
, wfTimestampNow(), 0, $expiry );
214 if (wfRunHooks('BlockIp', array(&$ban, &$wgUser))) {
218 wfRunHooks('BlockIpComplete', array($ban, $wgUser));
221 $log = new LogPage( 'block' );
222 $log->addEntry( 'block', Title
::makeTitle( NS_USER
, $this->BlockAddress
),
223 $this->BlockReason
, $expirestr );
226 $titleObj = Title
::makeTitle( NS_SPECIAL
, 'Blockip' );
227 $wgOut->redirect( $titleObj->getFullURL( 'action=success&ip=' .
228 urlencode( $this->BlockAddress
) ) );
232 function showSuccess() {
235 $wgOut->setPagetitle( wfMsg( 'blockip' ) );
236 $wgOut->setSubtitle( wfMsg( 'blockipsuccesssub' ) );
237 $text = wfMsg( 'blockipsuccesstext', $this->BlockAddress
);
238 $wgOut->addWikiText( $text );