MediaWiki REL1_33
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}
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two and(2) offer you this license which gives you legal permission to copy
getMain()
Get the main module.
Definition ApiBase.php:528
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
getResult()
Get the result object.
Definition ApiBase.php:632
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user,...
Definition ApiBase.php:743
getModuleName()
Get the name of the module being executed by this instance.
Definition ApiBase.php:512
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.
$data
Utility to generate mapping file used in mw.Title (phpCharToUpper.json)
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))
$params