r33914 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r33913‎ | r33914 | r33915 >
Date:15:30, 26 April 2008
Author:catrope
Status:old
Tags:
Comment:
(bug 13735) Added prop=categoryinfo module
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/AutoLoader.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQuery.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryCategoryInfo.php (added) (history)

Diff [purge]

Index: trunk/phase3/includes/api/ApiQuery.php
@@ -55,6 +55,7 @@
5656 'templates' => 'ApiQueryLinks',
5757 'categories' => 'ApiQueryCategories',
5858 'extlinks' => 'ApiQueryExternalLinks',
 59+ 'categoryinfo' => 'ApiQueryCategoryInfo',
5960 );
6061
6162 private $mQueryListModules = array (
Index: trunk/phase3/includes/api/ApiQueryCategoryInfo.php
@@ -0,0 +1,89 @@
 2+<?php
 3+
 4+/*
 5+ * Created on May 13, 2007
 6+ *
 7+ * API for MediaWiki 1.8+
 8+ *
 9+ * Copyright (C) 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com
 10+ *
 11+ * This program is free software; you can redistribute it and/or modify
 12+ * it under the terms of the GNU General Public License as published by
 13+ * the Free Software Foundation; either version 2 of the License, or
 14+ * (at your option) any later version.
 15+ *
 16+ * This program is distributed in the hope that it will be useful,
 17+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
 18+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 19+ * GNU General Public License for more details.
 20+ *
 21+ * You should have received a copy of the GNU General Public License along
 22+ * with this program; if not, write to the Free Software Foundation, Inc.,
 23+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 24+ * http://www.gnu.org/copyleft/gpl.html
 25+ */
 26+
 27+if (!defined('MEDIAWIKI')) {
 28+ // Eclipse helper - will be ignored in production
 29+ require_once ("ApiQueryBase.php");
 30+}
 31+
 32+/**
 33+ * This query adds <images> subelement to all pages with the list of images embedded into those pages.
 34+ *
 35+ * @addtogroup API
 36+ */
 37+class ApiQueryCategoryInfo extends ApiQueryBase {
 38+
 39+ public function __construct($query, $moduleName) {
 40+ parent :: __construct($query, $moduleName, 'ci');
 41+ }
 42+
 43+ public function execute() {
 44+ $alltitles = $this->getPageSet()->getAllTitlesByNamespace();
 45+ $categories = $alltitles[NS_CATEGORY];
 46+ if(empty($categories))
 47+ return;
 48+
 49+ $titles = $this->getPageSet()->getGoodTitles() +
 50+ $this->getPageSet()->getMissingTitles();
 51+ $cattitles = array();
 52+ foreach($categories as $c)
 53+ {
 54+ $t = $titles[$c];
 55+ $cattitles[$c] = $t->getDbKey();
 56+ }
 57+
 58+ $this->addTables('category');
 59+ $this->addFields(array('cat_title', 'cat_pages', 'cat_subcats', 'cat_files'));
 60+ $this->addWhere(array('cat_title' => $cattitles));
 61+
 62+ $db = $this->getDB();
 63+ $res = $this->select(__METHOD__);
 64+
 65+ $data = array();
 66+ $catids = array_flip($cattitles);
 67+ while($row = $db->fetchObject($res))
 68+ {
 69+ $vals = array();
 70+ $vals['size'] = $row->cat_pages;
 71+ $vals['pages'] = $row->cat_pages - $row->cat_subcats - $row->cat_files;
 72+ $vals['files'] = $row->cat_files;
 73+ $vals['subcats'] = $row->cat_subcats;
 74+ $this->addPageSubItems($catids[$row->cat_title], $vals);
 75+ }
 76+ $db->freeResult($res);
 77+ }
 78+
 79+ public function getDescription() {
 80+ return 'Returns information about the given categories';
 81+ }
 82+
 83+ protected function getExamples() {
 84+ return "api.php?action=query&prop=categoryinfo&titles=Category:Foo|Category:Bar";
 85+ }
 86+
 87+ public function getVersion() {
 88+ return __CLASS__ . ': $Id$';
 89+ }
 90+}
Property changes on: trunk/phase3/includes/api/ApiQueryCategoryInfo.php
___________________________________________________________________
Name: svn:eol-style
191 + native
Name: svn:keywords
292 + Id
Index: trunk/phase3/includes/AutoLoader.php
@@ -361,6 +361,7 @@
362362 'ApiQueryBase' => 'includes/api/ApiQueryBase.php',
363363 'ApiQueryCategories' => 'includes/api/ApiQueryCategories.php',
364364 'ApiQueryCategoryMembers' => 'includes/api/ApiQueryCategoryMembers.php',
 365+ 'ApiQueryCategoryInfo' => 'includes/api/ApiQueryCategoryInfo.php',
365366 'ApiQueryContributions' => 'includes/api/ApiQueryUserContributions.php',
366367 'ApiQueryExternalLinks' => 'includes/api/ApiQueryExternalLinks.php',
367368 'ApiQueryExtLinksUsage' => 'includes/api/ApiQueryExtLinksUsage.php',
Index: trunk/phase3/RELEASE-NOTES
@@ -269,6 +269,7 @@
270270 * Fixed handling of usernames containing spaces in list=block
271271 * (bug 13836) Fixed fatal errors resulting from combining iiprop=metadata with
272272 format=xml
 273+* (bug 13735) Added prop=categoryinfo module
273274
274275 === Languages updated in 1.13 ===
275276

Status & tagging log