r96761 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r96760‎ | r96761 | r96762 >
Date:00:08, 11 September 2011
Author:krinkle
Status:ok
Tags:
Comment:
[ResourceLoader2] (BREAKING CHANGE) Rename gd_name to gd_id to avoid confusion with "title"
* Database table
* Queries
* Class members
* Function names
* Function arguments
* Function documentation
* API parameter names and descriptions
* JavaScript usage
* SpecialPage variables

--
* Also changed typo in description of parameter 'names' in ApiQueryGadgetCategories.php

--

* To anyone who has this branch checked out, drop tables (mw_gadget and mw_gadgetpagelist) and run update.php. If needed we could write a migration script, but we're still very early on so not intending to support any previous installs here, since we're in a separate branch anyway.
Modified paths:
  • /branches/RL2/extensions/Gadgets/GadgetHooks.php (modified) (history)
  • /branches/RL2/extensions/Gadgets/Gadgets.php (modified) (history)
  • /branches/RL2/extensions/Gadgets/SpecialGadgetManager.php (modified) (history)
  • /branches/RL2/extensions/Gadgets/SpecialGadgets.php (modified) (history)
  • /branches/RL2/extensions/Gadgets/api/ApiGadgetManager.php (modified) (history)
  • /branches/RL2/extensions/Gadgets/api/ApiQueryGadgetCategories.php (modified) (history)
  • /branches/RL2/extensions/Gadgets/api/ApiQueryGadgets.php (modified) (history)
  • /branches/RL2/extensions/Gadgets/backend/Gadget.php (modified) (history)
  • /branches/RL2/extensions/Gadgets/backend/GadgetRepo.php (modified) (history)
  • /branches/RL2/extensions/Gadgets/backend/LocalGadgetRepo.php (modified) (history)
  • /branches/RL2/extensions/Gadgets/modules/ext.gadgets.gadgetmanager.api.js (modified) (history)
  • /branches/RL2/extensions/Gadgets/modules/ext.gadgets.gadgetmanager.ui.js (modified) (history)
  • /branches/RL2/extensions/Gadgets/sql/gadgets.sql (modified) (history)
  • /branches/RL2/extensions/Gadgets/tests/GadgetsTest.php (modified) (history)

Diff [purge]

Index: branches/RL2/extensions/Gadgets/sql/gadgets.sql
@@ -1,8 +1,8 @@
22 -- Add gadgets table
33
44 CREATE TABLE /*_*/gadgets (
5 - -- Name of gadget. Cannot be changed, ever.
6 - gd_name varchar(255) binary NOT NULL PRIMARY KEY,
 5+ -- Unique id of gadget. Cannot be changed, ever.
 6+ gd_id varchar(255) binary NOT NULL PRIMARY KEY,
77 -- JSON blob with gadget properties. See Gadget::__construct() for documentation on the format
88 gd_blob mediumblob NOT NULL,
99 -- Whether or not this gadget is allowed to be shared through a foreign repository
@@ -11,8 +11,8 @@
1212 gd_timestamp binary(14) NOT NULL
1313 ) /*$wgDBTableOptions*/;
1414
15 -CREATE INDEX /*i*/gd_shared_name ON /*_*/gadgets (gd_shared, gd_name);
16 -CREATE INDEX /*i*/gd_name_timestamp ON /*_*/gadgets (gd_name, gd_timestamp);
 15+CREATE INDEX /*i*/gd_shared_id ON /*_*/gadgets (gd_shared, gd_id);
 16+CREATE INDEX /*i*/gd_id_timestamp ON /*_*/gadgets (gd_id, gd_timestamp);
1717
1818 -- Table tracking .js and .css pages to make efficient prefix searches by extension possible
1919 -- (used for AJAX autocompletion)
Index: branches/RL2/extensions/Gadgets/tests/GadgetsTest.php
@@ -19,7 +19,7 @@
2020
2121 function testSimpleCases() {
2222 $g = $this->create( '* foo bar| foo.css|foo.js|foo.bar' );
23 - $this->assertEquals( 'foo_bar', $g->getName() );
 23+ $this->assertEquals( 'foo_bar', $g->getId() );
2424 $this->assertEquals( 'ext.gadget.foo_bar', $g->getModuleName() );
2525 $this->assertEquals( array( 'Gadget-foo.js' ), $g->getScripts() );
2626 $this->assertEquals( array( 'Gadget-foo.css' ), $g->getStyles() );
@@ -32,7 +32,7 @@
3333
3434 function testRLtag() {
3535 $g = $this->create( '*foo [ResourceLoader]|foo.js|foo.css' );
36 - $this->assertEquals( 'foo', $g->getName() );
 36+ $this->assertEquals( 'foo', $g->getId() );
3737 $this->assertTrue( $g->supportsResourceLoader() );
3838 $this->assertEquals(0, count( $g->getLegacyScripts() ) );
3939 }
Index: branches/RL2/extensions/Gadgets/Gadgets.php
@@ -81,7 +81,7 @@
8282 $wgNamespaceProtection[NS_GADGET][] = 'gadgets-edit';
8383 $wgNamespaceProtection[NS_GADGET_DEFINITION][] = 'gadgets-definition-edit';
8484
85 -// Page titles in this namespace should match gadget names,
 85+// Page titles in this namespace should match gadget ids,
8686 // which historically may start both lowercase or uppercase.
8787 $wgCapitalLinkOverrides[NS_GADGET_DEFINITION] = false;
8888
Index: branches/RL2/extensions/Gadgets/GadgetHooks.php
@@ -30,11 +30,11 @@
3131 if ( $title->getNamespace() !== NS_GADGET_DEFINITION || !preg_match( '!\.js$!u', $name ) ) {
3232 return true;
3333 }
34 - // Trim .js from the page name to obtain the gadget name
35 - $name = substr( $name, 0, -3 );
 34+ // Trim .js from the page name to obtain the gadget id
 35+ $id = substr( $name, 0, -3 );
3636
3737 $repo = new LocalGadgetRepo( array() );
38 - $repo->deleteGadget( $name );
 38+ $repo->deleteGadget( $id );
3939 // deleteGadget() may return an error if the Gadget didn't exist, but we don't care here
4040 return true;
4141 }
@@ -62,8 +62,8 @@
6363 if ( $title->getNamespace() !== NS_GADGET_DEFINITION || !preg_match( '!\.js$!u', $name ) || !$revision ) {
6464 return true;
6565 }
66 - // Trim .js from the page name to obtain the gadget name
67 - $name = substr( $name, 0, -3 );
 66+ // Trim .js from the page name to obtain the gadget id
 67+ $id = substr( $name, 0, -3 );
6868
6969 $previousRev = $revision->getPrevious();
7070 $prevTs = $previousRev instanceof Revision ? $previousRev->getTimestamp() : wfTimestampNow();
@@ -71,7 +71,7 @@
7272 // Update the database entry for this gadget
7373 $repo = new LocalGadgetRepo( array() );
7474 // TODO: Timestamp in the constructor is ugly
75 - $gadget = new Gadget( $name, $repo, $text, $prevTs );
 75+ $gadget = new Gadget( $id, $repo, $text, $prevTs );
7676 $repo->modifyGadget( $gadget, $revision->getTimestamp() );
7777
7878 // modifyGadget() returns a Status object with an error if there was a conflict,
@@ -94,13 +94,13 @@
9595 if ( $title->getNamespace() !== NS_GADGET_DEFINITION || !preg_match( '!\.js$!u', $name ) ) {
9696 return true;
9797 }
98 - // Trim .js from the page name to obtain the gadget name
99 - $name = substr( $name, 0, -3 );
 98+ // Trim .js from the page name to obtain the gadget id
 99+ $id = substr( $name, 0, -3 );
100100
101101 // Check whether this undeletion changed the latest revision of the page, by comparing
102102 // the timestamp of the latest revision with the timestamp in the DB
103103 $repo = new LocalGadgetRepo( array() );
104 - $gadget = $repo->getGadget( $name );
 104+ $gadget = $repo->getGadget( $id );
105105 $gadgetTS = $gadget ? $gadget->getTimestamp() : 0;
106106
107107 $rev = Revision::newFromTitle( $title );
@@ -111,7 +111,7 @@
112112 }
113113
114114 // Update the database entry for this gadget
115 - $newGadget = new Gadget( $name, $repo, $rev->getRawText(), $gadgetTS );
 115+ $newGadget = new Gadget( $id, $repo, $rev->getRawText(), $gadgetTS );
116116 $repo->modifyGadget( $newGadget, $rev->getTimestamp() );
117117
118118 // modifyGadget() returns a Status object with an error if there was a conflict,
@@ -190,11 +190,11 @@
191191 // TODO: Part of this is duplicated from registerModules(), factor out into the repo
192192 $repo = new LocalGadgetRepo( array() );
193193
194 - $gadgets = $repo->getGadgetNames();
 194+ $gadgets = $repo->getGadgetIds();
195195 $categories = array(); // array( category => array( desc => name ) )
196 - $default = array(); // array of Gadget names
197 - foreach ( $gadgets as $name ) {
198 - $gadget = $repo->getGadget( $name );
 196+ $default = array(); // array of Gadget ids
 197+ foreach ( $gadgets as $id ) {
 198+ $gadget = $repo->getGadget( $id );
199199 if ( !$gadget->isAllowed( $user ) || $gadget->isHidden() ) {
200200 continue;
201201 }
@@ -209,14 +209,14 @@
210210 } else {
211211 $text = wfMessage( 'gadgets-preference-description' )->rawParams( $title, $description )->parse();
212212 }
213 - $categories[$category][$text] = $name;
 213+ $categories[$category][$text] = $id;
214214 // Add the Gadget to the default list if enabled
215215 if ( $gadget->isEnabledForUser( $user ) ) {
216 - $default[] = $name;
 216+ $default[] = $id;
217217 }
218218 }
219219
220 - $options = array(); // array( desc1 => name1, category1 => array( desc2 => name2 ) )
 220+ $options = array(); // array( desc1 => gadget1, category1 => array( desc2 => gadget2 ) )
221221 foreach ( $categories as $category => $gadgets ) {
222222 if ( $category !== '' ) {
223223 $categoryMsg = wfMsgExt( "gadgetcategory-$category", 'parseinline' );
@@ -260,9 +260,9 @@
261261 unset( $params['class'] );
262262 $repo = new $repoClass( $params );
263263
264 - $gadgets = $repo->getGadgetNames();
265 - foreach ( $gadgets as $name ) {
266 - $gadget = $repo->getGadget( $name );
 264+ $gadgets = $repo->getGadgetIds();
 265+ foreach ( $gadgets as $id ) {
 266+ $gadget = $repo->getGadget( $id );
267267 $resourceLoader->register( $gadget->getModuleName(), $gadget->getModule() );
268268 }
269269 }
@@ -283,9 +283,9 @@
284284 unset( $params['class'] );
285285 $repo = new $repoClass( $params );
286286
287 - $gadgets = $repo->getGadgetNames();
288 - foreach ( $gadgets as $name ) {
289 - $gadget = $repo->getGadget( $name );
 287+ $gadgets = $repo->getGadgetIds();
 288+ foreach ( $gadgets as $id ) {
 289+ $gadget = $repo->getGadget( $id );
290290 if ( $gadget->isEnabledForUser( $wgUser ) && $gadget->isAllowed( $wgUser ) ) {
291291 $out->addModules( $gadget->getModuleName() );
292292 }
Index: branches/RL2/extensions/Gadgets/SpecialGadgets.php
@@ -85,16 +85,16 @@
8686 }
8787
8888 foreach ( $entries as $gadget ) {
89 - $t = Title::makeTitleSafe( NS_MEDIAWIKI, "Gadget-{$gadget->getName()}$lang" );
 89+ $t = Title::makeTitleSafe( NS_MEDIAWIKI, "Gadget-{$gadget->getId()}$lang" );
9090 if ( !$t ) continue;
9191
9292 $links = array();
9393 if ( $editInterfaceAllowed ) {
9494 $links[] = $skin->link( $t, wfMsgHTML( 'edit' ), array(), array( 'action' => 'edit' ) );
9595 }
96 - $links[] = $skin->link( $this->getTitle( "export/{$gadget->getName()}" ), wfMsgHtml( 'gadgets-export' ) );
 96+ $links[] = $skin->link( $this->getTitle( "export/{$gadget->getId()}" ), wfMsgHtml( 'gadgets-export' ) );
9797
98 - $ttext = wfMsgExt( "gadget-{$gadget->getName()}", $msgOpt );
 98+ $ttext = wfMsgExt( "gadget-{$gadget->getId()}", $msgOpt );
9999
100100 if( !$listOpen ) {
101101 $listOpen = true;
Index: branches/RL2/extensions/Gadgets/backend/Gadget.php
@@ -28,8 +28,8 @@
2929 * }
3030 */
3131 class Gadget {
32 - /** Gadget name (string) */
33 - protected $name;
 32+ /** Gadget id (string) */
 33+ protected $id;
3434
3535 /** Gadget repository this gadget came from (GadgetRepo object) */
3636 protected $repo;
@@ -54,13 +54,13 @@
5555
5656 /**
5757 * Constructor
58 - * @param $name string Name
 58+ * @param $id string Unique id of the gadget
5959 * @param $repo GadgetRepo that this gadget came from
6060 * @param $properties mixed Array or JSON blob (string) with settings and module info
6161 * @param $timestamp string Timestamp (TS_MW) this gadget's metadata was last touched
6262 * @throws MWException if $properties is invalid
6363 */
64 - public function __construct( $name, $repo, $properties, $timestamp ) {
 64+ public function __construct( $id, $repo, $properties, $timestamp ) {
6565 if ( is_string( $properties ) ) {
6666 $properties = FormatJson::decode( $properties, true );
6767 }
@@ -70,7 +70,7 @@
7171 throw new MWException( 'Invalid property array passed to ' . __METHOD__ );
7272 }
7373
74 - $this->name = $name;
 74+ $this->id = $id;
7575 $this->repo = $repo;
7676 $this->timestamp = $timestamp;
7777 $this->settings = $properties['settings'];
@@ -94,12 +94,13 @@
9595 }
9696
9797 /**
98 - * Get the name of the gadget. This name must be unique within its repository and must never change.
99 - * It is only used internally; the name displayed to the user is controlled by getNameMsg().
 98+ * Get the id of the gadget. This id must be unique within its repository and must never change.
 99+ * It is only used internally; the title displayed to the user is controlled by
 100+ * getTitleMessage() and getTitleMessageKey().
100101 * @return string
101102 */
102 - public function getName() {
103 - return $this->name;
 103+ public function getId() {
 104+ return $this->id;
104105 }
105106
106107 /**
@@ -120,17 +121,17 @@
121122
122123 /**
123124 * Get the key of the title message for this gadget. This is the interface message that
124 - * controls the name of the gadget as shown to the user.
 125+ * controls the title of the gadget as shown to the user.
125126 * @return string Message key
126127 */
127128 public function getTitleMessageKey() {
128 - return "gadget-{$this->name}-title";
 129+ return "gadget-{$this->id}-title";
129130 }
130131
131132 /**
132133 * Get the title message for this gadget
133134 * @param $langcode string Language code. If null, user language is used
134 - * @return The title message in the given language, or the name of the gadget if the message doesn't exist
 135+ * @return The title message in the given language, or the id of the gadget if the message doesn't exist
135136 */
136137 public function getTitleMessage( $langcode = null ) {
137138 $msg = wfMessage( $this->getTitleMessageKey() );
@@ -138,10 +139,10 @@
139140 $msg = $msg->inLanguage( $langcode );
140141 }
141142 if ( !$msg->exists() ) {
142 - // Fallback: return the name of the gadget
 143+ // Fallback: return the id of the gadget
143144 global $wgLang;
144145 $lang = $langcode === null ? $wgLang : Language::factory( $langcode );
145 - return $lang->ucfirst( $this->name );
 146+ return $lang->ucfirst( $this->id );
146147 }
147148 return $msg->plain();
148149
@@ -152,7 +153,7 @@
153154 * @return string Message key
154155 */
155156 public function getDescriptionMessageKey() {
156 - return "gadget-{$this->name}-desc";
 157+ return "gadget-{$this->id}-desc";
157158 }
158159
159160 /**
@@ -244,7 +245,7 @@
245246 * @return string Module name
246247 */
247248 public function getModuleName() {
248 - return "gadget.{$this->name}";
 249+ return "gadget.{$this->id}";
249250 }
250251
251252 public function getScripts() {
@@ -267,8 +268,8 @@
268269 * @return bool
269270 */
270271 public function isEnabledForUser( $user ) {
271 - $name = $this->getName();
272 - return (bool)$user->getOption( "gadget-$name", $this->isEnabledByDefault() );
 272+ $id = $this->getId();
 273+ return (bool)$user->getOption( "gadget-$id", $this->isEnabledByDefault() );
273274 }
274275
275276 /**
Index: branches/RL2/extensions/Gadgets/backend/LocalGadgetRepo.php
@@ -18,17 +18,17 @@
1919 // FIXME if there are none, drop the mandatory param
2020 }
2121
22 - public function getGadgetNames() {
 22+ public function getGadgetIds() {
2323 $this->loadData();
2424 return array_keys( $this->data );
2525 }
2626
27 - public function getGadget( $name ) {
 27+ public function getGadget( $id ) {
2828 $this->loadData();
29 - if ( !isset( $this->data[$name] ) ) {
 29+ if ( !isset( $this->data[$id] ) ) {
3030 return null;
3131 }
32 - return new Gadget( $name, $this, $this->data[$name]['json'], $this->data[$name]['timestamp'] );
 32+ return new Gadget( $id, $this, $this->data[$id]['json'], $this->data[$id]['timestamp'] );
3333 }
3434
3535 public function getSource() {
@@ -50,12 +50,12 @@
5151
5252 $dbw = $this->getMasterDB();
5353 $this->loadData();
54 - $name = $gadget->getName();
 54+ $id = $gadget->getId();
5555 $json = $gadget->getJSON();
5656 $ts = $dbw->timestamp( $gadget->getTimestamp() );
5757 $newTs = $dbw->timestamp( $timestamp );
5858 $row = array(
59 - 'gd_name' => $name,
 59+ 'gd_id' => $id,
6060 'gd_blob' => $json,
6161 'gd_shared' => $gadget->isShared(),
6262 'gd_timestamp' => $newTs
@@ -69,7 +69,7 @@
7070 // Then UPDATE it if it did already exist
7171 if ( !$created ) {
7272 $dbw->update( 'gadgets', $row, array(
73 - 'gd_name' => $name,
 73+ 'gd_id' => $id,
7474 'gd_timestamp <= ' . $dbw->addQuotes( $ts ) // for conflict detection
7575 ), __METHOD__
7676 );
@@ -79,7 +79,7 @@
8080 // Detect conflicts
8181 if ( $dbw->affectedRows() === 0 ) {
8282 // Some conflict occurred
83 - return Status::newFatal( 'gadgets-manager-modify-conflict', $name, $ts );
 83+ return Status::newFatal( 'gadgets-manager-modify-conflict', $id, $ts );
8484 }
8585
8686 // Update our in-object cache
@@ -87,26 +87,26 @@
8888 // to keep $this->data in a consistent format and have getGadget() always return
8989 // a clone. If it returned a reference to a cached object, the caller could change
9090 // that object and cause weird things to happen.
91 - $this->data[$name] = array( 'json' => $json, 'timestamp' => $newTs );
 91+ $this->data[$id] = array( 'json' => $json, 'timestamp' => $newTs );
9292
9393 return Status::newGood();
9494 }
9595
96 - public function deleteGadget( $name ) {
 96+ public function deleteGadget( $id ) {
9797 if ( !$this->isWriteable() ) {
9898 return Status::newFatal( 'gadget-manager-readonly-repository' );
9999 }
100100
101101 $this->loadData();
102 - if ( !isset( $this->data[$name] ) ) {
103 - return Status::newFatal( 'gadgets-manager-nosuchgadget', $name );
 102+ if ( !isset( $this->data[$id] ) ) {
 103+ return Status::newFatal( 'gadgets-manager-nosuchgadget', $id );
104104 }
105105
106 - unset( $this->data[$name] );
 106+ unset( $this->data[$id] );
107107 $dbw = $this->getMasterDB();
108 - $dbw->delete( 'gadgets', array( 'gd_name' => $name ), __METHOD__ );
 108+ $dbw->delete( 'gadgets', array( 'gd_id' => $id ), __METHOD__ );
109109 if ( $dbw->affectedRows() === 0 ) {
110 - return Status::newFatal( 'gadgets-manager-nosuchgadget', $name );
 110+ return Status::newFatal( 'gadgets-manager-nosuchgadget', $id );
111111 }
112112 return Status::newGood();
113113 }
@@ -150,7 +150,7 @@
151151 $query['options'], $query['join_conds'] );
152152
153153 foreach ( $res as $row ) {
154 - $this->data[$row->gd_name] = array( 'json' => $row->gd_blob, 'timestamp' => $row->gd_timestamp );
 154+ $this->data[$row->gd_id] = array( 'json' => $row->gd_blob, 'timestamp' => $row->gd_timestamp );
155155 }
156156 }
157157
@@ -161,7 +161,7 @@
162162 protected function getLoadDataQuery() {
163163 return array(
164164 'tables' => 'gadgets',
165 - 'fields' => array( 'gd_name', 'gd_blob', 'gd_timestamp' ),
 165+ 'fields' => array( 'gd_id', 'gd_blob', 'gd_timestamp' ),
166166 'conds' => '', // no WHERE clause
167167 'options' => array(),
168168 'join_conds' => array(),
Index: branches/RL2/extensions/Gadgets/backend/GadgetRepo.php
@@ -20,21 +20,21 @@
2121 abstract public function getSource();
2222
2323 /**
24 - * Get the names of the gadgets provided by this repository
25 - * @return array of names (strings)
 24+ * Get the ids of the gadgets provided by this repository
 25+ * @return array of ids (strings)
2626 */
27 - abstract public function getGadgetNames();
 27+ abstract public function getGadgetIds();
2828
2929 /**
30 - * Get a Gadget object for a given gadget name
31 - * @param $name string Gadget name
 30+ * Get a Gadget object for a given gadget id
 31+ * @param $id string Gadget id
3232 * @return Gadget object or null if no such gadget
3333 */
34 - abstract public function getGadget( $name );
 34+ abstract public function getGadget( $id );
3535
3636 /**
3737 * Clear any in-object caches this repository may have. In particular,
38 - * the return values of getGadgetNames() and getGadget() may be cached.
 38+ * the return values of getGadgetIds() and getGadget() may be cached.
3939 * Callers may wish to clear this cache and reobtain a Gadget object
4040 * when they get a conflict error.
4141 */
@@ -57,8 +57,8 @@
5858
5959 /**
6060 * Modify a gadget, replacing its metadata with the
61 - * metadata in the provided Gadget object. The name is taken
62 - * from the Gadget object as well. If no Gadget exists by that name,
 61+ * metadata in the provided Gadget object. The id is taken
 62+ * from the Gadget object as well. If no Gadget exists by that id,
6363 * it will be created.
6464 * @param $gadget Gadget object
6565 * @param $timestamp Timestamp to record for this action, or current timestamp if null
@@ -68,11 +68,11 @@
6969
7070 /**
7171 * Irrevocably delete a gadget from the repository. Will fail
72 - * if there is no gadget by the given name.
73 - * @param $name string Name of the gadget to delete
 72+ * if there is no gadget by the given id.
 73+ * @param $id string Unique id of the gadget to delete
7474 * @return Status
7575 */
76 - abstract public function deleteGadget( $name );
 76+ abstract public function deleteGadget( $id );
7777
7878 // TODO: cache purging
7979 }
Index: branches/RL2/extensions/Gadgets/modules/ext.gadgets.gadgetmanager.api.js
@@ -73,8 +73,8 @@
7474 format: 'json',
7575 action: 'query',
7676 list: 'gadgets',
77 - gaprop: 'name|metadata|desc',
78 - ganames: id,
 77+ gaprop: 'id|metadata|desc',
 78+ gaids: id,
7979 galanguage: mw.config.get( 'wgUserLanguage' )
8080 },
8181 type: 'GET',
Index: branches/RL2/extensions/Gadgets/modules/ext.gadgets.gadgetmanager.ui.js
@@ -108,7 +108,7 @@
109109 e.preventDefault();
110110 var $el = $( this );
111111 var gadget = {
112 - id: $el.data( 'gadgetname' ),
 112+ id: $el.data( 'gadget-id' ),
113113 displayTitle: $el.text(),
114114 metadata: null
115115 };
Index: branches/RL2/extensions/Gadgets/api/ApiQueryGadgets.php
@@ -22,7 +22,7 @@
2323 class ApiQueryGadgets extends ApiQueryBase {
2424 private $props,
2525 $category,
26 - $neededNames,
 26+ $neededIds,
2727 $listAllowed,
2828 $listEnabled;
2929
@@ -37,8 +37,8 @@
3838 $this->categories = isset( $params['categories'] )
3939 ? array_flip( $params['categories'] )
4040 : false;
41 - $this->neededNames = isset( $params['names'] )
42 - ? $params['names']
 41+ $this->neededIds = isset( $params['ids'] )
 42+ ? $params['ids']
4343 : false;
4444 $this->listAllowed = isset( $params['allowedonly'] ) && $params['allowedonly'];
4545 $this->listEnabled = isset( $params['enabledonly'] ) && $params['enabledonly'];
@@ -54,18 +54,18 @@
5555 $repo = new LocalGadgetRepo( array() );
5656 $result = array();
5757
58 - if ( $this->neededNames !== false ) {
59 - // Get all requested gadgets by name
60 - $names = $this->neededNames;
 58+ if ( $this->neededIds !== false ) {
 59+ // Get all requested gadgets by id
 60+ $ids = $this->neededIds;
6161 } else {
6262 // Get them all
63 - $names = $repo->getGadgetNames();
 63+ $ids = $repo->getGadgetIds();
6464 }
6565
66 - foreach ( $names as $name ) {
67 - $gadget = $repo->getGadget( $name );
 66+ foreach ( $ids as $id ) {
 67+ $gadget = $repo->getGadget( $id );
6868 if ( $gadget && $this->isNeeded( $gadget ) ) {
69 - $result[$name] = $gadget;
 69+ $result[$id] = $gadget;
7070 }
7171 }
7272
@@ -76,10 +76,10 @@
7777 $data = array();
7878 $result = $this->getResult();
7979
80 - foreach ( $gadgets as $name => $g ) {
 80+ foreach ( $gadgets as $id => $g ) {
8181 $row = array();
82 - if ( isset( $this->props['name'] ) ) {
83 - $row['name'] = $name;
 82+ if ( isset( $this->props['id'] ) ) {
 83+ $row['id'] = $id;
8484 }
8585 if ( isset( $this->props['metadata'] ) ) {
8686 $row['metadata'] = $g->getMetadata();
@@ -145,10 +145,10 @@
146146 public function getAllowedParams() {
147147 return array(
148148 'prop' => array(
149 - ApiBase::PARAM_DFLT => 'name|metadata',
 149+ ApiBase::PARAM_DFLT => 'id|metadata',
150150 ApiBase::PARAM_ISMULTI => true,
151151 ApiBase::PARAM_TYPE => array(
152 - 'name',
 152+ 'id',
153153 'metadata',
154154 'timestamp',
155155 'definitiontimestamp',
@@ -163,7 +163,7 @@
164164 ApiBase::PARAM_ISMULTI => true,
165165 ApiBase::PARAM_TYPE => 'string',
166166 ),
167 - 'names' => array(
 167+ 'ids' => array(
168168 ApiBase::PARAM_TYPE => 'string',
169169 ApiBase::PARAM_ISMULTI => true,
170170 ),
@@ -182,7 +182,7 @@
183183 return array(
184184 'prop' => array(
185185 'What gadget information to get:',
186 - ' name - Internal gadget name',
 186+ ' id - Internal gadget id',
187187 ' metadata - The gadget metadata',
188188 ' timestamp - Last changed timestamp of the gadget module, including any files it references',
189189 ' definitiontimestamp - Last changed timestamp of the gadget metadata',
@@ -193,7 +193,7 @@
194194 ),
195195 'language' => "Language code to use for {$p}prop=desc and {$p}prop=title. Defaults to the user language",
196196 'categories' => 'Gadgets from what categories to retrieve',
197 - 'names' => 'Name(s) of gadgets to retrieve',
 197+ 'ids' => 'Id(s) of gadgets to retrieve',
198198 'allowedonly' => 'List only gadgets allowed to current user',
199199 'enabledonly' => 'List only gadgets enabled by current user',
200200 'sharedonly' => 'Only list shared gadgets',
@@ -205,13 +205,13 @@
206206 $allProps = implode( '|', $params['prop'][ApiBase::PARAM_TYPE] );
207207 return array(
208208 'Get a list of gadgets along with their descriptions:',
209 - ' api.php?action=query&list=gadgets&gaprop=name|desc',
 209+ ' api.php?action=query&list=gadgets&gaprop=id|desc',
210210 'Get a list of gadgets with all possble properties:',
211211 " api.php?action=query&list=gadgets&gaprop=$allProps",
212212 'Get a list of gadgets belonging to caregory "foo":',
213213 ' api.php?action=query&list=gadgets&gacategories=foo',
214 - 'Get information about gadgets named "foo" and "bar":',
215 - ' api.php?action=query&list=gadgets&ganames=foo|bar&gaprop=name|desc|metadata',
 214+ 'Get information about gadgets "foo" and "bar":',
 215+ ' api.php?action=query&list=gadgets&gaids=foo|bar&gaprop=id|desc|metadata',
216216 'Get a list of gadgets enabled by current user:',
217217 ' api.php?action=query&list=gadgets&gaenabledonly',
218218 );
Index: branches/RL2/extensions/Gadgets/api/ApiGadgetManager.php
@@ -53,7 +53,7 @@
5454 }
5555
5656 // FIXME: Passing lasttimestamp into the constructor like this is a bit hacky
57 - $gadget = new Gadget( $params['name'], $repo, $json, $params['edittimestamp'] );
 57+ $gadget = new Gadget( $params['id'], $repo, $json, $params['edittimestamp'] );
5858 }
5959
6060 if ( $op === 'create' ) {
@@ -61,7 +61,7 @@
6262 } else if ( $op === 'modify' ) {
6363 $status = $repo->modifyGadget( $gadget );
6464 } else if ( $op === 'delete' ) {
65 - $status = $repo->deleteGadget( $params['name'] );
 65+ $status = $repo->deleteGadget( $params['id'] );
6666 }
6767
6868 if ( !$status->isGood() ) {
@@ -69,7 +69,7 @@
7070 $this->dieUsageMsg( $errors[0] ); // TODO: Actually register all the error messages in ApiBase::$messageMap somehow
7171 }
7272
73 - $r = array( 'result' => 'success', 'name' => $params['name'], 'op' => $op );
 73+ $r = array( 'result' => 'success', 'id' => $params['id'], 'op' => $op );
7474 $this->getResult()->addValue( null, $this->getModuleName(), $r );
7575 }
7676
@@ -87,7 +87,7 @@
8888 ApiBase::PARAM_TYPE => array( 'create', 'modify', 'delete' ),
8989 ApiBase::PARAM_REQUIRED => true
9090 ),
91 - 'name' => array(
 91+ 'id' => array(
9292 ApiBase::PARAM_TYPE => 'string',
9393 ApiBase::PARAM_REQUIRED => true
9494 ),
@@ -104,7 +104,7 @@
105105 public function getParamDescription() {
106106 return array(
107107 'op' => 'Operation to carry out',
108 - 'name' => 'Gadget name',
 108+ 'id' => 'Gadget id',
109109 'json' => 'If op=create or op=modify, JSON blob with the new gadget metadata. Ignored if op=delete',
110110 'edittimestamp' => 'If op=modify, the last modified timestamp of the gadget metadata, exactly as given by list=gadgets',
111111 'token' => 'Edit token',
Index: branches/RL2/extensions/Gadgets/api/ApiQueryGadgetCategories.php
@@ -44,12 +44,12 @@
4545 $data = array();
4646 $result = $this->getResult();
4747 $repo = new LocalGadgetRepo( array() );
48 - $gadgets = $repo->getGadgetNames();
 48+ $gadgets = $repo->getGadgetIds();
4949
5050 // TODO: Put the grouping in the repo
5151 $gadgetsByCategory = array();
52 - foreach ( $gadgets as $name ) {
53 - $gadget = $repo->getGadget( $name );
 52+ foreach ( $gadgets as $id ) {
 53+ $gadget = $repo->getGadget( $id );
5454 $gadgetsByCategory[$gadget->getCategory()][] = $gadget;
5555 }
5656
@@ -116,7 +116,7 @@
117117 ' title - Category title, translated in the given language',
118118 ' members - Number of gadgets in category',
119119 ),
120 - 'names' => 'Name(s) of gadgets to retrieve',
 120+ 'names' => 'Name(s) of categories to retrieve',
121121 'language' => "Language to use for {$p}prop=title",
122122 );
123123 }
Index: branches/RL2/extensions/Gadgets/SpecialGadgetManager.php
@@ -13,7 +13,7 @@
1414 }
1515
1616 /**
17 - * @param $par String: Optionally the gadgetname to show info for.
 17+ * @param $par String: Optionally the id of the gadget to show info for.
1818 */
1919 public function execute( $par ) {
2020 $out = $this->getOutput();
@@ -44,10 +44,10 @@
4545 global $wgGadgetEnableSharing;
4646
4747 $repo = new LocalGadgetRepo( array() );
48 - $gadgetNames = $repo->getGadgetNames();
 48+ $gadgetIds = $repo->getGadgetIds();
4949
5050 // If there there are no gadgets at all, exit early.
51 - if ( !count( $gadgetNames ) ) {
 51+ if ( !count( $gadgetIds ) ) {
5252 $noGadgetsMsgHtml = Html::element( 'p',
5353 array(
5454 'class' => 'mw-gadgetmanager-nogadgets'
@@ -62,9 +62,9 @@
6363
6464 // Sort gadgets by category
6565 $gadgetsByCategory = array();
66 - foreach ( $gadgetNames as $gadgetName ) {
67 - $gadget = $repo->getGadget( $gadgetName );
68 - $gadgetsByCategory[$gadget->getCategory()][$gadgetName] = $gadget;
 66+ foreach ( $gadgetIds as $gadgetId ) {
 67+ $gadget = $repo->getGadget( $gadgetId );
 68+ $gadgetsByCategory[$gadget->getCategory()][$gadgetId] = $gadget;
6969 }
7070
7171 // Sort categories alphabetically
@@ -99,7 +99,7 @@
100100 $html .= '<th>' . wfMessage( 'gadgetmanager-tablehead-lastmod' )->escaped() . '</th></tr>';
101101
102102 // Populate table rows for the current category
103 - foreach ( $gadgets as $gadgetName => $gadget ) {
 103+ foreach ( $gadgets as $gadgetId => $gadget ) {
104104 $html .= '<tr>';
105105
106106 $tickedCheckboxHtml = Html::element( 'input', array(
@@ -111,9 +111,9 @@
112112
113113 // Title
114114 $titleLink = Linker::link(
115 - $this->getTitle( $gadget->getName() ),
 115+ $this->getTitle( $gadget->getId() ),
116116 $gadget->getTitleMessage(),
117 - array( 'data-gadgetname' => $gadget->getName() )
 117+ array( 'data-gadget-id' => $gadget->getId() )
118118 );
119119 $html .= "<td class=\"mw-gadgetmanager-gadgets-title\">$titleLink</td>";
120120 // Default
@@ -130,7 +130,7 @@
131131
132132 // Last modified
133133 $lastModText = '';
134 - $definitionTitle = Title::makeTitleSafe( NS_GADGET_DEFINITION, $gadget->getName() . '.js' );
 134+ $definitionTitle = Title::makeTitleSafe( NS_GADGET_DEFINITION, $gadget->getId() . '.js' );
135135 if ( $definitionTitle ) {
136136 $definitionRev = Revision::newFromTitle( $definitionTitle );
137137 if ( $definitionRev ) {
@@ -174,9 +174,9 @@
175175 /**
176176 * @return String: HTML
177177 */
178 - public function generateGadgetView( $gadgetName ) {
 178+ public function generateGadgetView( $gadgetId ) {
179179 return 'TODO - This page is about "'
180 - . htmlspecialchars( $gadgetName )
 180+ . htmlspecialchars( $gadgetId )
181181 . '". Also used as permalink from other places.';
182182 }
183183 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r96832Fix description for gcnames parameter in list=gadgetcategories. Originated in...catrope11:03, 12 September 2011
r96833Update the Gadgets API in trunk for the name->ID change in r96761. See also r...catrope11:17, 12 September 2011
r97354[RL2] More renaming from 'name' to 'id'...krinkle01:32, 17 September 2011
r97363[RL2] More renaming from 'name' to 'id'...krinkle02:34, 17 September 2011

Status & tagging log