r87178 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r87177‎ | r87178 | r87179 >
Date:23:18, 30 April 2011
Author:reedy
Status:ok
Tags:
Comment:
Followup r85884

Fixup the APIs strange way of doing table aliases on a join....

Only used in very few places
Modified paths:
  • /trunk/phase3/includes/api/ApiQueryAllUsers.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryBase.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryWatchlist.php (modified) (history)
  • /trunk/phase3/includes/db/Database.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/db/Database.php
@@ -1651,7 +1651,7 @@
16521652 }
16531653
16541654 /**
1655 - * @private
 1655+ * @return string
16561656 */
16571657 function tableNamesWithUseIndexOrJOIN( $tables, $use_index = array(), $join_conds = array() ) {
16581658 $ret = array();
Index: trunk/phase3/includes/api/ApiQueryBase.php
@@ -84,23 +84,14 @@
8585 $this->tables = array_merge( $this->tables, $tables );
8686 } else {
8787 if ( !is_null( $alias ) ) {
88 - $tables = $this->getAliasedName( $tables, $alias );
 88+ $this->tables[$alias] = $tables;
 89+ } else {
 90+ $this->tables[] = $tables;
8991 }
90 - $this->tables[] = $tables;
9192 }
9293 }
9394
9495 /**
95 - * Get the SQL for a table name with alias
96 - * @param $table string Table name
97 - * @param $alias string Alias
98 - * @return string SQL
99 - */
100 - protected function getAliasedName( $table, $alias ) {
101 - return $this->getDB()->tableName( $table ) . ' ' . $alias;
102 - }
103 -
104 - /**
10596 * Add a set of JOIN conditions to the internal array
10697 *
10798 * JOIN conditions are formatted as array( tablename => array(jointype,
Index: trunk/phase3/includes/api/ApiQueryWatchlist.php
@@ -179,8 +179,6 @@
180180 $this->addWhere( 'rc_user_text != ' . $this->getDB()->addQuotes( $params['excludeuser'] ) );
181181 }
182182
183 -
184 -
185183 // This is an index optimization for mysql, as done in the Special:Watchlist page
186184 $this->addWhereIf( "rc_timestamp > ''", !isset( $params['start'] ) && !isset( $params['end'] ) && $db->getType() == 'mysql' );
187185
Index: trunk/phase3/includes/api/ApiQueryAllUsers.php
@@ -89,8 +89,7 @@
9090 $useIndex = false;
9191 // Filter only users that belong to a given group
9292 $this->addTables( 'user_groups', 'ug1' );
93 - $ug1 = $this->getAliasedName( 'user_groups', 'ug1' );
94 - $this->addJoinConds( array( $ug1 => array( 'INNER JOIN', array( 'ug1.ug_user=user_id',
 93+ $this->addJoinConds( array( 'ug1' => array( 'INNER JOIN', array( 'ug1.ug_user=user_id',
9594 'ug1.ug_group' => $params['group'] ) ) ) );
9695 }
9796
@@ -107,8 +106,7 @@
108107 $sqlLimit = $limit + $groupCount + 1;
109108
110109 $this->addTables( 'user_groups', 'ug2' );
111 - $tname = $this->getAliasedName( 'user_groups', 'ug2' );
112 - $this->addJoinConds( array( $tname => array( 'LEFT JOIN', 'ug2.ug_user=user_id' ) ) );
 110+ $this->addJoinConds( array( 'ug2' => array( 'LEFT JOIN', 'ug2.ug_user=user_id' ) ) );
113111 $this->addFields( 'ug2.ug_group ug_group2' );
114112 } else {
115113 $sqlLimit = $limit + 1;

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r85884Abstract tableName() by adding new function isQuotedIdentifier() to databases....platonides16:34, 12 April 2011

Status & tagging log