MediaWiki  1.23.14
ApiQueryCategoryInfo.php
Go to the documentation of this file.
1 <?php
34 
35  public function __construct( $query, $moduleName ) {
36  parent::__construct( $query, $moduleName, 'ci' );
37  }
38 
39  public function execute() {
40  $params = $this->extractRequestParams();
41  $alltitles = $this->getPageSet()->getAllTitlesByNamespace();
42  if ( empty( $alltitles[NS_CATEGORY] ) ) {
43  return;
44  }
45  $categories = $alltitles[NS_CATEGORY];
46 
47  $titles = $this->getPageSet()->getGoodTitles() +
48  $this->getPageSet()->getMissingTitles();
49  $cattitles = array();
50  foreach ( $categories as $c ) {
52  $t = $titles[$c];
53  $cattitles[$c] = $t->getDBkey();
54  }
55 
56  $this->addTables( array( 'category', 'page', 'page_props' ) );
57  $this->addJoinConds( array(
58  'page' => array( 'LEFT JOIN', array(
59  'page_namespace' => NS_CATEGORY,
60  'page_title=cat_title' ) ),
61  'page_props' => array( 'LEFT JOIN', array(
62  'pp_page=page_id',
63  'pp_propname' => 'hiddencat' ) ),
64  ) );
65 
66  $this->addFields( array(
67  'cat_title',
68  'cat_pages',
69  'cat_subcats',
70  'cat_files',
71  'cat_hidden' => 'pp_propname'
72  ) );
73  $this->addWhere( array( 'cat_title' => $cattitles ) );
74 
75  if ( !is_null( $params['continue'] ) ) {
76  $title = $this->getDB()->addQuotes( $params['continue'] );
77  $this->addWhere( "cat_title >= $title" );
78  }
79  $this->addOption( 'ORDER BY', 'cat_title' );
80 
81  $res = $this->select( __METHOD__ );
82 
83  $catids = array_flip( $cattitles );
84  foreach ( $res as $row ) {
85  $vals = array();
86  $vals['size'] = intval( $row->cat_pages );
87  $vals['pages'] = $row->cat_pages - $row->cat_subcats - $row->cat_files;
88  $vals['files'] = intval( $row->cat_files );
89  $vals['subcats'] = intval( $row->cat_subcats );
90  if ( $row->cat_hidden ) {
91  $vals['hidden'] = '';
92  }
93  $fit = $this->addPageSubItems( $catids[$row->cat_title], $vals );
94  if ( !$fit ) {
95  $this->setContinueEnumParameter( 'continue', $row->cat_title );
96  break;
97  }
98  }
99  }
100 
101  public function getCacheMode( $params ) {
102  return 'public';
103  }
104 
105  public function getAllowedParams() {
106  return array(
107  'continue' => null,
108  );
109  }
110 
111  public function getParamDescription() {
112  return array(
113  'continue' => 'When more results are available, use this to continue',
114  );
115  }
116 
117  public function getResultProperties() {
118  return array(
119  ApiBase::PROP_LIST => false,
120  '' => array(
121  'size' => array(
122  ApiBase::PROP_TYPE => 'integer',
123  ApiBase::PROP_NULLABLE => false
124  ),
125  'pages' => array(
126  ApiBase::PROP_TYPE => 'integer',
127  ApiBase::PROP_NULLABLE => false
128  ),
129  'files' => array(
130  ApiBase::PROP_TYPE => 'integer',
131  ApiBase::PROP_NULLABLE => false
132  ),
133  'subcats' => array(
134  ApiBase::PROP_TYPE => 'integer',
135  ApiBase::PROP_NULLABLE => false
136  ),
137  'hidden' => array(
138  ApiBase::PROP_TYPE => 'boolean',
139  ApiBase::PROP_NULLABLE => false
140  )
141  )
142  );
143  }
144 
145  public function getDescription() {
146  return 'Returns information about the given categories.';
147  }
148 
149  public function getExamples() {
150  return 'api.php?action=query&prop=categoryinfo&titles=Category:Foo|Category:Bar';
151  }
152 
153  public function getHelpUrls() {
154  return 'https://www.mediawiki.org/wiki/API:Properties#categoryinfo_.2F_ci';
155  }
156 }
ApiQueryBase\addPageSubItems
addPageSubItems( $pageId, $data)
Add a sub-element under the page element with the given page ID.
Definition: ApiQueryBase.php:366
ApiQueryBase\addFields
addFields( $value)
Add a set of fields to select to the internal array.
Definition: ApiQueryBase.php:117
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
ApiQueryCategoryInfo
This query adds the "<categories>" subelement to all pages with the list of categories the page is in...
Definition: ApiQueryCategoryInfo.php:33
ApiQueryCategoryInfo\getHelpUrls
getHelpUrls()
Definition: ApiQueryCategoryInfo.php:153
ApiQueryBase\select
select( $method, $extraQuery=array())
Execute a SELECT query based on the values in the internal arrays.
Definition: ApiQueryBase.php:274
$params
$params
Definition: styleTest.css.php:40
ApiQueryCategoryInfo\getCacheMode
getCacheMode( $params)
Get the cache mode for the data generated by this module.
Definition: ApiQueryCategoryInfo.php:101
ApiQueryBase\addOption
addOption( $name, $value=null)
Add an option such as LIMIT or USE INDEX.
Definition: ApiQueryBase.php:252
ApiBase\PROP_LIST
const PROP_LIST
Definition: ApiBase.php:73
ApiQueryCategoryInfo\getParamDescription
getParamDescription()
Returns an array of parameter descriptions.
Definition: ApiQueryCategoryInfo.php:111
$titles
linkcache txt The LinkCache class maintains a list of article titles and the information about whether or not the article exists in the database This is used to mark up links when displaying a page If the same link appears more than once on any page then it only has to be looked up once In most cases link lookups are done in batches with the LinkBatch class or the equivalent in so the link cache is mostly useful for short snippets of parsed and for links in the navigation areas of the skin The link cache was formerly used to track links used in a document for the purposes of updating the link tables This application is now deprecated To create a you can use the following $titles
Definition: linkcache.txt:17
ApiQueryBase
This is a base class for all Query modules.
Definition: ApiQueryBase.php:34
ApiQueryCategoryInfo\getResultProperties
getResultProperties()
Returns possible properties in the result, grouped by the value of the prop parameter that shows them...
Definition: ApiQueryCategoryInfo.php:117
ApiQueryBase\getDB
getDB()
Get the Query database connection (read-only)
Definition: ApiQueryBase.php:417
ApiQueryBase\addTables
addTables( $tables, $alias=null)
Add a set of tables to the internal array.
Definition: ApiQueryBase.php:82
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
NS_CATEGORY
const NS_CATEGORY
Definition: Defines.php:93
ApiBase\PROP_TYPE
const PROP_TYPE
Definition: ApiBase.php:74
ApiQueryCategoryInfo\execute
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
Definition: ApiQueryCategoryInfo.php:39
ApiBase\extractRequestParams
extractRequestParams( $parseLimit=true)
Using getAllowedParams(), this function makes an array of the values provided by the user,...
Definition: ApiBase.php:707
$title
presenting them properly to the user as errors is done by the caller $title
Definition: hooks.txt:1324
ApiQueryCategoryInfo\getExamples
getExamples()
Returns usage examples for this module.
Definition: ApiQueryCategoryInfo.php:149
ApiQueryCategoryInfo\__construct
__construct( $query, $moduleName)
Definition: ApiQueryCategoryInfo.php:35
ApiBase\PROP_NULLABLE
const PROP_NULLABLE
Definition: ApiBase.php:76
ApiQueryBase\addJoinConds
addJoinConds( $join_conds)
Add a set of JOIN conditions to the internal array.
Definition: ApiQueryBase.php:106
ApiQueryCategoryInfo\getAllowedParams
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
Definition: ApiQueryCategoryInfo.php:105
ApiQueryBase\getPageSet
getPageSet()
Get the PageSet object to work on.
Definition: ApiQueryBase.php:441
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
ApiQueryCategoryInfo\getDescription
getDescription()
Returns the description string for this module.
Definition: ApiQueryCategoryInfo.php:145
ApiQueryBase\addWhere
addWhere( $value)
Add a set of WHERE clauses to the internal array.
Definition: ApiQueryBase.php:152
$t
$t
Definition: testCompression.php:65
ApiQueryBase\setContinueEnumParameter
setContinueEnumParameter( $paramName, $paramValue)
Set a query-continue value.
Definition: ApiQueryBase.php:404
$query
return true to allow those checks to and false if checking is done use this to change the tables headers temp or archived zone change it to an object instance and return false override the list derivative used the name of the old file when set the default code will be skipped add a value to it if you want to add a cookie that have to vary cache options can modify $query
Definition: hooks.txt:1105
$res
$res
Definition: database.txt:21