From 1b9ca741a7e1b9577e6f769813a0423b2a5707f9 Mon Sep 17 00:00:00 2001 From: Thalia Date: Fri, 22 Mar 2019 15:16:40 +0000 Subject: [PATCH] Remove reliance on Block properties being public Use getters and setters for $mReason, $mTimestamp, $mExpiry and $mHideName; use Block::getType to check if a block is an autoblock instead of checking $mAuto; no change needed for $mParentBlockId, which is not accessed externally. Change-Id: I767ed44ce4c2e21f53962d75fb86891add2282f6 --- includes/Block.php | 141 ++++++++++++++---- includes/api/ApiBlock.php | 2 +- includes/api/ApiQueryUserInfo.php | 4 +- includes/auth/AuthManager.php | 2 +- ...kBlocksSecondaryAuthenticationProvider.php | 4 +- includes/specials/SpecialBlock.php | 36 ++--- includes/specials/SpecialUnblock.php | 4 +- includes/user/User.php | 6 +- tests/phpunit/includes/BlockTest.php | 10 +- .../phpunit/includes/TitlePermissionTest.php | 2 +- tests/phpunit/includes/api/ApiBlockTest.php | 2 +- .../includes/specials/SpecialBlockTest.php | 16 +- tests/phpunit/includes/user/UserTest.php | 2 +- 13 files changed, 155 insertions(+), 76 deletions(-) diff --git a/includes/Block.php b/includes/Block.php index 0693650238..7e32f7ec0d 100644 --- a/includes/Block.php +++ b/includes/Block.php @@ -165,13 +165,13 @@ class Block { $this->setBlocker( $options['byText'] ); } - $this->mReason = $options['reason']; + $this->setReason( $options['reason'] ); $this->mTimestamp = wfTimestamp( TS_MW, $options['timestamp'] ); - $this->mExpiry = wfGetDB( DB_REPLICA )->decodeExpiry( $options['expiry'] ); + $this->setExpiry( wfGetDB( DB_REPLICA )->decodeExpiry( $options['expiry'] ) ); # Boolean settings $this->mAuto = (bool)$options['auto']; - $this->mHideName = (bool)$options['hideName']; + $this->setHideName( (bool)$options['hideName'] ); $this->isHardblock( !$options['anonOnly'] ); $this->isAutoblocking( (bool)$options['enableAutoblock'] ); $this->isSitewide( (bool)$options['sitewide'] ); @@ -296,12 +296,12 @@ class Block { && $this->mAuto == $block->mAuto && $this->isHardblock() == $block->isHardblock() && $this->isCreateAccountBlocked() == $block->isCreateAccountBlocked() - && $this->mExpiry == $block->mExpiry + && $this->getExpiry() == $block->getExpiry() && $this->isAutoblocking() == $block->isAutoblocking() - && $this->mHideName == $block->mHideName + && $this->getHideName() == $block->getHideName() && $this->isEmailBlocked() == $block->isEmailBlocked() && $this->isUsertalkEditAllowed() == $block->isUsertalkEditAllowed() - && $this->mReason == $block->mReason + && $this->getReason() == $block->getReason() && $this->isSitewide() == $block->isSitewide() // Block::getRestrictions() may perform a database query, so keep it at // the end. @@ -473,16 +473,18 @@ class Block { $this->mTimestamp = wfTimestamp( TS_MW, $row->ipb_timestamp ); $this->mAuto = $row->ipb_auto; - $this->mHideName = $row->ipb_deleted; + $this->setHideName( $row->ipb_deleted ); $this->mId = (int)$row->ipb_id; $this->mParentBlockId = $row->ipb_parent_block_id; // I wish I didn't have to do this $db = wfGetDB( DB_REPLICA ); - $this->mExpiry = $db->decodeExpiry( $row->ipb_expiry ); - $this->mReason = CommentStore::getStore() + $this->setExpiry( $db->decodeExpiry( $row->ipb_expiry ) ); + $this->setReason( + CommentStore::getStore() // Legacy because $row may have come from self::selectFields() - ->getCommentLegacy( $db, 'ipb_reason', $row )->text; + ->getCommentLegacy( $db, 'ipb_reason', $row )->text + ); $this->isHardblock( !$row->ipb_anon_only ); $this->isAutoblocking( $row->ipb_enable_autoblock ); @@ -679,7 +681,7 @@ class Block { * @return array */ protected function getDatabaseArray( IDatabase $dbw ) { - $expiry = $dbw->encodeExpiry( $this->mExpiry ); + $expiry = $dbw->encodeExpiry( $this->getExpiry() ); if ( $this->forcedTargetID ) { $uid = $this->forcedTargetID; @@ -690,7 +692,7 @@ class Block { $a = [ 'ipb_address' => (string)$this->target, 'ipb_user' => $uid, - 'ipb_timestamp' => $dbw->timestamp( $this->mTimestamp ), + 'ipb_timestamp' => $dbw->timestamp( $this->getTimestamp() ), 'ipb_auto' => $this->mAuto, 'ipb_anon_only' => !$this->isHardblock(), 'ipb_create_account' => $this->isCreateAccountBlocked(), @@ -698,12 +700,12 @@ class Block { 'ipb_expiry' => $expiry, 'ipb_range_start' => $this->getRangeStart(), 'ipb_range_end' => $this->getRangeEnd(), - 'ipb_deleted' => intval( $this->mHideName ), // typecast required for SQLite + 'ipb_deleted' => intval( $this->getHideName() ), // typecast required for SQLite 'ipb_block_email' => $this->isEmailBlocked(), 'ipb_allow_usertalk' => $this->isUsertalkEditAllowed(), 'ipb_parent_block_id' => $this->mParentBlockId, 'ipb_sitewide' => $this->isSitewide(), - ] + CommentStore::getStore()->insert( $dbw, 'ipb_reason', $this->mReason ) + ] + CommentStore::getStore()->insert( $dbw, 'ipb_reason', $this->getReason() ) + ActorMigration::newMigration()->getInsertValues( $dbw, 'ipb_by', $this->getBlocker() ); return $a; @@ -716,10 +718,10 @@ class Block { protected function getAutoblockUpdateArray( IDatabase $dbw ) { return [ 'ipb_create_account' => $this->isCreateAccountBlocked(), - 'ipb_deleted' => (int)$this->mHideName, // typecast required for SQLite + '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->mReason ) + ] + CommentStore::getStore()->insert( $dbw, 'ipb_reason', $this->getReason() ) + ActorMigration::newMigration()->getInsertValues( $dbw, 'ipb_by', $this->getBlocker() ); } @@ -883,7 +885,7 @@ class Block { # Check if the block is an autoblock and would exceed the user block # if renewed. If so, do nothing, otherwise prolong the block time... if ( $ipblock->mAuto && // @todo Why not compare $ipblock->mExpiry? - $this->mExpiry > self::getAutoblockExpiry( $ipblock->mTimestamp ) + $this->getExpiry() > self::getAutoblockExpiry( $ipblock->getTimestamp() ) ) { # Reset block timestamp to now and its expiry to # $wgAutoblockExpiry in the future @@ -897,26 +899,28 @@ class Block { wfDebug( "Autoblocking {$this->getTarget()}@" . $autoblockIP . "\n" ); $autoblock->setTarget( $autoblockIP ); $autoblock->setBlocker( $this->getBlocker() ); - $autoblock->mReason = wfMessage( 'autoblocker', $this->getTarget(), $this->mReason ) - ->inContentLanguage()->plain(); + $autoblock->setReason( + wfMessage( 'autoblocker', $this->getTarget(), $this->getReason() ) + ->inContentLanguage()->plain() + ); $timestamp = wfTimestampNow(); $autoblock->mTimestamp = $timestamp; $autoblock->mAuto = 1; $autoblock->isCreateAccountBlocked( $this->isCreateAccountBlocked() ); # Continue suppressing the name if needed - $autoblock->mHideName = $this->mHideName; + $autoblock->setHideName( $this->getHideName() ); $autoblock->isUsertalkEditAllowed( $this->isUsertalkEditAllowed() ); $autoblock->mParentBlockId = $this->mId; $autoblock->isSitewide( $this->isSitewide() ); $autoblock->setRestrictions( $this->getRestrictions() ); - if ( $this->mExpiry == 'infinity' ) { + if ( $this->getExpiry() == 'infinity' ) { # Original block was indefinite, start an autoblock now - $autoblock->mExpiry = self::getAutoblockExpiry( $timestamp ); + $autoblock->setExpiry( self::getAutoblockExpiry( $timestamp ) ); } else { # If the user is already blocked with an expiry date, we don't # want to pile on top of that. - $autoblock->mExpiry = min( $this->mExpiry, self::getAutoblockExpiry( $timestamp ) ); + $autoblock->setExpiry( min( $this->getExpiry(), self::getAutoblockExpiry( $timestamp ) ) ); } # Insert the block... @@ -951,10 +955,10 @@ class Block { $timestamp = wfTimestampNow(); wfDebug( "Block::isExpired() checking current " . $timestamp . " vs $this->mExpiry\n" ); - if ( !$this->mExpiry ) { + if ( !$this->getExpiry() ) { return false; } else { - return $timestamp > $this->mExpiry; + return $timestamp > $this->getExpiry(); } } @@ -972,13 +976,13 @@ class Block { public function updateTimestamp() { if ( $this->mAuto ) { $this->mTimestamp = wfTimestamp(); - $this->mExpiry = self::getAutoblockExpiry( $this->mTimestamp ); + $this->setExpiry( self::getAutoblockExpiry( $this->getTimestamp() ) ); $dbw = wfGetDB( DB_MASTER ); $dbw->update( 'ipblocks', [ /* SET */ - 'ipb_timestamp' => $dbw->timestamp( $this->mTimestamp ), - 'ipb_expiry' => $dbw->timestamp( $this->mExpiry ), + 'ipb_timestamp' => $dbw->timestamp( $this->getTimestamp() ), + 'ipb_expiry' => $dbw->timestamp( $this->getExpiry() ), ], [ /* WHERE */ 'ipb_id' => $this->getId(), @@ -1074,6 +1078,46 @@ class Block { return $this; } + /** + * Get the reason given for creating the block + * + * @since 1.33 + * @return string + */ + public function getReason() { + return $this->mReason; + } + + /** + * Set the reason for creating the block + * + * @since 1.33 + * @param string $reason + */ + public function setReason( $reason ) { + $this->mReason = $reason; + } + + /** + * Get whether the block hides the target's username + * + * @since 1.33 + * @return bool The block hides the username + */ + public function getHideName() { + return $this->mHideName; + } + + /** + * Set whether ths block hides the target's username + * + * @since 1.33 + * @param bool $hideName The block hides the username + */ + public function setHideName( $hideName ) { + $this->mHideName = $hideName; + } + /** * Get the system block type, if any * @since 1.29 @@ -1660,14 +1704,45 @@ class Block { } /** - * @since 1.19 + * Get the block expiry time * - * @return mixed|string + * @since 1.19 + * @return string */ public function getExpiry() { return $this->mExpiry; } + /** + * Set the block expiry time + * + * @since 1.33 + * @param string $expiry + */ + public function setExpiry( $expiry ) { + $this->mExpiry = $expiry; + } + + /** + * Get the timestamp indicating when the block was created + * + * @since 1.33 + * @return string + */ + public function getTimestamp() { + return $this->mTimestamp; + } + + /** + * Set the timestamp indicating when the block was created + * + * @since 1.33 + * @param string $timestamp + */ + public function setTimestamp( $timestamp ) { + $this->mTimestamp = $timestamp; + } + /** * Set the target for this block, and update $this->type accordingly * @param mixed $target @@ -1830,7 +1905,7 @@ class Block { $link = $blocker; } - $reason = $this->mReason; + $reason = $this->getReason(); if ( $reason == '' ) { $reason = $context->msg( 'blockednoreason' )->text(); } @@ -1847,9 +1922,9 @@ class Block { $context->getRequest()->getIP(), $this->getByName(), $systemBlockType ?? $this->getId(), - $lang->formatExpiry( $this->mExpiry ), + $lang->formatExpiry( $this->getExpiry() ), (string)$intended, - $lang->userTimeAndDate( $this->mTimestamp, $context->getUser() ), + $lang->userTimeAndDate( $this->getTimestamp(), $context->getUser() ), ]; } diff --git a/includes/api/ApiBlock.php b/includes/api/ApiBlock.php index 14177edb89..673fc6b00c 100644 --- a/includes/api/ApiBlock.php +++ b/includes/api/ApiBlock.php @@ -135,7 +135,7 @@ class ApiBlock extends ApiBase { $block = Block::newFromTarget( $target, null, true ); if ( $block instanceof Block ) { - $res['expiry'] = ApiResult::formatExpiry( $block->mExpiry, 'infinite' ); + $res['expiry'] = ApiResult::formatExpiry( $block->getExpiry(), 'infinite' ); $res['id'] = $block->getId(); } else { # should be unreachable diff --git a/includes/api/ApiQueryUserInfo.php b/includes/api/ApiQueryUserInfo.php index a38d877d99..f594347ab0 100644 --- a/includes/api/ApiQueryUserInfo.php +++ b/includes/api/ApiQueryUserInfo.php @@ -67,8 +67,8 @@ class ApiQueryUserInfo extends ApiQueryBase { $vals['blockid'] = $block->getId(); $vals['blockedby'] = $block->getByName(); $vals['blockedbyid'] = $block->getBy(); - $vals['blockreason'] = $block->mReason; - $vals['blockedtimestamp'] = wfTimestamp( TS_ISO_8601, $block->mTimestamp ); + $vals['blockreason'] = $block->getReason(); + $vals['blockedtimestamp'] = wfTimestamp( TS_ISO_8601, $block->getTimestamp() ); $vals['blockexpiry'] = ApiResult::formatExpiry( $block->getExpiry(), 'infinite' ); $vals['blockpartial'] = !$block->isSitewide(); if ( $block->getSystemBlockType() !== null ) { diff --git a/includes/auth/AuthManager.php b/includes/auth/AuthManager.php index 946decf998..0c6218e6d4 100644 --- a/includes/auth/AuthManager.php +++ b/includes/auth/AuthManager.php @@ -1006,7 +1006,7 @@ class AuthManager implements LoggerAwareInterface { if ( $block ) { $errorParams = [ $block->getTarget(), - $block->mReason ?: wfMessage( 'blockednoreason' )->text(), + $block->getReason() ?: wfMessage( 'blockednoreason' )->text(), $block->getByName() ]; diff --git a/includes/auth/CheckBlocksSecondaryAuthenticationProvider.php b/includes/auth/CheckBlocksSecondaryAuthenticationProvider.php index 7488fbaaae..10925b50f7 100644 --- a/includes/auth/CheckBlocksSecondaryAuthenticationProvider.php +++ b/includes/auth/CheckBlocksSecondaryAuthenticationProvider.php @@ -77,8 +77,8 @@ class CheckBlocksSecondaryAuthenticationProvider extends AbstractSecondaryAuthen public function testUserForCreation( $user, $autocreate, array $options = [] ) { $block = $user->isBlockedFromCreateAccount(); if ( $block ) { - if ( $block->mReason ) { - $reason = $block->mReason; + if ( $block->getReason() ) { + $reason = $block->getReason(); } else { $msg = \Message::newFromKey( 'blockednoreason' ); if ( !\RequestContext::getMain()->getUser()->isSafeToLoad() ) { diff --git a/includes/specials/SpecialBlock.php b/includes/specials/SpecialBlock.php index 02a8d009d4..0cf790bdda 100644 --- a/includes/specials/SpecialBlock.php +++ b/includes/specials/SpecialBlock.php @@ -350,9 +350,11 @@ class SpecialBlock extends FormSpecialPage { $block = Block::newFromTarget( $this->target ); - if ( $block instanceof Block && !$block->mAuto # The block exists and isn't an autoblock - && ( $this->type != Block::TYPE_RANGE # The block isn't a rangeblock - || $block->getTarget() == $this->target ) # or if it is, the range is what we're about to block + // Populate fields if there is a block that is not an autoblock; if it is a range + // block, only populate the fields if the range is the same as $this->target + if ( $block instanceof Block && $block->getType() !== Block::TYPE_AUTO + && ( $this->type != Block::TYPE_RANGE + || $block->getTarget() == $this->target ) ) { $fields['HardBlock']['default'] = $block->isHardblock(); $fields['CreateAccount']['default'] = $block->isCreateAccountBlocked(); @@ -363,7 +365,7 @@ class SpecialBlock extends FormSpecialPage { } if ( isset( $fields['HideUser'] ) ) { - $fields['HideUser']['default'] = $block->mHideName; + $fields['HideUser']['default'] = $block->getHideName(); } if ( isset( $fields['DisableUTEdit'] ) ) { @@ -372,8 +374,8 @@ class SpecialBlock extends FormSpecialPage { // If the username was hidden (ipb_deleted == 1), don't show the reason // unless this user also has rights to hideuser: T37839 - if ( !$block->mHideName || $this->getUser()->isAllowed( 'hideuser' ) ) { - $fields['Reason']['default'] = $block->mReason; + if ( !$block->getHideName() || $this->getUser()->isAllowed( 'hideuser' ) ) { + $fields['Reason']['default'] = $block->getReason(); } else { $fields['Reason']['default'] = ''; } @@ -389,10 +391,10 @@ class SpecialBlock extends FormSpecialPage { $fields['Confirm']['default'] = 1; } - if ( $block->mExpiry == 'infinity' ) { + if ( $block->getExpiry() == 'infinity' ) { $fields['Expiry']['default'] = 'infinite'; } else { - $fields['Expiry']['default'] = wfTimestamp( TS_RFC2822, $block->mExpiry ); + $fields['Expiry']['default'] = wfTimestamp( TS_RFC2822, $block->getExpiry() ); } $fields['BlockId']['default'] = $block->getId(); @@ -873,14 +875,14 @@ class SpecialBlock extends FormSpecialPage { $block = new Block(); $block->setTarget( $target ); $block->setBlocker( $performer ); - $block->mReason = $data['Reason'][0]; - $block->mExpiry = $expiryTime; + $block->setReason( $data['Reason'][0] ); + $block->setExpiry( $expiryTime ); $block->isCreateAccountBlocked( $data['CreateAccount'] ); $block->isUsertalkEditAllowed( !$wgBlockAllowsUTEdit || !$data['DisableUTEdit'] ); $block->isEmailBlocked( $data['DisableEmail'] ); $block->isHardblock( $data['HardBlock'] ); $block->isAutoblocking( $data['AutoBlock'] ); - $block->mHideName = $data['HideUser']; + $block->setHideName( $data['HideUser'] ); if ( $isPartialBlock ) { $block->isSitewide( false ); @@ -939,19 +941,19 @@ class SpecialBlock extends FormSpecialPage { } # If the name was hidden and the blocking user cannot hide # names, then don't allow any block changes... - if ( $currentBlock->mHideName && !$performer->isAllowed( 'hideuser' ) ) { + if ( $currentBlock->getHideName() && !$performer->isAllowed( 'hideuser' ) ) { return [ 'cant-see-hidden-user' ]; } $priorBlock = clone $currentBlock; $currentBlock->isHardblock( $block->isHardblock() ); $currentBlock->isCreateAccountBlocked( $block->isCreateAccountBlocked() ); - $currentBlock->mExpiry = $block->mExpiry; + $currentBlock->setExpiry( $block->getExpiry() ); $currentBlock->isAutoblocking( $block->isAutoblocking() ); - $currentBlock->mHideName = $block->mHideName; + $currentBlock->setHideName( $block->getHideName() ); $currentBlock->isEmailBlocked( $block->isEmailBlocked() ); $currentBlock->isUsertalkEditAllowed( $block->isUsertalkEditAllowed() ); - $currentBlock->mReason = $block->mReason; + $currentBlock->setReason( $block->getReason() ); if ( $enablePartialBlocks ) { // Maintain the sitewide status. If partial blocks is not enabled, @@ -970,12 +972,12 @@ class SpecialBlock extends FormSpecialPage { $logaction = 'reblock'; # Unset _deleted fields if requested - if ( $currentBlock->mHideName && !$data['HideUser'] ) { + if ( $currentBlock->getHideName() && !$data['HideUser'] ) { RevisionDeleteUser::unsuppressUserName( $target, $userId ); } # If hiding/unhiding a name, this should go in the private logs - if ( (bool)$currentBlock->mHideName ) { + if ( (bool)$currentBlock->getHideName() ) { $data['HideUser'] = true; } diff --git a/includes/specials/SpecialUnblock.php b/includes/specials/SpecialUnblock.php index 632415cc1d..a04fe4e16d 100644 --- a/includes/specials/SpecialUnblock.php +++ b/includes/specials/SpecialUnblock.php @@ -205,7 +205,7 @@ class SpecialUnblock extends SpecialPage { # If the name was hidden and the blocking user cannot hide # names, then don't allow any block removals... - if ( !$performer->isAllowed( 'hideuser' ) && $block->mHideName ) { + if ( !$performer->isAllowed( 'hideuser' ) && $block->getHideName() ) { return [ 'unblock-hideuser' ]; } @@ -222,7 +222,7 @@ class SpecialUnblock extends SpecialPage { Hooks::run( 'UnblockUserComplete', [ $block, $performer ] ); # Unset _deleted fields as needed - if ( $block->mHideName ) { + if ( $block->getHideName() ) { # Something is deeply FUBAR if this is not a User object, but who knows? $id = $block->getTarget() instanceof User ? $block->getTarget()->getId() diff --git a/includes/user/User.php b/includes/user/User.php index 1c5c9e8a40..44df557a4d 100644 --- a/includes/user/User.php +++ b/includes/user/User.php @@ -1896,7 +1896,7 @@ class User implements IDBAccessObject, UserIdentity { if ( $block instanceof Block ) { # Mangle the reason to alert the user that the block # originated from matching the X-Forwarded-For header. - $block->mReason = wfMessage( 'xffblockreason', $block->mReason )->plain(); + $block->setReason( wfMessage( 'xffblockreason', $block->getReason() )->plain() ); } } @@ -1918,8 +1918,8 @@ class User implements IDBAccessObject, UserIdentity { wfDebug( __METHOD__ . ": Found block.\n" ); $this->mBlock = $block; $this->mBlockedby = $block->getByName(); - $this->mBlockreason = $block->mReason; - $this->mHideName = $block->mHideName; + $this->mBlockreason = $block->getReason(); + $this->mHideName = $block->getHideName(); $this->mAllowUsertalk = $block->isUsertalkEditAllowed(); } else { $this->mBlock = null; diff --git a/tests/phpunit/includes/BlockTest.php b/tests/phpunit/includes/BlockTest.php index 50a4e2fee0..7874688e7b 100644 --- a/tests/phpunit/includes/BlockTest.php +++ b/tests/phpunit/includes/BlockTest.php @@ -94,7 +94,7 @@ class BlockTest extends MediaWikiLangTestCase { $madeAt = wfTimestamp( TS_MW ); // delta to stop one-off errors when things happen to go over a second mark. - $delta = abs( $madeAt - $block->mTimestamp ); + $delta = abs( $madeAt - $block->getTimestamp() ); $this->assertLessThan( 2, $delta, @@ -302,8 +302,8 @@ class BlockTest extends MediaWikiLangTestCase { $block = new Block(); $block->setTarget( $target ); $block->setBlocker( $blocker ); - $block->mReason = $insBlock['desc']; - $block->mExpiry = 'infinity'; + $block->setReason( $insBlock['desc'] ); + $block->setExpiry( 'infinity' ); $block->isCreateAccountBlocked( $insBlock['ACDisable'] ); $block->isHardblock( $insBlock['isHardblock'] ); $block->isAutoblocking( $insBlock['isAutoBlocking'] ); @@ -369,7 +369,9 @@ class BlockTest extends MediaWikiLangTestCase { $xffblocks = Block::getBlocksForIPList( $list, true ); $this->assertEquals( $exCount, count( $xffblocks ), 'Number of blocks for ' . $xff ); $block = Block::chooseBlock( $xffblocks, $list ); - $this->assertEquals( $exResult, $block->mReason, 'Correct block type for XFF header ' . $xff ); + $this->assertEquals( + $exResult, $block->getReason(), 'Correct block type for XFF header ' . $xff + ); } /** diff --git a/tests/phpunit/includes/TitlePermissionTest.php b/tests/phpunit/includes/TitlePermissionTest.php index 3d8c6439bf..13def702a2 100644 --- a/tests/phpunit/includes/TitlePermissionTest.php +++ b/tests/phpunit/includes/TitlePermissionTest.php @@ -923,7 +923,7 @@ class TitlePermissionTest extends MediaWikiLangTestCase { 'auto' => true, 'expiry' => 0 ] ); - $this->user->mBlock->mTimestamp = 0; + $this->user->mBlock->setTimestamp( 0 ); $this->assertEquals( [ [ 'autoblockedtext', '[[User:Useruser|Useruser]]', 'no reason given', '127.0.0.1', 'Useruser', null, 'infinite', '127.0.8.1', diff --git a/tests/phpunit/includes/api/ApiBlockTest.php b/tests/phpunit/includes/api/ApiBlockTest.php index 01455edcaf..7274a546ee 100644 --- a/tests/phpunit/includes/api/ApiBlockTest.php +++ b/tests/phpunit/includes/api/ApiBlockTest.php @@ -62,7 +62,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->mReason ); + $this->assertSame( 'Some reason', $block->getReason() ); return $ret; } diff --git a/tests/phpunit/includes/specials/SpecialBlockTest.php b/tests/phpunit/includes/specials/SpecialBlockTest.php index 91f12f4f46..182ca0d043 100644 --- a/tests/phpunit/includes/specials/SpecialBlockTest.php +++ b/tests/phpunit/includes/specials/SpecialBlockTest.php @@ -91,7 +91,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->mReason, $fields['Reason']['default'] ); + $this->assertSame( $block->getReason(), $fields['Reason']['default'] ); $this->assertSame( 'infinite', $fields['Expiry']['default'] ); } @@ -179,7 +179,7 @@ class SpecialBlockTest extends SpecialPageTestBase { $this->assertTrue( $result ); $block = Block::newFromTarget( $badActor ); - $this->assertSame( $reason, $block->mReason ); + $this->assertSame( $reason, $block->getReason() ); $this->assertSame( $expiry, $block->getExpiry() ); } @@ -228,7 +228,7 @@ class SpecialBlockTest extends SpecialPageTestBase { $this->assertTrue( $result ); $block = Block::newFromTarget( $badActor ); - $this->assertSame( $reason, $block->mReason ); + $this->assertSame( $reason, $block->getReason() ); $this->assertSame( $expiry, $block->getExpiry() ); $this->assertSame( '1', $block->isAutoblocking() ); } @@ -277,7 +277,7 @@ class SpecialBlockTest extends SpecialPageTestBase { $this->assertTrue( $result ); $block = Block::newFromTarget( $badActor ); - $this->assertSame( $reason, $block->mReason ); + $this->assertSame( $reason, $block->getReason() ); $this->assertSame( $expiry, $block->getExpiry() ); $this->assertCount( 2, $block->getRestrictions() ); $this->assertTrue( BlockRestriction::equals( $block->getRestrictions(), [ @@ -331,7 +331,7 @@ class SpecialBlockTest extends SpecialPageTestBase { $this->assertTrue( $result ); $block = Block::newFromTarget( $badActor ); - $this->assertSame( $reason, $block->mReason ); + $this->assertSame( $reason, $block->getReason() ); $this->assertSame( $expiry, $block->getExpiry() ); $this->assertFalse( $block->isSitewide() ); $this->assertCount( 2, $block->getRestrictions() ); @@ -347,7 +347,7 @@ class SpecialBlockTest extends SpecialPageTestBase { $this->assertTrue( $result ); $block = Block::newFromTarget( $badActor ); - $this->assertSame( $reason, $block->mReason ); + $this->assertSame( $reason, $block->getReason() ); $this->assertSame( $expiry, $block->getExpiry() ); $this->assertFalse( $block->isSitewide() ); $this->assertCount( 1, $block->getRestrictions() ); @@ -362,7 +362,7 @@ class SpecialBlockTest extends SpecialPageTestBase { $this->assertTrue( $result ); $block = Block::newFromTarget( $badActor ); - $this->assertSame( $reason, $block->mReason ); + $this->assertSame( $reason, $block->getReason() ); $this->assertSame( $expiry, $block->getExpiry() ); $this->assertFalse( $block->isSitewide() ); $this->assertCount( 0, $block->getRestrictions() ); @@ -374,7 +374,7 @@ class SpecialBlockTest extends SpecialPageTestBase { $this->assertTrue( $result ); $block = Block::newFromTarget( $badActor ); - $this->assertSame( $reason, $block->mReason ); + $this->assertSame( $reason, $block->getReason() ); $this->assertSame( $expiry, $block->getExpiry() ); $this->assertTrue( $block->isSitewide() ); $this->assertCount( 0, $block->getRestrictions() ); diff --git a/tests/phpunit/includes/user/UserTest.php b/tests/phpunit/includes/user/UserTest.php index 642e8b4025..f84be3f1c4 100644 --- a/tests/phpunit/includes/user/UserTest.php +++ b/tests/phpunit/includes/user/UserTest.php @@ -757,7 +757,7 @@ class UserTest extends MediaWikiTestCase { // 3. Change the block's expiry (to 2 hours), and the cookie's should be changed also. $newExpiry = wfTimestamp() + 2 * 60 * 60; - $block->mExpiry = wfTimestamp( TS_MW, $newExpiry ); + $block->setExpiry( wfTimestamp( TS_MW, $newExpiry ) ); $block->update(); $user2tmp = $this->getTestUser()->getUser(); $request2 = new FauxRequest(); -- 2.20.1