Index: trunk/extensions/Gadgets/Gadgets.php |
— | — | @@ -39,6 +39,7 @@ |
40 | 40 | $wgExtensionMessagesFiles['Gadgets'] = $dir . 'Gadgets.i18n.php'; |
41 | 41 | $wgExtensionAliasesFiles['Gadgets'] = $dir . 'Gadgets.alias.php'; |
42 | 42 | |
| 43 | +$wgAutoloadClasses['ApiQueryGadgetCategories'] = $dir . 'ApiQueryGadgetCategories.php'; |
43 | 44 | $wgAutoloadClasses['ApiQueryGadgets'] = $dir . 'ApiQueryGadgets.php'; |
44 | 45 | $wgAutoloadClasses['Gadget'] = $dir . 'Gadgets_body.php'; |
45 | 46 | $wgAutoloadClasses['GadgetHooks'] = $dir . 'Gadgets_body.php'; |
— | — | @@ -48,4 +49,5 @@ |
49 | 50 | $wgSpecialPages['Gadgets'] = 'SpecialGadgets'; |
50 | 51 | $wgSpecialPageGroups['Gadgets'] = 'wiki'; |
51 | 52 | |
| 53 | +$wgAPIListModules['gadgetcategories'] = 'ApiQueryGadgetCategories'; |
52 | 54 | $wgAPIListModules['gadgets'] = 'ApiQueryGadgets'; |
Index: trunk/extensions/Gadgets/ApiQueryGadgetCategories.php |
— | — | @@ -0,0 +1,122 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Created on 16 April 2011 |
| 5 | + * API for Gadgets extension |
| 6 | + * |
| 7 | + * This program is free software; you can redistribute it and/or modify |
| 8 | + * it under the terms of the GNU General Public License as published by |
| 9 | + * the Free Software Foundation; either version 2 of the License, or |
| 10 | + * (at your option) any later version. |
| 11 | + * |
| 12 | + * This program is distributed in the hope that it will be useful, |
| 13 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | + * GNU General Public License for more details. |
| 16 | + * |
| 17 | + * You should have received a copy of the GNU General Public License along |
| 18 | + * with this program; if not, write to the Free Software Foundation, Inc., |
| 19 | + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 20 | + * http://www.gnu.org/copyleft/gpl.html |
| 21 | + */ |
| 22 | + |
| 23 | +class ApiQueryGadgetCategories extends ApiQueryBase { |
| 24 | + private $props, |
| 25 | + $neededNames; |
| 26 | + |
| 27 | + public function __construct( $query, $moduleName ) { |
| 28 | + parent::__construct( $query, $moduleName, 'gc' ); |
| 29 | + } |
| 30 | + |
| 31 | + public function execute() { |
| 32 | + $params = $this->extractRequestParams(); |
| 33 | + $this->props = array_flip( $params['prop'] ); |
| 34 | + $this->neededNames = isset( $params['names'] ) |
| 35 | + ? array_flip( $params['names'] ) |
| 36 | + : false; |
| 37 | + |
| 38 | + $this->getMain()->setCacheMode( 'public' ); |
| 39 | + |
| 40 | + $this->getList(); |
| 41 | + } |
| 42 | + |
| 43 | + private function getList() { |
| 44 | + $data = array(); |
| 45 | + $result = $this->getResult(); |
| 46 | + $gadgets = Gadget::loadStructuredList(); |
| 47 | + |
| 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 | + if ( $category !== "" ) { |
| 55 | + if ( isset( $this->props['desc'] ) ) { |
| 56 | + $row['desc'] = wfMessage( "gadget-section-$category" )->parse(); |
| 57 | + } |
| 58 | + if ( isset( $this->props['desc-raw'] ) ) { |
| 59 | + $row['desc-raw'] = wfMessage( "gadget-section-$category" )->plain(); |
| 60 | + } |
| 61 | + } |
| 62 | + if ( isset( $this->props['members'] ) ) { |
| 63 | + $row['members'] = count( $list ); |
| 64 | + } |
| 65 | + $data[] = $row; |
| 66 | + } |
| 67 | + } |
| 68 | + $result->setIndexedTagName( $data, 'category' ); |
| 69 | + $result->addValue( 'query', $this->getModuleName(), $data ); |
| 70 | + } |
| 71 | + |
| 72 | + public function getAllowedParams() { |
| 73 | + return array( |
| 74 | + 'prop' => array( |
| 75 | + ApiBase::PARAM_DFLT => 'name', |
| 76 | + ApiBase::PARAM_ISMULTI => true, |
| 77 | + ApiBase::PARAM_TYPE => array( |
| 78 | + 'name', |
| 79 | + 'desc', |
| 80 | + 'desc-raw', |
| 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 | + ' desc - Category description transformed into HTML (can be slow, use only if really needed)', |
| 101 | + ' desc-raw - Category description in raw wikitext', |
| 102 | + ' members - Number of gadgets in category', |
| 103 | + ), |
| 104 | + 'names' => 'Name(s) of gadgets to retrieve', |
| 105 | + ); |
| 106 | + } |
| 107 | + |
| 108 | + protected function getExamples() { |
| 109 | + $params = $this->getAllowedParams(); |
| 110 | + $allProps = implode( '|', $params['prop'][ApiBase::PARAM_TYPE] ); |
| 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 | + |
| 123 | +} |
Property changes on: trunk/extensions/Gadgets/ApiQueryGadgetCategories.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 124 | + native |
Added: svn:keywords |
2 | 125 | + Id |