X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FBlock.php;h=d1e78bb6cf791dbdfe443d1d65e2cc812d229bbd;hb=eed3cf7747dd9d183b62f2550c741584093e6373;hp=40095f18b88c22dd61140ea64bd4e03aa608321f;hpb=eb779496a61a51f0d2d12a8a7ff0d12d51b89204;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/Block.php b/includes/Block.php index 40095f18b8..d1e78bb6cf 100644 --- a/includes/Block.php +++ b/includes/Block.php @@ -183,11 +183,14 @@ class Block { */ public static function newFromID( $id ) { $dbr = wfGetDB( DB_REPLICA ); + $blockQuery = self::getQueryInfo(); $res = $dbr->selectRow( - 'ipblocks', - self::selectFields(), + $blockQuery['tables'], + $blockQuery['fields'], [ 'ipb_id' => $id ], - __METHOD__ + __METHOD__, + [], + $blockQuery['joins'] ); if ( $res ) { return self::newFromRow( $res ); @@ -199,11 +202,11 @@ 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(). + * @deprecated since 1.31, use self::getQueryInfo() instead. * @return array */ public static function selectFields() { + wfDeprecated( __METHOD__, '1.31' ); return [ 'ipb_id', 'ipb_address', @@ -222,6 +225,39 @@ class Block { ] + CommentStore::newKey( 'ipb_reason' )->getFields(); } + /** + * Return the tables, fields, and join conditions to be selected to create + * a new block object. + * @since 1.31 + * @return array With three keys: + * - tables: (string[]) to include in the `$table` to `IDatabase->select()` + * - fields: (string[]) to include in the `$vars` to `IDatabase->select()` + * - joins: (array) to include in the `$join_conds` to `IDatabase->select()` + */ + public static function getQueryInfo() { + $commentQuery = CommentStore::newKey( 'ipb_reason' )->getJoin(); + return [ + 'tables' => [ 'ipblocks' ] + $commentQuery['tables'], + 'fields' => [ + 'ipb_id', + 'ipb_address', + 'ipb_by', + 'ipb_by_text', + 'ipb_timestamp', + 'ipb_auto', + 'ipb_anon_only', + 'ipb_create_account', + 'ipb_enable_autoblock', + 'ipb_expiry', + 'ipb_deleted', + 'ipb_block_email', + 'ipb_allow_usertalk', + 'ipb_parent_block_id', + ] + $commentQuery['fields'], + 'joins' => $commentQuery['joins'], + ]; + } + /** * Check if two blocks are effectively equal. Doesn't check irrelevant things like * the blocking user or the block timestamp, only things which affect the blocked user @@ -295,7 +331,10 @@ class Block { } } - $res = $db->select( 'ipblocks', self::selectFields(), $conds, __METHOD__ ); + $blockQuery = self::getQueryInfo(); + $res = $db->select( + $blockQuery['tables'], $blockQuery['fields'], $conds, __METHOD__, [], $blockQuery['joins'] + ); # This result could contain a block on the user, a block on the IP, and a russian-doll # set of rangeblocks. We want to choose the most specific one, so keep a leader board. @@ -422,7 +461,7 @@ class Block { $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() + // Legacy because $row may have come from self::selectFields() ->getCommentLegacy( $db, $row )->text; $this->isHardblock( !$row->ipb_anon_only ); @@ -709,7 +748,7 @@ class Block { // 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 ) ); @@ -1187,14 +1226,14 @@ class Block { if ( !$isAnon ) { $conds = [ $conds, 'ipb_anon_only' => 0 ]; } - $selectFields = array_merge( - [ 'ipb_range_start', 'ipb_range_end' ], - self::selectFields() - ); - $rows = $db->select( 'ipblocks', - $selectFields, + $blockQuery = self::getQueryInfo(); + $rows = $db->select( + $blockQuery['tables'], + array_merge( [ 'ipb_range_start', 'ipb_range_end' ], $blockQuery['fields'] ), $conds, - __METHOD__ + __METHOD__, + [], + $blockQuery['joins'] ); $blocks = []; @@ -1329,7 +1368,7 @@ class Block { * 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 @@ -1396,7 +1435,7 @@ class Block { * 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() {