aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoan Kattouw <catrope@users.mediawiki.org>2011-11-14 08:19:55 +0000
committerRoan Kattouw <catrope@users.mediawiki.org>2011-11-14 08:19:55 +0000
commit2563e19c39a2d7e28860e99b46b459734d0a247e (patch)
treef6d1c1969ec811c78f419cf00272d751dba34ab5
parent6ff2162ffee7a8e84ce1f102eac5cd0f5d1b5f94 (diff)
downloadmediawikicore-2563e19c39a2d7e28860e99b46b459734d0a247e.tar.gz
mediawikicore-2563e19c39a2d7e28860e99b46b459734d0a247e.zip
(bug 26909) Add dir parameter for prop= API modules. Modified patch by Umherirrender
Notes
Notes: http://mediawiki.org/wiki/Special:Code/MediaWiki/102947
-rw-r--r--includes/api/ApiQueryBase.php9
-rw-r--r--includes/api/ApiQueryCategories.php17
-rw-r--r--includes/api/ApiQueryDuplicateFiles.php11
-rw-r--r--includes/api/ApiQueryIWLinks.php23
-rw-r--r--includes/api/ApiQueryImages.php18
-rw-r--r--includes/api/ApiQueryLangLinks.php23
-rw-r--r--includes/api/ApiQueryLinks.php30
7 files changed, 100 insertions, 31 deletions
diff --git a/includes/api/ApiQueryBase.php b/includes/api/ApiQueryBase.php
index daadcaad1771..49db0c2ced7d 100644
--- a/includes/api/ApiQueryBase.php
+++ b/includes/api/ApiQueryBase.php
@@ -214,11 +214,10 @@ abstract class ApiQueryBase extends ApiBase {
if ( $sort ) {
$order = $field . ( $isDirNewer ? '' : ' DESC' );
- if ( !isset( $this->options['ORDER BY'] ) ) {
- $this->addOption( 'ORDER BY', $order );
- } else {
- $this->addOption( 'ORDER BY', $this->options['ORDER BY'] . ', ' . $order );
- }
+ // Append ORDER BY
+ $optionOrderBy = isset( $this->options['ORDER BY'] ) ? (array)$this->options['ORDER BY'] : array();
+ $optionOrderBy[] = $order;
+ $this->addOption( 'ORDER BY', $optionOrderBy );
}
}
diff --git a/includes/api/ApiQueryCategories.php b/includes/api/ApiQueryCategories.php
index 8ed48465766b..823eef94a2a4 100644
--- a/includes/api/ApiQueryCategories.php
+++ b/includes/api/ApiQueryCategories.php
@@ -127,11 +127,16 @@ class ApiQueryCategories extends ApiQueryGeneratorBase {
}
$this->addOption( 'USE INDEX', array( 'categorylinks' => 'cl_from' ) );
+
+ $dir = ( $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' );
+ $this->addOption( 'ORDER BY', 'cl_to' . $dir );
} else {
- $this->addOption( 'ORDER BY', "cl_from, cl_to" );
+ $this->addOption( 'ORDER BY', array(
+ 'cl_from' . $dir,
+ 'cl_to' . $dir
+ ));
}
$res = $this->select( __METHOD__ );
@@ -213,6 +218,13 @@ class ApiQueryCategories extends ApiQueryGeneratorBase {
'categories' => array(
ApiBase::PARAM_ISMULTI => true,
),
+ 'dir' => array(
+ ApiBase::PARAM_DFLT => 'ascending',
+ ApiBase::PARAM_TYPE => array(
+ 'ascending',
+ 'descending'
+ )
+ ),
);
}
@@ -228,6 +240,7 @@ class ApiQueryCategories extends ApiQueryGeneratorBase {
'show' => 'Which kind of categories to show',
'continue' => 'When more results are available, use this to continue',
'categories' => 'Only list these categories. Useful for checking whether a certain page is in a certain category',
+ 'dir' => 'The direction in which to list',
);
}
diff --git a/includes/api/ApiQueryDuplicateFiles.php b/includes/api/ApiQueryDuplicateFiles.php
index 719367538538..90c345c4a801 100644
--- a/includes/api/ApiQueryDuplicateFiles.php
+++ b/includes/api/ApiQueryDuplicateFiles.php
@@ -94,7 +94,8 @@ class ApiQueryDuplicateFiles extends ApiQueryGeneratorBase {
);
}
- $this->addOption( 'ORDER BY', 'i1.img_name' );
+ $dir = ( $params['dir'] == 'descending' ? ' DESC' : '' );
+ $this->addOption( 'ORDER BY', 'i1.img_name' . $dir );
$this->addOption( 'LIMIT', $params['limit'] + 1 );
$res = $this->select( __METHOD__ );
@@ -141,6 +142,13 @@ class ApiQueryDuplicateFiles extends ApiQueryGeneratorBase {
ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2
),
'continue' => null,
+ 'dir' => array(
+ ApiBase::PARAM_DFLT => 'ascending',
+ ApiBase::PARAM_TYPE => array(
+ 'ascending',
+ 'descending'
+ )
+ ),
);
}
@@ -148,6 +156,7 @@ class ApiQueryDuplicateFiles extends ApiQueryGeneratorBase {
return array(
'limit' => 'How many files to return',
'continue' => 'When more results are available, use this to continue',
+ 'dir' => 'The direction in which to list',
);
}
diff --git a/includes/api/ApiQueryIWLinks.php b/includes/api/ApiQueryIWLinks.php
index 569f36f3fea1..a0cff72d6ae4 100644
--- a/includes/api/ApiQueryIWLinks.php
+++ b/includes/api/ApiQueryIWLinks.php
@@ -79,20 +79,27 @@ class ApiQueryIWLinks extends ApiQueryBase {
);
}
+ $dir = ( $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' );
+ $this->addOption( 'ORDER BY', 'iwl_from' . $dir );
} else {
- $this->addOption( 'ORDER BY', 'iwl_title, iwl_from' );
+ $this->addOption( 'ORDER BY', array(
+ 'iwl_title' . $dir,
+ 'iwl_from' . $dir
+ ));
}
} 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' );
+ $this->addOption( 'ORDER BY', 'iwl_prefix' . $dir );
} else {
- $this->addOption( 'ORDER BY', 'iwl_from, iwl_prefix' );
+ $this->addOption( 'ORDER BY', array (
+ 'iwl_from' . $dir,
+ 'iwl_prefix' . $dir
+ ));
}
}
@@ -142,6 +149,13 @@ class ApiQueryIWLinks extends ApiQueryBase {
'continue' => null,
'prefix' => null,
'title' => null,
+ 'dir' => array(
+ ApiBase::PARAM_DFLT => 'ascending',
+ ApiBase::PARAM_TYPE => array(
+ 'ascending',
+ 'descending'
+ )
+ ),
);
}
@@ -152,6 +166,7 @@ class ApiQueryIWLinks extends ApiQueryBase {
'continue' => 'When more results are available, use this to continue',
'prefix' => 'Prefix for the interwiki',
'title' => "Interwiki link to search for. Must be used with {$this->getModulePrefix()}prefix",
+ 'dir' => 'The direction in which to list',
);
}
diff --git a/includes/api/ApiQueryImages.php b/includes/api/ApiQueryImages.php
index c69ea93ef8dc..dfd5722d8a2c 100644
--- a/includes/api/ApiQueryImages.php
+++ b/includes/api/ApiQueryImages.php
@@ -79,11 +79,15 @@ class ApiQueryImages extends ApiQueryGeneratorBase {
);
}
+ $dir = ( $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' );
+ $this->addOption( 'ORDER BY', 'il_to' . $dir );
} else {
- $this->addOption( 'ORDER BY', 'il_from, il_to' );
+ $this->addOption( 'ORDER BY', array(
+ 'il_from' . $dir,
+ 'il_to' . $dir
+ ));
}
$this->addOption( 'LIMIT', $params['limit'] + 1 );
@@ -154,7 +158,14 @@ class ApiQueryImages extends ApiQueryGeneratorBase {
'continue' => null,
'images' => array(
ApiBase::PARAM_ISMULTI => true,
- )
+ ),
+ 'dir' => array(
+ ApiBase::PARAM_DFLT => 'ascending',
+ ApiBase::PARAM_TYPE => array(
+ 'ascending',
+ 'descending'
+ )
+ ),
);
}
@@ -163,6 +174,7 @@ class ApiQueryImages extends ApiQueryGeneratorBase {
'limit' => 'How many images to return',
'continue' => 'When more results are available, use this to continue',
'images' => 'Only list these images. Useful for checking whether a certain page has a certain Image.',
+ 'dir' => 'The direction in which to list',
);
}
diff --git a/includes/api/ApiQueryLangLinks.php b/includes/api/ApiQueryLangLinks.php
index b0880bb5ef80..aafa2947e293 100644
--- a/includes/api/ApiQueryLangLinks.php
+++ b/includes/api/ApiQueryLangLinks.php
@@ -74,20 +74,27 @@ class ApiQueryLangLinks extends ApiQueryBase {
);
}
+ $dir = ( $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' );
+ $this->addOption( 'ORDER BY', 'll_from' . $dir );
} else {
- $this->addOption( 'ORDER BY', 'll_title, ll_from' );
+ $this->addOption( 'ORDER BY', array(
+ 'll_title' . $dir,
+ 'll_from' . $dir
+ ));
}
} 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' );
+ $this->addOption( 'ORDER BY', 'll_lang' . $dir );
} else {
- $this->addOption( 'ORDER BY', 'll_from, ll_lang' );
+ $this->addOption( 'ORDER BY', array(
+ 'll_from' . $dir,
+ 'll_lang' . $dir
+ ));
}
}
@@ -135,6 +142,13 @@ class ApiQueryLangLinks extends ApiQueryBase {
'url' => false,
'lang' => null,
'title' => null,
+ 'dir' => array(
+ ApiBase::PARAM_DFLT => 'ascending',
+ ApiBase::PARAM_TYPE => array(
+ 'ascending',
+ 'descending'
+ )
+ ),
);
}
@@ -145,6 +159,7 @@ class ApiQueryLangLinks extends ApiQueryBase {
'url' => 'Whether to get the full URL',
'lang' => 'Language code',
'title' => "Link to search for. Must be used with {$this->getModulePrefix()}lang",
+ 'dir' => 'The direction in which to list',
);
}
diff --git a/includes/api/ApiQueryLinks.php b/includes/api/ApiQueryLinks.php
index 8090dafa7483..e2524a5066db 100644
--- a/includes/api/ApiQueryLinks.php
+++ b/includes/api/ApiQueryLinks.php
@@ -48,6 +48,7 @@ class ApiQueryLinks extends ApiQueryGeneratorBase {
$this->prefix = 'pl';
$this->description = 'link';
$this->titlesParam = 'titles';
+ $this->titlesParamDescription = 'Only list links to these titles. Useful for checking whether a certain page links to a certain title.';
$this->helpUrl = 'http://www.mediawiki.org/wiki/API:Properties#links_.2F_pl';
break;
case self::TEMPLATES:
@@ -55,6 +56,7 @@ class ApiQueryLinks extends ApiQueryGeneratorBase {
$this->prefix = 'tl';
$this->description = 'template';
$this->titlesParam = 'templates';
+ $this->titlesParamDescription = 'Only list these templates. Useful for checking whether a certain page uses a certain template.';
$this->helpUrl = 'http://www.mediawiki.org/wiki/API:Properties#templates_.2F_tl';
break;
default:
@@ -131,6 +133,7 @@ class ApiQueryLinks extends ApiQueryGeneratorBase {
);
}
+ $dir = ( $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
@@ -138,15 +141,15 @@ class ApiQueryLinks extends ApiQueryGeneratorBase {
// clause from the ORDER BY clause
$order = array();
if ( count( $this->getPageSet()->getGoodTitles() ) != 1 ) {
- $order[] = "{$this->prefix}_from";
+ $order[] = $this->prefix . '_from' . $dir;
}
if ( count( $params['namespace'] ) != 1 ) {
- $order[] = "{$this->prefix}_namespace";
+ $order[] = $this->prefix . '_namespace' . $dir;
}
- $order[] = "{$this->prefix}_title";
- $this->addOption( 'ORDER BY', implode( ', ', $order ) );
- $this->addOption( 'USE INDEX', "{$this->prefix}_from" );
+ $order[] = $this->prefix . "_title" . $dir;
+ $this->addOption( 'ORDER BY', $order );
+ $this->addOption( 'USE INDEX', $this->prefix . '_from' );
$this->addOption( 'LIMIT', $params['limit'] + 1 );
$res = $this->select( __METHOD__ );
@@ -207,22 +210,25 @@ class ApiQueryLinks extends ApiQueryGeneratorBase {
$this->titlesParam => array(
ApiBase::PARAM_ISMULTI => true,
),
+ 'dir' => array(
+ ApiBase::PARAM_DFLT => 'ascending',
+ ApiBase::PARAM_TYPE => array(
+ 'ascending',
+ 'descending'
+ )
+ ),
);
}
public function getParamDescription() {
$desc = $this->description;
- $arr = array(
+ return array(
'namespace' => "Show {$desc}s in this namespace(s) only",
'limit' => "How many {$desc}s to return",
'continue' => 'When more results are available, use this to continue',
+ $this->titlesParam => $this->titlesParamDescription,
+ 'dir' => 'The direction in which to list',
);
- if ( $this->getModuleName() == self::LINKS ) {
- $arr[$this->titlesParam] = 'Only list links to these titles. Useful for checking whether a certain page links to a certain title.';
- } elseif ( $this->getModuleName() == self::TEMPLATES ) {
- $arr[$this->titlesParam] = 'Only list these templates. Useful for checking whether a certain page uses a certain template.';
- }
- return $arr;
}
public function getDescription() {