MediaWiki  1.28.0
ApiQueryCategoryInfo.php
Go to the documentation of this file.
1 <?php
34 
35  public function __construct( ApiQuery $query, $moduleName ) {
36  parent::__construct( $query, $moduleName, 'ci' );
37  }
38 
39  public function execute() {
40  $params = $this->extractRequestParams();
41  $alltitles = $this->getPageSet()->getGoodAndMissingTitlesByNamespace();
42  if ( empty( $alltitles[NS_CATEGORY] ) ) {
43  return;
44  }
45  $categories = $alltitles[NS_CATEGORY];
46 
47  $titles = $this->getPageSet()->getGoodAndMissingTitles();
48  $cattitles = [];
49  foreach ( $categories as $c ) {
51  $t = $titles[$c];
52  $cattitles[$c] = $t->getDBkey();
53  }
54 
55  $this->addTables( [ 'category', 'page', 'page_props' ] );
56  $this->addJoinConds( [
57  'page' => [ 'LEFT JOIN', [
58  'page_namespace' => NS_CATEGORY,
59  'page_title=cat_title' ] ],
60  'page_props' => [ 'LEFT JOIN', [
61  'pp_page=page_id',
62  'pp_propname' => 'hiddencat' ] ],
63  ] );
64 
65  $this->addFields( [
66  'cat_title',
67  'cat_pages',
68  'cat_subcats',
69  'cat_files',
70  'cat_hidden' => 'pp_propname'
71  ] );
72  $this->addWhere( [ 'cat_title' => $cattitles ] );
73 
74  if ( !is_null( $params['continue'] ) ) {
75  $title = $this->getDB()->addQuotes( $params['continue'] );
76  $this->addWhere( "cat_title >= $title" );
77  }
78  $this->addOption( 'ORDER BY', 'cat_title' );
79 
80  $res = $this->select( __METHOD__ );
81 
82  $catids = array_flip( $cattitles );
83  foreach ( $res as $row ) {
84  $vals = [];
85  $vals['size'] = intval( $row->cat_pages );
86  $vals['pages'] = $row->cat_pages - $row->cat_subcats - $row->cat_files;
87  $vals['files'] = intval( $row->cat_files );
88  $vals['subcats'] = intval( $row->cat_subcats );
89  $vals['hidden'] = (bool)$row->cat_hidden;
90  $fit = $this->addPageSubItems( $catids[$row->cat_title], $vals );
91  if ( !$fit ) {
92  $this->setContinueEnumParameter( 'continue', $row->cat_title );
93  break;
94  }
95  }
96  }
97 
98  public function getCacheMode( $params ) {
99  return 'public';
100  }
101 
102  public function getAllowedParams() {
103  return [
104  'continue' => [
105  ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
106  ],
107  ];
108  }
109 
110  protected function getExamplesMessages() {
111  return [
112  'action=query&prop=categoryinfo&titles=Category:Foo|Category:Bar'
113  => 'apihelp-query+categoryinfo-example-simple',
114  ];
115  }
116 
117  public function getHelpUrls() {
118  return 'https://www.mediawiki.org/wiki/API:Categoryinfo';
119  }
120 }
getDB()
Get the Query database connection (read-only)
null for the local wiki Added should default to null in handler for backwards compatibility add a value to it if you want to add a cookie that have to vary cache options can modify $query
Definition: hooks.txt:1555
This is a base class for all Query modules.
extractRequestParams($parseLimit=true)
Using getAllowedParams(), this function makes an array of the values provided by the user...
Definition: ApiBase.php:678
getPageSet()
Get the PageSet object to work on.
select($method, $extraQuery=[], array &$hookData=null)
Execute a SELECT query based on the values in the internal arrays.
addWhere($value)
Add a set of WHERE clauses to the internal array.
addJoinConds($join_conds)
Add a set of JOIN conditions to the internal array.
$res
Definition: database.txt:21
addOption($name, $value=null)
Add an option such as LIMIT or USE INDEX.
$params
const NS_CATEGORY
Definition: Defines.php:70
__construct(ApiQuery $query, $moduleName)
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:953
This is the main query class.
Definition: ApiQuery.php:38
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
const PARAM_HELP_MSG
(string|array|Message) Specify an alternative i18n documentation message for this parameter...
Definition: ApiBase.php:125
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
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
addFields($value)
Add a set of fields to select to the internal array.
setContinueEnumParameter($paramName, $paramValue)
Set a query-continue value.
addTables($tables, $alias=null)
Add a set of tables to the internal array.
This query adds the "" subelement to all pages with the list of categories the page is in...