API: Use parenthesized join in ApiQueryBase::showHiddenUsersAddBlockInfo
authorBrad Jorsch <bjorsch@wikimedia.org>
Mon, 3 Dec 2018 14:29:50 +0000 (09:29 -0500)
committerTim Starling <tstarling@wikimedia.org>
Wed, 12 Dec 2018 01:57:13 +0000 (01:57 +0000)
The query is LEFT JOINing ipblocks, so we need to properly scope the new
JOINs with the comment and actor tables to get the block reason and
by-actor.

Bug: T210937
Change-Id: I230a4ab78e3ba6e83008b0466eeca8d40013ba3d

includes/api/ApiQueryBase.php

index b243cee..d9fe50b 100644 (file)
@@ -464,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' );