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 ) { $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 ) {
44 global $wgOut, $wgUser, $wgLang, $wgDefaultBlockExpiry;
47 $wgOut->setPagetitle( htmlspecialchars( wfMsg( 'blockip' ) ) );
48 $wgOut->addWikiText( htmlspecialchars( wfMsg( 'blockiptext' ) ) );
50 if ( is_null( $this->BlockExpiry
) ||
$this->BlockExpiry
=== '' ) {
51 $this->BlockExpiry
= $wgDefaultBlockExpiry;
54 $mIpaddress = htmlspecialchars( wfMsg( 'ipaddress' ) );
55 $mIpbexpiry = htmlspecialchars( wfMsg( 'ipbexpiry' ) );
56 $mIpbreason = htmlspecialchars( wfMsg( 'ipbreason' ) );
57 $mIpbsubmit = htmlspecialchars( wfMsg( 'ipbsubmit' ) );
58 $titleObj = Title
::makeTitle( NS_SPECIAL
, 'Blockip' );
59 $action = $titleObj->escapeLocalURL( "action=submit" );
62 $wgOut->setSubtitle( htmlspecialchars( wfMsg( 'formerror' ) ) );
63 $wgOut->addHTML( "<p class='error'>{$err}</p>\n" );
66 $scBlockAddress = htmlspecialchars( $this->BlockAddress
);
67 $scBlockExpiry = htmlspecialchars( $this->BlockExpiry
);
68 $scBlockReason = htmlspecialchars( $this->BlockReason
);
71 <form id=\"blockip\" method=\"post\" action=\"{$action}\">
74 <td align=\"right\">{$mIpaddress}:</td>
76 <input tabindex='1' type='text' size='20' name=\"wpBlockAddress\" value=\"{$scBlockAddress}\" />
80 <td align=\"right\">{$mIpbexpiry}:</td>
82 <input tabindex='2' type='text' size='20' name=\"wpBlockExpiry\" value=\"{$scBlockExpiry}\" />
86 <td align=\"right\">{$mIpbreason}:</td>
88 <input tabindex='3' type='text' size='40' name=\"wpBlockReason\" value=\"{$scBlockReason}\" />
94 <input tabindex='4' type='submit' name=\"wpBlock\" value=\"{$mIpbsubmit}\" />
102 function doSubmit() {
103 global $wgOut, $wgUser, $wgLang;
104 global $wgSysopUserBans, $wgSysopRangeBans;
107 $this->BlockAddress
= trim( $this->BlockAddress
);
108 $rxIP = '\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}';
110 # Check for invalid specifications
111 if ( ! preg_match( "/^$rxIP$/", $this->BlockAddress
) ) {
112 if ( preg_match( "/^($rxIP)\\/(\\d{1,2})$/", $this->BlockAddress
, $matches ) ) {
113 if ( $wgSysopRangeBans ) {
114 if ( $matches[2] > 31 ||
$matches[2] < 16 ) {
115 $this->showForm( wfMsg( 'ip_range_invalid' ) );
118 $this->BlockAddress
= Block
::normaliseRange( $this->BlockAddress
);
120 # Range block illegal
121 $this->showForm( wfMsg( 'range_block_disabled' ) );
126 if ( $wgSysopUserBans ) {
127 $userId = User
::idFromName( $this->BlockAddress
);
128 if ( $userId == 0 ) {
129 $this->showForm( wfMsg( 'nosuchusershort', htmlspecialchars( $this->BlockAddress
) ) );
133 $this->showForm( wfMsg( 'badipaddress' ) );
139 if ( $this->BlockExpiry
== 'infinite' ||
$this->BlockExpiry
== 'indefinite' ) {
142 # Convert GNU-style date, returns -1 on error
143 $expiry = strtotime( $this->BlockExpiry
);
146 $this->showForm( wfMsg( 'ipb_expiry_invalid' ) );
150 $expiry = wfUnix2Timestamp( $expiry );
154 if ( $this->BlockReason
== '') {
155 $this->showForm( wfMsg( 'noblockreason' ) );
160 # Note: for a user block, ipb_address is only for display purposes
162 $ban = new Block( $this->BlockAddress
, $userId, $wgUser->getID(),
163 wfStrencode( $this->BlockReason
), wfTimestampNow(), 0, $expiry );
167 $log = new LogPage( 'block' );
168 $log->addEntry( 'block', Title
::makeTitle( NS_USER
, $this->BlockAddress
), $this->BlockReason
);
171 $titleObj = Title
::makeTitle( NS_SPECIAL
, 'Blockip' );
172 $wgOut->redirect( $titleObj->getFullURL( 'action=success&ip='.$this->BlockAddress
) );
175 function showSuccess() {
176 global $wgOut, $wgUser;
178 $wgOut->setPagetitle( wfMsg( 'blockip' ) );
179 $wgOut->setSubtitle( wfMsg( 'blockipsuccesssub' ) );
180 $text = wfMsg( 'blockipsuccesstext', $this->BlockAddress
);
181 $wgOut->addWikiText( $text );