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->sysopRequired();
19 $ipb = new IPBlockForm( $par );
21 $action = $wgRequest->getVal( 'action' );
22 if ( 'success' == $action ) {
24 } else if ( $wgRequest->wasPosted() && 'submit' == $action &&
25 $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) {
36 * @subpackage SpecialPage
39 var $BlockAddress, $BlockExpiry, $BlockReason;
41 function IPBlockForm( $par ) {
44 $this->BlockAddress
= $wgRequest->getVal( 'wpBlockAddress', $wgRequest->getVal( 'ip', $par ) );
45 $this->BlockReason
= $wgRequest->getText( 'wpBlockReason' );
46 $this->BlockExpiry
= $wgRequest->getVal( 'wpBlockExpiry', wfMsg('ipbotheroption') );
47 $this->BlockOther
= $wgRequest->getVal( 'wpBlockOther', '' );
50 function showForm( $err ) {
51 global $wgOut, $wgUser, $wgRequest, $wgSysopUserBans;
53 $wgOut->setPagetitle( wfMsg( 'blockip' ) );
54 $wgOut->addWikiText( wfMsg( 'blockiptext' ) );
56 if($wgSysopUserBans) {
57 $mIpaddress = wfMsgHtml( 'ipadressorusername' );
59 $mIpaddress = wfMsgHtml( 'ipaddress' );
61 $mIpbexpiry = wfMsgHtml( 'ipbexpiry' );
62 $mIpbother = wfMsgHtml( 'ipbother' );
63 $mIpbothertime = wfMsgHtml( 'ipbotheroption' );
64 $mIpbreason = wfMsgHtml( 'ipbreason' );
65 $mIpbsubmit = wfMsgHtml( 'ipbsubmit' );
66 $titleObj = Title
::makeTitle( NS_SPECIAL
, 'Blockip' );
67 $action = $titleObj->escapeLocalURL( "action=submit" );
70 $wgOut->setSubtitle( wfMsgHtml( 'formerror' ) );
71 $wgOut->addHTML( "<p class='error'>{$err}</p>\n" );
74 $scBlockAddress = htmlspecialchars( $this->BlockAddress
);
75 $scBlockExpiry = htmlspecialchars( $this->BlockExpiry
);
76 $scBlockReason = htmlspecialchars( $this->BlockReason
);
77 $scBlockOtherTime = htmlspecialchars( $this->BlockOther
);
78 $scBlockExpiryOptions = htmlspecialchars( wfMsgForContent( 'ipboptions' ) );
80 $showblockoptions = $scBlockExpiryOptions != '-';
81 if (!$showblockoptions)
82 $mIpbother = $mIpbexpiry;
84 $blockExpiryFormOptions = "<option value=\"other\">$mIpbothertime</option>";
85 foreach (explode(',', $scBlockExpiryOptions) as $option) {
86 if ( strpos($option, ":") === false ) $option = "$option:$option";
87 list($show, $value) = explode(":", $option);
88 $show = htmlspecialchars($show);
89 $value = htmlspecialchars($value);
91 if ($this->BlockExpiry
=== $value)
92 $selected = ' selected="selected"';
93 $blockExpiryFormOptions .= "<option value=\"$value\"$selected>$show</option>";
96 $token = htmlspecialchars( $wgUser->editToken() );
99 <form id=\"blockip\" method=\"post\" action=\"{$action}\">
102 <td align=\"right\">{$mIpaddress}:</td>
104 <input tabindex='1' type='text' size='20' name=\"wpBlockAddress\" value=\"{$scBlockAddress}\" />
108 if ($showblockoptions) {
110 <td align=\"right\">{$mIpbexpiry}:</td>
112 <select tabindex='2' id='wpBlockExpiry' name=\"wpBlockExpiry\" onchange=\"considerChangingExpiryFocus()\">
113 $blockExpiryFormOptions
120 <tr id='wpBlockOther'>
121 <td align=\"right\">{$mIpbother}:</td>
123 <input tabindex='3' type='text' size='40' name=\"wpBlockOther\" value=\"{$scBlockOtherTime}\" />
127 <td align=\"right\">{$mIpbreason}:</td>
129 <input tabindex='3' type='text' size='40' name=\"wpBlockReason\" value=\"{$scBlockReason}\" />
135 <input tabindex='4' type='submit' name=\"wpBlock\" value=\"{$mIpbsubmit}\" />
139 <input type='hidden' name='wpEditToken' value=\"{$token}\" />
144 function doSubmit() {
145 global $wgOut, $wgUser, $wgSysopUserBans, $wgSysopRangeBans;
148 $this->BlockAddress
= trim( $this->BlockAddress
);
149 $rxIP = '\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}';
151 # Check for invalid specifications
152 if ( ! preg_match( "/^$rxIP$/", $this->BlockAddress
) ) {
153 if ( preg_match( "/^($rxIP)\\/(\\d{1,2})$/", $this->BlockAddress
, $matches ) ) {
154 if ( $wgSysopRangeBans ) {
155 if ( $matches[2] > 31 ||
$matches[2] < 16 ) {
156 $this->showForm( wfMsg( 'ip_range_invalid' ) );
159 $this->BlockAddress
= Block
::normaliseRange( $this->BlockAddress
);
161 # Range block illegal
162 $this->showForm( wfMsg( 'range_block_disabled' ) );
167 if ( $wgSysopUserBans ) {
168 $userId = User
::idFromName( $this->BlockAddress
);
169 if ( $userId == 0 ) {
170 $this->showForm( wfMsg( 'nosuchusershort', htmlspecialchars( $this->BlockAddress
) ) );
174 $this->showForm( wfMsg( 'badipaddress' ) );
180 $expirestr = $this->BlockExpiry
;
181 if( $expirestr == 'other' )
182 $expirestr = $this->BlockOther
;
184 if (strlen($expirestr) == 0) {
185 $this->showForm( wfMsg( 'ipb_expiry_invalid' ) );
189 if ( $expirestr == 'infinite' ||
$expirestr == 'indefinite' ) {
192 # Convert GNU-style date, on error returns -1 for PHP <5.1 and false for PHP >=5.1
193 $expiry = strtotime( $expirestr );
195 if ( $expiry < 0 ||
$expiry === false ) {
196 $this->showForm( wfMsg( 'ipb_expiry_invalid' ) );
200 $expiry = wfTimestamp( TS_MW
, $expiry );
205 # Note: for a user block, ipb_address is only for display purposes
207 $ban = new Block( $this->BlockAddress
, $userId, $wgUser->getID(),
208 $this->BlockReason
, wfTimestampNow(), 0, $expiry );
210 if (wfRunHooks('BlockIp', array(&$ban, &$wgUser))) {
214 wfRunHooks('BlockIpComplete', array($ban, $wgUser));
217 $log = new LogPage( 'block' );
218 $log->addEntry( 'block', Title
::makeTitle( NS_USER
, $this->BlockAddress
),
219 $this->BlockReason
, $expirestr );
222 $titleObj = Title
::makeTitle( NS_SPECIAL
, 'Blockip' );
223 $wgOut->redirect( $titleObj->getFullURL( 'action=success&ip=' .
224 urlencode( $this->BlockAddress
) ) );
228 function showSuccess() {
229 global $wgOut, $wgUser;
231 $wgOut->setPagetitle( wfMsg( 'blockip' ) );
232 $wgOut->setSubtitle( wfMsg( 'blockipsuccesssub' ) );
233 $text = wfMsg( 'blockipsuccesstext', $this->BlockAddress
);
234 $wgOut->addWikiText( $text );