X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fapi%2FApiQueryBase.php;h=d9fe50b8d6051e143164424128f2fc7fe866a784;hb=2a6469dbd1aaa7656bb7b18031da38d952af268f;hp=fe01f03367cd1cbff3cf5423b0c09e9b065a3e9e;hpb=d2b7662bbae2b6ff6599e72eb449cb2ce444e877;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/api/ApiQueryBase.php b/includes/api/ApiQueryBase.php index fe01f03367..d9fe50b8d6 100644 --- a/includes/api/ApiQueryBase.php +++ b/includes/api/ApiQueryBase.php @@ -263,6 +263,30 @@ abstract class ApiQueryBase extends ApiBase { } } + /** + * Like addWhereFld for an integer list of IDs + * @since 1.33 + * @param string $table Table name + * @param string $field Field name + * @param int[] $ids IDs + * @return int Count of IDs actually included + */ + protected function addWhereIDsFld( $table, $field, $ids ) { + // Use count() to its full documented capabilities to simultaneously + // test for null, empty array or empty countable object + if ( count( $ids ) ) { + $ids = $this->filterIDs( [ [ $table, $field ] ], $ids ); + + if ( !count( $ids ) ) { + // Return nothing, no IDs are valid + $this->where[] = '0 = 1'; + } else { + $this->where[$field] = $ids; + } + } + return count( $ids ); + } + /** * Add a WHERE clause corresponding to a range, and an ORDER BY * clause to sort in the right direction @@ -440,32 +464,31 @@ abstract class ApiQueryBase extends ApiBase { public function showHiddenUsersAddBlockInfo( $showBlockInfo ) { $db = $this->getDB(); - $this->addTables( 'ipblocks' ); - $this->addJoinConds( [ - 'ipblocks' => [ 'LEFT JOIN', [ + $tables = [ 'ipblocks' ]; + $fields = [ 'ipb_deleted' ]; + $joinConds = [ + 'blk' => [ 'LEFT JOIN', [ 'ipb_user=user_id', 'ipb_expiry > ' . $db->addQuotes( $db->timestamp() ), ] ], - ] ); - - $this->addFields( 'ipb_deleted' ); + ]; if ( $showBlockInfo ) { - $this->addFields( [ + $actorQuery = ActorMigration::newMigration()->getJoin( 'ipb_by' ); + $commentQuery = CommentStore::getStore()->getJoin( 'ipb_reason' ); + $tables += $actorQuery['tables'] + $commentQuery['tables']; + $joinConds += $actorQuery['joins'] + $commentQuery['joins']; + $fields = array_merge( $fields, [ 'ipb_id', 'ipb_expiry', 'ipb_timestamp' - ] ); - $actorQuery = ActorMigration::newMigration()->getJoin( 'ipb_by' ); - $this->addTables( $actorQuery['tables'] ); - $this->addFields( $actorQuery['fields'] ); - $this->addJoinConds( $actorQuery['joins'] ); - $commentQuery = CommentStore::getStore()->getJoin( 'ipb_reason' ); - $this->addTables( $commentQuery['tables'] ); - $this->addFields( $commentQuery['fields'] ); - $this->addJoinConds( $commentQuery['joins'] ); + ], $actorQuery['fields'], $commentQuery['fields'] ); } + $this->addTables( [ 'blk' => $tables ] ); + $this->addFields( $fields ); + $this->addJoinConds( $joinConds ); + // Don't show hidden names if ( !$this->getUser()->isAllowed( 'hideuser' ) ) { $this->addWhere( 'ipb_deleted = 0 OR ipb_deleted IS NULL' );