X-Git-Url: http://git.cyclocoop.org/%22%20.%20generer_url_ecrire%28%22suivi_revisions%22%29%20.%20%22?a=blobdiff_plain;f=includes%2FBlock.php;h=40095f18b88c22dd61140ea64bd4e03aa608321f;hb=01a10dba5a38101fcd92d4cc9e6684b938af0911;hp=843ea5448431c0dbd974c034256dc5c4cee66503;hpb=eed40548aebee311531108460da91c39296656e9;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/Block.php b/includes/Block.php index 843ea54484..40095f18b8 100644 --- a/includes/Block.php +++ b/includes/Block.php @@ -199,6 +199,8 @@ class Block { /** * 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() { @@ -207,7 +209,6 @@ class Block { 'ipb_address', 'ipb_by', 'ipb_by_text', - 'ipb_reason', 'ipb_timestamp', 'ipb_auto', 'ipb_anon_only', @@ -218,7 +219,7 @@ class Block { 'ipb_block_email', 'ipb_allow_usertalk', 'ipb_parent_block_id', - ]; + ] + CommentStore::newKey( 'ipb_reason' )->getFields(); } /** @@ -411,7 +412,6 @@ class Block { $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; @@ -419,7 +419,11 @@ class Block { $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 ); @@ -488,8 +492,7 @@ class Block { 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(); @@ -558,7 +561,7 @@ class Block { // update corresponding autoblock(s) (T50813) $dbw->update( 'ipblocks', - $this->getAutoblockUpdateArray(), + $this->getAutoblockUpdateArray( $dbw ), [ 'ipb_parent_block_id' => $this->getId() ], __METHOD__ ); @@ -583,14 +586,11 @@ class Block { /** * 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; @@ -603,8 +603,7 @@ class Block { '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' ), @@ -616,23 +615,23 @@ class Block { '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 ); } /** @@ -1354,7 +1353,7 @@ class Block { 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 ]; } @@ -1513,7 +1512,7 @@ class Block { * * @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).