From 41988661e450a645e1aade44b73ba6bb34786b02 Mon Sep 17 00:00:00 2001 From: umherirrender Date: Sun, 13 May 2012 00:06:48 +0200 Subject: [PATCH] GROUP BY and ORDER BY supports arrays in Database class Change-Id: Ib431b07ffa2ce6843e21536de2ff19c648e0a595 --- includes/Export.php | 2 +- includes/Pager.php | 4 ++-- includes/QueryPage.php | 2 +- includes/specials/SpecialActiveusers.php | 2 +- includes/specials/SpecialEditWatchlist.php | 2 +- includes/specials/SpecialFewestrevisions.php | 2 +- includes/specials/SpecialListfiles.php | 5 ++--- includes/specials/SpecialMostcategories.php | 2 +- includes/specials/SpecialMostlinked.php | 4 ++-- includes/specials/SpecialMostlinkedtemplates.php | 2 +- includes/specials/SpecialUndelete.php | 4 ++-- includes/specials/SpecialWantedpages.php | 2 +- includes/specials/SpecialWantedtemplates.php | 2 +- 13 files changed, 17 insertions(+), 18 deletions(-) diff --git a/includes/Export.php b/includes/Export.php index ea6fd9421b..c201c97ada 100644 --- a/includes/Export.php +++ b/includes/Export.php @@ -338,7 +338,7 @@ class WikiExporter { } elseif ( $this->history & WikiExporter::RANGE ) { # Dump of revisions within a specified range $join['revision'] = array( 'INNER JOIN', 'page_id=rev_page' ); - $opts['ORDER BY'] = 'rev_page ASC, rev_id ASC'; + $opts['ORDER BY'] = array( 'rev_page ASC', 'rev_id ASC' ); } else { # Uknown history specification parameter? wfProfileOut( __METHOD__ ); diff --git a/includes/Pager.php b/includes/Pager.php index f0f187648d..438a99ae84 100644 --- a/includes/Pager.php +++ b/includes/Pager.php @@ -313,14 +313,14 @@ abstract class IndexPager extends ContextSource implements Pager { $join_conds = isset( $info['join_conds'] ) ? $info['join_conds'] : array(); $sortColumns = array_merge( array( $this->mIndexField ), $this->mExtraSortFields ); if ( $descending ) { - $options['ORDER BY'] = implode( ',', $sortColumns ); + $options['ORDER BY'] = $sortColumns; $operator = '>'; } else { $orderBy = array(); foreach ( $sortColumns as $col ) { $orderBy[] = $col . ' DESC'; } - $options['ORDER BY'] = implode( ',', $orderBy ); + $options['ORDER BY'] = $orderBy; $operator = '<'; } if ( $offset != '' ) { diff --git a/includes/QueryPage.php b/includes/QueryPage.php index f28aeeec3f..1c42b1c84c 100644 --- a/includes/QueryPage.php +++ b/includes/QueryPage.php @@ -376,7 +376,7 @@ abstract class QueryPage extends SpecialPage { $options = isset( $query['options'] ) ? (array)$query['options'] : array(); $join_conds = isset( $query['join_conds'] ) ? (array)$query['join_conds'] : array(); if ( count( $order ) ) { - $options['ORDER BY'] = implode( ', ', $order ); + $options['ORDER BY'] = $order; } if ( $limit !== false ) { $options['LIMIT'] = intval( $limit ); diff --git a/includes/specials/SpecialActiveusers.php b/includes/specials/SpecialActiveusers.php index 8f4a9431ce..06a4694219 100644 --- a/includes/specials/SpecialActiveusers.php +++ b/includes/specials/SpecialActiveusers.php @@ -106,7 +106,7 @@ class ActiveUsersPager extends UsersPager { 'MAX(ipb_user) AS blocked' ), 'options' => array( - 'GROUP BY' => 'rc_user_text, user_id', + 'GROUP BY' => array( 'rc_user_text', 'user_id' ), 'USE INDEX' => array( 'recentchanges' => 'rc_user_text' ) ), 'join_conds' => array( diff --git a/includes/specials/SpecialEditWatchlist.php b/includes/specials/SpecialEditWatchlist.php index b46ef0e58b..b7f1e61686 100644 --- a/includes/specials/SpecialEditWatchlist.php +++ b/includes/specials/SpecialEditWatchlist.php @@ -277,7 +277,7 @@ class SpecialEditWatchlist extends UnlistedSpecialPage { array( 'wl_namespace', 'wl_title' ), array( 'wl_user' => $this->getUser()->getId() ), __METHOD__, - array( 'ORDER BY' => 'wl_namespace, wl_title' ) + array( 'ORDER BY' => array( 'wl_namespace', 'wl_title' ) ) ); $lb = new LinkBatch(); diff --git a/includes/specials/SpecialFewestrevisions.php b/includes/specials/SpecialFewestrevisions.php index 767709501c..5610cc2bc8 100644 --- a/includes/specials/SpecialFewestrevisions.php +++ b/includes/specials/SpecialFewestrevisions.php @@ -56,7 +56,7 @@ class FewestrevisionsPage extends QueryPage { // useful to remove this. People _do_ create pages // and never revise them, they aren't necessarily // redirects. - 'GROUP BY' => 'page_namespace, page_title, page_is_redirect' ) + 'GROUP BY' => array( 'page_namespace', 'page_title', 'page_is_redirect' ) ) ); } diff --git a/includes/specials/SpecialListfiles.php b/includes/specials/SpecialListfiles.php index fd48cb08dd..abd83acbdf 100644 --- a/includes/specials/SpecialListfiles.php +++ b/includes/specials/SpecialListfiles.php @@ -156,9 +156,8 @@ class ImageListPager extends TablePager { if( $dbr->implicitGroupby() ) { $options = array( 'GROUP BY' => 'img_name' ); } else { - $columnlist = implode( ',', - preg_grep( '/^img/', array_keys( $this->getFieldNames() ) ) ); - $options = array( 'GROUP BY' => "img_user, $columnlist" ); + $columnlist = preg_grep( '/^img/', array_keys( $this->getFieldNames() ) ); + $options = array( 'GROUP BY' => array_merge( array( 'img_user' ), $columnlist ) ); } $join_conds = array( 'oldimage' => array( 'LEFT JOIN', 'oi_name = img_name' ) ); } diff --git a/includes/specials/SpecialMostcategories.php b/includes/specials/SpecialMostcategories.php index 98b736756d..51745670bc 100644 --- a/includes/specials/SpecialMostcategories.php +++ b/includes/specials/SpecialMostcategories.php @@ -46,7 +46,7 @@ class MostcategoriesPage extends QueryPage { 'COUNT(*) AS value' ), 'conds' => array ( 'page_namespace' => MWNamespace::getContentNamespaces() ), 'options' => array ( 'HAVING' => 'COUNT(*) > 1', - 'GROUP BY' => 'page_namespace, page_title' ), + 'GROUP BY' => array( 'page_namespace', 'page_title' ) ), 'join_conds' => array ( 'page' => array ( 'LEFT JOIN', 'page_id = cl_from' ) ) ); diff --git a/includes/specials/SpecialMostlinked.php b/includes/specials/SpecialMostlinked.php index a16f0872b5..47e8fbfd0b 100644 --- a/includes/specials/SpecialMostlinked.php +++ b/includes/specials/SpecialMostlinked.php @@ -47,8 +47,8 @@ class MostlinkedPage extends QueryPage { 'COUNT(*) AS value', 'page_namespace' ), 'options' => array ( 'HAVING' => 'COUNT(*) > 1', - 'GROUP BY' => 'pl_namespace, pl_title, '. - 'page_namespace' ), + 'GROUP BY' => array( 'pl_namespace', 'pl_title', + 'page_namespace' ) ), 'join_conds' => array ( 'page' => array ( 'LEFT JOIN', array ( 'page_namespace = pl_namespace', 'page_title = pl_title' ) ) ) diff --git a/includes/specials/SpecialMostlinkedtemplates.php b/includes/specials/SpecialMostlinkedtemplates.php index 72dc15bbb8..370ba68b88 100644 --- a/includes/specials/SpecialMostlinkedtemplates.php +++ b/includes/specials/SpecialMostlinkedtemplates.php @@ -68,7 +68,7 @@ class MostlinkedTemplatesPage extends QueryPage { 'tl_title AS title', 'COUNT(*) AS value' ), 'conds' => array ( 'tl_namespace' => NS_TEMPLATE ), - 'options' => array( 'GROUP BY' => 'tl_namespace, tl_title' ) + 'options' => array( 'GROUP BY' => array( 'tl_namespace', 'tl_title' ) ) ); } diff --git a/includes/specials/SpecialUndelete.php b/includes/specials/SpecialUndelete.php index d1bb3f01a4..654d5b7fb0 100644 --- a/includes/specials/SpecialUndelete.php +++ b/includes/specials/SpecialUndelete.php @@ -97,8 +97,8 @@ class PageArchive { $condition, __METHOD__, array( - 'GROUP BY' => 'ar_namespace,ar_title', - 'ORDER BY' => 'ar_namespace,ar_title', + 'GROUP BY' => array( 'ar_namespace', 'ar_title' ), + 'ORDER BY' => array( 'ar_namespace', 'ar_title' ), 'LIMIT' => 100, ) ) diff --git a/includes/specials/SpecialWantedpages.php b/includes/specials/SpecialWantedpages.php index 4624b3550d..9f5d52d5cb 100644 --- a/includes/specials/SpecialWantedpages.php +++ b/includes/specials/SpecialWantedpages.php @@ -72,7 +72,7 @@ class WantedPagesPage extends WantedQueryPage { ), 'options' => array( 'HAVING' => "COUNT(*) > $count", - 'GROUP BY' => 'pl_namespace, pl_title' + 'GROUP BY' => array( 'pl_namespace', 'pl_title' ) ), 'join_conds' => array( 'pg1' => array( diff --git a/includes/specials/SpecialWantedtemplates.php b/includes/specials/SpecialWantedtemplates.php index ab9d604673..2b4364bc46 100644 --- a/includes/specials/SpecialWantedtemplates.php +++ b/includes/specials/SpecialWantedtemplates.php @@ -46,7 +46,7 @@ class WantedTemplatesPage extends WantedQueryPage { 'conds' => array ( 'page_title IS NULL', 'tl_namespace' => NS_TEMPLATE ), 'options' => array ( - 'GROUP BY' => 'tl_namespace, tl_title' ), + 'GROUP BY' => array( 'tl_namespace', 'tl_title' ) ), 'join_conds' => array ( 'page' => array ( 'LEFT JOIN', array ( 'page_namespace = tl_namespace', 'page_title = tl_title' ) ) ) -- 2.20.1