From ab28af877cfd2f114c9558efe4abc14923a02a9b Mon Sep 17 00:00:00 2001 From: Sam Reed Date: Sat, 30 Apr 2011 23:18:34 +0000 Subject: [PATCH] Followup r85884 Fixup the APIs strange way of doing table aliases on a join.... Only used in very few places --- includes/api/ApiQueryAllUsers.php | 6 ++---- includes/api/ApiQueryBase.php | 15 +++------------ includes/api/ApiQueryWatchlist.php | 2 -- includes/db/Database.php | 2 +- 4 files changed, 6 insertions(+), 19 deletions(-) diff --git a/includes/api/ApiQueryAllUsers.php b/includes/api/ApiQueryAllUsers.php index 03634367c3..7552da9815 100644 --- a/includes/api/ApiQueryAllUsers.php +++ b/includes/api/ApiQueryAllUsers.php @@ -89,8 +89,7 @@ class ApiQueryAllUsers extends ApiQueryBase { $useIndex = false; // Filter only users that belong to a given group $this->addTables( 'user_groups', 'ug1' ); - $ug1 = $this->getAliasedName( 'user_groups', 'ug1' ); - $this->addJoinConds( array( $ug1 => array( 'INNER JOIN', array( 'ug1.ug_user=user_id', + $this->addJoinConds( array( 'ug1' => array( 'INNER JOIN', array( 'ug1.ug_user=user_id', 'ug1.ug_group' => $params['group'] ) ) ) ); } @@ -107,8 +106,7 @@ class ApiQueryAllUsers extends ApiQueryBase { $sqlLimit = $limit + $groupCount + 1; $this->addTables( 'user_groups', 'ug2' ); - $tname = $this->getAliasedName( 'user_groups', 'ug2' ); - $this->addJoinConds( array( $tname => array( 'LEFT JOIN', 'ug2.ug_user=user_id' ) ) ); + $this->addJoinConds( array( 'ug2' => array( 'LEFT JOIN', 'ug2.ug_user=user_id' ) ) ); $this->addFields( 'ug2.ug_group ug_group2' ); } else { $sqlLimit = $limit + 1; diff --git a/includes/api/ApiQueryBase.php b/includes/api/ApiQueryBase.php index c9c2273f5a..3812ba1dad 100644 --- a/includes/api/ApiQueryBase.php +++ b/includes/api/ApiQueryBase.php @@ -84,22 +84,13 @@ abstract class ApiQueryBase extends ApiBase { $this->tables = array_merge( $this->tables, $tables ); } else { if ( !is_null( $alias ) ) { - $tables = $this->getAliasedName( $tables, $alias ); + $this->tables[$alias] = $tables; + } else { + $this->tables[] = $tables; } - $this->tables[] = $tables; } } - /** - * Get the SQL for a table name with alias - * @param $table string Table name - * @param $alias string Alias - * @return string SQL - */ - protected function getAliasedName( $table, $alias ) { - return $this->getDB()->tableName( $table ) . ' ' . $alias; - } - /** * Add a set of JOIN conditions to the internal array * diff --git a/includes/api/ApiQueryWatchlist.php b/includes/api/ApiQueryWatchlist.php index 17e8e0c204..d7bc60bbdb 100644 --- a/includes/api/ApiQueryWatchlist.php +++ b/includes/api/ApiQueryWatchlist.php @@ -179,8 +179,6 @@ class ApiQueryWatchlist extends ApiQueryGeneratorBase { $this->addWhere( 'rc_user_text != ' . $this->getDB()->addQuotes( $params['excludeuser'] ) ); } - - // This is an index optimization for mysql, as done in the Special:Watchlist page $this->addWhereIf( "rc_timestamp > ''", !isset( $params['start'] ) && !isset( $params['end'] ) && $db->getType() == 'mysql' ); diff --git a/includes/db/Database.php b/includes/db/Database.php index 77f7c7c758..a3d8a3a5cf 100644 --- a/includes/db/Database.php +++ b/includes/db/Database.php @@ -1651,7 +1651,7 @@ abstract class DatabaseBase implements DatabaseType { } /** - * @private + * @return string */ function tableNamesWithUseIndexOrJOIN( $tables, $use_index = array(), $join_conds = array() ) { $ret = array(); -- 2.20.1