Inject UserFactory into BlockErrorFormatter

Bug: T265311
Change-Id: Ifdd6669f95689aba67bf4eef337c49115a1a6d07
This commit is contained in:
DannyS712 2020-10-12 20:41:01 +00:00 committed by Umherirrender
parent dcf682a521
commit 500a13db73
3 changed files with 18 additions and 2 deletions

View file

@ -176,7 +176,9 @@ return [
},
'BlockErrorFormatter' => function ( MediaWikiServices $services ) : BlockErrorFormatter {
return new BlockErrorFormatter();
return new BlockErrorFormatter(
$services->getUserFactory()
);
},
'BlockManager' => function ( MediaWikiServices $services ) : BlockManager {

View file

@ -22,6 +22,7 @@ namespace MediaWiki\Block;
use CommentStoreComment;
use Language;
use MediaWiki\User\UserFactory;
use Message;
use User;
@ -32,6 +33,17 @@ use User;
* @since 1.35
*/
class BlockErrorFormatter {
/** @var UserFactory */
private $userFactory;
/**
* @param UserFactory $userFactory
*/
public function __construct( UserFactory $userFactory ) {
$this->userFactory = $userFactory;
}
/**
* Get a block error message. Different message keys are chosen depending on the
* block features. Message paramaters are formatted for the specified user and
@ -137,7 +149,7 @@ class BlockErrorFormatter {
return $blockerName;
}
$blocker = User::newFromId( $blockerId );
$blocker = $this->userFactory->newFromId( (int)$blockerId );
$blockerUserpage = $blocker->getUserPage();
$blockerText = $language->embedBidi( $blockerUserpage->getText() );
return "[[{$blockerUserpage->getPrefixedText()}|{$blockerText}]]";

View file

@ -6,6 +6,8 @@ use MediaWiki\Block\SystemBlock;
use MediaWiki\MediaWikiServices;
/**
* @todo Can this be converted to unit tests?
*
* @group Blocking
* @coversDefaultClass \MediaWiki\Block\BlockErrorFormatter
*/