r96006 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r96005‎ | r96006 | r96007 >
Date:16:08, 1 September 2011
Author:catrope
Status:ok
Tags:
Comment:
Gadgets: To prevent back compat hacks in 1.19, change the Gadgets API to be compatible with the one in the RL2 branch. The time to do this is now, because the Gadgets API was introduced after 1.17. Needs backporting to 1.18 too.
Modified paths:
  • /trunk/extensions/Gadgets/ApiQueryGadgetCategories.php (modified) (history)
  • /trunk/extensions/Gadgets/ApiQueryGadgets.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Gadgets/ApiQueryGadgets.php
@@ -74,40 +74,13 @@
7575 if ( isset( $this->props['name'] ) ) {
7676 $row['name'] = $g->getName();
7777 }
 78+ if ( isset( $this->props['metadata'] ) ) {
 79+ $row['metadata'] = $this->fakeMetadata( $g );
 80+ $this->setIndexedTagNameForMetadata( $row['metadata'] );
 81+ }
7882 if ( isset( $this->props['desc'] ) ) {
7983 $row['desc'] = $g->getDescription();
8084 }
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 - }
11285 $data[] = $row;
11386 }
11487 $result->setIndexedTagName( $data, 'gadget' );
@@ -124,26 +97,57 @@
12598 && ( !$this->listAllowed || $gadget->isAllowed( $wgUser ) )
12699 && ( !$this->listEnabled || $gadget->isEnabled( $wgUser ) );
127100 }
 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+ }
128119
 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+
129140 public function getAllowedParams() {
130141 return array(
131142 'prop' => array(
132 - ApiBase::PARAM_DFLT => 'name',
 143+ ApiBase::PARAM_DFLT => 'name|metadata',
133144 ApiBase::PARAM_ISMULTI => true,
134145 ApiBase::PARAM_TYPE => array(
135146 'name',
 147+ 'metadata',
136148 'desc',
137 - 'desc-raw',
138 - 'category',
139 - 'resourceloader',
140 - 'scripts',
141 - 'styles',
142 - 'dependencies',
143 - 'rights',
144 - 'default',
145 - 'definition',
146149 ),
147150 ),
 151+ 'language' => null,
148152 'categories' => array(
149153 ApiBase::PARAM_ISMULTI => true,
150154 ApiBase::PARAM_TYPE => 'string',
@@ -162,20 +166,13 @@
163167 }
164168
165169 public function getParamDescription() {
 170+ $p = $this->getModulePrefix();
166171 return array(
167172 'prop' => array(
168173 'What gadget information to get:',
169174 ' name - Internal gadget name',
 175+ ' metadata - The gadget metadata',
170176 ' 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',
180177 ),
181178 'categories' => 'Gadgets from what categories to retrieve',
182179 'names' => 'Name(s) of gadgets to retrieve',
@@ -195,7 +192,7 @@
196193 'Get a list of gadgets belonging to caregory "foo":',
197194 ' api.php?action=query&list=gadgets&gacategories=foo',
198195 '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',
200197 'Get a list of gadgets enabled by current user:',
201198 ' api.php?action=query&list=gadgets&gaenabledonly',
202199 );
Index: trunk/extensions/Gadgets/ApiQueryGadgetCategories.php
@@ -51,12 +51,9 @@
5252 $row['name'] = $category;
5353 }
5454 if ( $category !== "" ) {
55 - if ( isset( $this->props['desc'] ) ) {
 55+ if ( isset( $this->props['title'] ) ) {
5656 $row['desc'] = wfMessage( "gadget-section-$category" )->parse();
5757 }
58 - if ( isset( $this->props['desc-raw'] ) ) {
59 - $row['desc-raw'] = wfMessage( "gadget-section-$category" )->plain();
60 - }
6158 }
6259 if ( isset( $this->props['members'] ) ) {
6360 $row['members'] = count( $list );
@@ -75,8 +72,7 @@
7673 ApiBase::PARAM_ISMULTI => true,
7774 ApiBase::PARAM_TYPE => array(
7875 'name',
79 - 'desc',
80 - 'desc-raw',
 76+ 'title',
8177 'members',
8278 ),
8379 ),
@@ -96,8 +92,7 @@
9793 'prop' => array(
9894 'What gadget category information to get:',
9995 ' 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',
10297 ' members - Number of gadgets in category',
10398 ),
10499 'names' => 'Name(s) of gadgets to retrieve',

Sign-offs

UserFlagDate
Reedyinspected11:12, 9 September 2011

Follow-up revisions

RevisionCommit summaryAuthorDate
r96833Update the Gadgets API in trunk for the name->ID change in r96761. See also r...catrope11:17, 12 September 2011
r96850REL1_18: MFT r96006, 96627reedy15:10, 12 September 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r95971RL2: Kill a bunch of unneeded properties (covered in the JSON blob) in list=g...catrope12:27, 1 September 2011

Status & tagging log