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' );
48 function showForm( $err ) {
49 global $wgOut, $wgUser, $wgLang, $wgBlockExpiryOptions;
50 global $wgRequest, $wgSysopUserBans;
52 $wgOut->setPagetitle( htmlspecialchars( wfMsg( 'blockip' ) ) );
53 $wgOut->addWikiText( wfMsg( 'blockiptext' ) );
55 if($wgSysopUserBans) {
56 $mIpaddress = htmlspecialchars( wfMsg( 'ipadressorusername' ) );
58 $mIpaddress = htmlspecialchars( wfMsg( 'ipaddress' ) );
60 $mIpbexpiry = htmlspecialchars( wfMsg( 'ipbexpiry' ) );
61 $mIpbreason = htmlspecialchars( wfMsg( 'ipbreason' ) );
62 $mIpbsubmit = htmlspecialchars( wfMsg( 'ipbsubmit' ) );
63 $titleObj = Title
::makeTitle( NS_SPECIAL
, 'Blockip' );
64 $action = $titleObj->escapeLocalURL( "action=submit" );
67 $wgOut->setSubtitle( htmlspecialchars( wfMsg( 'formerror' ) ) );
68 $wgOut->addHTML( "<p class='error'>{$err}</p>\n" );
71 $scBlockAddress = htmlspecialchars( $this->BlockAddress
);
72 $scBlockExpiry = htmlspecialchars( $this->BlockExpiry
);
73 $scBlockReason = htmlspecialchars( $this->BlockReason
);
75 $blockExpiryFormOptions = '<option>' .
76 implode("</option>\n\t\t\t\t\t<option>", explode(',', $wgBlockExpiryOptions)) .
79 $token = htmlspecialchars( $wgUser->editToken() );
82 <form id=\"blockip\" method=\"post\" action=\"{$action}\">
85 <td align=\"right\">{$mIpaddress}:</td>
87 <input tabindex='1' type='text' size='20' name=\"wpBlockAddress\" value=\"{$scBlockAddress}\" />
91 <td align=\"right\">{$mIpbexpiry}:</td>
93 <select tabindex='2' name=\"wpBlockExpiry\">
94 $blockExpiryFormOptions
99 <td align=\"right\">{$mIpbreason}:</td>
101 <input tabindex='3' type='text' size='40' name=\"wpBlockReason\" value=\"{$scBlockReason}\" />
107 <input tabindex='4' type='submit' name=\"wpBlock\" value=\"{$mIpbsubmit}\" />
111 <input type='hidden' name='wpEditToken' value=\"{$token}\" />
116 function doSubmit() {
117 global $wgOut, $wgUser, $wgLang;
118 global $wgSysopUserBans, $wgSysopRangeBans;
121 $this->BlockAddress
= trim( $this->BlockAddress
);
122 $rxIP = '\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}';
124 # Check for invalid specifications
125 if ( ! preg_match( "/^$rxIP$/", $this->BlockAddress
) ) {
126 if ( preg_match( "/^($rxIP)\\/(\\d{1,2})$/", $this->BlockAddress
, $matches ) ) {
127 if ( $wgSysopRangeBans ) {
128 if ( $matches[2] > 31 ||
$matches[2] < 16 ) {
129 $this->showForm( wfMsg( 'ip_range_invalid' ) );
132 $this->BlockAddress
= Block
::normaliseRange( $this->BlockAddress
);
134 # Range block illegal
135 $this->showForm( wfMsg( 'range_block_disabled' ) );
140 if ( $wgSysopUserBans ) {
141 $userId = User
::idFromName( $this->BlockAddress
);
142 if ( $userId == 0 ) {
143 $this->showForm( wfMsg( 'nosuchusershort', htmlspecialchars( $this->BlockAddress
) ) );
147 $this->showForm( wfMsg( 'badipaddress' ) );
153 if ( $this->BlockExpiry
== 'infinite' ||
$this->BlockExpiry
== 'indefinite' ) {
156 # Convert GNU-style date, returns -1 on error
157 $expiry = strtotime( $this->BlockExpiry
);
160 $this->showForm( wfMsg( 'ipb_expiry_invalid' ) );
164 $expiry = wfTimestamp( TS_MW
, $expiry );
169 if ( $this->BlockReason
== '') {
170 $this->showForm( wfMsg( 'noblockreason' ) );
175 # Note: for a user block, ipb_address is only for display purposes
177 $ban = new Block( $this->BlockAddress
, $userId, $wgUser->getID(),
178 $this->BlockReason
, wfTimestampNow(), 0, $expiry );
180 if (wfRunHooks('BlockIp', array(&$ban, &$wgUser))) {
184 wfRunHooks('BlockIpComplete', array($ban, $wgUser));
187 $log = new LogPage( 'block' );
188 $log->addEntry( 'block', Title
::makeTitle( NS_USER
, $this->BlockAddress
),
189 $this->BlockReason
, $this->BlockExpiry
);
192 $titleObj = Title
::makeTitle( NS_SPECIAL
, 'Blockip' );
193 $wgOut->redirect( $titleObj->getFullURL( 'action=success&ip=' .
194 urlencode( $this->BlockAddress
) ) );
198 function showSuccess() {
199 global $wgOut, $wgUser;
201 $wgOut->setPagetitle( wfMsg( 'blockip' ) );
202 $wgOut->setSubtitle( wfMsg( 'blockipsuccesssub' ) );
203 $text = wfMsg( 'blockipsuccesstext', $this->BlockAddress
);
204 $wgOut->addWikiText( $text );