Merge "Add checkDependencies.php"
[lhc/web/wiklou.git] / includes / api / ApiQueryBase.php
index 8630561..2505334 100644 (file)
@@ -157,16 +157,14 @@ abstract class ApiQueryBase extends ApiBase {
         */
        protected function addTables( $tables, $alias = null ) {
                if ( is_array( $tables ) ) {
-                       if ( !is_null( $alias ) ) {
+                       if ( $alias !== null ) {
                                ApiBase::dieDebug( __METHOD__, 'Multiple table aliases not supported' );
                        }
                        $this->tables = array_merge( $this->tables, $tables );
+               } elseif ( $alias !== null ) {
+                       $this->tables[$alias] = $tables;
                } else {
-                       if ( !is_null( $alias ) ) {
-                               $this->tables[$alias] = $tables;
-                       } else {
-                               $this->tables[] = $tables;
-                       }
+                       $this->tables[] = $tables;
                }
        }
 
@@ -263,6 +261,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 ( $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
@@ -401,33 +423,6 @@ abstract class ApiQueryBase extends ApiBase {
                return Hooks::run( 'ApiQueryBaseProcessRow', [ $this, $row, &$data, &$hookData ] );
        }
 
-       /**
-        * @param string|null $query
-        * @param string|null $protocol
-        * @return null|string
-        */
-       public function prepareUrlQuerySearchString( $query = null, $protocol = null ) {
-               $db = $this->getDB();
-               if ( !is_null( $query ) || $query != '' ) {
-                       if ( is_null( $protocol ) ) {
-                               $protocol = 'http://';
-                       }
-
-                       $likeQuery = LinkFilter::makeLikeArray( $query, $protocol );
-                       if ( !$likeQuery ) {
-                               $this->dieWithError( 'apierror-badquery' );
-                       }
-
-                       $likeQuery = LinkFilter::keepOneWildcard( $likeQuery );
-
-                       return 'el_index ' . $db->buildLike( $likeQuery );
-               } elseif ( !is_null( $protocol ) ) {
-                       return 'el_index ' . $db->buildLike( "$protocol", $db->anyString() );
-               }
-
-               return null;
-       }
-
        /**
         * Filters hidden users (where the user doesn't have the right to view them)
         * Also adds relevant block information
@@ -438,32 +433,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' );
@@ -485,7 +479,7 @@ abstract class ApiQueryBase extends ApiBase {
         * @param string $prefix Module prefix
         */
        public static function addTitleInfo( &$arr, $title, $prefix = '' ) {
-               $arr[$prefix . 'ns'] = intval( $title->getNamespace() );
+               $arr[$prefix . 'ns'] = (int)$title->getNamespace();
                $arr[$prefix . 'title'] = $title->getPrefixedText();
        }
 
@@ -499,7 +493,7 @@ abstract class ApiQueryBase extends ApiBase {
                $result = $this->getResult();
                ApiResult::setIndexedTagName( $data, $this->getModulePrefix() );
 
-               return $result->addValue( [ 'query', 'pages', intval( $pageId ) ],
+               return $result->addValue( [ 'query', 'pages', (int)$pageId ],
                        $this->getModuleName(),
                        $data );
        }
@@ -507,7 +501,7 @@ abstract class ApiQueryBase extends ApiBase {
        /**
         * Same as addPageSubItems(), but one element of $data at a time
         * @param int $pageId Page ID
-        * @param array $item Data array à la ApiResult
+        * @param mixed $item Data à la ApiResult
         * @param string|null $elemname XML element name. If null, getModuleName()
         *  is used
         * @return bool Whether the element fit in the result