r95980 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r95979‎ | r95980 | r95981 >
Date:13:20, 1 September 2011
Author:catrope
Status:ok
Tags:
Comment:
RL2: Expose the Gadget metadata natively, rather than JSON wrapped in another format (which may even be JSON in JSON, eww)
Modified paths:
  • /branches/RL2/extensions/Gadgets/api/ApiQueryGadgets.php (modified) (history)

Diff [purge]

Index: branches/RL2/extensions/Gadgets/api/ApiQueryGadgets.php
@@ -81,8 +81,9 @@
8282 if ( isset( $this->props['name'] ) ) {
8383 $row['name'] = $name;
8484 }
85 - if ( isset( $this->props['json'] ) ) {
86 - $row['json'] = $g->getJSON();
 85+ if ( isset( $this->props['metadata'] ) ) {
 86+ $row['metadata'] = $g->getMetadata();
 87+ $this->setIndexedTagNameForMetadata( $row['metadata'] );
8788 }
8889 if ( isset( $this->props['timestamp'] ) ) {
8990 $context = ResourceLoaderContext::newDummyContext();
@@ -120,15 +121,35 @@
121122 && ( !$this->listShared || $gadget->isShared() )
122123 && ( !$this->categories || isset( $this->categories[$g->getCategory()] ) );
123124 }
 125+
 126+ private function setIndexedTagNameForMetadata( &$metadata ) {
 127+ static $tagNames = array(
 128+ 'rights' => 'right',
 129+ 'scripts' => 'script',
 130+ 'styles' => 'style',
 131+ 'dependencies' => 'dependency',
 132+ 'messages' => 'message',
 133+ );
 134+
 135+ $result = $this->getResult();
 136+ foreach ( $metadata as $type => &$data ) {
 137+ foreach ( $data as $key => &$value ) {
 138+ if ( is_array( $value ) ) {
 139+ $tag = isset( $tagNames[$key] ) ? $tagNames[$key] : $key;
 140+ $result->setIndexedTagName( $value, $tag );
 141+ }
 142+ }
 143+ }
 144+ }
124145
125146 public function getAllowedParams() {
126147 return array(
127148 'prop' => array(
128 - ApiBase::PARAM_DFLT => 'name|json',
 149+ ApiBase::PARAM_DFLT => 'name|metadata',
129150 ApiBase::PARAM_ISMULTI => true,
130151 ApiBase::PARAM_TYPE => array(
131152 'name',
132 - 'json',
 153+ 'metadata',
133154 'timestamp',
134155 'definitiontimestamp',
135156 'desc',
@@ -162,7 +183,7 @@
163184 'prop' => array(
164185 'What gadget information to get:',
165186 ' name - Internal gadget name',
166 - ' json - JSON representation of the gadget metadata.',
 187+ ' metadata - The gadget metadata',
167188 ' timestamp - Last changed timestamp of the gadget module, including any files it references',
168189 ' definitiontimestamp - Last changed timestamp of the gadget metadata',
169190 ' desc - Gadget description translated in the given language and transformed into HTML (can be slow, use only if really needed)',

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r95979RL2: Factor the building of the metadata array in Gadget::getJSON() out to Ga...catrope13:18, 1 September 2011

Status & tagging log