r45733 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r45732‎ | r45733 | r45734 >
Date:17:04, 14 January 2009
Author:catrope
Status:ok (Comments)
Tags:
Comment:
API: (bug 16844) Added clcategories parameter to prop=category to make checking whether a certain page is in a certain category more efficient
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryCategories.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/api/ApiQueryCategories.php
@@ -81,6 +81,19 @@
8282
8383 $this->addTables('categorylinks');
8484 $this->addWhereFld('cl_from', array_keys($this->getPageSet()->getGoodTitles()));
 85+ if(!is_null($params['categories']))
 86+ {
 87+ $cats = array();
 88+ foreach($params['categories'] as $cat)
 89+ {
 90+ $title = Title::newFromText($cat);
 91+ if($title->getNamespace() != NS_CATEGORY)
 92+ $this->setWarning("``$cat'' is not a category");
 93+ else
 94+ $cats[] = $title->getDBkey();
 95+ }
 96+ $this->addWhereFld('cl_to', $cats);
 97+ }
8598 if(!is_null($params['continue'])) {
8699 $cont = explode('|', $params['continue']);
87100 if(count($cont) != 2)
@@ -112,6 +125,7 @@
113126 $this->addWhere(array('pp_propname IS NULL'));
114127 }
115128
 129+ $this->addOption('USE INDEX', array('categorylinks' => 'cl_from'));
116130 # Don't order by cl_from if it's constant in the WHERE clause
117131 if(count($this->getPageSet()->getGoodTitles()) == 1)
118132 $this->addOption('ORDER BY', 'cl_to');
@@ -202,6 +216,9 @@
203217 ApiBase :: PARAM_MAX2 => ApiBase :: LIMIT_BIG2
204218 ),
205219 'continue' => null,
 220+ 'categories' => array(
 221+ ApiBase :: PARAM_ISMULTI => true,
 222+ ),
206223 );
207224 }
208225
@@ -211,6 +228,7 @@
212229 'limit' => 'How many categories to return',
213230 'show' => 'Which kind of categories to show',
214231 'continue' => 'When more results are available, use this to continue',
 232+ 'categories' => 'Only list these categories. Useful for checking whether a certain page is in a certain category',
215233 );
216234 }
217235
Index: trunk/phase3/RELEASE-NOTES
@@ -49,6 +49,7 @@
5050 incorrectly
5151 * (bug 16858) Revamped list=deletedrevs to make listing deleted contributions
5252 and listing all deleted pages possible
 53+* (bug 16844) Added clcategories parameter to prop=categories
5354
5455 === Languages updated in 1.15 ===
5556

Comments

#Comment by Umherirrender (talk | contribs)   17:31, 28 February 2009

I think the warning "``$cat is not a category" can changed to "$cat is not a category", to use the same apostrophe.

#Comment by Catrope (talk | contribs)   18:17, 28 February 2009

Actually, the ``foo quoting style is used pretty consistently throughout the API, and I see no reason to go change it everywhere.

#Comment by Umherirrender (talk | contribs)   21:25, 1 March 2009

Okay, I have not seen the format before, but when it used at other place than is there no reason to change it, that's right.

Status & tagging log