MediaWiki REL1_31
ApiQueryGadgetCategories.php
Go to the documentation of this file.
1<?php
26 private $props;
27
31 private $neededNames;
32
33 public function __construct( ApiQuery $queryModule, $moduleName ) {
34 parent::__construct( $queryModule, $moduleName, 'gc' );
35 }
36
37 public function execute() {
39 $this->props = array_flip( $params['prop'] );
40 $this->neededNames = isset( $params['names'] )
41 ? array_flip( $params['names'] )
42 : false;
43
44 $this->getMain()->setCacheMode( 'public' );
45
46 $this->getList();
47 }
48
49 private function getList() {
50 $data = [];
51 $result = $this->getResult();
52 $gadgets = GadgetRepo::singleton()->getStructuredList();
53
54 if ( $gadgets ) {
55 foreach ( $gadgets as $category => $list ) {
56 if ( !$this->neededNames || isset( $this->neededNames[$category] ) ) {
57 $row = [];
58 if ( isset( $this->props['name'] ) ) {
59 $row['name'] = $category;
60 }
61
62 if ( $category !== "" ) {
63 if ( isset( $this->props['title'] ) ) {
64 $row['desc'] = $this->msg( "gadget-section-$category" )->parse();
65 }
66 }
67
68 if ( isset( $this->props['members'] ) ) {
69 $row['members'] = count( $list );
70 }
71
72 $data[] = $row;
73 }
74 }
75 }
76 $result->setIndexedTagName( $data, 'category' );
77 $result->addValue( 'query', $this->getModuleName(), $data );
78 }
79
80 public function getAllowedParams() {
81 return [
82 'prop' => [
83 ApiBase::PARAM_DFLT => 'name',
86 'name',
87 'title',
88 'members',
89 ],
90 ],
91 'names' => [
92 ApiBase::PARAM_TYPE => 'string',
94 ],
95 ];
96 }
97
102 protected function getExamplesMessages() {
103 return [
104 'action=query&list=gadgetcategories'
105 => 'apihelp-query+gadgetcategories-example-1',
106 'action=query&list=gadgetcategories&gcnames=foo|bar&gcprop=name|title|members'
107 => 'apihelp-query+gadgetcategories-example-2',
108 ];
109 }
110}
getMain()
Get the main module.
Definition ApiBase.php:537
const PARAM_TYPE
(string|string[]) Either an array of allowed value strings, or a string type as described below.
Definition ApiBase.php:87
const PARAM_DFLT
(null|boolean|integer|string) Default value of the parameter.
Definition ApiBase.php:48
extractRequestParams( $parseLimit=true)
Using getAllowedParams(), this function makes an array of the values provided by the user,...
Definition ApiBase.php:749
getResult()
Get the result object.
Definition ApiBase.php:641
getModuleName()
Get the name of the module being executed by this instance.
Definition ApiBase.php:521
const PARAM_ISMULTI
(boolean) Accept multiple pipe-separated values for this parameter (e.g.
Definition ApiBase.php:51
This is a base class for all Query modules.
Created on 16 April 2011 API for Gadgets extension.
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
__construct(ApiQuery $queryModule, $moduleName)
This is the main query class.
Definition ApiQuery.php:36
msg( $key)
Get a Message object with context set Parameters are the same as wfMessage()
static singleton()
Get the configured default GadgetRepo.
$params