3 * Created on 16 April 2011
4 * API for Gadgets extension
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 * http://www.gnu.org/copyleft/gpl.html
22 class ApiQueryGadgetCategories extends ApiQueryBase {
33 public function __construct( ApiQuery $queryModule, $moduleName ) {
34 parent::__construct( $queryModule, $moduleName, 'gc' );
37 public function execute() {
38 $params = $this->extractRequestParams();
39 $this->props = array_flip( $params['prop'] );
40 $this->neededNames = isset( $params['names'] )
41 ? array_flip( $params['names'] )
44 $this->getMain()->setCacheMode( 'public' );
49 private function getList() {
51 $result = $this->getResult();
52 $gadgets = GadgetRepo::singleton()->getStructuredList();
55 foreach ( $gadgets as $category => $list ) {
56 if ( !$this->neededNames || isset( $this->neededNames[$category] ) ) {
58 if ( isset( $this->props['name'] ) ) {
59 $row['name'] = $category;
62 if ( $category !== "" ) {
63 if ( isset( $this->props['title'] ) ) {
64 $row['desc'] = $this->msg( "gadget-section-$category" )->parse();
68 if ( isset( $this->props['members'] ) ) {
69 $row['members'] = count( $list );
76 $result->setIndexedTagName( $data, 'category' );
77 $result->addValue( 'query', $this->getModuleName(), $data );
80 public function getAllowedParams() {
83 ApiBase::PARAM_DFLT => 'name',
84 ApiBase::PARAM_ISMULTI => true,
85 ApiBase::PARAM_TYPE => [
92 ApiBase::PARAM_TYPE => 'string',
93 ApiBase::PARAM_ISMULTI => true,
99 * @see ApiBase::getExamplesMessages()
102 protected function getExamplesMessages() {
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',