Index: branches/querypage-work2/phase3/includes/db/Database.php |
— | — | @@ -877,7 +877,7 @@ |
878 | 878 | /** |
879 | 879 | * SELECT wrapper |
880 | 880 | * |
881 | | - * @param $table Mixed: Array or string, table name(s) (prefix auto-added) |
| 881 | + * @param $table Mixed: Array or string, table name(s) (prefix auto-added). Array keys are table aliases (optional) |
882 | 882 | * @param $vars Mixed: Array or string, field name(s) to be retrieved |
883 | 883 | * @param $conds Mixed: Array or string, condition(s) for WHERE |
884 | 884 | * @param $fname String: Calling function name (use __METHOD__) for logs/profiling |
— | — | @@ -898,7 +898,7 @@ |
899 | 899 | if ( !empty($join_conds) || ( isset( $options['USE INDEX'] ) && is_array( @$options['USE INDEX'] ) ) ) |
900 | 900 | $from = ' FROM ' . $this->tableNamesWithUseIndexOrJOIN( $table, @$options['USE INDEX'], $join_conds ); |
901 | 901 | else |
902 | | - $from = ' FROM ' . implode( ',', array_map( array( &$this, 'tableName' ), $table ) ); |
| 902 | + $from = ' FROM ' . implode( ',', $this->tableNamesWithAlias( $table ) ); |
903 | 903 | } elseif ($table!='') { |
904 | 904 | if ($table{0}==' ') { |
905 | 905 | $from = ' FROM ' . $table; |
— | — | @@ -1445,6 +1445,35 @@ |
1446 | 1446 | } |
1447 | 1447 | |
1448 | 1448 | /** |
| 1449 | + * Get an aliased table name. |
| 1450 | + * @param $name string Table name, see tableName() |
| 1451 | + * @param $alias string Alias (optional) |
| 1452 | + * @return string SQL name for aliased table. Will not alias a table to its own name |
| 1453 | + */ |
| 1454 | + public function tableNameWithAlias( $name, $alias ) { |
| 1455 | + if ( !$alias || $alias == $name ) { |
| 1456 | + return $this->tableName( $name ); |
| 1457 | + } else { |
| 1458 | + return $this->tableName( $name ) . ' `' . $alias . '`'; |
| 1459 | + } |
| 1460 | + } |
| 1461 | + |
| 1462 | + /** |
| 1463 | + * @param $tables array( [alias] => table ) |
| 1464 | + * @return array of strings, see tableNameWithAlias() |
| 1465 | + */ |
| 1466 | + public function tableNamesWithAlias( $tables ) { |
| 1467 | + $retval = array(); |
| 1468 | + foreach ( $tables as $alias => $table ) { |
| 1469 | + if ( is_numeric( $alias ) ) { |
| 1470 | + $alias = $table; |
| 1471 | + } |
| 1472 | + $retval[] = $this->tableNameWithAlias( $table, $alias ); |
| 1473 | + } |
| 1474 | + return $retval; |
| 1475 | + } |
| 1476 | + |
| 1477 | + /** |
1449 | 1478 | * @private |
1450 | 1479 | */ |
1451 | 1480 | function tableNamesWithUseIndexOrJOIN( $tables, $use_index = array(), $join_conds = array() ) { |
— | — | @@ -1452,25 +1481,29 @@ |
1453 | 1482 | $retJOIN = array(); |
1454 | 1483 | $use_index_safe = is_array($use_index) ? $use_index : array(); |
1455 | 1484 | $join_conds_safe = is_array($join_conds) ? $join_conds : array(); |
1456 | | - foreach ( $tables as $table ) { |
| 1485 | + foreach ( $tables as $alias => $table ) { |
| 1486 | + if ( !is_string( $alias ) ) { |
| 1487 | + // No alias? Set it equal to the table name |
| 1488 | + $alias = $table; |
| 1489 | + } |
1457 | 1490 | // Is there a JOIN and INDEX clause for this table? |
1458 | | - if ( isset($join_conds_safe[$table]) && isset($use_index_safe[$table]) ) { |
1459 | | - $tableClause = $join_conds_safe[$table][0] . ' ' . $this->tableName( $table ); |
1460 | | - $tableClause .= ' ' . $this->useIndexClause( implode( ',', (array)$use_index_safe[$table] ) ); |
1461 | | - $tableClause .= ' ON (' . $this->makeList((array)$join_conds_safe[$table][1], LIST_AND) . ')'; |
| 1491 | + if ( isset($join_conds_safe[$alias]) && isset($use_index_safe[$alias]) ) { |
| 1492 | + $tableClause = $join_conds_safe[$alias][0] . ' ' . $this->tableNameWithAlias( $table, $alias ); |
| 1493 | + $tableClause .= ' ' . $this->useIndexClause( implode( ',', (array)$use_index_safe[$alias] ) ); |
| 1494 | + $tableClause .= ' ON (' . $this->makeList((array)$join_conds_safe[$alias][1], LIST_AND) . ')'; |
1462 | 1495 | $retJOIN[] = $tableClause; |
1463 | 1496 | // Is there an INDEX clause? |
1464 | | - } else if ( isset($use_index_safe[$table]) ) { |
1465 | | - $tableClause = $this->tableName( $table ); |
1466 | | - $tableClause .= ' ' . $this->useIndexClause( implode( ',', (array)$use_index_safe[$table] ) ); |
| 1497 | + } else if ( isset($use_index_safe[$alias]) ) { |
| 1498 | + $tableClause = $this->tableNameWithAlias( $table, $alias ); |
| 1499 | + $tableClause .= ' ' . $this->useIndexClause( implode( ',', (array)$use_index_safe[$alias] ) ); |
1467 | 1500 | $ret[] = $tableClause; |
1468 | 1501 | // Is there a JOIN clause? |
1469 | | - } else if ( isset($join_conds_safe[$table]) ) { |
1470 | | - $tableClause = $join_conds_safe[$table][0] . ' ' . $this->tableName( $table ); |
1471 | | - $tableClause .= ' ON (' . $this->makeList((array)$join_conds_safe[$table][1], LIST_AND) . ')'; |
| 1502 | + } else if ( isset($join_conds_safe[$alias]) ) { |
| 1503 | + $tableClause = $join_conds_safe[$alias][0] . ' ' . $this->tableNameWithAlias( $table, $alias ); |
| 1504 | + $tableClause .= ' ON (' . $this->makeList((array)$join_conds_safe[$alias][1], LIST_AND) . ')'; |
1472 | 1505 | $retJOIN[] = $tableClause; |
1473 | 1506 | } else { |
1474 | | - $tableClause = $this->tableName( $table ); |
| 1507 | + $tableClause = $this->tableNameWithAlias( $table, $alias ); |
1475 | 1508 | $ret[] = $tableClause; |
1476 | 1509 | } |
1477 | 1510 | } |
Index: branches/querypage-work2/phase3/includes/specials/SpecialBrokenRedirects.php |
— | — | @@ -26,7 +26,8 @@ |
27 | 27 | |
28 | 28 | function getQueryInfo() { |
29 | 29 | return array( |
30 | | - 'tables' => array( 'redirect', 'page p1', 'page p2' ), |
| 30 | + 'tables' => array( 'redirect', 'p1' => 'page', |
| 31 | + 'p2' => 'page' ), |
31 | 32 | 'fields' => array( 'p1.page_namespace AS namespace', |
32 | 33 | 'p1.page_title AS title', |
33 | 34 | 'rd_namespace', |
— | — | @@ -35,10 +36,10 @@ |
36 | 37 | 'conds' => array( 'rd_namespace >= 0', |
37 | 38 | 'p2.page_namespace IS NULL' |
38 | 39 | ), |
39 | | - 'join_conds' => array( 'page p1' => array( 'LEFT JOIN', array( |
| 40 | + 'join_conds' => array( 'p1' => array( 'LEFT JOIN', array( |
40 | 41 | 'rd_from=p1.page_id', |
41 | 42 | ) ), |
42 | | - 'page p2' => array( 'LEFT JOIN', array( |
| 43 | + 'p2' => array( 'LEFT JOIN', array( |
43 | 44 | 'rd_namespace=p2.page_namespace', |
44 | 45 | 'rd_title=p2.page_title' |
45 | 46 | ) ) |
Index: branches/querypage-work2/phase3/includes/specials/SpecialMostlinkedtemplates.php |
— | — | @@ -14,7 +14,7 @@ |
15 | 15 | class MostlinkedTemplatesPage extends QueryPage { |
16 | 16 | |
17 | 17 | function __construct() { |
18 | | - SpecialPage::__construct( 'MostlinkedTemplatesPage' ); |
| 18 | + SpecialPage::__construct( 'Mostlinkedtemplates' ); |
19 | 19 | } |
20 | 20 | |
21 | 21 | /** |
— | — | @@ -113,13 +113,3 @@ |
114 | 114 | } |
115 | 115 | } |
116 | 116 | |
117 | | -/** |
118 | | - * Execution function |
119 | | - * |
120 | | - * @param $par Mixed: parameters passed to the page |
121 | | - */ |
122 | | -function wfSpecialMostlinkedtemplates( $par = false ) { |
123 | | - list( $limit, $offset ) = wfCheckLimits(); |
124 | | - $mlt = new SpecialMostlinkedtemplates(); |
125 | | - $mlt->doQuery( $offset, $limit ); |
126 | | -} |
Index: branches/querypage-work2/phase3/includes/specials/SpecialDoubleRedirects.php |
— | — | @@ -27,9 +27,9 @@ |
28 | 28 | function reallyGetQueryInfo( $namespace = null, $title = null ) { |
29 | 29 | $limitToTitle = !( $namespace === null && $title === null ); |
30 | 30 | $retval = array ( |
31 | | - 'tables' => array ( 'redirect ra', 'redirect rb', |
32 | | - 'page pa', 'page pb', |
33 | | - 'page pc' ), |
| 31 | + 'tables' => array ( 'ra' => 'redirect', |
| 32 | + 'rb' => 'redirect', 'pa' => 'page', |
| 33 | + 'pb' => 'page', 'pc' => 'page' ), |
34 | 34 | 'fields' => array ( 'pa.page_namespace AS namespace', |
35 | 35 | 'pa.page_title AS title', |
36 | 36 | 'pb.page_namespace AS nsb', |
Index: branches/querypage-work2/phase3/includes/specials/SpecialListredirects.php |
— | — | @@ -25,7 +25,7 @@ |
26 | 26 | |
27 | 27 | function getQueryInfo() { |
28 | 28 | return array( |
29 | | - 'tables' => array( 'page p1', 'redirect', 'page p2' ), |
| 29 | + 'tables' => array( 'p1' => 'page', 'redirect', 'p2' => 'page' ), |
30 | 30 | 'fields' => array( 'p1.page_namespace AS namespace', |
31 | 31 | 'p1.page_title AS title', |
32 | 32 | 'rd_namespace', |
— | — | @@ -34,7 +34,7 @@ |
35 | 35 | 'conds' => array( 'p1.page_is_redirect' => 1 ), |
36 | 36 | 'join_conds' => array( 'redirect' => array( |
37 | 37 | 'LEFT JOIN', 'rd_from=p1.page_id' ), |
38 | | - 'page p2' => array( 'LEFT JOIN', array( |
| 38 | + 'p2' => array( 'LEFT JOIN', array( |
39 | 39 | 'p2.page_namespace=rd_namespace', |
40 | 40 | 'p2.page_title=rd_title' ) ) ) |
41 | 41 | ); |