/**
* 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 );
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 );
}
/**
// than getting the msg raw and explode()'ing it.
$cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
$lines = $cache->getWithSetCallback(
- $cache->makeKey( 'ipb', 'autoblock', 'whitelist' ),
+ $cache->makeKey( 'ip-autoblock', 'whitelist' ),
$cache::TTL_DAY,
function ( $curValue, &$ttl, array &$setOpts ) {
$setOpts += Database::getCacheSetOptions( wfGetDB( DB_REPLICA ) );
* 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
self::TYPE_IP
];
- } elseif ( IP::isValidBlock( $target ) ) {
+ } elseif ( IP::isValidRange( $target ) ) {
# Can't create a User from an IP range
return [ IP::sanitizeRange( $target ), self::TYPE_RANGE ];
}
* 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() {