ORDER BY/GROUP BY accept arrays
renaming all variable which hold "' DESC'" to $sort to keep it all the same Change-Id: I75118f8cdd701f53949fe5cdd7155fb07f78ff65
This commit is contained in:
parent
820ed8667f
commit
81dd7fefa5
16 changed files with 71 additions and 44 deletions
|
|
@ -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'] ) );
|
||||
|
|
|
|||
|
|
@ -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__ );
|
||||
|
||||
|
|
|
|||
|
|
@ -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__ );
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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' ) {
|
||||
|
|
|
|||
|
|
@ -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 );
|
||||
|
|
|
|||
|
|
@ -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__ );
|
||||
|
||||
|
|
|
|||
|
|
@ -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 );
|
||||
|
|
|
|||
|
|
@ -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
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 );
|
||||
|
|
|
|||
|
|
@ -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 );
|
||||
|
|
|
|||
|
|
@ -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
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 );
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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__ );
|
||||
|
|
|
|||
Loading…
Reference in a new issue