From a6533885b8954d5521c075bc5a12fef59eb2aca0 Mon Sep 17 00:00:00 2001 From: Tchanders Date: Sun, 20 Oct 2019 00:04:00 +0000 Subject: [PATCH] Revert "Revert "Store block reasons as CommentStoreComments in block classes"" This reverts commit 5f06efb318ba5abf2c97afde47c32f61a525ce8a, which reverted 9335363789009eabea57cc5550c96180508b2c9d, which makes the deprecated property AbstractBlock::mReason private. After 9335363789, AbstractBlock::mReason is obsolete, since the block reason is now stored as a CommentStoreComment, AbstractBlock::reason. Change-Id: Ica0a74be90383689ca8e4cfe6d0fb25c9a5942c5 --- RELEASE-NOTES-1.35 | 6 ++ includes/api/ApiBlockInfoTrait.php | 23 ++++++- includes/auth/AuthManager.php | 8 ++- ...kBlocksSecondaryAuthenticationProvider.php | 19 +++--- includes/block/AbstractBlock.php | 38 +++++++++--- includes/block/BlockErrorFormatter.php | 14 +++-- includes/block/BlockManager.php | 9 +-- includes/block/DatabaseBlock.php | 22 +++++-- includes/specials/SpecialBlock.php | 4 +- includes/user/User.php | 10 +++- tests/phpunit/includes/api/ApiBaseTest.php | 14 +++-- .../includes/api/ApiBlockInfoTraitTest.php | 1 + tests/phpunit/includes/api/ApiBlockTest.php | 2 +- .../block/BlockErrorFormatterTest.php | 60 ++++++++++++------- .../includes/block/DatabaseBlockTest.php | 2 +- .../includes/specials/SpecialBlockTest.php | 16 ++--- 16 files changed, 167 insertions(+), 81 deletions(-) diff --git a/RELEASE-NOTES-1.35 b/RELEASE-NOTES-1.35 index 8f87272caa8..1412e93530f 100644 --- a/RELEASE-NOTES-1.35 +++ b/RELEASE-NOTES-1.35 @@ -96,6 +96,7 @@ because of Phabricator reports. * ApiQueryUserInfo::getBlockInfo, deprecated in 1.34, was removed. Use ApiBlockInfoTrait::getBlockDetails instead. * The mediawiki.ui.text module, deprecated in 1.28 and unused, was removed. +* AbstractBlock::mReason, deprecated in 1.34, is no longer public. * … === Deprecations in 1.35 === @@ -109,6 +110,11 @@ because of Phabricator reports. methods on the LanguageFallback class: getFirst, getAll, and getAllIncludingSiteLanguage. * Title::countRevisionsBetween has been deprecated and moved into RevisionStore. +* AbstractBlock::getReason is deprecated, since reasons are actually stored as + CommentStoreComments, and getReason returns a string with no caller control + over language or formatting. Instead use AbstractBlock::getReasonComment, + which returns the CommentStoreComment. +* … === Other changes in 1.35 === * … diff --git a/includes/api/ApiBlockInfoTrait.php b/includes/api/ApiBlockInfoTrait.php index a9c7a1ae6ed..ed4ddace03d 100644 --- a/includes/api/ApiBlockInfoTrait.php +++ b/includes/api/ApiBlockInfoTrait.php @@ -29,6 +29,7 @@ trait ApiBlockInfoTrait { /** * Get basic info about a given block * @param AbstractBlock $block + * @param Language|null $language * @return array Array containing several keys: * - blockid - ID of the block * - blockedby - username of the blocker @@ -39,12 +40,20 @@ trait ApiBlockInfoTrait { * - blockpartial - block only applies to certain pages, namespaces and/or actions * - systemblocktype - system block type, if any */ - private function getBlockDetails( AbstractBlock $block ) { + private function getBlockDetails( + AbstractBlock $block, + $language = null + ) { + if ( $language === null ) { + $language = $this->getLanguage(); + } + $vals = []; $vals['blockid'] = $block->getId(); $vals['blockedby'] = $block->getByName(); $vals['blockedbyid'] = $block->getBy(); - $vals['blockreason'] = $block->getReason(); + $vals['blockreason'] = $block->getReasonComment() + ->message->inLanguage( $language )->plain(); $vals['blockedtimestamp'] = wfTimestamp( TS_ISO_8601, $block->getTimestamp() ); $vals['blockexpiry'] = ApiResult::formatExpiry( $block->getExpiry(), 'infinite' ); $vals['blockpartial'] = !$block->isSitewide(); @@ -54,4 +63,14 @@ trait ApiBlockInfoTrait { return $vals; } + /** + * @name Methods required from ApiBase + * @{ + */ + + /** @see IContextSource::getLanguage */ + abstract public function getLanguage(); + + /**@}*/ + } diff --git a/includes/auth/AuthManager.php b/includes/auth/AuthManager.php index 4fcaf4e9e9d..1ca78962fa9 100644 --- a/includes/auth/AuthManager.php +++ b/includes/auth/AuthManager.php @@ -1008,10 +1008,12 @@ class AuthManager implements LoggerAwareInterface { $block = $creator->isBlockedFromCreateAccount(); if ( $block ) { + $language = \RequestContext::getMain()->getLanguage(); + $errorParams = [ - $block->getTarget(), - $block->getReason() ?: wfMessage( 'blockednoreason' )->text(), - $block->getByName() + $language->embedBidi( $block->getTarget() ), + $block->getReasonComment()->message->inLanguage( $language )->plain(), + $language->embedBidi( $block->getByName() ), ]; if ( $block->getType() === DatabaseBlock::TYPE_RANGE ) { diff --git a/includes/auth/CheckBlocksSecondaryAuthenticationProvider.php b/includes/auth/CheckBlocksSecondaryAuthenticationProvider.php index 92b06a4e7dd..e7a0f2ebc04 100644 --- a/includes/auth/CheckBlocksSecondaryAuthenticationProvider.php +++ b/includes/auth/CheckBlocksSecondaryAuthenticationProvider.php @@ -23,6 +23,7 @@ namespace MediaWiki\Auth; use Config; use MediaWiki\Block\DatabaseBlock; +use MediaWiki\MediaWikiServices; use StatusValue; /** @@ -80,20 +81,14 @@ class CheckBlocksSecondaryAuthenticationProvider extends AbstractSecondaryAuthen public function testUserForCreation( $user, $autocreate, array $options = [] ) { $block = $user->isBlockedFromCreateAccount(); if ( $block ) { - if ( $block->getReason() ) { - $reason = $block->getReason(); - } else { - $msg = \Message::newFromKey( 'blockednoreason' ); - if ( !\RequestContext::getMain()->getUser()->isSafeToLoad() ) { - $msg->inContentLanguage(); - } - $reason = $msg->text(); - } + $language = \RequestContext::getMain()->getUser()->isSafeToLoad() ? + \RequestContext::getMain()->getLanguage() : + MediaWikiServices::getInstance()->getContentLanguage(); $errorParams = [ - $block->getTarget(), - $reason, - $block->getByName() + $language->embedBidi( $block->getTarget() ), + $block->getReasonComment()->message->inLanguage( $language )->plain(), + $language->embedBidi( $block->getByName() ), ]; if ( $block->getType() === DatabaseBlock::TYPE_RANGE ) { diff --git a/includes/block/AbstractBlock.php b/includes/block/AbstractBlock.php index 05355588114..92e20ff0ff0 100644 --- a/includes/block/AbstractBlock.php +++ b/includes/block/AbstractBlock.php @@ -20,10 +20,12 @@ namespace MediaWiki\Block; +use CommentStoreComment; use IContextSource; use InvalidArgumentException; use IP; use MediaWiki\MediaWikiServices; +use Message; use RequestContext; use Title; use User; @@ -33,10 +35,13 @@ use User; */ abstract class AbstractBlock { /** - * @deprecated since 1.34. Use getReason and setReason instead. - * @var string + * @deprecated since 1.34. Use getReasonComment and setReason instead. + * Internally, use $reason. */ - public $mReason; + protected $mReason; + + /** @var CommentStoreComment */ + protected $reason; /** * @deprecated since 1.34. Use getTimestamp and setTimestamp instead. @@ -93,7 +98,7 @@ abstract class AbstractBlock { * @param array $options Parameters of the block, with supported options: * - address: (string|User) Target user name, User object, IP address or IP range * - by: (int) User ID of the blocker - * - reason: (string) Reason of the block + * - reason: (string|Message|CommentStoreComment) Reason for the block * - timestamp: (string) The time at which the block comes into effect * - byText: (string) Username of the blocker (for foreign users) * - hideName: (bool) Hide the target user name @@ -161,23 +166,38 @@ abstract class AbstractBlock { abstract public function getIdentifier(); /** - * Get the reason given for creating the block + * Get the reason given for creating the block, as a string. * + * Deprecated, since this gives the caller no control over the language + * or format, and no access to the comment's data. + * + * @deprecated since 1.35. Use getReasonComment instead. * @since 1.33 * @return string */ public function getReason() { - return $this->mReason; + $language = RequestContext::getMain()->getLanguage(); + return $this->reason->message->inLanguage( $language )->plain(); } /** - * Set the reason for creating the block + * Get the reason for creating the block. + * + * @since 1.35 + * @return CommentStoreComment + */ + public function getReasonComment() { + return $this->reason; + } + + /** + * Set the reason for creating the block. * * @since 1.33 - * @param string $reason + * @param string|Message|CommentStoreComment $reason */ public function setReason( $reason ) { - $this->mReason = $reason; + $this->reason = CommentStoreComment::newUnsavedComment( $reason ); } /** diff --git a/includes/block/BlockErrorFormatter.php b/includes/block/BlockErrorFormatter.php index 70889b865eb..0fabb15df31 100644 --- a/includes/block/BlockErrorFormatter.php +++ b/includes/block/BlockErrorFormatter.php @@ -20,6 +20,7 @@ namespace MediaWiki\Block; +use CommentStoreComment; use Language; use Message; use User; @@ -72,7 +73,7 @@ class BlockErrorFormatter { 'targetName' => (string)$block->getTarget(), 'blockerName' => $block->getByName(), 'blockerId' => $block->getBy(), - 'reason' => $block->getReason(), + 'reason' => $block->getReasonComment(), 'expiry' => $block->getExpiry(), 'timestamp' => $block->getTimestamp(), ]; @@ -82,6 +83,7 @@ class BlockErrorFormatter { * Get a standard set of block details for building a block error message, * formatted for a specified user and language. * + * @since 1.35 * @param AbstractBlock $block * @param User $user * @param Language $language @@ -105,16 +107,18 @@ class BlockErrorFormatter { } /** - * @param string $reason + * Format the block reason as plain wikitext in the specified language. + * + * @param CommentStoreComment $reason * @param Language $language * @return string */ - private function formatBlockReason( $reason, Language $language ) { - if ( $reason === '' ) { + private function formatBlockReason( CommentStoreComment $reason, Language $language ) { + if ( $reason->text === '' ) { $message = new Message( 'blockednoreason', [], $language ); return $message->text(); } - return $reason; + return $reason->message->inLanguage( $language )->plain(); } /** diff --git a/includes/block/BlockManager.php b/includes/block/BlockManager.php index 400421401e5..e7498121211 100644 --- a/includes/block/BlockManager.php +++ b/includes/block/BlockManager.php @@ -28,6 +28,7 @@ use LogicException; use MediaWiki\Config\ServiceOptions; use MediaWiki\Permissions\PermissionManager; use MediaWiki\User\UserIdentity; +use Message; use MWCryptHash; use Psr\Log\LoggerInterface; use User; @@ -158,7 +159,7 @@ class BlockManager { $block = new CompositeBlock( [ 'address' => $ip, 'byText' => 'MediaWiki default', - 'reason' => wfMessage( 'blockedtext-composite-reason' )->plain(), + 'reason' => new Message( 'blockedtext-composite-reason' ), 'originalBlocks' => $blocks, ] ); } @@ -202,14 +203,14 @@ class BlockManager { if ( $this->isLocallyBlockedProxy( $ip ) ) { $blocks[] = new SystemBlock( [ 'byText' => wfMessage( 'proxyblocker' )->text(), - 'reason' => wfMessage( 'proxyblockreason' )->plain(), + 'reason' => new Message( 'proxyblockreason' ), 'address' => $ip, 'systemBlock' => 'proxy', ] ); } elseif ( $isAnon && $this->isDnsBlacklisted( $ip ) ) { $blocks[] = new SystemBlock( [ 'byText' => wfMessage( 'sorbs' )->text(), - 'reason' => wfMessage( 'sorbsreason' )->plain(), + 'reason' => new Message( 'sorbsreason' ), 'address' => $ip, 'systemBlock' => 'dnsbl', ] ); @@ -221,7 +222,7 @@ class BlockManager { $blocks[] = new SystemBlock( [ 'address' => $ip, 'byText' => 'MediaWiki default', - 'reason' => wfMessage( 'softblockrangesreason', $ip )->plain(), + 'reason' => new Message( 'softblockrangesreason', [ $ip ] ), 'anonOnly' => true, 'systemBlock' => 'wgSoftBlockRanges', ] ); diff --git a/includes/block/DatabaseBlock.php b/includes/block/DatabaseBlock.php index f7aafd3de80..c73ce9cc1e3 100644 --- a/includes/block/DatabaseBlock.php +++ b/includes/block/DatabaseBlock.php @@ -211,7 +211,7 @@ class DatabaseBlock extends AbstractBlock { && $this->getHideName() == $block->getHideName() && $this->isEmailBlocked() == $block->isEmailBlocked() && $this->isUsertalkEditAllowed() == $block->isUsertalkEditAllowed() - && $this->getReason() == $block->getReason() + && $this->getReasonComment()->text == $block->getReasonComment()->text && $this->isSitewide() == $block->isSitewide() // DatabaseBlock::getRestrictions() may perform a database query, so // keep it at the end. @@ -436,7 +436,7 @@ class DatabaseBlock extends AbstractBlock { $this->setReason( CommentStore::getStore() // Legacy because $row may have come from self::selectFields() - ->getCommentLegacy( $db, 'ipb_reason', $row )->text + ->getCommentLegacy( $db, 'ipb_reason', $row ) ); $this->isHardblock( !$row->ipb_anon_only ); @@ -657,7 +657,7 @@ class DatabaseBlock extends AbstractBlock { 'ipb_allow_usertalk' => $this->isUsertalkEditAllowed(), 'ipb_parent_block_id' => $this->mParentBlockId, 'ipb_sitewide' => $this->isSitewide(), - ] + CommentStore::getStore()->insert( $dbw, 'ipb_reason', $this->getReason() ) + ] + CommentStore::getStore()->insert( $dbw, 'ipb_reason', $this->getReasonComment() ) + ActorMigration::newMigration()->getInsertValues( $dbw, 'ipb_by', $this->getBlocker() ); return $a; @@ -673,7 +673,7 @@ class DatabaseBlock extends AbstractBlock { 'ipb_deleted' => (int)$this->getHideName(), // typecast required for SQLite 'ipb_allow_usertalk' => $this->isUsertalkEditAllowed(), 'ipb_sitewide' => $this->isSitewide(), - ] + CommentStore::getStore()->insert( $dbw, 'ipb_reason', $this->getReason() ) + ] + CommentStore::getStore()->insert( $dbw, 'ipb_reason', $this->getReasonComment() ) + ActorMigration::newMigration()->getInsertValues( $dbw, 'ipb_by', $this->getBlocker() ); } @@ -847,8 +847,7 @@ class DatabaseBlock extends AbstractBlock { $autoblock->setTarget( $autoblockIP ); $autoblock->setBlocker( $this->getBlocker() ); $autoblock->setReason( - wfMessage( 'autoblocker', $this->getTarget(), $this->getReason() ) - ->inContentLanguage()->plain() + wfMessage( 'autoblocker', $this->getTarget(), $this->getReasonComment()->text ) ); $timestamp = wfTimestampNow(); $autoblock->setTimestamp( $timestamp ); @@ -980,6 +979,17 @@ class DatabaseBlock extends AbstractBlock { } } + /** + * @inheritDoc + * @deprecated since 1.35. Use getReasonComment instead. + */ + public function getReason() { + if ( $this->getType() === self::TYPE_AUTO ) { + return $this->reason->message->inContentLanguage()->plain(); + } + return $this->reason->text; + } + /** * @inheritDoc */ diff --git a/includes/specials/SpecialBlock.php b/includes/specials/SpecialBlock.php index a03455bbe6d..e5b1e739a09 100644 --- a/includes/specials/SpecialBlock.php +++ b/includes/specials/SpecialBlock.php @@ -371,7 +371,7 @@ class SpecialBlock extends FormSpecialPage { ->getPermissionManager() ->userHasRight( $this->getUser(), 'hideuser' ) ) { - $fields['Reason']['default'] = $block->getReason(); + $fields['Reason']['default'] = $block->getReasonComment()->text; } else { $fields['Reason']['default'] = ''; } @@ -964,7 +964,7 @@ class SpecialBlock extends FormSpecialPage { $currentBlock->setHideName( $block->getHideName() ); $currentBlock->isEmailBlocked( $block->isEmailBlocked() ); $currentBlock->isUsertalkEditAllowed( $block->isUsertalkEditAllowed() ); - $currentBlock->setReason( $block->getReason() ); + $currentBlock->setReason( $block->getReasonComment() ); if ( $enablePartialBlocks ) { // Maintain the sitewide status. If partial blocks is not enabled, diff --git a/includes/user/User.php b/includes/user/User.php index f7e6ec6b5f9..78e2d2e9781 100644 --- a/includes/user/User.php +++ b/includes/user/User.php @@ -180,7 +180,11 @@ class User implements IDBAccessObject, UserIdentity { public $mBlockedby; /** @var string */ protected $mHash; - /** @var string */ + /** + * TODO: This should be removed when User::BlockedFor + * and AbstractBlock::getReason are hard deprecated. + * @var string + */ protected $mBlockreason; /** @var array */ protected $mEffectiveGroups; @@ -2093,7 +2097,9 @@ class User implements IDBAccessObject, UserIdentity { } /** - * If user is blocked, return the specified reason for the block + * If user is blocked, return the specified reason for the block. + * + * @deprecated since 1.35 Use AbstractBlock::getReasonComment instead * @return string Blocking reason */ public function blockedFor() { diff --git a/tests/phpunit/includes/api/ApiBaseTest.php b/tests/phpunit/includes/api/ApiBaseTest.php index 5144900f8d9..85f91d8c4a0 100644 --- a/tests/phpunit/includes/api/ApiBaseTest.php +++ b/tests/phpunit/includes/api/ApiBaseTest.php @@ -1342,9 +1342,10 @@ class ApiBaseTest extends ApiTestCase { 'expiry' => time() + 100500, ] ); $block->insert(); - $userInfoTrait = TestingAccessWrapper::newFromObject( - $this->getMockForTrait( ApiBlockInfoTrait::class ) - ); + + $mockTrait = $this->getMockForTrait( ApiBlockInfoTrait::class ); + $mockTrait->method( 'getLanguage' )->willReturn( 'en' ); + $userInfoTrait = TestingAccessWrapper::newFromObject( $mockTrait ); $blockinfo = [ 'blockinfo' => $userInfoTrait->getBlockDetails( $block ) ]; $expect = Status::newGood(); @@ -1400,9 +1401,10 @@ class ApiBaseTest extends ApiTestCase { 'expiry' => time() + 100500, ] ); $block->insert(); - $userInfoTrait = TestingAccessWrapper::newFromObject( - $this->getObjectForTrait( ApiBlockInfoTrait::class ) - ); + + $mockTrait = $this->getMockForTrait( ApiBlockInfoTrait::class ); + $mockTrait->method( 'getLanguage' )->willReturn( 'en' ); + $userInfoTrait = TestingAccessWrapper::newFromObject( $mockTrait ); $blockinfo = [ 'blockinfo' => $userInfoTrait->getBlockDetails( $block ) ]; $expect = Status::newGood(); diff --git a/tests/phpunit/includes/api/ApiBlockInfoTraitTest.php b/tests/phpunit/includes/api/ApiBlockInfoTraitTest.php index ba5c0037766..1f4d8ad1861 100644 --- a/tests/phpunit/includes/api/ApiBlockInfoTraitTest.php +++ b/tests/phpunit/includes/api/ApiBlockInfoTraitTest.php @@ -13,6 +13,7 @@ class ApiBlockInfoTraitTest extends MediaWikiTestCase { */ public function testGetBlockDetails( $block, $expectedInfo ) { $mock = $this->getMockForTrait( ApiBlockInfoTrait::class ); + $mock->method( 'getLanguage' )->willReturn( 'en' ); $info = TestingAccessWrapper::newFromObject( $mock )->getBlockDetails( $block ); $subset = array_merge( [ 'blockid' => null, diff --git a/tests/phpunit/includes/api/ApiBlockTest.php b/tests/phpunit/includes/api/ApiBlockTest.php index d63eb49c67f..3d9e758135b 100644 --- a/tests/phpunit/includes/api/ApiBlockTest.php +++ b/tests/phpunit/includes/api/ApiBlockTest.php @@ -66,7 +66,7 @@ class ApiBlockTest extends ApiTestCase { $this->assertTrue( !is_null( $block ), 'Block is valid' ); $this->assertSame( $this->mUser->getName(), (string)$block->getTarget() ); - $this->assertSame( 'Some reason', $block->getReason() ); + $this->assertSame( 'Some reason', $block->getReasonComment()->text ); return $ret; } diff --git a/tests/phpunit/includes/block/BlockErrorFormatterTest.php b/tests/phpunit/includes/block/BlockErrorFormatterTest.php index 116797154eb..f4605a11a14 100644 --- a/tests/phpunit/includes/block/BlockErrorFormatterTest.php +++ b/tests/phpunit/includes/block/BlockErrorFormatterTest.php @@ -9,7 +9,7 @@ use MediaWiki\MediaWikiServices; * @group Blocking * @coversDefaultClass \MediaWiki\Block\BlockErrorFormatter */ -class BlockErrorFormatterTest extends MediaWikiLangTestCase { +class BlockErrorFormatterTest extends MediaWikiTestCase { /** * @dataProvider provideTestGetMessage * @covers ::getMessage @@ -31,7 +31,7 @@ class BlockErrorFormatterTest extends MediaWikiLangTestCase { $message = $formatter->getMessage( $block, $context->getUser(), - $context->getLanguage(), + Language::factory( 'qqx' ), $context->getRequest()->getIP() ); @@ -46,11 +46,13 @@ class BlockErrorFormatterTest extends MediaWikiLangTestCase { $databaseBlock = new DatabaseBlock( [ 'timestamp' => $timestamp, 'expiry' => $expiry, + 'reason' => 'Test reason.', ] ); $systemBlock = new SystemBlock( [ 'timestamp' => $timestamp, 'systemBlock' => 'test', + 'reason' => new Message( 'proxyblockreason' ), ] ); $compositeBlock = new CompositeBlock( [ @@ -67,13 +69,13 @@ class BlockErrorFormatterTest extends MediaWikiLangTestCase { 'blockedtext', [ '', - 'no reason given', + 'Test reason.', '1.2.3.4', '', null, // Block not inserted - '00:00, 1 January 2001', + '00:00, 1 (january) 2001', '', - '00:00, 1 January 2000', + '00:00, 1 (january) 2000', ], ], 'Database block (autoblock)' => [ @@ -85,13 +87,13 @@ class BlockErrorFormatterTest extends MediaWikiLangTestCase { 'autoblockedtext', [ '', - 'no reason given', + '(blockednoreason)', '1.2.3.4', '', - null, - '00:00, 1 January 2001', + null, // Block not inserted + '00:00, 1 (january) 2001', '', - '00:00, 1 January 2000', + '00:00, 1 (january) 2000', ], ], 'Database block (partial block)' => [ @@ -103,13 +105,13 @@ class BlockErrorFormatterTest extends MediaWikiLangTestCase { 'blockedtext-partial', [ '', - 'no reason given', + '(blockednoreason)', '1.2.3.4', '', - null, - '00:00, 1 January 2001', + null, // Block not inserted + '00:00, 1 (january) 2001', '', - '00:00, 1 January 2000', + '00:00, 1 (january) 2000', ], ], 'System block (type \'test\')' => [ @@ -117,13 +119,31 @@ class BlockErrorFormatterTest extends MediaWikiLangTestCase { 'systemblockedtext', [ '', - 'no reason given', + '(proxyblockreason)', '1.2.3.4', '', 'test', - 'infinite', + '(infiniteblock)', '', - '00:00, 1 January 2000', + '00:00, 1 (january) 2000', + ], + ], + 'System block (type \'test\') with reason parameters' => [ + new SystemBlock( [ + 'timestamp' => $timestamp, + 'systemBlock' => 'test', + 'reason' => new Message( 'softblockrangesreason', [ '1.2.3.4' ] ), + ] ), + 'systemblockedtext', + [ + '', + '(softblockrangesreason: 1.2.3.4)', + '1.2.3.4', + '', + 'test', + '(infiniteblock)', + '', + '00:00, 1 (january) 2000', ], ], 'Composite block (original blocks not inserted)' => [ @@ -131,13 +151,13 @@ class BlockErrorFormatterTest extends MediaWikiLangTestCase { 'blockedtext-composite', [ '', - 'no reason given', + '(blockednoreason)', '1.2.3.4', '', - 'Your IP address appears in multiple blacklists', - 'infinite', + '(blockedtext-composite-no-ids)', + '(infiniteblock)', '', - '00:00, 1 January 2000', + '00:00, 1 (january) 2000', ], ], ]; diff --git a/tests/phpunit/includes/block/DatabaseBlockTest.php b/tests/phpunit/includes/block/DatabaseBlockTest.php index cfab9e5e4e6..d6bd972386a 100644 --- a/tests/phpunit/includes/block/DatabaseBlockTest.php +++ b/tests/phpunit/includes/block/DatabaseBlockTest.php @@ -445,7 +445,7 @@ class DatabaseBlockTest extends MediaWikiLangTestCase { $this->assertEquals( $exCount, count( $xffblocks ), 'Number of blocks for ' . $xff ); $block = DatabaseBlock::chooseBlock( $xffblocks, $list ); $this->assertEquals( - $exResult, $block->getReason(), 'Correct block type for XFF header ' . $xff + $exResult, $block->getReasonComment()->text, 'Correct block type for XFF header ' . $xff ); } diff --git a/tests/phpunit/includes/specials/SpecialBlockTest.php b/tests/phpunit/includes/specials/SpecialBlockTest.php index 5f11a016bf7..fe333fee53e 100644 --- a/tests/phpunit/includes/specials/SpecialBlockTest.php +++ b/tests/phpunit/includes/specials/SpecialBlockTest.php @@ -93,7 +93,7 @@ class SpecialBlockTest extends SpecialPageTestBase { $this->assertSame( $block->isCreateAccountBlocked(), $fields['CreateAccount']['default'] ); $this->assertSame( $block->isAutoblocking(), $fields['AutoBlock']['default'] ); $this->assertSame( !$block->isUsertalkEditAllowed(), $fields['DisableUTEdit']['default'] ); - $this->assertSame( $block->getReason(), $fields['Reason']['default'] ); + $this->assertSame( $block->getReasonComment()->text, $fields['Reason']['default'] ); $this->assertSame( 'infinite', $fields['Expiry']['default'] ); } @@ -181,7 +181,7 @@ class SpecialBlockTest extends SpecialPageTestBase { $this->assertTrue( $result ); $block = DatabaseBlock::newFromTarget( $badActor ); - $this->assertSame( $reason, $block->getReason() ); + $this->assertSame( $reason, $block->getReasonComment()->text ); $this->assertSame( $expiry, $block->getExpiry() ); } @@ -230,7 +230,7 @@ class SpecialBlockTest extends SpecialPageTestBase { $this->assertTrue( $result ); $block = DatabaseBlock::newFromTarget( $badActor ); - $this->assertSame( $reason, $block->getReason() ); + $this->assertSame( $reason, $block->getReasonComment()->text ); $this->assertSame( $expiry, $block->getExpiry() ); $this->assertSame( '1', $block->isAutoblocking() ); } @@ -279,7 +279,7 @@ class SpecialBlockTest extends SpecialPageTestBase { $this->assertTrue( $result ); $block = DatabaseBlock::newFromTarget( $badActor ); - $this->assertSame( $reason, $block->getReason() ); + $this->assertSame( $reason, $block->getReasonComment()->text ); $this->assertSame( $expiry, $block->getExpiry() ); $this->assertCount( 2, $block->getRestrictions() ); $this->assertTrue( $this->getBlockRestrictionStore()->equals( $block->getRestrictions(), [ @@ -333,7 +333,7 @@ class SpecialBlockTest extends SpecialPageTestBase { $this->assertTrue( $result ); $block = DatabaseBlock::newFromTarget( $badActor ); - $this->assertSame( $reason, $block->getReason() ); + $this->assertSame( $reason, $block->getReasonComment()->text ); $this->assertSame( $expiry, $block->getExpiry() ); $this->assertFalse( $block->isSitewide() ); $this->assertCount( 2, $block->getRestrictions() ); @@ -349,7 +349,7 @@ class SpecialBlockTest extends SpecialPageTestBase { $this->assertTrue( $result ); $block = DatabaseBlock::newFromTarget( $badActor ); - $this->assertSame( $reason, $block->getReason() ); + $this->assertSame( $reason, $block->getReasonComment()->text ); $this->assertSame( $expiry, $block->getExpiry() ); $this->assertFalse( $block->isSitewide() ); $this->assertCount( 1, $block->getRestrictions() ); @@ -364,7 +364,7 @@ class SpecialBlockTest extends SpecialPageTestBase { $this->assertTrue( $result ); $block = DatabaseBlock::newFromTarget( $badActor ); - $this->assertSame( $reason, $block->getReason() ); + $this->assertSame( $reason, $block->getReasonComment()->text ); $this->assertSame( $expiry, $block->getExpiry() ); $this->assertFalse( $block->isSitewide() ); $this->assertCount( 0, $block->getRestrictions() ); @@ -376,7 +376,7 @@ class SpecialBlockTest extends SpecialPageTestBase { $this->assertTrue( $result ); $block = DatabaseBlock::newFromTarget( $badActor ); - $this->assertSame( $reason, $block->getReason() ); + $this->assertSame( $reason, $block->getReasonComment()->text ); $this->assertSame( $expiry, $block->getExpiry() ); $this->assertTrue( $block->isSitewide() ); $this->assertCount( 0, $block->getRestrictions() );