public $mParentBlockId;
/** @var int */
- protected $mId;
+ private $mId;
/** @var bool */
- protected $mFromMaster;
+ private $mFromMaster;
/** @var bool */
- protected $mBlockEmail;
+ private $mBlockEmail;
/** @var bool */
- protected $mDisableUsertalk;
+ private $mDisableUsertalk;
/** @var bool */
- protected $mCreateAccount;
+ private $mCreateAccount;
/** @var User|string */
- protected $target;
+ private $target;
/** @var int Hack for foreign blocking (CentralAuth) */
- protected $forcedTargetID;
+ private $forcedTargetID;
/** @var int Block::TYPE_ constant. Can only be USER, IP or RANGE internally */
- protected $type;
+ private $type;
/** @var User */
- protected $blocker;
+ private $blocker;
/** @var bool */
- protected $isHardblock;
+ private $isHardblock;
/** @var bool */
- protected $isAutoblocking;
+ private $isAutoblocking;
/** @var string|null */
- protected $systemBlockType;
+ private $systemBlockType;
# TYPE constants
const TYPE_USER = 1;
/**
* Return the list of ipblocks fields that should be selected to create
* a new block.
+ * @todo Deprecate this in favor of a method that returns tables and joins
+ * as well, and use CommentStore::getJoin().
* @return array
*/
public static function selectFields() {
'ipb_address',
'ipb_by',
'ipb_by_text',
- 'ipb_reason',
'ipb_timestamp',
'ipb_auto',
'ipb_anon_only',
'ipb_block_email',
'ipb_allow_usertalk',
'ipb_parent_block_id',
- ];
+ ] + CommentStore::newKey( 'ipb_reason' )->getFields();
}
/**
$this->setBlocker( $row->ipb_by_text );
}
- $this->mReason = $row->ipb_reason;
$this->mTimestamp = wfTimestamp( TS_MW, $row->ipb_timestamp );
$this->mAuto = $row->ipb_auto;
$this->mHideName = $row->ipb_deleted;
$this->mParentBlockId = $row->ipb_parent_block_id;
// I wish I didn't have to do this
- $this->mExpiry = wfGetDB( DB_REPLICA )->decodeExpiry( $row->ipb_expiry );
+ $db = wfGetDB( DB_REPLICA );
+ $this->mExpiry = $db->decodeExpiry( $row->ipb_expiry );
+ $this->mReason = CommentStore::newKey( 'ipb_reason' )
+ // Legacy because $row probably came from self::selectFields()
+ ->getCommentLegacy( $db, $row )->text;
$this->isHardblock( !$row->ipb_anon_only );
$this->isAutoblocking( $row->ipb_enable_autoblock );
# Periodic purge via commit hooks
if ( mt_rand( 0, 9 ) == 0 ) {
- Block::purgeExpired();
+ self::purgeExpired();
}
- $row = $this->getDatabaseArray();
- $row['ipb_id'] = $dbw->nextSequenceValue( "ipblocks_ipb_id_seq" );
+ $row = $this->getDatabaseArray( $dbw );
$dbw->insert( 'ipblocks', $row, __METHOD__, [ 'IGNORE' ] );
$affected = $dbw->affectedRows();
// update corresponding autoblock(s) (T50813)
$dbw->update(
'ipblocks',
- $this->getAutoblockUpdateArray(),
+ $this->getAutoblockUpdateArray( $dbw ),
[ 'ipb_parent_block_id' => $this->getId() ],
__METHOD__
);
/**
* Get an array suitable for passing to $dbw->insert() or $dbw->update()
- * @param IDatabase $db
+ * @param IDatabase $dbw
* @return array
*/
- protected function getDatabaseArray( $db = null ) {
- if ( !$db ) {
- $db = wfGetDB( DB_REPLICA );
- }
- $expiry = $db->encodeExpiry( $this->mExpiry );
+ protected function getDatabaseArray( IDatabase $dbw ) {
+ $expiry = $dbw->encodeExpiry( $this->mExpiry );
if ( $this->forcedTargetID ) {
$uid = $this->forcedTargetID;
'ipb_user' => $uid,
'ipb_by' => $this->getBy(),
'ipb_by_text' => $this->getByName(),
- 'ipb_reason' => $this->mReason,
- 'ipb_timestamp' => $db->timestamp( $this->mTimestamp ),
+ 'ipb_timestamp' => $dbw->timestamp( $this->mTimestamp ),
'ipb_auto' => $this->mAuto,
'ipb_anon_only' => !$this->isHardblock(),
'ipb_create_account' => $this->prevents( 'createaccount' ),
'ipb_block_email' => $this->prevents( 'sendemail' ),
'ipb_allow_usertalk' => !$this->prevents( 'editownusertalk' ),
'ipb_parent_block_id' => $this->mParentBlockId
- ];
+ ] + CommentStore::newKey( 'ipb_reason' )->insert( $dbw, $this->mReason );
return $a;
}
/**
+ * @param IDatabase $dbw
* @return array
*/
- protected function getAutoblockUpdateArray() {
+ protected function getAutoblockUpdateArray( IDatabase $dbw ) {
return [
'ipb_by' => $this->getBy(),
'ipb_by_text' => $this->getByName(),
- 'ipb_reason' => $this->mReason,
'ipb_create_account' => $this->prevents( 'createaccount' ),
'ipb_deleted' => (int)$this->mHideName, // typecast required for SQLite
'ipb_allow_usertalk' => !$this->prevents( 'editownusertalk' ),
- ];
+ ] + CommentStore::newKey( 'ipb_reason' )->insert( $dbw, $this->mReason );
}
/**
# It's okay to autoblock. Go ahead and insert/update the block...
# Do not add a *new* block if the IP is already blocked.
- $ipblock = Block::newFromTarget( $autoblockIP );
+ $ipblock = self::newFromTarget( $autoblockIP );
if ( $ipblock ) {
# 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 > Block::getAutoblockExpiry( $ipblock->mTimestamp )
+ $this->mExpiry > self::getAutoblockExpiry( $ipblock->mTimestamp )
) {
# Reset block timestamp to now and its expiry to
# $wgAutoblockExpiry in the future
if ( $this->mExpiry == 'infinity' ) {
# Original block was indefinite, start an autoblock now
- $autoblock->mExpiry = Block::getAutoblockExpiry( $timestamp );
+ $autoblock->mExpiry = 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, Block::getAutoblockExpiry( $timestamp ) );
+ $autoblock->mExpiry = min( $this->mExpiry, self::getAutoblockExpiry( $timestamp ) );
}
# Insert the block...
public function updateTimestamp() {
if ( $this->mAuto ) {
$this->mTimestamp = wfTimestamp();
- $this->mExpiry = Block::getAutoblockExpiry( $this->mTimestamp );
+ $this->mExpiry = self::getAutoblockExpiry( $this->mTimestamp );
$dbw = wfGetDB( DB_MASTER );
$dbw->update( 'ipblocks',
/**
* Get the system block type, if any
+ * @since 1.29
* @return string|null
*/
public function getSystemBlockType() {
*/
public static function newFromTarget( $specificTarget, $vagueTarget = null, $fromMaster = false ) {
list( $target, $type ) = self::parseTarget( $specificTarget );
- if ( $type == Block::TYPE_ID || $type == Block::TYPE_AUTO ) {
- return Block::newFromID( $target );
+ if ( $type == self::TYPE_ID || $type == self::TYPE_AUTO ) {
+ return self::newFromID( $target );
} elseif ( $target === null && $vagueTarget == '' ) {
# We're not going to find anything useful here
} elseif ( in_array(
$type,
- [ Block::TYPE_USER, Block::TYPE_IP, Block::TYPE_RANGE, null ] )
+ [ self::TYPE_USER, self::TYPE_IP, self::TYPE_RANGE, null ] )
) {
$block = new Block();
$block->fromMaster( $fromMaster );
}
$selectFields = array_merge(
[ 'ipb_range_start', 'ipb_range_end' ],
- Block::selectFields()
+ self::selectFields()
);
$rows = $db->select( 'ipblocks',
$selectFields,
* which in turn gives User::getName().
*
* @param string|int|User|null $target
- * @return array( User|String|null, Block::TYPE_ constant|null )
+ * @return array [ User|String|null, Block::TYPE_ constant|null ]
*/
public static function parseTarget( $target ) {
# We may have been through this before
# off validation checking (which would exclude IP addresses)
return [
User::newFromName( IP::sanitizeIP( $target ), false ),
- Block::TYPE_IP
+ self::TYPE_IP
];
- } elseif ( IP::isValidBlock( $target ) ) {
+ } elseif ( IP::isValidRange( $target ) ) {
# Can't create a User from an IP range
- return [ IP::sanitizeRange( $target ), Block::TYPE_RANGE ];
+ return [ IP::sanitizeRange( $target ), self::TYPE_RANGE ];
}
# Consider the possibility that this is not a username at all
# Note that since numbers are valid usernames, a $target of "12345" will be
# considered a User. If you want to pass a block ID, prepend a hash "#12345",
# since hash characters are not valid in usernames or titles generally.
- return [ $userObj, Block::TYPE_USER ];
+ return [ $userObj, self::TYPE_USER ];
} elseif ( preg_match( '/^#\d+$/', $target ) ) {
# Autoblock reference in the form "#12345"
- return [ substr( $target, 1 ), Block::TYPE_AUTO ];
+ return [ substr( $target, 1 ), self::TYPE_AUTO ];
} else {
# WTF?
* Get the target and target type for this particular Block. Note that for autoblocks,
* this returns the unredacted name; frontend functions need to call $block->getRedactedName()
* in this situation.
- * @return array( User|String, Block::TYPE_ constant )
+ * @return array [ User|String, Block::TYPE_ constant ]
* @todo FIXME: This should be an integral part of the Block member variables
*/
public function getTargetAndType() {
* Set the 'BlockID' cookie to this block's ID and expiry time. The cookie's expiry will be
* the same as the block's, to a maximum of 24 hours.
*
+ * @since 1.29
+ *
* @param WebResponse $response The response on which to set the cookie.
*/
public function setCookie( WebResponse $response ) {
/**
* Unset the 'BlockID' cookie.
*
+ * @since 1.29
+ *
* @param WebResponse $response The response on which to unset the cookie.
*/
public static function clearCookie( WebResponse $response ) {
* Get the BlockID cookie's value for this block. This is usually the block ID concatenated
* with an HMAC in order to avoid spoofing (T152951), but if wgSecretKey is not set will just
* be the block ID.
+ *
+ * @since 1.29
+ *
* @return string The block ID, probably concatenated with "!" and the HMAC.
*/
public function getCookieValue() {
return $id;
}
$hmac = MWCryptHash::hmac( $id, $secretKey, false );
- $cookieValue = $id . '!' . $hmac;
+ $cookieValue = $id . '!' . $hmac;
return $cookieValue;
}
/**
* Get the stored ID from the 'BlockID' cookie. The cookie's value is usually a combination of
* the ID and a HMAC (see Block::setCookie), but will sometimes only be the ID.
+ *
+ * @since 1.29
+ *
* @param string $cookieValue The string in which to find the ID.
- * @return integer|null The block ID, or null if the HMAC is present and invalid.
+ *
+ * @return int|null The block ID, or null if the HMAC is present and invalid.
*/
public static function getIdFromCookieValue( $cookieValue ) {
// Extract the ID prefix from the cookie value (may be the whole value, if no bang found).