00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 if (!defined('MEDIAWIKI')) {
00027
00028 require_once ("ApiQueryBase.php");
00029 }
00030
00036 class ApiQueryCategoryInfo extends ApiQueryBase {
00037
00038 public function __construct($query, $moduleName) {
00039 parent :: __construct($query, $moduleName, 'ci');
00040 }
00041
00042 public function execute() {
00043 $params = $this->extractRequestParams();
00044 $alltitles = $this->getPageSet()->getAllTitlesByNamespace();
00045 if ( empty( $alltitles[NS_CATEGORY] ) ) {
00046 return;
00047 }
00048 $categories = $alltitles[NS_CATEGORY];
00049
00050 $titles = $this->getPageSet()->getGoodTitles() +
00051 $this->getPageSet()->getMissingTitles();
00052 $cattitles = array();
00053 foreach($categories as $c)
00054 {
00055 $t = $titles[$c];
00056 $cattitles[$c] = $t->getDBKey();
00057 }
00058
00059 $this->addTables(array('category', 'page', 'page_props'));
00060 $this->addJoinConds(array(
00061 'page' => array('LEFT JOIN', array(
00062 'page_namespace' => NS_CATEGORY,
00063 'page_title=cat_title')),
00064 'page_props' => array('LEFT JOIN', array(
00065 'pp_page=page_id',
00066 'pp_propname' => 'hiddencat')),
00067 ));
00068 $this->addFields(array('cat_title', 'cat_pages', 'cat_subcats', 'cat_files', 'pp_propname AS cat_hidden'));
00069 $this->addWhere(array('cat_title' => $cattitles));
00070 if(!is_null($params['continue']))
00071 {
00072 $title = $this->getDB()->addQuotes($params['continue']);
00073 $this->addWhere("cat_title >= $title");
00074 }
00075 $this->addOption('ORDER BY', 'cat_title');
00076
00077 $db = $this->getDB();
00078 $res = $this->select(__METHOD__);
00079
00080 $catids = array_flip($cattitles);
00081 while($row = $db->fetchObject($res))
00082 {
00083 $vals = array();
00084 $vals['size'] = intval($row->cat_pages);
00085 $vals['pages'] = $row->cat_pages - $row->cat_subcats - $row->cat_files;
00086 $vals['files'] = intval($row->cat_files);
00087 $vals['subcats'] = intval($row->cat_subcats);
00088 if($row->cat_hidden)
00089 $vals['hidden'] = '';
00090 $fit = $this->addPageSubItems($catids[$row->cat_title], $vals);
00091 if(!$fit)
00092 {
00093 $this->setContinueEnumParameter('continue', $row->cat_title);
00094 break;
00095 }
00096 }
00097 $db->freeResult($res);
00098 }
00099
00100 public function getAllowedParams() {
00101 return array (
00102 'continue' => null,
00103 );
00104 }
00105
00106 public function getParamDescription() {
00107 return array (
00108 'continue' => 'When more results are available, use this to continue',
00109 );
00110 }
00111
00112 public function getDescription() {
00113 return 'Returns information about the given categories';
00114 }
00115
00116 protected function getExamples() {
00117 return "api.php?action=query&prop=categoryinfo&titles=Category:Foo|Category:Bar";
00118 }
00119
00120 public function getVersion() {
00121 return __CLASS__ . ': $Id: ApiQueryCategoryInfo.php 47865 2009-02-27 16:03:01Z catrope $';
00122 }
00123 }