From d70050053ad359102384a38f332db0e3ea59f991 Mon Sep 17 00:00:00 2001 From: Roan Kattouw Date: Wed, 14 Jan 2009 17:04:46 +0000 Subject: [PATCH] API: (bug 16844) Added clcategories parameter to prop=category to make checking whether a certain page is in a certain category more efficient --- RELEASE-NOTES | 1 + includes/api/ApiQueryCategories.php | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 2e0609c519..dceef20503 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -49,6 +49,7 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN incorrectly * (bug 16858) Revamped list=deletedrevs to make listing deleted contributions and listing all deleted pages possible +* (bug 16844) Added clcategories parameter to prop=categories === Languages updated in 1.15 === diff --git a/includes/api/ApiQueryCategories.php b/includes/api/ApiQueryCategories.php index cbff86bd0f..badca7ccc7 100644 --- a/includes/api/ApiQueryCategories.php +++ b/includes/api/ApiQueryCategories.php @@ -81,6 +81,19 @@ class ApiQueryCategories extends ApiQueryGeneratorBase { $this->addTables('categorylinks'); $this->addWhereFld('cl_from', array_keys($this->getPageSet()->getGoodTitles())); + if(!is_null($params['categories'])) + { + $cats = array(); + foreach($params['categories'] as $cat) + { + $title = Title::newFromText($cat); + if($title->getNamespace() != NS_CATEGORY) + $this->setWarning("``$cat'' is not a category"); + else + $cats[] = $title->getDBkey(); + } + $this->addWhereFld('cl_to', $cats); + } if(!is_null($params['continue'])) { $cont = explode('|', $params['continue']); if(count($cont) != 2) @@ -112,6 +125,7 @@ class ApiQueryCategories extends ApiQueryGeneratorBase { $this->addWhere(array('pp_propname IS NULL')); } + $this->addOption('USE INDEX', array('categorylinks' => 'cl_from')); # 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'); @@ -202,6 +216,9 @@ class ApiQueryCategories extends ApiQueryGeneratorBase { ApiBase :: PARAM_MAX2 => ApiBase :: LIMIT_BIG2 ), 'continue' => null, + 'categories' => array( + ApiBase :: PARAM_ISMULTI => true, + ), ); } @@ -211,6 +228,7 @@ class ApiQueryCategories extends ApiQueryGeneratorBase { 'limit' => 'How many categories to return', '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', ); } -- 2.20.1