X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FSpecialBlockip.php;h=5da520d49bfb577816b9185b35567fd48bc1bc59;hb=0ee9a04366b22971725e45af9abd6b28827880dc;hp=a82a2fb62857dbacce4fcad526ee4ade3eb7f080;hpb=217fe2a19feafbcdbd4fe2963d4378d23b4973e1;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/SpecialBlockip.php b/includes/SpecialBlockip.php index a82a2fb628..5da520d49b 100644 --- a/includes/SpecialBlockip.php +++ b/includes/SpecialBlockip.php @@ -1,163 +1,206 @@ isSysop() ) { +/** + * Constructor for Special:Blockip page + * + * @package MediaWiki + * @subpackage SpecialPage + */ + +/** + * Constructor + */ +function wfSpecialBlockip() { + global $wgUser, $wgOut, $wgRequest; + + if ( ! $wgUser->isAllowed('block') ) { $wgOut->sysopRequired(); return; } - $fields = array( "wpBlockAddress", "wpBlockReason", "wpBlockExpiry" ); - wfCleanFormFields( $fields ); $ipb = new IPBlockForm(); - if ( "success" == $action ) { $ipb->showSuccess(); } - else if ( "submit" == $action ) { $ipb->doSubmit(); } - else { $ipb->showForm( "" ); } + $action = $wgRequest->getVal( 'action' ); + if ( 'success' == $action ) { + $ipb->showSuccess(); + } else if ( $wgRequest->wasPosted() && 'submit' == $action && + $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) { + $ipb->doSubmit(); + } else { + $ipb->showForm( '' ); + } } +/** + * Form object + * + * @package MediaWiki + * @subpackage SpecialPage + */ class IPBlockForm { + var $BlockAddress, $BlockExpiry, $BlockReason; - function showForm( $err ) - { - global $wgOut, $wgUser, $wgLang, $wgDefaultBlockExpiry; - global $ip, $wpBlockAddress, $wpBlockExpiry, $wpBlockReason; + function IPBlockForm() { + global $wgRequest; + $this->BlockAddress = $wgRequest->getVal( 'wpBlockAddress', $wgRequest->getVal( 'ip' ) ); + $this->BlockReason = $wgRequest->getText( 'wpBlockReason' ); + $this->BlockExpiry = $wgRequest->getVal( 'wpBlockExpiry' ); + } + + function showForm( $err ) { + global $wgOut, $wgUser, $wgLang, $wgBlockExpiryOptions; + global $wgRequest, $wgSysopUserBans; - $wgOut->setPagetitle( wfMsg( "blockip" ) ); - $wgOut->addWikiText( wfMsg( "blockiptext" ) ); + $wgOut->setPagetitle( htmlspecialchars( wfMsg( 'blockip' ) ) ); + $wgOut->addWikiText( wfMsg( 'blockiptext' ) ); - if ( ! $wpBlockAddress ) { - $wpBlockAddress = $ip; + if($wgSysopUserBans) { + $mIpaddress = htmlspecialchars( wfMsg( 'ipadressorusername' ) ); + } else { + $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" ); - if ( is_null( $wpBlockExpiry ) || $wpBlockExpiry === "" ) { - $wpBlockExpiry = $wgDefaultBlockExpiry; + if ( "" != $err ) { + $wgOut->setSubtitle( htmlspecialchars( wfMsg( 'formerror' ) ) ); + $wgOut->addHTML( "

{$err}

\n" ); } - $mIpaddress = wfMsg( "ipaddress" ); - $mIpbexpiry = wfMsg( "ipbexpiry" ); - $mIpbreason = wfMsg( "ipbreason" ); - $mIpbsubmit = wfMsg( "ipbsubmit" ); - $action = wfLocalUrlE( $wgLang->specialPage( "Blockip" ), - "action=submit" ); + $scBlockAddress = htmlspecialchars( $this->BlockAddress ); + $scBlockExpiry = htmlspecialchars( $this->BlockExpiry ); + $scBlockReason = htmlspecialchars( $this->BlockReason ); - if ( "" != $err ) { - $wgOut->setSubtitle( wfMsg( "formerror" ) ); - $wgOut->addHTML( "

{$err}\n" ); - } + $blockExpiryFormOptions = '\n\t\t\t\t\t'; - $scBlockAddress = htmlspecialchars( $wpBlockAddress ); - $scBlockExpiry = htmlspecialchars( $wpBlockExpiry ); - $scBlockReason = htmlspecialchars( $wpBlockReason ); + $token = htmlspecialchars( $wgUser->editToken() ); - $wgOut->addHTML( "

+ $wgOut->addHTML( "

- - - - - - - -
{$mIpaddress}: - -
{$mIpbexpiry}: - -
{$mIpbreason}: - -
  - -
+ + + + + + + + + + + + + + + + + +
{$mIpaddress}: + +
{$mIpbexpiry}: + +
{$mIpbreason}: + +
  + +
+
\n" ); } - function doSubmit() - { + function doSubmit() { global $wgOut, $wgUser, $wgLang; - global $ip, $wpBlockAddress, $wpBlockReason, $wpBlockExpiry; global $wgSysopUserBans, $wgSysopRangeBans; $userId = 0; - $wpBlockAddress = trim( $wpBlockAddress ); + $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$/", $wpBlockAddress ) ) { - if ( preg_match( "/^($rxIP)\\/(\\d{1,2})$/", $wpBlockAddress, $matches ) ) { + if ( ! preg_match( "/^$rxIP$/", $this->BlockAddress ) ) { + if ( preg_match( "/^($rxIP)\\/(\\d{1,2})$/", $this->BlockAddress, $matches ) ) { if ( $wgSysopRangeBans ) { - if ( $matches[2] > 31 || $matches[2] < 1 ) { - $this->showForm( wfMsg( "ip_range_invalid" ) ); + if ( $matches[2] > 31 || $matches[2] < 16 ) { + $this->showForm( wfMsg( 'ip_range_invalid' ) ); + return; } - $wpBlockAddress = Block::normaliseRange( $wpBlockAddress ); + $this->BlockAddress = Block::normaliseRange( $this->BlockAddress ); } else { # Range block illegal - $this->showForm( wfMsg( "range_block_disabled" ) ); + $this->showForm( wfMsg( 'range_block_disabled' ) ); return; } } else { # Username block if ( $wgSysopUserBans ) { - $userId = User::idFromName( $wpBlockAddress ); + $userId = User::idFromName( $this->BlockAddress ); if ( $userId == 0 ) { - $this->showForm( wfMsg( "nosuchuser", htmlspecialchars( $wpBlockAddress ) ) ); + $this->showForm( wfMsg( 'nosuchusershort', htmlspecialchars( $this->BlockAddress ) ) ); return; } } else { - $this->showForm( wfMsg( "badipaddress" ) ); + $this->showForm( wfMsg( 'badipaddress' ) ); return; } } } - if ( $wpBlockExpiry == "infinite" || $wpBlockExpiry == "indefinite" ) { + if ( $this->BlockExpiry == 'infinite' || $this->BlockExpiry == 'indefinite' ) { $expiry = ''; } else { # Convert GNU-style date, returns -1 on error - $expiry = strtotime( $wpBlockExpiry ); + $expiry = strtotime( $this->BlockExpiry ); if ( $expiry < 0 ) { - $this->showForm( wfMsg( "ipb_expiry_invalid" ) ); + $this->showForm( wfMsg( 'ipb_expiry_invalid' ) ); return; } - $expiry = wfUnix2Timestamp( $expiry ); + $expiry = wfTimestamp( TS_MW, $expiry ); } - - if ( "" == $wpBlockReason ) { - $this->showForm( wfMsg( "noblockreason" ) ); + + if ( $this->BlockReason == '') { + $this->showForm( wfMsg( 'noblockreason' ) ); return; } # Create block # Note: for a user block, ipb_address is only for display purposes - $ban = new Block( $wpBlockAddress, $userId, $wgUser->getID(), - wfStrencode( $wpBlockReason ), wfTimestampNow(), 0, $expiry ); - $ban->insert(); - - # Make log entry - $log = new LogPage( wfMsg( "blocklogpage" ), wfMsg( "blocklogtext" ) ); - $action = wfMsg( "blocklogentry", $wpBlockAddress, $wpBlockExpiry ); - $log->addEntry( $action, $wpBlockReason ); - - # Report to the user - $success = wfLocalUrl( $wgLang->specialPage( "Blockip" ), - "action=success&ip={$wpBlockAddress}" ); - $wgOut->redirect( $success ); + $ban = new Block( $this->BlockAddress, $userId, $wgUser->getID(), + $this->BlockReason, wfTimestampNow(), 0, $expiry ); + + if (wfRunHooks('BlockIp', array(&$ban, &$wgUser))) { + + $ban->insert(); + + wfRunHooks('BlockIpComplete', array($ban, $wgUser)); + + # Make log entry + $log = new LogPage( 'block' ); + $log->addEntry( 'block', Title::makeTitle( NS_USER, $this->BlockAddress ), + $this->BlockReason, $this->BlockExpiry ); + + # Report to the user + $titleObj = Title::makeTitle( NS_SPECIAL, 'Blockip' ); + $wgOut->redirect( $titleObj->getFullURL( 'action=success&ip=' . + urlencode( $this->BlockAddress ) ) ); + } } - function showSuccess() - { + function showSuccess() { global $wgOut, $wgUser; - global $ip; - $wgOut->setPagetitle( wfMsg( "blockip" ) ); - $wgOut->setSubtitle( wfMsg( "blockipsuccesssub" ) ); - $text = wfMsg( "blockipsuccesstext", $ip ); + $wgOut->setPagetitle( wfMsg( 'blockip' ) ); + $wgOut->setSubtitle( wfMsg( 'blockipsuccesssub' ) ); + $text = wfMsg( 'blockipsuccesstext', $this->BlockAddress ); $wgOut->addWikiText( $text ); } }