3 * Constructor for Special:Blockip page
6 * @subpackage SpecialPage
12 function wfSpecialBlockip() {
13 global $wgUser, $wgOut, $wgRequest;
15 if ( ! $wgUser->isSysop() ) {
16 $wgOut->sysopRequired();
19 $ipb = new IPBlockForm();
21 $action = $wgRequest->getVal( 'action' );
22 if ( "success" == $action ) { $ipb->showSuccess(); }
23 else if ( $wgRequest->wasPosted() && "submit" == $action ) { $ipb->doSubmit(); }
24 else { $ipb->showForm( "" ); }
31 * @subpackage SpecialPage
34 var $BlockAddress, $BlockExpiry, $BlockReason;
36 function IPBlockForm() {
38 $this->BlockAddress
= $wgRequest->getVal( 'wpBlockAddress', $wgRequest->getVal( 'ip' ) );
39 $this->BlockReason
= $wgRequest->getText( 'wpBlockReason' );
40 $this->BlockExpiry
= $wgRequest->getVal( 'wpBlockExpiry' );
43 function showForm( $err )
45 global $wgOut, $wgUser, $wgLang, $wgDefaultBlockExpiry;
48 $wgOut->setPagetitle( htmlspecialchars( wfMsg( "blockip" ) ) );
49 $wgOut->addWikiText( htmlspecialchars( wfMsg( "blockiptext" ) ) );
51 if ( is_null( $this->BlockExpiry
) ||
$this->BlockExpiry
=== "" ) {
52 $this->BlockExpiry
= $wgDefaultBlockExpiry;
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
);
72 <form id=\"blockip\" method=\"post\" action=\"{$action}\">
75 <td align=\"right\">{$mIpaddress}:</td>
77 <input tabindex='1' type='text' size='20' name=\"wpBlockAddress\" value=\"{$scBlockAddress}\" />
81 <td align=\"right\">{$mIpbexpiry}:</td>
83 <input tabindex='2' type='text' size='20' name=\"wpBlockExpiry\" value=\"{$scBlockExpiry}\" />
87 <td align=\"right\">{$mIpbreason}:</td>
89 <input tabindex='3' type='text' size='40' name=\"wpBlockReason\" value=\"{$scBlockReason}\" />
95 <input tabindex='4' type='submit' name=\"wpBlock\" value=\"{$mIpbsubmit}\" />
103 function doSubmit() {
104 global $wgOut, $wgUser, $wgLang;
105 global $wgSysopUserBans, $wgSysopRangeBans;
108 $this->BlockAddress
= trim( $this->BlockAddress
);
109 $rxIP = '\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}';
111 # Check for invalid specifications
112 if ( ! preg_match( "/^$rxIP$/", $this->BlockAddress
) ) {
113 if ( preg_match( "/^($rxIP)\\/(\\d{1,2})$/", $this->BlockAddress
, $matches ) ) {
114 if ( $wgSysopRangeBans ) {
115 if ( $matches[2] > 31 ||
$matches[2] < 16 ) {
116 $this->showForm( wfMsg( "ip_range_invalid" ) );
119 $this->BlockAddress
= Block
::normaliseRange( $this->BlockAddress
);
121 # Range block illegal
122 $this->showForm( wfMsg( "range_block_disabled" ) );
127 if ( $wgSysopUserBans ) {
128 $userId = User
::idFromName( $this->BlockAddress
);
129 if ( $userId == 0 ) {
130 $this->showForm( wfMsg( "nosuchuser", htmlspecialchars( $this->BlockAddress
) ) );
134 $this->showForm( wfMsg( "badipaddress" ) );
140 if ( $this->BlockExpiry
== "infinite" ||
$this->BlockExpiry
== "indefinite" ) {
143 # Convert GNU-style date, returns -1 on error
144 $expiry = strtotime( $this->BlockExpiry
);
147 $this->showForm( wfMsg( "ipb_expiry_invalid" ) );
151 $expiry = wfUnix2Timestamp( $expiry );
156 if ( "" == $this->BlockReason
) {
157 $this->showForm( wfMsg( "noblockreason" ) );
162 # Note: for a user block, ipb_address is only for display purposes
164 $ban = new Block( $this->BlockAddress
, $userId, $wgUser->getID(),
165 wfStrencode( $this->BlockReason
), wfTimestampNow(), 0, $expiry );
169 $log = new LogPage( 'block' );
170 $log->addEntry( 'block', Title
::makeTitle( NS_USER
, $this->BlockAddress
), $this->BlockReason
);
173 $titleObj = Title
::makeTitle( NS_SPECIAL
, "Blockip" );
174 $wgOut->redirect( $titleObj->getFullURL( "action=success&ip={$this->BlockAddress}" ) );
177 function showSuccess() {
178 global $wgOut, $wgUser;
180 $wgOut->setPagetitle( wfMsg( "blockip" ) );
181 $wgOut->setSubtitle( wfMsg( "blockipsuccesssub" ) );
182 $text = wfMsg( "blockipsuccesstext", $this->BlockAddress
);
183 $wgOut->addWikiText( $text );