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;
52 $wgOut->setPagetitle( htmlspecialchars( wfMsg( 'blockip' ) ) );
53 $wgOut->addWikiText( htmlspecialchars( wfMsg( 'blockiptext' ) ) );
55 $mIpaddress = htmlspecialchars( wfMsg( 'ipaddress' ) );
56 $mIpbexpiry = htmlspecialchars( wfMsg( 'ipbexpiry' ) );
57 $mIpbreason = htmlspecialchars( wfMsg( 'ipbreason' ) );
58 $mIpbsubmit = htmlspecialchars( wfMsg( 'ipbsubmit' ) );
59 $titleObj = Title
::makeTitle( NS_SPECIAL
, 'Blockip' );
60 $action = $titleObj->escapeLocalURL( "action=submit" );
63 $wgOut->setSubtitle( htmlspecialchars( wfMsg( 'formerror' ) ) );
64 $wgOut->addHTML( "<p class='error'>{$err}</p>\n" );
67 $scBlockAddress = htmlspecialchars( $this->BlockAddress
);
68 $scBlockExpiry = htmlspecialchars( $this->BlockExpiry
);
69 $scBlockReason = htmlspecialchars( $this->BlockReason
);
71 $blockExpiryFormOptions = join("</option><option>", split(",", $wgBlockExpiryOptions));
72 $blockExpiryFormOptions = "<option>" . $blockExpiryFormOptions . "</option>";
74 $token = htmlspecialchars( $wgUser->editToken() );
77 <form id=\"blockip\" method=\"post\" action=\"{$action}\">
80 <td align=\"right\">{$mIpaddress}:</td>
82 <input tabindex='1' type='text' size='20' name=\"wpBlockAddress\" value=\"{$scBlockAddress}\" />
86 <td align=\"right\">{$mIpbexpiry}:</td>
88 <select tabindex='2' name=\"wpBlockExpiry\"/>
89 $blockExpiryFormOptions
94 <td align=\"right\">{$mIpbreason}:</td>
96 <input tabindex='3' type='text' size='40' name=\"wpBlockReason\" value=\"{$scBlockReason}\" />
102 <input tabindex='4' type='submit' name=\"wpBlock\" value=\"{$mIpbsubmit}\" />
106 <input type='hidden' name='wpEditToken' value=\"{$token}\" />
111 function doSubmit() {
112 global $wgOut, $wgUser, $wgLang;
113 global $wgSysopUserBans, $wgSysopRangeBans;
116 $this->BlockAddress
= trim( $this->BlockAddress
);
117 $rxIP = '\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}';
119 # Check for invalid specifications
120 if ( ! preg_match( "/^$rxIP$/", $this->BlockAddress
) ) {
121 if ( preg_match( "/^($rxIP)\\/(\\d{1,2})$/", $this->BlockAddress
, $matches ) ) {
122 if ( $wgSysopRangeBans ) {
123 if ( $matches[2] > 31 ||
$matches[2] < 16 ) {
124 $this->showForm( wfMsg( 'ip_range_invalid' ) );
127 $this->BlockAddress
= Block
::normaliseRange( $this->BlockAddress
);
129 # Range block illegal
130 $this->showForm( wfMsg( 'range_block_disabled' ) );
135 if ( $wgSysopUserBans ) {
136 $userId = User
::idFromName( $this->BlockAddress
);
137 if ( $userId == 0 ) {
138 $this->showForm( wfMsg( 'nosuchusershort', htmlspecialchars( $this->BlockAddress
) ) );
142 $this->showForm( wfMsg( 'badipaddress' ) );
148 if ( $this->BlockExpiry
== 'infinite' ||
$this->BlockExpiry
== 'indefinite' ) {
151 # Convert GNU-style date, returns -1 on error
152 $expiry = strtotime( $this->BlockExpiry
);
155 $this->showForm( wfMsg( 'ipb_expiry_invalid' ) );
159 $expiry = wfTimestamp( TS_MW
, $expiry );
164 if ( $this->BlockReason
== '') {
165 $this->showForm( wfMsg( 'noblockreason' ) );
170 # Note: for a user block, ipb_address is only for display purposes
172 $ban = new Block( $this->BlockAddress
, $userId, $wgUser->getID(),
173 $this->BlockReason
, wfTimestampNow(), 0, $expiry );
175 if (wfRunHooks('BlockIp', array(&$ban, &$wgUser))) {
179 wfRunHooks('BlockIpComplete', array($ban, $wgUser));
182 $log = new LogPage( 'block' );
183 $log->addEntry( 'block', Title
::makeTitle( NS_USER
, $this->BlockAddress
),
184 $this->BlockReason
, $this->BlockExpiry
);
187 $titleObj = Title
::makeTitle( NS_SPECIAL
, 'Blockip' );
188 $wgOut->redirect( $titleObj->getFullURL( 'action=success&ip=' .
189 urlencode( $this->BlockAddress
) ) );
193 function showSuccess() {
194 global $wgOut, $wgUser;
196 $wgOut->setPagetitle( wfMsg( 'blockip' ) );
197 $wgOut->setSubtitle( wfMsg( 'blockipsuccesssub' ) );
198 $text = wfMsg( 'blockipsuccesstext', $this->BlockAddress
);
199 $wgOut->addWikiText( $text );