42f11eb665a4c32ac83482e4ae3da8786e7a07d6
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( htmlspecialchars( wfMsg( "blockip" ) ) );
35 $wgOut->addWikiText( htmlspecialchars( wfMsg( "blockiptext" ) ) );
37 if ( is_null( $this->BlockExpiry
) ||
$this->BlockExpiry
=== "" ) {
38 $this->BlockExpiry
= $wgDefaultBlockExpiry;
41 $mIpaddress = htmlspecialchars( wfMsg( "ipaddress" ) );
42 $mIpbexpiry = htmlspecialchars( wfMsg( "ipbexpiry" ) );
43 $mIpbreason = htmlspecialchars( wfMsg( "ipbreason" ) );
44 $mIpbsubmit = htmlspecialchars( wfMsg( "ipbsubmit" ) );
45 $titleObj = Title
::makeTitle( NS_SPECIAL
, "Blockip" );
46 $action = $titleObj->escapeLocalURL( "action=submit" );
49 $wgOut->setSubtitle( htmlspecialchars( wfMsg( "formerror" ) ) );
50 $wgOut->addHTML( "<p class='error'>{$err}</p>\n" );
53 $scBlockAddress = htmlspecialchars( $this->BlockAddress
);
54 $scBlockExpiry = htmlspecialchars( $this->BlockExpiry
);
55 $scBlockReason = htmlspecialchars( $this->BlockReason
);
58 <form id=\"blockip\" method=\"post\" action=\"{$action}\">
61 <td align=\"right\">{$mIpaddress}:</td>
63 <input tabindex='1' type='text' size='20' name=\"wpBlockAddress\" value=\"{$scBlockAddress}\" />
67 <td align=\"right\">{$mIpbexpiry}:</td>
69 <input tabindex='2' type='text' size='20' name=\"wpBlockExpiry\" value=\"{$scBlockExpiry}\" />
73 <td align=\"right\">{$mIpbreason}:</td>
75 <input tabindex='3' type='text' size='40' name=\"wpBlockReason\" value=\"{$scBlockReason}\" />
81 <input tabindex='4' type='submit' name=\"wpBlock\" value=\"{$mIpbsubmit}\" />
91 global $wgOut, $wgUser, $wgLang;
92 global $wgSysopUserBans, $wgSysopRangeBans;
95 $this->BlockAddress
= trim( $this->BlockAddress
);
96 $rxIP = '\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}';
98 # Check for invalid specifications
99 if ( ! preg_match( "/^$rxIP$/", $this->BlockAddress
) ) {
100 if ( preg_match( "/^($rxIP)\\/(\\d{1,2})$/", $this->BlockAddress
, $matches ) ) {
101 if ( $wgSysopRangeBans ) {
102 if ( $matches[2] > 31 ||
$matches[2] < 16 ) {
103 $this->showForm( wfMsg( "ip_range_invalid" ) );
106 $this->BlockAddress
= Block
::normaliseRange( $this->BlockAddress
);
108 # Range block illegal
109 $this->showForm( wfMsg( "range_block_disabled" ) );
114 if ( $wgSysopUserBans ) {
115 $userId = User
::idFromName( $this->BlockAddress
);
116 if ( $userId == 0 ) {
117 $this->showForm( wfMsg( "nosuchuser", htmlspecialchars( $this->BlockAddress
) ) );
121 $this->showForm( wfMsg( "badipaddress" ) );
127 if ( $this->BlockExpiry
== "infinite" ||
$this->BlockExpiry
== "indefinite" ) {
130 # Convert GNU-style date, returns -1 on error
131 $expiry = strtotime( $this->BlockExpiry
);
134 $this->showForm( wfMsg( "ipb_expiry_invalid" ) );
138 $expiry = wfUnix2Timestamp( $expiry );
143 if ( "" == $this->BlockReason
) {
144 $this->showForm( wfMsg( "noblockreason" ) );
149 # Note: for a user block, ipb_address is only for display purposes
151 $ban = new Block( $this->BlockAddress
, $userId, $wgUser->getID(),
152 wfStrencode( $this->BlockReason
), wfTimestampNow(), 0, $expiry );
156 $log = new LogPage( 'block' );
157 $log->addEntry( 'block', Title
::makeTitle( NS_USER
, $this->BlockAddress
), $this->BlockReason
);
160 $titleObj = Title
::makeTitle( NS_SPECIAL
, "Blockip" );
161 $wgOut->redirect( $titleObj->getFullURL( "action=success&ip={$this->BlockAddress}" ) );
164 function showSuccess()
166 global $wgOut, $wgUser;
168 $wgOut->setPagetitle( wfMsg( "blockip" ) );
169 $wgOut->setSubtitle( wfMsg( "blockipsuccesssub" ) );
170 $text = wfMsg( "blockipsuccesstext", $this->BlockAddress
);
171 $wgOut->addWikiText( $text );