2004-02-18 02:15:00 +00:00
|
|
|
<?php
|
2003-04-14 23:10:40 +00:00
|
|
|
|
|
|
|
|
function wfSpecialBlockip()
|
|
|
|
|
{
|
2004-03-08 09:09:35 +00:00
|
|
|
global $wgUser, $wgOut, $wgRequest;
|
2003-04-14 23:10:40 +00:00
|
|
|
|
|
|
|
|
if ( ! $wgUser->isSysop() ) {
|
|
|
|
|
$wgOut->sysopRequired();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
$ipb = new IPBlockForm();
|
|
|
|
|
|
2004-03-08 09:09:35 +00:00
|
|
|
$action = $wgRequest->getVal( 'action' );
|
2003-04-14 23:10:40 +00:00
|
|
|
if ( "success" == $action ) { $ipb->showSuccess(); }
|
2004-03-08 09:09:35 +00:00
|
|
|
else if ( $wgRequest->wasPosted() && "submit" == $action ) { $ipb->doSubmit(); }
|
2003-04-14 23:10:40 +00:00
|
|
|
else { $ipb->showForm( "" ); }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class IPBlockForm {
|
2004-03-08 09:09:35 +00:00
|
|
|
var $BlockAddress, $BlockExpiry, $BlockReason;
|
2003-04-14 23:10:40 +00:00
|
|
|
|
2004-03-08 09:09:35 +00:00
|
|
|
function IPBlockForm() {
|
|
|
|
|
global $wgRequest;
|
|
|
|
|
$this->BlockAddress = $wgRequest->getVal( 'wpBlockAddress', $wgRequest->getVal( 'ip' ) );
|
|
|
|
|
$this->BlockReason = $wgRequest->getText( 'wpBlockReason' );
|
|
|
|
|
$this->BlockExpiry = $wgRequest->getVal( 'wpBlockExpiry' );
|
|
|
|
|
}
|
|
|
|
|
|
2003-04-14 23:10:40 +00:00
|
|
|
function showForm( $err )
|
|
|
|
|
{
|
2004-02-14 12:37:25 +00:00
|
|
|
global $wgOut, $wgUser, $wgLang, $wgDefaultBlockExpiry;
|
2004-03-08 09:09:35 +00:00
|
|
|
global $wgRequest;
|
2003-04-14 23:10:40 +00:00
|
|
|
|
2004-04-26 07:35:20 +00:00
|
|
|
$wgOut->setPagetitle( htmlspecialchars( wfMsg( "blockip" ) ) );
|
|
|
|
|
$wgOut->addWikiText( htmlspecialchars( wfMsg( "blockiptext" ) ) );
|
2003-04-14 23:10:40 +00:00
|
|
|
|
2004-03-08 09:09:35 +00:00
|
|
|
if ( is_null( $this->BlockExpiry ) || $this->BlockExpiry === "" ) {
|
|
|
|
|
$this->BlockExpiry = $wgDefaultBlockExpiry;
|
2004-02-14 12:37:25 +00:00
|
|
|
}
|
|
|
|
|
|
2004-04-26 07:35:20 +00:00
|
|
|
$mIpaddress = htmlspecialchars( wfMsg( "ipaddress" ) );
|
|
|
|
|
$mIpbexpiry = htmlspecialchars( wfMsg( "ipbexpiry" ) );
|
|
|
|
|
$mIpbreason = htmlspecialchars( wfMsg( "ipbreason" ) );
|
|
|
|
|
$mIpbsubmit = htmlspecialchars( wfMsg( "ipbsubmit" ) );
|
2004-03-06 01:49:16 +00:00
|
|
|
$titleObj = Title::makeTitle( NS_SPECIAL, "Blockip" );
|
2004-03-07 07:26:56 +00:00
|
|
|
$action = $titleObj->escapeLocalURL( "action=submit" );
|
2003-04-14 23:10:40 +00:00
|
|
|
|
|
|
|
|
if ( "" != $err ) {
|
2004-04-26 07:35:20 +00:00
|
|
|
$wgOut->setSubtitle( htmlspecialchars( wfMsg( "formerror" ) ) );
|
|
|
|
|
$wgOut->addHTML( "<p class='error'>{$err}</p>\n" );
|
2003-04-14 23:10:40 +00:00
|
|
|
}
|
2004-02-14 12:37:25 +00:00
|
|
|
|
2004-03-08 09:09:35 +00:00
|
|
|
$scBlockAddress = htmlspecialchars( $this->BlockAddress );
|
|
|
|
|
$scBlockExpiry = htmlspecialchars( $this->BlockExpiry );
|
|
|
|
|
$scBlockReason = htmlspecialchars( $this->BlockReason );
|
2004-02-14 12:37:25 +00:00
|
|
|
|
2004-04-26 07:35:20 +00:00
|
|
|
$wgOut->addHTML( "
|
2003-04-14 23:10:40 +00:00
|
|
|
<form id=\"blockip\" method=\"post\" action=\"{$action}\">
|
2004-04-26 07:35:20 +00:00
|
|
|
<table border='0'>
|
|
|
|
|
<tr>
|
|
|
|
|
<td align=\"right\">{$mIpaddress}:</td>
|
|
|
|
|
<td align=\"left\">
|
|
|
|
|
<input tabindex='1' type='text' size='20' name=\"wpBlockAddress\" value=\"{$scBlockAddress}\" />
|
|
|
|
|
</td>
|
|
|
|
|
</tr>
|
|
|
|
|
<tr>
|
|
|
|
|
<td align=\"right\">{$mIpbexpiry}:</td>
|
|
|
|
|
<td align=\"left\">
|
|
|
|
|
<input tabindex='2' type='text' size='20' name=\"wpBlockExpiry\" value=\"{$scBlockExpiry}\" />
|
|
|
|
|
</td>
|
|
|
|
|
</tr>
|
|
|
|
|
<tr>
|
|
|
|
|
<td align=\"right\">{$mIpbreason}:</td>
|
|
|
|
|
<td align=\"left\">
|
|
|
|
|
<input tabindex='3' type='text' size='40' name=\"wpBlockReason\" value=\"{$scBlockReason}\" />
|
|
|
|
|
</td>
|
|
|
|
|
</tr>
|
|
|
|
|
<tr>
|
|
|
|
|
<td> </td>
|
|
|
|
|
<td align=\"left\">
|
|
|
|
|
<input tabindex='4' type='submit' name=\"wpBlock\" value=\"{$mIpbsubmit}\" />
|
|
|
|
|
</td>
|
|
|
|
|
</tr>
|
|
|
|
|
</table>
|
2003-04-14 23:10:40 +00:00
|
|
|
</form>\n" );
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function doSubmit()
|
|
|
|
|
{
|
|
|
|
|
global $wgOut, $wgUser, $wgLang;
|
2004-02-14 12:37:25 +00:00
|
|
|
global $wgSysopUserBans, $wgSysopRangeBans;
|
2003-08-31 14:30:24 +00:00
|
|
|
|
|
|
|
|
$userId = 0;
|
2004-03-08 09:09:35 +00:00
|
|
|
$this->BlockAddress = trim( $this->BlockAddress );
|
2004-02-14 12:37:25 +00:00
|
|
|
$rxIP = '\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}';
|
|
|
|
|
|
|
|
|
|
# Check for invalid specifications
|
2004-03-08 09:09:35 +00:00
|
|
|
if ( ! preg_match( "/^$rxIP$/", $this->BlockAddress ) ) {
|
|
|
|
|
if ( preg_match( "/^($rxIP)\\/(\\d{1,2})$/", $this->BlockAddress, $matches ) ) {
|
2004-02-14 12:37:25 +00:00
|
|
|
if ( $wgSysopRangeBans ) {
|
2004-02-22 04:45:25 +00:00
|
|
|
if ( $matches[2] > 31 || $matches[2] < 16 ) {
|
2004-02-14 12:37:25 +00:00
|
|
|
$this->showForm( wfMsg( "ip_range_invalid" ) );
|
2004-03-14 02:02:59 +00:00
|
|
|
return;
|
2004-02-14 12:37:25 +00:00
|
|
|
}
|
2004-03-08 09:09:35 +00:00
|
|
|
$this->BlockAddress = Block::normaliseRange( $this->BlockAddress );
|
2004-02-14 12:37:25 +00:00
|
|
|
} else {
|
|
|
|
|
# Range block illegal
|
|
|
|
|
$this->showForm( wfMsg( "range_block_disabled" ) );
|
2003-09-01 13:13:56 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2004-02-14 12:37:25 +00:00
|
|
|
# Username block
|
|
|
|
|
if ( $wgSysopUserBans ) {
|
2004-03-08 09:09:35 +00:00
|
|
|
$userId = User::idFromName( $this->BlockAddress );
|
2004-02-14 12:37:25 +00:00
|
|
|
if ( $userId == 0 ) {
|
2004-03-08 09:09:35 +00:00
|
|
|
$this->showForm( wfMsg( "nosuchuser", htmlspecialchars( $this->BlockAddress ) ) );
|
2004-02-14 12:37:25 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
$this->showForm( wfMsg( "badipaddress" ) );
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2004-03-08 09:09:35 +00:00
|
|
|
if ( $this->BlockExpiry == "infinite" || $this->BlockExpiry == "indefinite" ) {
|
2004-02-22 02:58:34 +00:00
|
|
|
$expiry = '';
|
2004-02-14 12:37:25 +00:00
|
|
|
} else {
|
|
|
|
|
# Convert GNU-style date, returns -1 on error
|
2004-03-08 09:09:35 +00:00
|
|
|
$expiry = strtotime( $this->BlockExpiry );
|
2004-02-14 12:37:25 +00:00
|
|
|
|
2004-02-22 02:58:34 +00:00
|
|
|
if ( $expiry < 0 ) {
|
|
|
|
|
$this->showForm( wfMsg( "ipb_expiry_invalid" ) );
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$expiry = wfUnix2Timestamp( $expiry );
|
|
|
|
|
|
2004-02-14 12:37:25 +00:00
|
|
|
}
|
|
|
|
|
|
2004-02-22 02:58:34 +00:00
|
|
|
|
2004-03-08 09:09:35 +00:00
|
|
|
if ( "" == $this->BlockReason ) {
|
2003-04-14 23:10:40 +00:00
|
|
|
$this->showForm( wfMsg( "noblockreason" ) );
|
|
|
|
|
return;
|
|
|
|
|
}
|
2003-08-31 14:30:24 +00:00
|
|
|
|
2003-10-16 13:30:45 +00:00
|
|
|
# Create block
|
2003-08-31 14:30:24 +00:00
|
|
|
# Note: for a user block, ipb_address is only for display purposes
|
2004-02-14 12:37:25 +00:00
|
|
|
|
2004-03-08 09:09:35 +00:00
|
|
|
$ban = new Block( $this->BlockAddress, $userId, $wgUser->getID(),
|
|
|
|
|
wfStrencode( $this->BlockReason ), wfTimestampNow(), 0, $expiry );
|
2003-09-07 13:56:25 +00:00
|
|
|
$ban->insert();
|
2003-04-14 23:10:40 +00:00
|
|
|
|
2003-10-16 13:30:45 +00:00
|
|
|
# Make log entry
|
|
|
|
|
$log = new LogPage( wfMsg( "blocklogpage" ), wfMsg( "blocklogtext" ) );
|
2004-03-08 09:09:35 +00:00
|
|
|
$action = wfMsg( "blocklogentry", $this->BlockAddress, $this->BlockExpiry );
|
|
|
|
|
$log->addEntry( $action, $this->BlockReason );
|
2003-10-16 13:30:45 +00:00
|
|
|
|
|
|
|
|
# Report to the user
|
2004-03-06 01:49:16 +00:00
|
|
|
$titleObj = Title::makeTitle( NS_SPECIAL, "Blockip" );
|
2004-03-08 09:09:35 +00:00
|
|
|
$wgOut->redirect( $titleObj->getFullURL( "action=success&ip={$this->BlockAddress}" ) );
|
2003-04-14 23:10:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function showSuccess()
|
|
|
|
|
{
|
|
|
|
|
global $wgOut, $wgUser;
|
|
|
|
|
|
|
|
|
|
$wgOut->setPagetitle( wfMsg( "blockip" ) );
|
|
|
|
|
$wgOut->setSubtitle( wfMsg( "blockipsuccesssub" ) );
|
2004-03-08 09:09:35 +00:00
|
|
|
$text = wfMsg( "blockipsuccesstext", $this->BlockAddress );
|
2003-04-14 23:10:40 +00:00
|
|
|
$wgOut->addWikiText( $text );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
?>
|