wiki.techinc.nl/includes/SpecialBlockip.php

186 lines
5.1 KiB
PHP
Raw Normal View History

<?php
/**
* Constructor for Special:Blockip page
*
* @package MediaWiki
* @subpackage SpecialPage
*/
/**
* Constructor
*/
function wfSpecialBlockip() {
global $wgUser, $wgOut, $wgRequest;
2003-04-14 23:10:40 +00:00
if ( ! $wgUser->isAllowed('block') ) {
2003-04-14 23:10:40 +00:00
$wgOut->sysopRequired();
return;
}
$ipb = new IPBlockForm();
$action = $wgRequest->getVal( 'action' );
2004-09-19 19:04:52 +00:00
if ( 'success' == $action ) { $ipb->showSuccess(); }
else if ( $wgRequest->wasPosted() && 'submit' == $action ) { $ipb->doSubmit(); }
else { $ipb->showForm( '' ); }
2003-04-14 23:10:40 +00:00
}
/**
* Form object
*
* @package MediaWiki
* @subpackage SpecialPage
*/
2003-04-14 23:10:40 +00:00
class IPBlockForm {
var $BlockAddress, $BlockExpiry, $BlockReason;
2003-04-14 23:10:40 +00:00
function IPBlockForm() {
global $wgRequest;
$this->BlockAddress = $wgRequest->getVal( 'wpBlockAddress', $wgRequest->getVal( 'ip' ) );
$this->BlockReason = $wgRequest->getText( 'wpBlockReason' );
$this->BlockExpiry = $wgRequest->getVal( 'wpBlockExpiry' );
}
2004-09-19 19:04:52 +00:00
function showForm( $err ) {
global $wgOut, $wgUser, $wgLang, $wgDefaultBlockExpiry;
global $wgRequest;
2003-04-14 23:10:40 +00:00
2004-09-19 19:04:52 +00:00
$wgOut->setPagetitle( htmlspecialchars( wfMsg( 'blockip' ) ) );
$wgOut->addWikiText( htmlspecialchars( wfMsg( 'blockiptext' ) ) );
2003-04-14 23:10:40 +00:00
2004-09-19 19:04:52 +00:00
if ( is_null( $this->BlockExpiry ) || $this->BlockExpiry === '' ) {
$this->BlockExpiry = $wgDefaultBlockExpiry;
}
2004-09-19 19:04:52 +00:00
$mIpaddress = htmlspecialchars( wfMsg( 'ipaddress' ) );
$mIpbexpiry = htmlspecialchars( wfMsg( 'ipbexpiry' ) );
$mIpbreason = htmlspecialchars( wfMsg( 'ipbreason' ) );
$mIpbsubmit = htmlspecialchars( wfMsg( 'ipbsubmit' ) );
$titleObj = Title::makeTitle( NS_SPECIAL, 'Blockip' );
$action = $titleObj->escapeLocalURL( "action=submit" );
2003-04-14 23:10:40 +00:00
if ( "" != $err ) {
2004-09-19 19:04:52 +00:00
$wgOut->setSubtitle( htmlspecialchars( wfMsg( 'formerror' ) ) );
2004-04-26 07:35:20 +00:00
$wgOut->addHTML( "<p class='error'>{$err}</p>\n" );
2003-04-14 23:10:40 +00:00
}
$scBlockAddress = htmlspecialchars( $this->BlockAddress );
$scBlockExpiry = htmlspecialchars( $this->BlockExpiry );
$scBlockReason = htmlspecialchars( $this->BlockReason );
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>&nbsp;</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() {
2003-04-14 23:10:40 +00:00
global $wgOut, $wgUser, $wgLang;
global $wgSysopUserBans, $wgSysopRangeBans;
$userId = 0;
$this->BlockAddress = trim( $this->BlockAddress );
$rxIP = '\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}';
# Check for invalid specifications
if ( ! preg_match( "/^$rxIP$/", $this->BlockAddress ) ) {
if ( preg_match( "/^($rxIP)\\/(\\d{1,2})$/", $this->BlockAddress, $matches ) ) {
if ( $wgSysopRangeBans ) {
2004-02-22 04:45:25 +00:00
if ( $matches[2] > 31 || $matches[2] < 16 ) {
2004-09-19 19:04:52 +00:00
$this->showForm( wfMsg( 'ip_range_invalid' ) );
return;
}
$this->BlockAddress = Block::normaliseRange( $this->BlockAddress );
} else {
# Range block illegal
2004-09-19 19:04:52 +00:00
$this->showForm( wfMsg( 'range_block_disabled' ) );
return;
}
} else {
# Username block
if ( $wgSysopUserBans ) {
$userId = User::idFromName( $this->BlockAddress );
if ( $userId == 0 ) {
$this->showForm( wfMsg( 'nosuchusershort', htmlspecialchars( $this->BlockAddress ) ) );
return;
}
} else {
2004-09-19 19:04:52 +00:00
$this->showForm( wfMsg( 'badipaddress' ) );
return;
}
}
}
2004-09-19 19:04:52 +00:00
if ( $this->BlockExpiry == 'infinite' || $this->BlockExpiry == 'indefinite' ) {
2004-02-22 02:58:34 +00:00
$expiry = '';
} else {
# Convert GNU-style date, returns -1 on error
$expiry = strtotime( $this->BlockExpiry );
2004-02-22 02:58:34 +00:00
if ( $expiry < 0 ) {
2004-09-19 19:04:52 +00:00
$this->showForm( wfMsg( 'ipb_expiry_invalid' ) );
2004-02-22 02:58:34 +00:00
return;
}
$expiry = wfUnix2Timestamp( $expiry );
}
2004-02-22 02:58:34 +00:00
2004-09-19 19:04:52 +00:00
if ( $this->BlockReason == '') {
$this->showForm( wfMsg( 'noblockreason' ) );
2003-04-14 23:10:40 +00:00
return;
}
# Create block
# Note: for a user block, ipb_address is only for display purposes
$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
# Make log entry
$log = new LogPage( 'block' );
$log->addEntry( 'block', Title::makeTitle( NS_USER, $this->BlockAddress ), $this->BlockReason );
# Report to the user
2004-09-19 19:04:52 +00:00
$titleObj = Title::makeTitle( NS_SPECIAL, 'Blockip' );
$wgOut->redirect( $titleObj->getFullURL( 'action=success&ip='.$this->BlockAddress ) );
2003-04-14 23:10:40 +00:00
}
function showSuccess() {
2003-04-14 23:10:40 +00:00
global $wgOut, $wgUser;
2004-09-19 19:04:52 +00:00
$wgOut->setPagetitle( wfMsg( 'blockip' ) );
$wgOut->setSubtitle( wfMsg( 'blockipsuccesssub' ) );
$text = wfMsg( 'blockipsuccesstext', $this->BlockAddress );
2003-04-14 23:10:40 +00:00
$wgOut->addWikiText( $text );
}
}
?>