098309d131ebe2f834466cfa03d68d3d2399337e
3 * Constructor for Special:Blockip page
10 function wfSpecialBlockip() {
11 global $wgUser, $wgOut, $wgRequest;
13 if ( ! $wgUser->isSysop() ) {
14 $wgOut->sysopRequired();
17 $ipb = new IPBlockForm();
19 $action = $wgRequest->getVal( 'action' );
20 if ( "success" == $action ) { $ipb->showSuccess(); }
21 else if ( $wgRequest->wasPosted() && "submit" == $action ) { $ipb->doSubmit(); }
22 else { $ipb->showForm( "" ); }
30 var $BlockAddress, $BlockExpiry, $BlockReason;
32 function IPBlockForm() {
34 $this->BlockAddress
= $wgRequest->getVal( 'wpBlockAddress', $wgRequest->getVal( 'ip' ) );
35 $this->BlockReason
= $wgRequest->getText( 'wpBlockReason' );
36 $this->BlockExpiry
= $wgRequest->getVal( 'wpBlockExpiry' );
39 function showForm( $err )
41 global $wgOut, $wgUser, $wgLang, $wgDefaultBlockExpiry;
44 $wgOut->setPagetitle( htmlspecialchars( wfMsg( "blockip" ) ) );
45 $wgOut->addWikiText( htmlspecialchars( wfMsg( "blockiptext" ) ) );
47 if ( is_null( $this->BlockExpiry
) ||
$this->BlockExpiry
=== "" ) {
48 $this->BlockExpiry
= $wgDefaultBlockExpiry;
51 $mIpaddress = htmlspecialchars( wfMsg( "ipaddress" ) );
52 $mIpbexpiry = htmlspecialchars( wfMsg( "ipbexpiry" ) );
53 $mIpbreason = htmlspecialchars( wfMsg( "ipbreason" ) );
54 $mIpbsubmit = htmlspecialchars( wfMsg( "ipbsubmit" ) );
55 $titleObj = Title
::makeTitle( NS_SPECIAL
, "Blockip" );
56 $action = $titleObj->escapeLocalURL( "action=submit" );
59 $wgOut->setSubtitle( htmlspecialchars( wfMsg( "formerror" ) ) );
60 $wgOut->addHTML( "<p class='error'>{$err}</p>\n" );
63 $scBlockAddress = htmlspecialchars( $this->BlockAddress
);
64 $scBlockExpiry = htmlspecialchars( $this->BlockExpiry
);
65 $scBlockReason = htmlspecialchars( $this->BlockReason
);
68 <form id=\"blockip\" method=\"post\" action=\"{$action}\">
71 <td align=\"right\">{$mIpaddress}:</td>
73 <input tabindex='1' type='text' size='20' name=\"wpBlockAddress\" value=\"{$scBlockAddress}\" />
77 <td align=\"right\">{$mIpbexpiry}:</td>
79 <input tabindex='2' type='text' size='20' name=\"wpBlockExpiry\" value=\"{$scBlockExpiry}\" />
83 <td align=\"right\">{$mIpbreason}:</td>
85 <input tabindex='3' type='text' size='40' name=\"wpBlockReason\" value=\"{$scBlockReason}\" />
91 <input tabindex='4' type='submit' name=\"wpBlock\" value=\"{$mIpbsubmit}\" />
100 global $wgOut, $wgUser, $wgLang;
101 global $wgSysopUserBans, $wgSysopRangeBans;
104 $this->BlockAddress
= trim( $this->BlockAddress
);
105 $rxIP = '\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}';
107 # Check for invalid specifications
108 if ( ! preg_match( "/^$rxIP$/", $this->BlockAddress
) ) {
109 if ( preg_match( "/^($rxIP)\\/(\\d{1,2})$/", $this->BlockAddress
, $matches ) ) {
110 if ( $wgSysopRangeBans ) {
111 if ( $matches[2] > 31 ||
$matches[2] < 16 ) {
112 $this->showForm( wfMsg( "ip_range_invalid" ) );
115 $this->BlockAddress
= Block
::normaliseRange( $this->BlockAddress
);
117 # Range block illegal
118 $this->showForm( wfMsg( "range_block_disabled" ) );
123 if ( $wgSysopUserBans ) {
124 $userId = User
::idFromName( $this->BlockAddress
);
125 if ( $userId == 0 ) {
126 $this->showForm( wfMsg( "nosuchuser", htmlspecialchars( $this->BlockAddress
) ) );
130 $this->showForm( wfMsg( "badipaddress" ) );
136 if ( $this->BlockExpiry
== "infinite" ||
$this->BlockExpiry
== "indefinite" ) {
139 # Convert GNU-style date, returns -1 on error
140 $expiry = strtotime( $this->BlockExpiry
);
143 $this->showForm( wfMsg( "ipb_expiry_invalid" ) );
147 $expiry = wfUnix2Timestamp( $expiry );
152 if ( "" == $this->BlockReason
) {
153 $this->showForm( wfMsg( "noblockreason" ) );
158 # Note: for a user block, ipb_address is only for display purposes
160 $ban = new Block( $this->BlockAddress
, $userId, $wgUser->getID(),
161 wfStrencode( $this->BlockReason
), wfTimestampNow(), 0, $expiry );
165 $log = new LogPage( 'block' );
166 $log->addEntry( 'block', Title
::makeTitle( NS_USER
, $this->BlockAddress
), $this->BlockReason
);
169 $titleObj = Title
::makeTitle( NS_SPECIAL
, "Blockip" );
170 $wgOut->redirect( $titleObj->getFullURL( "action=success&ip={$this->BlockAddress}" ) );
173 function showSuccess() {
174 global $wgOut, $wgUser;
176 $wgOut->setPagetitle( wfMsg( "blockip" ) );
177 $wgOut->setSubtitle( wfMsg( "blockipsuccesssub" ) );
178 $text = wfMsg( "blockipsuccesstext", $this->BlockAddress
);
179 $wgOut->addWikiText( $text );