[ Index ] |
PHP Cross Reference of MediaWiki-1.24.0 |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Created on 16 April 2011 4 * API for Gadgets extension 5 * 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. 10 * 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. 15 * 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 20 */ 21 22 class ApiQueryGadgetCategories extends ApiQueryBase { 23 private $props, 24 $neededNames; 25 26 public function __construct( $query, $moduleName ) { 27 parent::__construct( $query, $moduleName, 'gc' ); 28 } 29 30 public function execute() { 31 $params = $this->extractRequestParams(); 32 $this->props = array_flip( $params['prop'] ); 33 $this->neededNames = isset( $params['names'] ) 34 ? array_flip( $params['names'] ) 35 : false; 36 37 $this->getMain()->setCacheMode( 'public' ); 38 39 $this->getList(); 40 } 41 42 private function getList() { 43 $data = array(); 44 $result = $this->getResult(); 45 $gadgets = Gadget::loadStructuredList(); 46 47 if ( $gadgets ) { 48 foreach ( $gadgets as $category => $list ) { 49 if ( !$this->neededNames || isset( $this->neededNames[$category] ) ) { 50 $row = array(); 51 if ( isset( $this->props['name'] ) ) { 52 $row['name'] = $category; 53 } 54 55 if ( $category !== "" ) { 56 if ( isset( $this->props['title'] ) ) { 57 $row['desc'] = $this->msg( "gadget-section-$category" )->parse(); 58 } 59 } 60 61 if ( isset( $this->props['members'] ) ) { 62 $row['members'] = count( $list ); 63 } 64 65 $data[] = $row; 66 } 67 } 68 } 69 $result->setIndexedTagName( $data, 'category' ); 70 $result->addValue( 'query', $this->getModuleName(), $data ); 71 } 72 73 public function getAllowedParams() { 74 return array( 75 'prop' => array( 76 ApiBase::PARAM_DFLT => 'name', 77 ApiBase::PARAM_ISMULTI => true, 78 ApiBase::PARAM_TYPE => array( 79 'name', 80 'title', 81 'members', 82 ), 83 ), 84 'names' => array( 85 ApiBase::PARAM_TYPE => 'string', 86 ApiBase::PARAM_ISMULTI => true, 87 ), 88 ); 89 } 90 91 public function getDescription() { 92 return 'Returns a list of gadget categories'; 93 } 94 95 public function getParamDescription() { 96 return array( 97 'prop' => array( 98 'What gadget category information to get:', 99 ' name - Internal category name', 100 ' title - Category title', 101 ' members - Number of gadgets in category', 102 ), 103 'names' => 'Name(s) of categories to retrieve', 104 ); 105 } 106 107 public function getExamples() { 108 $params = $this->getAllowedParams(); 109 $allProps = implode( '|', $params['prop'][ApiBase::PARAM_TYPE] ); 110 111 return array( 112 'Get a list of existing gadget categories:', 113 ' api.php?action=query&list=gadgetcategories', 114 'Get all information about categories named "foo" and "bar":', 115 " api.php?action=query&list=gadgetcategories&gcnames=foo|bar&gcprop=$allProps", 116 ); 117 } 118 119 public function getVersion() { 120 return __CLASS__ . ': $Id$'; 121 } 122 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 14:03:12 2014 | Cross-referenced by PHPXref 0.7.1 |