X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FSpecialBlockip.php;h=d45603572d2fa37d9d131b87020b8f5f2ec7193c;hb=5516fef269e71b5962afa34bd7e7403b13b57d12;hp=e93f6f693a6a17e8820df43e8e6738a2a1547d03;hpb=6cbacc93d49e560019a7d4c7fbae023d5637e757;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/SpecialBlockip.php b/includes/SpecialBlockip.php index e93f6f693a..d45603572d 100644 --- a/includes/SpecialBlockip.php +++ b/includes/SpecialBlockip.php @@ -2,7 +2,8 @@ /** * Constructor for Special:Blockip page * - * @addtogroup SpecialPage + * @file + * @ingroup SpecialPage */ /** @@ -39,7 +40,7 @@ function wfSpecialBlockip( $par ) { /** * Form object for the Special:Blockip page. * - * @addtogroup SpecialPage + * @ingroup SpecialPage */ class IPBlockForm { var $BlockAddress, $BlockExpiry, $BlockReason; @@ -62,35 +63,32 @@ class IPBlockForm { $this->BlockCreateAccount = $wgRequest->getBool( 'wpCreateAccount', $byDefault ); $this->BlockEnableAutoblock = $wgRequest->getBool( 'wpEnableAutoblock', $byDefault ); $this->BlockEmail = $wgRequest->getBool( 'wpEmailBan', false ); + $this->BlockWatchUser = $wgRequest->getBool( 'wpWatchUser', false ); # Re-check user's rights to hide names, very serious, defaults to 0 $this->BlockHideName = ( $wgRequest->getBool( 'wpHideName', 0 ) && $wgUser->isAllowed( 'hideuser' ) ) ? 1 : 0; } function showForm( $err ) { - global $wgOut, $wgUser, $wgSysopUserBans, $wgContLang; + global $wgOut, $wgUser, $wgSysopUserBans; $wgOut->setPagetitle( wfMsg( 'blockip' ) ); - $wgOut->addWikiText( wfMsg( 'blockiptext' ) ); + $wgOut->addWikiMsg( 'blockiptext' ); if($wgSysopUserBans) { $mIpaddress = Xml::label( wfMsg( 'ipadressorusername' ), 'mw-bi-target' ); } else { - $mIpaddress = Xml::label( wfMsg( 'ipadress' ), 'mw-bi-target' ); + $mIpaddress = Xml::label( wfMsg( 'ipaddress' ), 'mw-bi-target' ); } $mIpbexpiry = Xml::label( wfMsg( 'ipbexpiry' ), 'wpBlockExpiry' ); $mIpbother = Xml::label( wfMsg( 'ipbother' ), 'mw-bi-other' ); - $mIpbothertime = wfMsgHtml( 'ipbotheroption' ); $mIpbreasonother = Xml::label( wfMsg( 'ipbreason' ), 'wpBlockReasonList' ); $mIpbreason = Xml::label( wfMsg( 'ipbotherreason' ), 'mw-bi-reason' ); - $mIpbreasonotherlist = wfMsgHtml( 'ipbreasonotherlist' ); $titleObj = SpecialPage::getTitleFor( 'Blockip' ); - $action = $titleObj->escapeLocalURL( "action=submit" ); - $alignRight = $wgContLang->isRtl() ? 'left' : 'right'; if ( "" != $err ) { $wgOut->setSubtitle( wfMsgHtml( 'formerror' ) ); - $wgOut->addHTML( "

{$err}

\n" ); + $wgOut->addHTML( Xml::tags( 'p', array( 'class' => 'error' ), $err ) ); } $scBlockExpiryOptions = wfMsgForContent( 'ipboptions' ); @@ -99,176 +97,164 @@ class IPBlockForm { if (!$showblockoptions) $mIpbother = $mIpbexpiry; - $blockExpiryFormOptions = ""; + $blockExpiryFormOptions = Xml::option( wfMsg( 'ipbotheroption' ), 'other' ); foreach (explode(',', $scBlockExpiryOptions) as $option) { if ( strpos($option, ":") === false ) $option = "$option:$option"; list($show, $value) = explode(":", $option); $show = htmlspecialchars($show); $value = htmlspecialchars($value); - $selected = ""; - if ($this->BlockExpiry === $value) - $selected = ' selected="selected"'; - $blockExpiryFormOptions .= ""; + $blockExpiryFormOptions .= Xml::option( $show, $value, $this->BlockExpiry === $value ? true : false ) . "\n"; } - $scBlockReasonList = wfMsgForContent( 'ipbreason-dropdown' ); - $blockReasonList = ''; - if ( $scBlockReasonList != '' && $scBlockReasonList != '-' ) { - $blockReasonList = ""; - $optgroup = ""; - foreach ( explode( "\n", $scBlockReasonList ) as $option) { - $value = trim( htmlspecialchars($option) ); - if ( $value == '' ) { - continue; - } elseif ( substr( $value, 0, 1) == '*' && substr( $value, 1, 1) != '*' ) { - // A new group is starting ... - $value = trim( substr( $value, 1 ) ); - $blockReasonList .= "$optgroup"; - $optgroup = ""; - } elseif ( substr( $value, 0, 2) == '**' ) { - // groupmember - $selected = ""; - $value = trim( substr( $value, 2 ) ); - if ( $this->BlockReasonList === $value) - $selected = ' selected="selected"'; - $blockReasonList .= ""; - } else { - // groupless block reason - $selected = ""; - if ( $this->BlockReasonList === $value) - $selected = ' selected="selected"'; - $blockReasonList .= "$optgroup"; - $optgroup = ""; - } - } - $blockReasonList .= $optgroup; - } - - $token = $wgUser->editToken(); + $reasonDropDown = Xml::listDropDown( 'wpBlockReasonList', + wfMsgForContent( 'ipbreason-dropdown' ), + wfMsgForContent( 'ipbreasonotherlist' ), '', 'wpBlockDropDown', 4 ); global $wgStylePath, $wgStyleVersion; - $wgOut->addHTML( " - -
- - - - - - "); - if ($showblockoptions) { + $wgOut->addHTML( + Xml::tags( 'script', array( 'type' => 'text/javascript', 'src' => "$wgStylePath/common/block.js?$wgStyleVersion" ), '' ) . + Xml::openElement( 'form', array( 'method' => 'post', 'action' => $titleObj->getLocalURL( "action=submit" ), 'id' => 'blockip' ) ) . + Xml::openElement( 'fieldset' ) . + Xml::element( 'legend', null, wfMsg( 'blockip-legend' ) ) . + Xml::openElement( 'table', array ( 'border' => '0', 'id' => 'mw-blockip-table' ) ) . + " + + + + " + ); + if ( $showblockoptions ) { $wgOut->addHTML(" - - - "); + + " + ); } $wgOut->addHTML(" - - - - - "); - if ( $blockReasonList != '' ) { - $wgOut->addHTML(" + + + + + - - - "); - } - $wgOut->addHTML(" - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + - - "); - + array( 'tabindex' => '8' ) ) . " + + " + ); + global $wgSysopEmailBans; if ( $wgSysopEmailBans && $wgUser->isAllowed( 'blockemail' ) ) { $wgOut->addHTML(" - - - + + - - "); + array( 'tabindex' => '9' )) . " + + " + ); } // Allow some users to hide name from block log, blocklist and listusers if ( $wgUser->isAllowed( 'hideuser' ) ) { $wgOut->addHTML(" - - - + + - - "); + array( 'tabindex' => '10' ) ) . " + + " + ); } + # Watchlist their user page? + $wgOut->addHTML(" + + + + " + ); + $wgOut->addHTML(" - - - - -
{$mIpaddress} - " . Xml::input( 'wpBlockAddress', 45, $this->BlockAddress, - array( - 'tabindex' => '1', - 'id' => 'mw-bi-target', - 'onchange' => 'updateBlockOptions()' ) ) . " -
+ {$mIpaddress} + " . + Xml::input( 'wpBlockAddress', 45, $this->BlockAddress, + array( + 'tabindex' => '1', + 'id' => 'mw-bi-target', + 'onchange' => 'updateBlockOptions()' ) ). " +
{$mIpbexpiry} - - + {$mIpbexpiry} + " . + Xml::tags( 'select', + array( + 'id' => 'wpBlockExpiry', + 'name' => 'wpBlockExpiry', + 'onchange' => 'considerChangingExpiryFocus()', + 'tabindex' => '2' ), + $blockExpiryFormOptions ) . + "
{$mIpbother} - " . Xml::input( 'wpBlockOther', 45, $this->BlockOther, - array( 'tabindex' => '3', 'id' => 'mw-bi-other' ) ) . " -
+ {$mIpbother} + " . + Xml::input( 'wpBlockOther', 45, $this->BlockOther, + array( 'tabindex' => '3', 'id' => 'mw-bi-other' ) ) . " +
{$mIpbreasonother} - + + {$mIpbreasonother}
{$mIpbreason} - " . Xml::input( 'wpBlockReason', 45, $this->BlockReason, - array( 'tabindex' => '5', 'id' => 'mw-bi-reason', - 'maxlength'=> '200' ) ) . " -
  - " . wfCheckLabel( wfMsgHtml( 'ipbanononly' ), - 'wpAnonOnly', 'wpAnonOnly', $this->BlockAnonOnly, - array( 'tabindex' => '6' ) ) . " -
  - " . wfCheckLabel( wfMsgHtml( 'ipbcreateaccount' ), - 'wpCreateAccount', 'wpCreateAccount', $this->BlockCreateAccount, - array( 'tabindex' => '7' ) ) . " -
  - " . wfCheckLabel( wfMsgHtml( 'ipbenableautoblock' ), + + {$reasonDropDown} +
+ {$mIpbreason} + " . + Xml::input( 'wpBlockReason', 45, $this->BlockReason, + array( 'tabindex' => '5', 'id' => 'mw-bi-reason', 'maxlength'=> '200' ) ) . " +
 " . + Xml::checkLabel( wfMsg( 'ipbanononly' ), + 'wpAnonOnly', 'wpAnonOnly', $this->BlockAnonOnly, + array( 'tabindex' => '6' ) ) . " +
 " . + Xml::checkLabel( wfMsg( 'ipbcreateaccount' ), + 'wpCreateAccount', 'wpCreateAccount', $this->BlockCreateAccount, + array( 'tabindex' => '7' ) ) . " +
 " . + Xml::checkLabel( wfMsg( 'ipbenableautoblock' ), 'wpEnableAutoblock', 'wpEnableAutoblock', $this->BlockEnableAutoblock, - array( 'tabindex' => '8' ) ) . " -
  - " . wfCheckLabel( wfMsgHtml( 'ipbemailban' ), +
 " . + Xml::checkLabel( wfMsg( 'ipbemailban' ), 'wpEmailBan', 'wpEmailBan', $this->BlockEmail, - array( 'tabindex' => '10' )) . " -
  - " . wfCheckLabel( wfMsgHtml( 'ipbhidename' ), +
 " . + Xml::checkLabel( wfMsg( 'ipbhidename' ), 'wpHideName', 'wpHideName', $this->BlockHideName, - array( 'tabindex' => '9' ) ) . " -
 " . + Xml::checkLabel( wfMsg( 'ipbwatchuser' ), + 'wpWatchUser', 'wpWatchUser', $this->BlockWatchUser, + array( 'tabindex' => '11' ) ) . " +
  - " . Xml::submitButton( wfMsg( 'ipbsubmit' ), - array( 'name' => 'wpBlock', 'tabindex' => '11' ) ) . " -
" . - Xml::hidden( 'wpEditToken', $token ) . -"
- -\n" ); + +   + " . + Xml::submitButton( wfMsg( 'ipbsubmit' ), + array( 'name' => 'wpBlock', 'tabindex' => '12' ) ) . " + + " . + Xml::closeElement( 'table' ) . + Xml::hidden( 'wpEditToken', $wgUser->editToken() ) . + Xml::closeElement( 'fieldset' ) . + Xml::closeElement( 'form' ) . + Xml::tags( 'script', array( 'type' => 'text/javascript' ), 'updateBlockOptions()' ) . "\n" + ); $wgOut->addHtml( $this->getConvenienceLinks() ); @@ -282,17 +268,10 @@ class IPBlockForm { } } - const BLOCK_SUCCESS = 0; // Success - const BLOCK_RANGE_INVALID = 1; // Invalid IP range - const BLOCK_RANGE_DISABLED = 2; // Sysops can't block ranges - const BLOCK_NONEXISTENT_USER = 3; // No such user - const BLOCK_IP_INVALID = 4; // Invalid IP address - const BLOCK_EXPIRY_INVALID = 5; // Invalid expiry time - const BLOCK_ALREADY_BLOCKED = 6; // User is already blocked /** * Backend block code. * $userID and $expiry will be filled accordingly - * Returns one of the BLOCK_* constants + * @return array(message key, arguments) on failure, empty array on success */ function doBlock(&$userId = null, &$expiry = null) { @@ -305,7 +284,7 @@ class IPBlockForm { $rxIP4 = '\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}'; $rxIP6 = '\w{1,4}:\w{1,4}:\w{1,4}:\w{1,4}:\w{1,4}:\w{1,4}:\w{1,4}:\w{1,4}'; $rxIP = "($rxIP4|$rxIP6)"; - + # Check for invalid specifications if ( !preg_match( "/^$rxIP$/", $this->BlockAddress ) ) { $matches = array(); @@ -313,37 +292,37 @@ class IPBlockForm { # IPv4 if ( $wgSysopRangeBans ) { if ( !IP::isIPv4( $this->BlockAddress ) || $matches[2] < 16 || $matches[2] > 32 ) { - return self::BLOCK_RANGE_INVALID; + return array('ip_range_invalid'); } $this->BlockAddress = Block::normaliseRange( $this->BlockAddress ); } else { # Range block illegal - return self::BLOCK_RANGE_DISABLED; + return array('range_block_disabled'); } } else if ( preg_match( "/^($rxIP6)\\/(\\d{1,3})$/", $this->BlockAddress, $matches ) ) { # IPv6 if ( $wgSysopRangeBans ) { if ( !IP::isIPv6( $this->BlockAddress ) || $matches[2] < 64 || $matches[2] > 128 ) { - return self::BLOCK_RANGE_INVALID; + return array('ip_range_invalid'); } $this->BlockAddress = Block::normaliseRange( $this->BlockAddress ); } else { # Range block illegal - return self::BLOCK_RANGE_DISABLED; + return array('range_block_disabled'); } } else { # Username block if ( $wgSysopUserBans ) { $user = User::newFromName( $this->BlockAddress ); - if( !is_null( $user ) && $user->getID() ) { + if( !is_null( $user ) && $user->getId() ) { # Use canonical name + $userId = $user->getId(); $this->BlockAddress = $user->getName(); - $userId = $user->getID(); } else { - return self::BLOCK_NONEXISTENT_USER; + return array('nosuchusershort', htmlspecialchars( $user ? $user->getName() : $this->BlockAddress ) ); } } else { - return self::BLOCK_IP_INVALID; + return array('badipaddress'); } } } @@ -361,33 +340,29 @@ class IPBlockForm { $expirestr = $this->BlockOther; if (strlen($expirestr) == 0) { - return self::BLOCK_EXPIRY_INVALID; + return array('ipb_expiry_invalid'); } - - if ( $expirestr == 'infinite' || $expirestr == 'indefinite' ) { - $expiry = Block::infinity(); - } else { - # Convert GNU-style date, on error returns -1 for PHP <5.1 and false for PHP >=5.1 - $expiry = strtotime( $expirestr ); - - if ( $expiry < 0 || $expiry === false ) { - return self::BLOCK_EXPIRY_INVALID; - } - - $expiry = wfTimestamp( TS_MW, $expiry ); + + if ( false === ($expiry = Block::parseExpiryInput( $expirestr )) ) { + // Bad expiry. + return array('ipb_expiry_invalid'); } # Create block # Note: for a user block, ipb_address is only for display purposes - $block = new Block( $this->BlockAddress, $userId, $wgUser->getID(), + $block = new Block( $this->BlockAddress, $userId, $wgUser->getId(), $reasonstr, wfTimestampNow(), 0, $expiry, $this->BlockAnonOnly, $this->BlockCreateAccount, $this->BlockEnableAutoblock, $this->BlockHideName, $this->BlockEmail); + if ( $this->BlockWatchUser ) { + $wgUser->addWatch ( Title::makeTitle( NS_USER, $this->BlockAddress ) ); + } + if (wfRunHooks('BlockIp', array(&$block, &$wgUser))) { if ( !$block->insert() ) { - return self::BLOCK_ALREADY_BLOCKED; + return array('ipb_already_blocked', htmlspecialchars($this->BlockAddress)); } wfRunHooks('BlockIpComplete', array($block, $wgUser)); @@ -398,14 +373,16 @@ class IPBlockForm { $logParams[] = $this->blockLogFlags(); # Make log entry, if the name is hidden, put it in the oversight log - $log_type = ($this->BlockHideName) ? 'oversight' : 'block'; + $log_type = ($this->BlockHideName) ? 'suppress' : 'block'; $log = new LogPage( $log_type ); $log->addEntry( 'block', Title::makeTitle( NS_USER, $this->BlockAddress ), $reasonstr, $logParams ); # Report to the user - return self::BLOCK_SUCCESS; + return array(); } + else + return array('hookaborted'); } /** @@ -416,34 +393,14 @@ class IPBlockForm { { global $wgOut; $retval = $this->doBlock(); - switch($retval) - { - case self::BLOCK_RANGE_INVALID: - $this->showForm( wfMsg( 'ip_range_invalid' ) ); - return; - case self::BLOCK_RANGE_DISABLED: - $this->showForm( wfMsg( 'range_block_disabled' ) ); - return; - case self::BLOCK_NONEXISTENT_USER: - $this->showForm( wfMsg( 'nosuchusershort', htmlspecialchars( $this->BlockAddress ) ) ); - return; - case self::BLOCK_IP_INVALID: - $this->showForm( wfMsg( 'badipaddress' ) ); - return; - case self::BLOCK_EXPIRY_INVALID: - $this->showForm( wfMsg( 'ipb_expiry_invalid' ) ); - return; - case self::BLOCK_ALREADY_BLOCKED: - $this->showForm( wfMsg( 'ipb_already_blocked', htmlspecialchars( $this->BlockAddress ) ) ); - return; - case self::BLOCK_SUCCESS: - $titleObj = SpecialPage::getTitleFor( 'Blockip' ); - $wgOut->redirect( $titleObj->getFullURL( 'action=success&ip=' . - urlencode( $this->BlockAddress ) ) ); - return; - default: - throw new MWException( __METHOD__ . ": Unknown return value ``{$retval}''" ); + if(empty($retval)) { + $titleObj = SpecialPage::getTitleFor( 'Blockip' ); + $wgOut->redirect( $titleObj->getFullURL( 'action=success&ip=' . + urlencode( $this->BlockAddress ) ) ); + return; } + $key = array_shift($retval); + $this->showForm(wfMsgReal($key, $retval)); } function showSuccess() { @@ -451,15 +408,13 @@ class IPBlockForm { $wgOut->setPagetitle( wfMsg( 'blockip' ) ); $wgOut->setSubtitle( wfMsg( 'blockipsuccesssub' ) ); - $text = wfMsg( 'blockipsuccesstext', $this->BlockAddress ); - $wgOut->addWikiText( $text ); + $text = wfMsgExt( 'blockipsuccesstext', array( 'parse' ), $this->BlockAddress ); + $wgOut->addHtml( $text ); } function showLogFragment( $out, $title ) { - $out->addHtml( wfElement( 'h2', NULL, LogPage::logName( 'block' ) ) ); - $request = new FauxRequest( array( 'page' => $title->getPrefixedText(), 'type' => 'block' ) ); - $viewer = new LogViewer( new LogReader( $request ) ); - $viewer->showList( $out ); + $out->addHtml( Xml::element( 'h2', NULL, LogPage::logName( 'block' ) ) ); + LogEventsList::showLogExtract( $out, 'block', $title->getPrefixedText() ); } /** @@ -490,7 +445,7 @@ class IPBlockForm { private function getConvenienceLinks() { global $wgUser; $skin = $wgUser->getSkin(); - $links[] = $skin->makeLink ( 'MediaWiki:ipbreason-dropdown', wfMsgHtml( 'ipb-edit-dropdown' ) ); + $links[] = $skin->makeLink ( 'MediaWiki:Ipbreason-dropdown', wfMsgHtml( 'ipb-edit-dropdown' ) ); $links[] = $this->getUnblockLink( $skin ); $links[] = $this->getBlockListLink( $skin ); return ''; @@ -532,4 +487,3 @@ class IPBlockForm { } } } -