ORDER BY/GROUP BY accept arrays
authorumherirrender <umherirrender_de.wp@web.de>
Sat, 5 May 2012 13:29:08 +0000 (15:29 +0200)
committerumherirrender <umherirrender_de.wp@web.de>
Sat, 5 May 2012 13:29:08 +0000 (15:29 +0200)
renaming all variable which hold "' DESC'" to $sort
to keep it all the same

Change-Id: I75118f8cdd701f53949fe5cdd7155fb07f78ff65

16 files changed:
includes/api/ApiQueryAllCategories.php
includes/api/ApiQueryAllImages.php
includes/api/ApiQueryAllLinks.php
includes/api/ApiQueryAllPages.php
includes/api/ApiQueryCategories.php
includes/api/ApiQueryDeletedrevs.php
includes/api/ApiQueryDuplicateFiles.php
includes/api/ApiQueryFilearchive.php
includes/api/ApiQueryIWBacklinks.php
includes/api/ApiQueryIWLinks.php
includes/api/ApiQueryImages.php
includes/api/ApiQueryLangBacklinks.php
includes/api/ApiQueryLangLinks.php
includes/api/ApiQueryLinks.php
includes/api/ApiQueryRevisions.php
includes/api/ApiQueryWatchlistRaw.php

index ce28d03..b0f272b 100644 (file)
@@ -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'] ) );
index 60a05a7..87e7024 100644 (file)
@@ -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__ );
 
index 903f144..7e7fc40 100644 (file)
@@ -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__ );
index f3254c5..7e89a95 100644 (file)
@@ -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;
                }
 
index 243d1ac..cbda6ab 100644 (file)
@@ -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
                        ));
                }
 
index 397bdc4..c25f561 100644 (file)
@@ -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' ) {
index 0132d67..6fb3ea3 100644 (file)
@@ -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 );
index 268b1e4..9b9432c 100644 (file)
@@ -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__ );
 
index 47ab346..8ebe3ec 100644 (file)
@@ -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 );
index bc42fe0..f39835a 100644 (file)
@@ -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
                                ));
                        }
                }
index 64d7ff4..6f488cd 100644 (file)
@@ -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 );
index d8c678a..4233560 100644 (file)
@@ -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 );
index 21cc925..b6f9a99 100644 (file)
@@ -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
                                ));
                        }
                }
index 6e6da53..4dea419 100644 (file)
@@ -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 );
index fa58bdf..7390546 100644 (file)
@@ -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;
index 4adadf1..ce4ce50 100644 (file)
@@ -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__ );