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 <select name=\"wpBlockExpiry\"/>
83 <option>2 hours</option>
84 <option>1 day</option>
85 <option>3 days</option>
86 <option>1 week</option>
87 <option>2 weeks</option>
88 <option>1 month</option>
89 <option>3 months</option>
90 <option>6 months</option>
91 <option>1 year</option>
92 <option>indefinite</option>
97 <td align=\"right\">{$mIpbreason}:</td>
99 <input tabindex='3' type='text' size='40' name=\"wpBlockReason\" value=\"{$scBlockReason}\" />
105 <input tabindex='4' type='submit' name=\"wpBlock\" value=\"{$mIpbsubmit}\" />
113 function doSubmit() {
114 global $wgOut, $wgUser, $wgLang;
115 global $wgSysopUserBans, $wgSysopRangeBans;
118 $this->BlockAddress
= trim( $this->BlockAddress
);
119 $rxIP = '\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}';
121 # Check for invalid specifications
122 if ( ! preg_match( "/^$rxIP$/", $this->BlockAddress
) ) {
123 if ( preg_match( "/^($rxIP)\\/(\\d{1,2})$/", $this->BlockAddress
, $matches ) ) {
124 if ( $wgSysopRangeBans ) {
125 if ( $matches[2] > 31 ||
$matches[2] < 16 ) {
126 $this->showForm( wfMsg( 'ip_range_invalid' ) );
129 $this->BlockAddress
= Block
::normaliseRange( $this->BlockAddress
);
131 # Range block illegal
132 $this->showForm( wfMsg( 'range_block_disabled' ) );
137 if ( $wgSysopUserBans ) {
138 $userId = User
::idFromName( $this->BlockAddress
);
139 if ( $userId == 0 ) {
140 $this->showForm( wfMsg( 'nosuchusershort', htmlspecialchars( $this->BlockAddress
) ) );
144 $this->showForm( wfMsg( 'badipaddress' ) );
150 if ( $this->BlockExpiry
== 'infinite' ||
$this->BlockExpiry
== 'indefinite' ) {
153 # Convert GNU-style date, returns -1 on error
154 $expiry = strtotime( $this->BlockExpiry
);
157 $this->showForm( wfMsg( 'ipb_expiry_invalid' ) );
161 $expiry = wfTimestamp( TS_MW
, $expiry );
165 if ( $this->BlockReason
== '') {
166 $this->showForm( wfMsg( 'noblockreason' ) );
171 # Note: for a user block, ipb_address is only for display purposes
173 $ban = new Block( $this->BlockAddress
, $userId, $wgUser->getID(),
174 $this->BlockReason
, wfTimestampNow(), 0, $expiry );
176 if (wfRunHooks('BlockIp', $ban, $wgUser)) {
180 wfRunHooks('BlockIpComplete', $ban, $wgUser);
183 $log = new LogPage( 'block' );
184 $log->addEntry( 'block', Title
::makeTitle( NS_USER
, $this->BlockAddress
),
185 $this->BlockReason
, $this->BlockExpiry
);
188 $titleObj = Title
::makeTitle( NS_SPECIAL
, 'Blockip' );
189 $wgOut->redirect( $titleObj->getFullURL( 'action=success&ip=' .
190 urlencode( $this->BlockAddress
) ) );
194 function showSuccess() {
195 global $wgOut, $wgUser;
197 $wgOut->setPagetitle( wfMsg( 'blockip' ) );
198 $wgOut->setSubtitle( wfMsg( 'blockipsuccesssub' ) );
199 $text = wfMsg( 'blockipsuccesstext', $this->BlockAddress
);
200 $wgOut->addWikiText( $text );