From: umherirrender Date: Sat, 5 May 2012 13:29:08 +0000 (+0200) Subject: ORDER BY/GROUP BY accept arrays X-Git-Tag: 1.31.0-rc.0~23693^2 X-Git-Url: http://git.cyclocoop.org//%22%22.str_replace%28%27%22%27%2C?a=commitdiff_plain;h=81dd7fefa59a6a53c96ec17be1c4e2a3d8068f37;p=lhc%2Fweb%2Fwiklou.git ORDER BY/GROUP BY accept arrays renaming all variable which hold "' DESC'" to $sort to keep it all the same Change-Id: I75118f8cdd701f53949fe5cdd7155fb07f78ff65 --- diff --git a/includes/api/ApiQueryAllCategories.php b/includes/api/ApiQueryAllCategories.php index ce28d03673..b0f272b6b4 100644 --- a/includes/api/ApiQueryAllCategories.php +++ b/includes/api/ApiQueryAllCategories.php @@ -77,7 +77,8 @@ class ApiQueryAllCategories extends ApiQueryGeneratorBase { } $this->addOption( 'LIMIT', $params['limit'] + 1 ); - $this->addOption( 'ORDER BY', 'cat_title' . ( $params['dir'] == 'descending' ? ' DESC' : '' ) ); + $sort = ( $params['dir'] == 'descending' ? ' DESC' : '' ); + $this->addOption( 'ORDER BY', 'cat_title' . $sort ); $prop = array_flip( $params['prop'] ); $this->addFieldsIf( array( 'cat_pages', 'cat_subcats', 'cat_files' ), isset( $prop['size'] ) ); diff --git a/includes/api/ApiQueryAllImages.php b/includes/api/ApiQueryAllImages.php index 60a05a7e3c..87e70248df 100644 --- a/includes/api/ApiQueryAllImages.php +++ b/includes/api/ApiQueryAllImages.php @@ -137,8 +137,8 @@ class ApiQueryAllImages extends ApiQueryGeneratorBase { $limit = $params['limit']; $this->addOption( 'LIMIT', $limit + 1 ); - $this->addOption( 'ORDER BY', 'img_name' . - ( $params['dir'] == 'descending' ? ' DESC' : '' ) ); + $sort = ( $params['dir'] == 'descending' ? ' DESC' : '' ); + $this->addOption( 'ORDER BY', 'img_name' . $sort ); $res = $this->select( __METHOD__ ); diff --git a/includes/api/ApiQueryAllLinks.php b/includes/api/ApiQueryAllLinks.php index 903f144fe4..7e7fc403d7 100644 --- a/includes/api/ApiQueryAllLinks.php +++ b/includes/api/ApiQueryAllLinks.php @@ -105,7 +105,10 @@ class ApiQueryAllLinks extends ApiQueryGeneratorBase { $this->addOption( 'LIMIT', $limit + 1 ); if ( !$params['unique'] ) { - $this->addOption( 'ORDER BY', 'pl_title, pl_from' ); + $this->addOption( 'ORDER BY', array( + 'pl_title', + 'pl_from' + )); } $res = $this->select( __METHOD__ ); diff --git a/includes/api/ApiQueryAllPages.php b/includes/api/ApiQueryAllPages.php index f3254c5b5d..7e89a95b6a 100644 --- a/includes/api/ApiQueryAllPages.php +++ b/includes/api/ApiQueryAllPages.php @@ -153,7 +153,7 @@ class ApiQueryAllPages extends ApiQueryGeneratorBase { $this->addOption( 'STRAIGHT_JOIN' ); // We have to GROUP BY all selected fields to stop // PostgreSQL from whining - $this->addOption( 'GROUP BY', implode( ', ', $selectFields ) ); + $this->addOption( 'GROUP BY', $selectFields ); $forceNameTitleIndex = false; } diff --git a/includes/api/ApiQueryCategories.php b/includes/api/ApiQueryCategories.php index 243d1acf12..cbda6ab82d 100644 --- a/includes/api/ApiQueryCategories.php +++ b/includes/api/ApiQueryCategories.php @@ -124,14 +124,14 @@ class ApiQueryCategories extends ApiQueryGeneratorBase { $this->addOption( 'USE INDEX', array( 'categorylinks' => 'cl_from' ) ); - $dir = ( $params['dir'] == 'descending' ? ' DESC' : '' ); + $sort = ( $params['dir'] == 'descending' ? ' DESC' : '' ); // Don't order by cl_from if it's constant in the WHERE clause if ( count( $this->getPageSet()->getGoodTitles() ) == 1 ) { - $this->addOption( 'ORDER BY', 'cl_to' . $dir ); + $this->addOption( 'ORDER BY', 'cl_to' . $sort ); } else { $this->addOption( 'ORDER BY', array( - 'cl_from' . $dir, - 'cl_to' . $dir + 'cl_from' . $sort, + 'cl_to' . $sort )); } diff --git a/includes/api/ApiQueryDeletedrevs.php b/includes/api/ApiQueryDeletedrevs.php index 397bdc4097..c25f561781 100644 --- a/includes/api/ApiQueryDeletedrevs.php +++ b/includes/api/ApiQueryDeletedrevs.php @@ -180,7 +180,10 @@ class ApiQueryDeletedrevs extends ApiQueryBase { if ( $params['unique'] ) { $this->addOption( 'GROUP BY', 'ar_title' ); } else { - $this->addOption( 'ORDER BY', 'ar_title, ar_timestamp' ); + $this->addOption( 'ORDER BY', array( + 'ar_title', + 'ar_timestamp' + )); } } else { if ( $mode == 'revs' ) { diff --git a/includes/api/ApiQueryDuplicateFiles.php b/includes/api/ApiQueryDuplicateFiles.php index 0132d67c5d..6fb3ea3590 100644 --- a/includes/api/ApiQueryDuplicateFiles.php +++ b/includes/api/ApiQueryDuplicateFiles.php @@ -91,14 +91,14 @@ class ApiQueryDuplicateFiles extends ApiQueryGeneratorBase { ); } - $dir = ( $params['dir'] == 'descending' ? ' DESC' : '' ); + $sort = ( $params['dir'] == 'descending' ? ' DESC' : '' ); // Don't order by i1.img_name if it's constant in the WHERE clause if ( count( $this->getPageSet()->getGoodTitles() ) == 1 ) { - $this->addOption( 'ORDER BY', 'i2.img_name' . $dir ); + $this->addOption( 'ORDER BY', 'i2.img_name' . $sort ); } else { $this->addOption( 'ORDER BY', array( - 'i1.img_name' . $dir, - 'i2.img_name' . $dir + 'i1.img_name' . $sort, + 'i2.img_name' . $sort )); } $this->addOption( 'LIMIT', $params['limit'] + 1 ); diff --git a/includes/api/ApiQueryFilearchive.php b/includes/api/ApiQueryFilearchive.php index 268b1e4611..9b9432cda6 100644 --- a/includes/api/ApiQueryFilearchive.php +++ b/includes/api/ApiQueryFilearchive.php @@ -117,8 +117,8 @@ class ApiQueryFilearchive extends ApiQueryBase { $limit = $params['limit']; $this->addOption( 'LIMIT', $limit + 1 ); - $this->addOption( 'ORDER BY', 'fa_name' . - ( $params['dir'] == 'descending' ? ' DESC' : '' ) ); + $sort = ( $params['dir'] == 'descending' ? ' DESC' : '' ); + $this->addOption( 'ORDER BY', 'fa_name' . $sort ); $res = $this->select( __METHOD__ ); diff --git a/includes/api/ApiQueryIWBacklinks.php b/includes/api/ApiQueryIWBacklinks.php index 47ab34647c..8ebe3ec569 100644 --- a/includes/api/ApiQueryIWBacklinks.php +++ b/includes/api/ApiQueryIWBacklinks.php @@ -89,10 +89,17 @@ class ApiQueryIWBacklinks extends ApiQueryGeneratorBase { $this->addWhereFld( 'iwl_title', $params['title'] ); $this->addOption( 'ORDER BY', 'iwl_from' ); } else { - $this->addOption( 'ORDER BY', 'iwl_title, iwl_from' ); + $this->addOption( 'ORDER BY', array( + 'iwl_title', + 'iwl_from' + )); } } else { - $this->addOption( 'ORDER BY', 'iwl_prefix, iwl_title, iwl_from' ); + $this->addOption( 'ORDER BY', array( + 'iwl_prefix', + 'iwl_title', + 'iwl_from' + )); } $this->addOption( 'LIMIT', $params['limit'] + 1 ); diff --git a/includes/api/ApiQueryIWLinks.php b/includes/api/ApiQueryIWLinks.php index bc42fe0fa8..f39835a1d6 100644 --- a/includes/api/ApiQueryIWLinks.php +++ b/includes/api/ApiQueryIWLinks.php @@ -76,26 +76,26 @@ class ApiQueryIWLinks extends ApiQueryBase { ); } - $dir = ( $params['dir'] == 'descending' ? ' DESC' : '' ); + $sort = ( $params['dir'] == 'descending' ? ' DESC' : '' ); if ( isset( $params['prefix'] ) ) { $this->addWhereFld( 'iwl_prefix', $params['prefix'] ); if ( isset( $params['title'] ) ) { $this->addWhereFld( 'iwl_title', $params['title'] ); - $this->addOption( 'ORDER BY', 'iwl_from' . $dir ); + $this->addOption( 'ORDER BY', 'iwl_from' . $sort ); } else { $this->addOption( 'ORDER BY', array( - 'iwl_title' . $dir, - 'iwl_from' . $dir + 'iwl_title' . $sort, + 'iwl_from' . $sort )); } } else { // Don't order by iwl_from if it's constant in the WHERE clause if ( count( $this->getPageSet()->getGoodTitles() ) == 1 ) { - $this->addOption( 'ORDER BY', 'iwl_prefix' . $dir ); + $this->addOption( 'ORDER BY', 'iwl_prefix' . $sort ); } else { $this->addOption( 'ORDER BY', array ( - 'iwl_from' . $dir, - 'iwl_prefix' . $dir + 'iwl_from' . $sort, + 'iwl_prefix' . $sort )); } } diff --git a/includes/api/ApiQueryImages.php b/includes/api/ApiQueryImages.php index 64d7ff42ce..6f488cd60c 100644 --- a/includes/api/ApiQueryImages.php +++ b/includes/api/ApiQueryImages.php @@ -75,14 +75,14 @@ class ApiQueryImages extends ApiQueryGeneratorBase { ); } - $dir = ( $params['dir'] == 'descending' ? ' DESC' : '' ); + $sort = ( $params['dir'] == 'descending' ? ' DESC' : '' ); // Don't order by il_from if it's constant in the WHERE clause if ( count( $this->getPageSet()->getGoodTitles() ) == 1 ) { - $this->addOption( 'ORDER BY', 'il_to' . $dir ); + $this->addOption( 'ORDER BY', 'il_to' . $sort ); } else { $this->addOption( 'ORDER BY', array( - 'il_from' . $dir, - 'il_to' . $dir + 'il_from' . $sort, + 'il_to' . $sort )); } $this->addOption( 'LIMIT', $params['limit'] + 1 ); diff --git a/includes/api/ApiQueryLangBacklinks.php b/includes/api/ApiQueryLangBacklinks.php index d8c678a49a..4233560b17 100644 --- a/includes/api/ApiQueryLangBacklinks.php +++ b/includes/api/ApiQueryLangBacklinks.php @@ -89,10 +89,17 @@ class ApiQueryLangBacklinks extends ApiQueryGeneratorBase { $this->addWhereFld( 'll_title', $params['title'] ); $this->addOption( 'ORDER BY', 'll_from' ); } else { - $this->addOption( 'ORDER BY', 'll_title, ll_from' ); + $this->addOption( 'ORDER BY', array( + 'll_title', + 'll_from' + )); } } else { - $this->addOption( 'ORDER BY', 'll_lang, ll_title, ll_from' ); + $this->addOption( 'ORDER BY', array( + 'll_lang', + 'll_title', + 'll_from' + )); } $this->addOption( 'LIMIT', $params['limit'] + 1 ); diff --git a/includes/api/ApiQueryLangLinks.php b/includes/api/ApiQueryLangLinks.php index 21cc925900..b6f9a99108 100644 --- a/includes/api/ApiQueryLangLinks.php +++ b/includes/api/ApiQueryLangLinks.php @@ -70,26 +70,26 @@ class ApiQueryLangLinks extends ApiQueryBase { ); } - $dir = ( $params['dir'] == 'descending' ? ' DESC' : '' ); + $sort = ( $params['dir'] == 'descending' ? ' DESC' : '' ); if ( isset( $params['lang'] ) ) { $this->addWhereFld( 'll_lang', $params['lang'] ); if ( isset( $params['title'] ) ) { $this->addWhereFld( 'll_title', $params['title'] ); - $this->addOption( 'ORDER BY', 'll_from' . $dir ); + $this->addOption( 'ORDER BY', 'll_from' . $sort ); } else { $this->addOption( 'ORDER BY', array( - 'll_title' . $dir, - 'll_from' . $dir + 'll_title' . $sort, + 'll_from' . $sort )); } } else { // Don't order by ll_from if it's constant in the WHERE clause if ( count( $this->getPageSet()->getGoodTitles() ) == 1 ) { - $this->addOption( 'ORDER BY', 'll_lang' . $dir ); + $this->addOption( 'ORDER BY', 'll_lang' . $sort ); } else { $this->addOption( 'ORDER BY', array( - 'll_from' . $dir, - 'll_lang' . $dir + 'll_from' . $sort, + 'll_lang' . $sort )); } } diff --git a/includes/api/ApiQueryLinks.php b/includes/api/ApiQueryLinks.php index 6e6da53d34..4dea419e6e 100644 --- a/includes/api/ApiQueryLinks.php +++ b/includes/api/ApiQueryLinks.php @@ -129,7 +129,7 @@ class ApiQueryLinks extends ApiQueryGeneratorBase { ); } - $dir = ( $params['dir'] == 'descending' ? ' DESC' : '' ); + $sort = ( $params['dir'] == 'descending' ? ' DESC' : '' ); // Here's some MySQL craziness going on: if you use WHERE foo='bar' // and later ORDER BY foo MySQL doesn't notice the ORDER BY is pointless // but instead goes and filesorts, because the index for foo was used @@ -137,13 +137,13 @@ class ApiQueryLinks extends ApiQueryGeneratorBase { // clause from the ORDER BY clause $order = array(); if ( count( $this->getPageSet()->getGoodTitles() ) != 1 ) { - $order[] = $this->prefix . '_from' . $dir; + $order[] = $this->prefix . '_from' . $sort; } if ( count( $params['namespace'] ) != 1 ) { - $order[] = $this->prefix . '_namespace' . $dir; + $order[] = $this->prefix . '_namespace' . $sort; } - $order[] = $this->prefix . "_title" . $dir; + $order[] = $this->prefix . '_title' . $sort; $this->addOption( 'ORDER BY', $order ); $this->addOption( 'USE INDEX', $this->prefix . '_from' ); $this->addOption( 'LIMIT', $params['limit'] + 1 ); diff --git a/includes/api/ApiQueryRevisions.php b/includes/api/ApiQueryRevisions.php index fa58bdf047..7390546492 100644 --- a/includes/api/ApiQueryRevisions.php +++ b/includes/api/ApiQueryRevisions.php @@ -327,7 +327,10 @@ class ApiQueryRevisions extends ApiQueryBase { "rev_id >= '$revid')" ); } - $this->addOption( 'ORDER BY', 'rev_page, rev_id' ); + $this->addOption( 'ORDER BY', array( + 'rev_page', + 'rev_id' + )); // assumption testing -- we should never get more then $pageCount rows. $limit = $pageCount; diff --git a/includes/api/ApiQueryWatchlistRaw.php b/includes/api/ApiQueryWatchlistRaw.php index 4adadf1e32..ce4ce50ffb 100644 --- a/includes/api/ApiQueryWatchlistRaw.php +++ b/includes/api/ApiQueryWatchlistRaw.php @@ -90,7 +90,10 @@ class ApiQueryWatchlistRaw extends ApiQueryGeneratorBase { if ( count( $params['namespace'] ) == 1 ) { $this->addOption( 'ORDER BY', 'wl_title' . $sort ); } else { - $this->addOption( 'ORDER BY', 'wl_namespace' . $sort . ', wl_title' . $sort ); + $this->addOption( 'ORDER BY', array( + 'wl_namespace' . $sort, + 'wl_title' . $sort + )); } $this->addOption( 'LIMIT', $params['limit'] + 1 ); $res = $this->select( __METHOD__ );