3 function wfSpecialBlockip()
5 global $wgUser, $wgOut, $wgRequest;
7 if ( ! $wgUser->isSysop() ) {
8 $wgOut->sysopRequired();
11 $ipb = new IPBlockForm();
13 $action = $wgRequest->getVal( 'action' );
14 if ( "success" == $action ) { $ipb->showSuccess(); }
15 else if ( $wgRequest->wasPosted() && "submit" == $action ) { $ipb->doSubmit(); }
16 else { $ipb->showForm( "" ); }
20 var $BlockAddress, $BlockExpiry, $BlockReason;
22 function IPBlockForm() {
24 $this->BlockAddress
= $wgRequest->getVal( 'wpBlockAddress', $wgRequest->getVal( 'ip' ) );
25 $this->BlockReason
= $wgRequest->getText( 'wpBlockReason' );
26 $this->BlockExpiry
= $wgRequest->getVal( 'wpBlockExpiry' );
29 function showForm( $err )
31 global $wgOut, $wgUser, $wgLang, $wgDefaultBlockExpiry;
34 $wgOut->setPagetitle( wfMsg( "blockip" ) );
35 $wgOut->addWikiText( wfMsg( "blockiptext" ) );
37 if ( is_null( $this->BlockExpiry
) ||
$this->BlockExpiry
=== "" ) {
38 $this->BlockExpiry
= $wgDefaultBlockExpiry;
41 $mIpaddress = wfMsg( "ipaddress" );
42 $mIpbexpiry = wfMsg( "ipbexpiry" );
43 $mIpbreason = wfMsg( "ipbreason" );
44 $mIpbsubmit = wfMsg( "ipbsubmit" );
45 $titleObj = Title
::makeTitle( NS_SPECIAL
, "Blockip" );
46 $action = $titleObj->escapeLocalURL( "action=submit" );
49 $wgOut->setSubtitle( wfMsg( "formerror" ) );
50 $wgOut->addHTML( "<p><font color='red' size='+1'>{$err}</font>\n" );
53 $scBlockAddress = htmlspecialchars( $this->BlockAddress
);
54 $scBlockExpiry = htmlspecialchars( $this->BlockExpiry
);
55 $scBlockReason = htmlspecialchars( $this->BlockReason
);
58 <form id=\"blockip\" method=\"post\" action=\"{$action}\">
60 <td align=\"right\">{$mIpaddress}:</td>
62 <input tabindex=1 type=text size=20 name=\"wpBlockAddress\" value=\"{$scBlockAddress}\">
64 <td align=\"right\">{$mIpbexpiry}:</td>
66 <input tabindex=2 type=text size=20 name=\"wpBlockExpiry\" value=\"{$scBlockExpiry}\">
68 <td align=\"right\">{$mIpbreason}:</td>
70 <input tabindex=3 type=text size=40 name=\"wpBlockReason\" value=\"{$scBlockReason}\">
72 <td> </td><td align=\"left\">
73 <input tabindex=4 type=submit name=\"wpBlock\" value=\"{$mIpbsubmit}\">
81 global $wgOut, $wgUser, $wgLang;
82 global $wgSysopUserBans, $wgSysopRangeBans;
85 $this->BlockAddress
= trim( $this->BlockAddress
);
86 $rxIP = '\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}';
88 # Check for invalid specifications
89 if ( ! preg_match( "/^$rxIP$/", $this->BlockAddress
) ) {
90 if ( preg_match( "/^($rxIP)\\/(\\d{1,2})$/", $this->BlockAddress
, $matches ) ) {
91 if ( $wgSysopRangeBans ) {
92 if ( $matches[2] > 31 ||
$matches[2] < 16 ) {
93 $this->showForm( wfMsg( "ip_range_invalid" ) );
96 $this->BlockAddress
= Block
::normaliseRange( $this->BlockAddress
);
99 $this->showForm( wfMsg( "range_block_disabled" ) );
104 if ( $wgSysopUserBans ) {
105 $userId = User
::idFromName( $this->BlockAddress
);
106 if ( $userId == 0 ) {
107 $this->showForm( wfMsg( "nosuchuser", htmlspecialchars( $this->BlockAddress
) ) );
111 $this->showForm( wfMsg( "badipaddress" ) );
117 if ( $this->BlockExpiry
== "infinite" ||
$this->BlockExpiry
== "indefinite" ) {
120 # Convert GNU-style date, returns -1 on error
121 $expiry = strtotime( $this->BlockExpiry
);
124 $this->showForm( wfMsg( "ipb_expiry_invalid" ) );
128 $expiry = wfUnix2Timestamp( $expiry );
133 if ( "" == $this->BlockReason
) {
134 $this->showForm( wfMsg( "noblockreason" ) );
139 # Note: for a user block, ipb_address is only for display purposes
141 $ban = new Block( $this->BlockAddress
, $userId, $wgUser->getID(),
142 wfStrencode( $this->BlockReason
), wfTimestampNow(), 0, $expiry );
146 $log = new LogPage( wfMsg( "blocklogpage" ), wfMsg( "blocklogtext" ) );
147 $action = wfMsg( "blocklogentry", $this->BlockAddress
, $this->BlockExpiry
);
148 $log->addEntry( $action, $this->BlockReason
);
151 $titleObj = Title
::makeTitle( NS_SPECIAL
, "Blockip" );
152 $wgOut->redirect( $titleObj->getFullURL( "action=success&ip={$this->BlockAddress}" ) );
155 function showSuccess()
157 global $wgOut, $wgUser;
159 $wgOut->setPagetitle( wfMsg( "blockip" ) );
160 $wgOut->setSubtitle( wfMsg( "blockipsuccesssub" ) );
161 $text = wfMsg( "blockipsuccesstext", $this->BlockAddress
);
162 $wgOut->addWikiText( $text );