From 8cc0b601aa2db6db09ac0e4d70847293d75875aa Mon Sep 17 00:00:00 2001 From: Kevin Israel Date: Wed, 3 Apr 2013 17:44:00 -0400 Subject: [PATCH] Remove is_numeric check from Title::checkUserBlock This should allow the usernames of administrators such as "7" to show correctly on permissions error pages. I extracted the working code from UserBlockedError::__construct into a separate method Block::getPermissionsError, called from both places with context provided as an argument. Bug: 46768 Change-Id: Ic3fa926a5a4c109faff35fffbccb60fb06ea4a18 --- RELEASE-NOTES-1.22 | 1 + includes/Block.php | 39 +++++++++++++++++++++++++++++++++++++++ includes/Exception.php | 36 +++--------------------------------- includes/Title.php | 34 ++-------------------------------- 4 files changed, 45 insertions(+), 65 deletions(-) diff --git a/RELEASE-NOTES-1.22 b/RELEASE-NOTES-1.22 index 5c0098db20..00198ab8c7 100644 --- a/RELEASE-NOTES-1.22 +++ b/RELEASE-NOTES-1.22 @@ -14,6 +14,7 @@ production. === New features in 1.22 === === Bug fixes in 1.22 === +* (bug 46768) Usernames of blocking users now display correctly, even if numeric. === API changes in 1.22 === diff --git a/includes/Block.php b/includes/Block.php index 4da0f8f7e6..1a0949caa3 100644 --- a/includes/Block.php +++ b/includes/Block.php @@ -1384,4 +1384,43 @@ class Block { public function setBlocker( $user ) { $this->blocker = $user; } + + /** + * Get the key and parameters for the corresponding error message. + * + * @since 1.22 + * @param IContextSource $context + * @return array + */ + public function getPermissionsError( IContextSource $context ) { + $blocker = $this->getBlocker(); + if ( $blocker instanceof User ) { // local user + $blockerUserpage = $blocker->getUserPage(); + $link = "[[{$blockerUserpage->getPrefixedText()}|{$blockerUserpage->getText()}]]"; + } else { // foreign user + $link = $blocker; + } + + $reason = $this->mReason; + if ( $reason == '' ) { + $reason = $context->msg( 'blockednoreason' )->text(); + } + + /* $ip returns who *is* being blocked, $intended contains who was meant to be blocked. + * This could be a username, an IP range, or a single IP. */ + $intended = $this->getTarget(); + + $lang = $context->getLanguage(); + return array( + $this->mAuto ? 'autoblockedtext' : 'blockedtext', + $link, + $reason, + $context->getRequest()->getIP(), + $this->getByName(), + $this->getId(), + $lang->formatExpiry( $this->mExpiry ), + $intended, + $lang->timeanddate( wfTimestamp( TS_MW, $this->mTimestamp ), true ), + ); + } } diff --git a/includes/Exception.php b/includes/Exception.php index 21952bbf5b..855eb091e6 100644 --- a/includes/Exception.php +++ b/includes/Exception.php @@ -467,39 +467,9 @@ class ThrottledError extends ErrorPageError { */ class UserBlockedError extends ErrorPageError { public function __construct( Block $block ) { - global $wgLang, $wgRequest; - - $blocker = $block->getBlocker(); - if ( $blocker instanceof User ) { // local user - $blockerUserpage = $block->getBlocker()->getUserPage(); - $link = "[[{$blockerUserpage->getPrefixedText()}|{$blockerUserpage->getText()}]]"; - } else { // foreign user - $link = $blocker; - } - - $reason = $block->mReason; - if( $reason == '' ) { - $reason = wfMessage( 'blockednoreason' )->text(); - } - - /* $ip returns who *is* being blocked, $intended contains who was meant to be blocked. - * This could be a username, an IP range, or a single IP. */ - $intended = $block->getTarget(); - - parent::__construct( - 'blockedtitle', - $block->mAuto ? 'autoblockedtext' : 'blockedtext', - array( - $link, - $reason, - $wgRequest->getIP(), - $block->getByName(), - $block->getId(), - $wgLang->formatExpiry( $block->mExpiry ), - $intended, - $wgLang->timeanddate( wfTimestamp( TS_MW, $block->mTimestamp ), true ) - ) - ); + // @todo FIXME: Implement a more proper way to get context here. + $params = $block->getPermissionsError( RequestContext::getMain() ); + parent::__construct( 'blockedtitle', array_shift( $params ), $params ); } } diff --git a/includes/Title.php b/includes/Title.php index aa8fb93f31..6ac17d6904 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -2049,38 +2049,8 @@ class Title { // Don't block the user from editing their own talk page unless they've been // explicitly blocked from that too. } elseif( $user->isBlocked() && $user->mBlock->prevents( $action ) !== false ) { - $block = $user->getBlock(); - - // This is from OutputPage::blockedPage - // Copied at r23888 by werdna - - $id = $user->blockedBy(); - $reason = $user->blockedFor(); - if ( $reason == '' ) { - $reason = wfMessage( 'blockednoreason' )->text(); - } - $ip = $user->getRequest()->getIP(); - - if ( is_numeric( $id ) ) { - $name = User::whoIs( $id ); - } else { - $name = $id; - } - - $link = '[[' . $wgContLang->getNsText( NS_USER ) . ":{$name}|{$name}]]"; - $blockid = $block->getId(); - $blockExpiry = $block->getExpiry(); - $blockTimestamp = $wgLang->timeanddate( wfTimestamp( TS_MW, $block->mTimestamp ), true ); - if ( $blockExpiry == 'infinity' ) { - $blockExpiry = wfMessage( 'infiniteblock' )->text(); - } else { - $blockExpiry = $wgLang->timeanddate( wfTimestamp( TS_MW, $blockExpiry ), true ); - } - - $intended = strval( $block->getTarget() ); - - $errors[] = array( ( $block->mAuto ? 'autoblockedtext' : 'blockedtext' ), $link, $reason, $ip, $name, - $blockid, $blockExpiry, $intended, $blockTimestamp ); + // @todo FIXME: Pass the relevant context into this function. + $errors[] = $user->getBlock()->getPermissionsError( RequestContext::getMain() ); } return $errors; -- 2.20.1