X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fspecials%2FSpecialBlockip.php;h=438bc358964c0e5a55cbccb147d3bc7ca94e9300;hb=90c703d61c485c633b214f78f48102c2848b82d8;hp=31edbe2032adf6fe468e3a1f806485540f5d1320;hpb=9990ba163eb596adb867355ffc6a1dba16bfdd9b;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/specials/SpecialBlockip.php b/includes/specials/SpecialBlockip.php index 31edbe2032..438bc35896 100644 --- a/includes/specials/SpecialBlockip.php +++ b/includes/specials/SpecialBlockip.php @@ -1,60 +1,78 @@ readOnlyPage(); - return; - } - # Permission check - if( !$wgUser->isAllowed( 'block' ) ) { - $wgOut->permissionRequired( 'block' ); - return; + public function __construct() { + parent::__construct( 'Blockip', 'block' ); } - $ipb = new IPBlockForm( $par ); + public function execute( $par ) { + global $wgUser, $wgOut, $wgRequest; + + # Can't block when the database is locked + if( wfReadOnly() ) { + $wgOut->readOnlyPage(); + return; + } + # Permission check + if( !$this->userCanExecute( $wgUser ) ) { + $wgOut->permissionRequired( 'block' ); + return; + } + + $this->setup( $par ); - # bug 15810: blocked admins should have limited access here - if( $wgUser->isBlocked() ){ - $status = IPBlockForm::checkUnblockSelf( $ipb->BlockAddress ); - if( $status !== true ){ - throw new ErrorPageError( 'badaccess', $status ); - } - } + # bug 15810: blocked admins should have limited access here + if ( $wgUser->isBlocked() ) { + $status = IPBlockForm::checkUnblockSelf( $this->BlockAddress ); + if ( $status !== true ) { + throw new ErrorPageError( 'badaccess', $status ); + } + } - $action = $wgRequest->getVal( 'action' ); - if( 'success' == $action ) { - $ipb->showSuccess(); - } elseif( $wgRequest->wasPosted() && 'submit' == $action && - $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) { - $ipb->doSubmit(); - } else { - $ipb->showForm( '' ); + $action = $wgRequest->getVal( 'action' ); + if( 'success' == $action ) { + $this->showSuccess(); + } elseif( $wgRequest->wasPosted() && 'submit' == $action && + $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) { + $this->doSubmit(); + } else { + $this->showForm( '' ); + } } -} -/** - * Form object for the Special:Blockip page. - * - * @ingroup SpecialPage - */ -class IPBlockForm { - var $BlockAddress, $BlockExpiry, $BlockReason; - // The maximum number of edits a user can have and still be hidden - const HIDEUSER_CONTRIBLIMIT = 1000; - - public function __construct( $par ) { + private function setup( $par ) { global $wgRequest, $wgUser, $wgBlockAllowsUTEdit; $this->BlockAddress = $wgRequest->getVal( 'wpBlockAddress', $wgRequest->getVal( 'ip', $par ) ); @@ -105,6 +123,9 @@ class IPBlockForm { $titleObj = SpecialPage::getTitleFor( 'Blockip' ); $user = User::newFromName( $this->BlockAddress ); + if ( is_object( $user ) || User::isIP( $this->BlockAddress ) ) { + $wgUser->getSkin()->setRelevantUser( is_object($user) ? $user : User::newFromName( $this->BlockAddress, false ) ); + } $alreadyBlocked = false; $otherBlockedMsgs = array(); @@ -146,7 +167,7 @@ class IPBlockForm { # Show other blocks from extensions, i.e. GlockBlocking and TorBlock if( count( $otherBlockedMsgs ) ) { $wgOut->addHTML( - Html::rawElement( 'h2', array(), wfMsgExt( 'ipb-otherblocks-header', 'parseinline', count( $otherBlockedMsgs ) ) ) . "\n" + Html::rawElement( 'h2', array(), wfMsgExt( 'ipb-otherblocks-header', 'parseinline', count( $otherBlockedMsgs ) ) ) . "\n" ); $list = ''; foreach( $otherBlockedMsgs as $link ) { @@ -157,7 +178,7 @@ class IPBlockForm { # Username/IP is blocked already locally if( $alreadyBlocked ) { - $wgOut->addWikiMsg( 'ipb-needreblock', $this->BlockAddress ); + $wgOut->wrapWikiMsg( "
\n$1\n
", array( 'ipb-needreblock', $this->BlockAddress ) ); } $scBlockExpiryOptions = wfMsgForContent( 'ipboptions' ); @@ -171,16 +192,15 @@ class IPBlockForm { list( $show, $value ) = explode( ':', $option ); $show = htmlspecialchars( $show ); $value = htmlspecialchars( $value ); - $blockExpiryFormOptions .= Xml::option( $show, $value, $this->BlockExpiry === $value ? true : false ) . "\n"; + $blockExpiryFormOptions .= Xml::option( $show, $value, $this->BlockExpiry === $value ) . "\n"; } $reasonDropDown = Xml::listDropDown( 'wpBlockReasonList', wfMsgForContent( 'ipbreason-dropdown' ), wfMsgForContent( 'ipbreasonotherlist' ), $this->BlockReasonList, 'wpBlockDropDown', 4 ); - global $wgStylePath, $wgStyleVersion; + $wgOut->addModules( 'mediawiki.legacy.block' ); $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' ) ) . @@ -250,7 +270,7 @@ class IPBlockForm { -   +   " . Xml::checkLabel( wfMsg( 'ipbanononly' ), 'wpAnonOnly', 'wpAnonOnly', $this->BlockAnonOnly, @@ -258,7 +278,7 @@ class IPBlockForm { -   +   " . Xml::checkLabel( wfMsg( 'ipbcreateaccount' ), 'wpCreateAccount', 'wpCreateAccount', $this->BlockCreateAccount, @@ -266,7 +286,7 @@ class IPBlockForm { -   +   " . Xml::checkLabel( wfMsg( 'ipbenableautoblock' ), 'wpEnableAutoblock', 'wpEnableAutoblock', $this->BlockEnableAutoblock, @@ -278,7 +298,7 @@ class IPBlockForm { if( self::canBlockEmail( $wgUser ) ) { $wgOut->addHTML(" -   +   " . Xml::checkLabel( wfMsg( 'ipbemailban' ), 'wpEmailBan', 'wpEmailBan', $this->BlockEmail, @@ -292,7 +312,7 @@ class IPBlockForm { if( $wgUser->isAllowed( 'hideuser' ) ) { $wgOut->addHTML(" -   +   " . Xml::checkLabel( wfMsg( 'ipbhidename' ), 'wpHideName', 'wpHideName', $this->BlockHideName, @@ -307,7 +327,7 @@ class IPBlockForm { if( $wgUser->isLoggedIn() ) { $wgOut->addHTML(" -   +   " . Xml::checkLabel( wfMsg( 'ipbwatchuser' ), 'wpWatchUser', 'wpWatchUser', $this->BlockWatchUser, @@ -322,7 +342,7 @@ class IPBlockForm { if( $wgBlockAllowsUTEdit ){ $wgOut->addHTML(" -   +   " . Xml::checkLabel( wfMsg( 'ipballowusertalk' ), 'wpAllowUsertalk', 'wpAllowUsertalk', $this->BlockAllowUsertalk, @@ -334,18 +354,18 @@ class IPBlockForm { $wgOut->addHTML(" -   +   " . Xml::submitButton( wfMsg( $alreadyBlocked ? 'ipb-change-block' : 'ipbsubmit' ), - array( 'name' => 'wpBlock', 'tabindex' => '13', 'accesskey' => 's' ) ) . " + array( 'name' => 'wpBlock', 'tabindex' => '13' ) + + $wgUser->getSkin()->tooltipAndAccessKeyAttribs( 'blockip-block' ) ). " " . Xml::closeElement( 'table' ) . - Xml::hidden( 'wpEditToken', $wgUser->editToken() ) . - ( $alreadyBlocked ? Xml::hidden( 'wpChangeBlock', 1 ) : "" ) . + Html::hidden( 'wpEditToken', $wgUser->editToken() ) . + ( $alreadyBlocked ? Html::hidden( 'wpChangeBlock', 1 ) : "" ) . Xml::closeElement( 'fieldset' ) . - Xml::closeElement( 'form' ) . - Xml::tags( 'script', array( 'type' => 'text/javascript' ), 'updateBlockOptions()' ) . "\n" + Xml::closeElement( 'form' ) ); $wgOut->addHTML( $this->getConvenienceLinks() ); @@ -361,8 +381,8 @@ class IPBlockForm { /** * Can we do an email block? - * @param User $user The sysop wanting to make a block - * @return boolean + * @param $user User: the sysop wanting to make a block + * @return Boolean */ public static function canBlockEmail( $user ) { global $wgEnableUserEmail, $wgSysopEmailBans; @@ -375,18 +395,16 @@ class IPBlockForm { * either. * @param $user User, Int or String */ - public static function checkUnblockSelf( $user ){ + public static function checkUnblockSelf( $user ) { global $wgUser; - if( is_int( $user ) ){ + if ( is_int( $user ) ) { $user = User::newFromId( $user ); - } elseif ( is_string( $user ) ){ + } elseif ( is_string( $user ) ) { $user = User::newFromName( $user ); } - if( $user instanceof User - && $user->getId() == $wgUser->getId() ) - { + if( $user instanceof User && $user->getId() == $wgUser->getId() ) { # User is trying to unblock themselves - if( $wgUser->isAllowed( 'unblockself' ) ){ + if ( $wgUser->isAllowed( 'unblockself' ) ) { return true; } else { return 'ipbnounblockself'; @@ -795,32 +813,20 @@ class IPBlockForm { * @return string */ private function getBlockListLink( $skin ) { - $list = SpecialPage::getTitleFor( 'Ipblocklist' ); - $query = array(); - - if( $this->BlockAddress ) { - $addr = strtr( $this->BlockAddress, '_', ' ' ); - $message = wfMsg( 'ipb-blocklist-addr', $addr ); - $query['ip'] = $this->BlockAddress; - } else { - $message = wfMsg( 'ipb-blocklist' ); - } - return $skin->linkKnown( - $list, - htmlspecialchars( $message ), - array(), - $query + SpecialPage::getTitleFor( 'Ipblocklist' ), + wfMsg( 'ipb-blocklist' ) ); } /** * Block a list of selected users - * @param array $users - * @param string $reason - * @param string $tag replaces user pages - * @param string $talkTag replaces user talk pages - * @returns array, list of html-safe usernames + * + * @param $users Array + * @param $reason String + * @param $tag String: replaces user pages + * @param $talkTag String: replaces user talk pages + * @return Array: list of html-safe usernames */ public static function doMassUserBlock( $users, $reason = '', $tag = '', $talkTag = '' ) { global $wgUser;