Index: trunk/extensions/Gadgets/ApiQueryGadgets.php |
— | — | @@ -74,40 +74,13 @@ |
75 | 75 | if ( isset( $this->props['name'] ) ) { |
76 | 76 | $row['name'] = $g->getName(); |
77 | 77 | } |
| 78 | + if ( isset( $this->props['metadata'] ) ) { |
| 79 | + $row['metadata'] = $this->fakeMetadata( $g ); |
| 80 | + $this->setIndexedTagNameForMetadata( $row['metadata'] ); |
| 81 | + } |
78 | 82 | if ( isset( $this->props['desc'] ) ) { |
79 | 83 | $row['desc'] = $g->getDescription(); |
80 | 84 | } |
81 | | - if ( isset( $this->props['desc-raw'] ) ) { |
82 | | - $row['desc-raw'] = $g->getRawDescription(); |
83 | | - } |
84 | | - if ( isset( $this->props['category'] ) ) { |
85 | | - $row['category'] = $g->getCategory(); |
86 | | - } |
87 | | - if ( isset( $this->props['resourceloader'] ) && $g->supportsResourceLoader() ) { |
88 | | - $row['resourceloader'] = ''; |
89 | | - } |
90 | | - if ( isset( $this->props['scripts'] ) ) { |
91 | | - $row['scripts'] = $g->getScripts(); |
92 | | - $result->setIndexedTagName( $row['scripts'], 'script' ); |
93 | | - } |
94 | | - if ( isset( $this->props['styles'] ) ) { |
95 | | - $row['styles'] = $g->getStyles(); |
96 | | - $result->setIndexedTagName( $row['styles'], 'style' ); |
97 | | - } |
98 | | - if ( isset( $this->props['dependencies'] ) ) { |
99 | | - $row['dependencies'] = $g->getDependencies(); |
100 | | - $result->setIndexedTagName( $row['dependencies'], 'module' ); |
101 | | - } |
102 | | - if ( isset( $this->props['rights'] ) ) { |
103 | | - $row['rights'] = $g->getRequiredRights(); |
104 | | - $result->setIndexedTagName( $row['rights'], 'right' ); |
105 | | - } |
106 | | - if ( isset( $this->props['default'] ) && $g->isOnByDefault() ) { |
107 | | - $row['default'] = ''; |
108 | | - } |
109 | | - if ( isset( $this->props['definition'] ) ) { |
110 | | - $row['definition'] = $g->getDefinition(); |
111 | | - } |
112 | 85 | $data[] = $row; |
113 | 86 | } |
114 | 87 | $result->setIndexedTagName( $data, 'gadget' ); |
— | — | @@ -124,26 +97,57 @@ |
125 | 98 | && ( !$this->listAllowed || $gadget->isAllowed( $wgUser ) ) |
126 | 99 | && ( !$this->listEnabled || $gadget->isEnabled( $wgUser ) ); |
127 | 100 | } |
| 101 | + |
| 102 | + private function fakeMetadata( Gadget $g ) { |
| 103 | + return array( |
| 104 | + 'settings' => array( |
| 105 | + 'rights' => $g->getRequiredRights(), |
| 106 | + 'default' => $g->isOnByDefault(), |
| 107 | + 'hidden' => false, // Only exists in RL2 branch |
| 108 | + 'shared' => false, // Only exists in RL2 branch |
| 109 | + 'category' => $g->getCategory(), |
| 110 | + ), |
| 111 | + 'module' => array( |
| 112 | + 'scripts' => $g->getScripts(), |
| 113 | + 'styles' => $g->getStyles(), |
| 114 | + 'dependencies' => $g->getDependencies(), |
| 115 | + 'messages' => array(), // Only exists in RL2 branch |
| 116 | + ) |
| 117 | + ); |
| 118 | + } |
128 | 119 | |
| 120 | + private function setIndexedTagNameForMetadata( &$metadata ) { |
| 121 | + static $tagNames = array( |
| 122 | + 'rights' => 'right', |
| 123 | + 'scripts' => 'script', |
| 124 | + 'styles' => 'style', |
| 125 | + 'dependencies' => 'dependency', |
| 126 | + 'messages' => 'message', |
| 127 | + ); |
| 128 | + |
| 129 | + $result = $this->getResult(); |
| 130 | + foreach ( $metadata as $type => &$data ) { |
| 131 | + foreach ( $data as $key => &$value ) { |
| 132 | + if ( is_array( $value ) ) { |
| 133 | + $tag = isset( $tagNames[$key] ) ? $tagNames[$key] : $key; |
| 134 | + $result->setIndexedTagName( $value, $tag ); |
| 135 | + } |
| 136 | + } |
| 137 | + } |
| 138 | + } |
| 139 | + |
129 | 140 | public function getAllowedParams() { |
130 | 141 | return array( |
131 | 142 | 'prop' => array( |
132 | | - ApiBase::PARAM_DFLT => 'name', |
| 143 | + ApiBase::PARAM_DFLT => 'name|metadata', |
133 | 144 | ApiBase::PARAM_ISMULTI => true, |
134 | 145 | ApiBase::PARAM_TYPE => array( |
135 | 146 | 'name', |
| 147 | + 'metadata', |
136 | 148 | 'desc', |
137 | | - 'desc-raw', |
138 | | - 'category', |
139 | | - 'resourceloader', |
140 | | - 'scripts', |
141 | | - 'styles', |
142 | | - 'dependencies', |
143 | | - 'rights', |
144 | | - 'default', |
145 | | - 'definition', |
146 | 149 | ), |
147 | 150 | ), |
| 151 | + 'language' => null, |
148 | 152 | 'categories' => array( |
149 | 153 | ApiBase::PARAM_ISMULTI => true, |
150 | 154 | ApiBase::PARAM_TYPE => 'string', |
— | — | @@ -162,20 +166,13 @@ |
163 | 167 | } |
164 | 168 | |
165 | 169 | public function getParamDescription() { |
| 170 | + $p = $this->getModulePrefix(); |
166 | 171 | return array( |
167 | 172 | 'prop' => array( |
168 | 173 | 'What gadget information to get:', |
169 | 174 | ' name - Internal gadget name', |
| 175 | + ' metadata - The gadget metadata', |
170 | 176 | ' desc - Gadget description transformed into HTML (can be slow, use only if really needed)', |
171 | | - ' desc-raw - Gadget description in raw wikitext', |
172 | | - ' category - Internal name of a category gadget belongs to (empty if top-level gadget)', |
173 | | - ' resourceloader - Whether gadget supports ResourceLoader', |
174 | | - " scripts - List of gadget's scripts", |
175 | | - " styles - List of gadget's styles", |
176 | | - ' dependencies - List of ResourceLoader modules gadget depends on', |
177 | | - ' rights - List of rights required to use gadget, if any', |
178 | | - ' default - Whether gadget is enabled by default', |
179 | | - ' definition - Line from MediaWiki:Gadgets-definition used to define the gadget', |
180 | 177 | ), |
181 | 178 | 'categories' => 'Gadgets from what categories to retrieve', |
182 | 179 | 'names' => 'Name(s) of gadgets to retrieve', |
— | — | @@ -195,7 +192,7 @@ |
196 | 193 | 'Get a list of gadgets belonging to caregory "foo":', |
197 | 194 | ' api.php?action=query&list=gadgets&gacategories=foo', |
198 | 195 | 'Get information about gadgets named "foo" and "bar":', |
199 | | - ' api.php?action=query&list=gadgets&ganames=foo|bar&gaprop=name|desc|category', |
| 196 | + ' api.php?action=query&list=gadgets&ganames=foo|bar&gaprop=name|desc|metadata', |
200 | 197 | 'Get a list of gadgets enabled by current user:', |
201 | 198 | ' api.php?action=query&list=gadgets&gaenabledonly', |
202 | 199 | ); |
Index: trunk/extensions/Gadgets/ApiQueryGadgetCategories.php |
— | — | @@ -51,12 +51,9 @@ |
52 | 52 | $row['name'] = $category; |
53 | 53 | } |
54 | 54 | if ( $category !== "" ) { |
55 | | - if ( isset( $this->props['desc'] ) ) { |
| 55 | + if ( isset( $this->props['title'] ) ) { |
56 | 56 | $row['desc'] = wfMessage( "gadget-section-$category" )->parse(); |
57 | 57 | } |
58 | | - if ( isset( $this->props['desc-raw'] ) ) { |
59 | | - $row['desc-raw'] = wfMessage( "gadget-section-$category" )->plain(); |
60 | | - } |
61 | 58 | } |
62 | 59 | if ( isset( $this->props['members'] ) ) { |
63 | 60 | $row['members'] = count( $list ); |
— | — | @@ -75,8 +72,7 @@ |
76 | 73 | ApiBase::PARAM_ISMULTI => true, |
77 | 74 | ApiBase::PARAM_TYPE => array( |
78 | 75 | 'name', |
79 | | - 'desc', |
80 | | - 'desc-raw', |
| 76 | + 'title', |
81 | 77 | 'members', |
82 | 78 | ), |
83 | 79 | ), |
— | — | @@ -96,8 +92,7 @@ |
97 | 93 | 'prop' => array( |
98 | 94 | 'What gadget category information to get:', |
99 | 95 | ' 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', |
| 96 | + ' title - Category title', |
102 | 97 | ' members - Number of gadgets in category', |
103 | 98 | ), |
104 | 99 | 'names' => 'Name(s) of gadgets to retrieve', |