$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'] );
&& $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.
$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 );
* @return array
*/
protected function getDatabaseArray( IDatabase $dbw ) {
- $expiry = $dbw->encodeExpiry( $this->mExpiry );
+ $expiry = $dbw->encodeExpiry( $this->getExpiry() );
if ( $this->forcedTargetID ) {
$uid = $this->forcedTargetID;
$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(),
'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;
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() );
}
# 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
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...
$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();
}
}
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(),
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
}
/**
- * @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
$link = $blocker;
}
- $reason = $this->mReason;
+ $reason = $this->getReason();
if ( $reason == '' ) {
$reason = $context->msg( 'blockednoreason' )->text();
}
$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() ),
];
}
$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
$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 ) {
if ( $block ) {
$errorParams = [
$block->getTarget(),
- $block->mReason ?: wfMessage( 'blockednoreason' )->text(),
+ $block->getReason() ?: wfMessage( 'blockednoreason' )->text(),
$block->getByName()
];
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() ) {
$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();
}
if ( isset( $fields['HideUser'] ) ) {
- $fields['HideUser']['default'] = $block->mHideName;
+ $fields['HideUser']['default'] = $block->getHideName();
}
if ( isset( $fields['DisableUTEdit'] ) ) {
// 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'] = '';
}
$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();
$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 );
}
# 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,
$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;
}
# 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' ];
}
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()
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() );
}
}
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;
$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,
$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'] );
$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
+ );
}
/**
'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',
$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;
}
$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'] );
}
$this->assertTrue( $result );
$block = Block::newFromTarget( $badActor );
- $this->assertSame( $reason, $block->mReason );
+ $this->assertSame( $reason, $block->getReason() );
$this->assertSame( $expiry, $block->getExpiry() );
}
$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() );
}
$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(), [
$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() );
$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() );
$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() );
$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() );
// 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();