3 * Constructor for Special:Blockip page
6 * @subpackage SpecialPage
12 function wfSpecialBlockip() {
13 global $wgUser, $wgOut, $wgRequest;
15 if ( ! $wgUser->isAllowed('block') ) {
16 $wgOut->sysopRequired();
19 $ipb = new IPBlockForm();
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() {
43 $this->BlockAddress
= $wgRequest->getVal( 'wpBlockAddress', $wgRequest->getVal( 'ip' ) );
44 $this->BlockReason
= $wgRequest->getText( 'wpBlockReason' );
45 $this->BlockExpiry
= $wgRequest->getVal( 'wpBlockExpiry' );
46 $this->BlockOther
= $wgRequest->getVal( 'wpBlockOther' );
49 function showForm( $err ) {
50 global $wgOut, $wgUser, $wgLang, $wgBlockExpiryOptions;
51 global $wgRequest, $wgSysopUserBans;
53 $wgOut->setPagetitle( htmlspecialchars( wfMsg( 'blockip' ) ) );
54 $wgOut->addWikiText( wfMsg( 'blockiptext' ) );
56 if($wgSysopUserBans) {
57 $mIpaddress = htmlspecialchars( wfMsg( 'ipadressorusername' ) );
59 $mIpaddress = htmlspecialchars( wfMsg( 'ipaddress' ) );
61 $mIpbexpiry = htmlspecialchars( wfMsg( 'ipbexpiry' ) );
62 $mIpbother = htmlspecialchars( wfMsg( 'ipbother' ) );
63 $mIpbothertime = htmlspecialchars( wfMsg( 'ipbotheroption' ) );
64 $mIpbreason = htmlspecialchars( wfMsg( 'ipbreason' ) );
65 $mIpbsubmit = htmlspecialchars( wfMsg( 'ipbsubmit' ) );
66 $titleObj = Title
::makeTitle( NS_SPECIAL
, 'Blockip' );
67 $action = $titleObj->escapeLocalURL( "action=submit" );
70 $wgOut->setSubtitle( wfMsg( '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->BlockOtherTime
);
78 $scBlockExpiryOptions = htmlspecialchars( wfMsg( 'ipboptions' ) );
80 $blockExpiryFormOptions = "<option value=\"other\">$mIpbothertime</option>";
81 foreach (explode(',', $scBlockExpiryOptions) as $option) {
83 if ($this->BlockExpiry
=== $option)
84 $selected = ' selected="selected"';
85 $blockExpiryFormOptions .= "<option$selected>$option</option>";
88 $token = htmlspecialchars( $wgUser->editToken() );
91 <form id=\"blockip\" method=\"post\" action=\"{$action}\">
94 <td align=\"right\">{$mIpaddress}:</td>
96 <input tabindex='1' type='text' size='20' name=\"wpBlockAddress\" value=\"{$scBlockAddress}\" />
100 <td align=\"right\">{$mIpbexpiry}:</td>
102 <select tabindex='2' name=\"wpBlockExpiry\">
103 $blockExpiryFormOptions
108 <td align=\"right\">{$mIpbother}:</td>
110 <input tabindex='3' type='text' size='40' name=\"wpBlockOther\" value=\"{$scBlockOtherTime}\" />
114 <td align=\"right\">{$mIpbreason}:</td>
116 <input tabindex='3' type='text' size='40' name=\"wpBlockReason\" value=\"{$scBlockReason}\" />
122 <input tabindex='4' type='submit' name=\"wpBlock\" value=\"{$mIpbsubmit}\" />
126 <input type='hidden' name='wpEditToken' value=\"{$token}\" />
131 function doSubmit() {
132 global $wgOut, $wgUser, $wgLang;
133 global $wgSysopUserBans, $wgSysopRangeBans;
136 $this->BlockAddress
= trim( $this->BlockAddress
);
137 $rxIP = '\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}';
139 # Check for invalid specifications
140 if ( ! preg_match( "/^$rxIP$/", $this->BlockAddress
) ) {
141 if ( preg_match( "/^($rxIP)\\/(\\d{1,2})$/", $this->BlockAddress
, $matches ) ) {
142 if ( $wgSysopRangeBans ) {
143 if ( $matches[2] > 31 ||
$matches[2] < 16 ) {
144 $this->showForm( wfMsg( 'ip_range_invalid' ) );
147 $this->BlockAddress
= Block
::normaliseRange( $this->BlockAddress
);
149 # Range block illegal
150 $this->showForm( wfMsg( 'range_block_disabled' ) );
155 if ( $wgSysopUserBans ) {
156 $userId = User
::idFromName( $this->BlockAddress
);
157 if ( $userId == 0 ) {
158 $this->showForm( wfMsg( 'nosuchusershort', htmlspecialchars( $this->BlockAddress
) ) );
162 $this->showForm( wfMsg( 'badipaddress' ) );
168 $expirestr = $this->BlockExpiry
;
169 if (strlen($expirestr) == 0 ||
$expirestr == wfMsg('ipbotheroption'))
170 $expirestr = $this->BlockOther
;
172 if ( $expirestr == 'infinite' ||
$expirestr == 'indefinite' ) {
175 # Convert GNU-style date, returns -1 on error
176 $expiry = strtotime( $expirestr );
179 $this->showForm( wfMsg( 'ipb_expiry_invalid' ) );
183 $expiry = wfTimestamp( TS_MW
, $expiry );
188 # Note: for a user block, ipb_address is only for display purposes
190 $ban = new Block( $this->BlockAddress
, $userId, $wgUser->getID(),
191 $this->BlockReason
, wfTimestampNow(), 0, $expiry );
193 if (wfRunHooks('BlockIp', array(&$ban, &$wgUser))) {
197 wfRunHooks('BlockIpComplete', array($ban, $wgUser));
200 $log = new LogPage( 'block' );
201 $log->addEntry( 'block', Title
::makeTitle( NS_USER
, $this->BlockAddress
),
202 $this->BlockReason
, $expirestr );
205 $titleObj = Title
::makeTitle( NS_SPECIAL
, 'Blockip' );
206 $wgOut->redirect( $titleObj->getFullURL( 'action=success&ip=' .
207 urlencode( $this->BlockAddress
) ) );
211 function showSuccess() {
212 global $wgOut, $wgUser;
214 $wgOut->setPagetitle( wfMsg( 'blockip' ) );
215 $wgOut->setSubtitle( wfMsg( 'blockipsuccesssub' ) );
216 $text = wfMsg( 'blockipsuccesstext', $this->BlockAddress
);
217 $wgOut->addWikiText( $text );