r90708 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r90707‎ | r90708 | r90709 >
Date:10:22, 24 June 2011
Author:salvatoreingala
Status:deferred
Tags:
Comment:
- GadgetHooks::userSaveOptions now omits gadget preferences if they equal their default value
- Gadget::setPrefsDescription invalidates gadget's preferences, if they had previously been set
Modified paths:
  • /branches/salvatoreingala/Gadgets/backend/Gadget.php (modified) (history)
  • /branches/salvatoreingala/Gadgets/backend/GadgetHooks.php (modified) (history)

Diff [purge]

Index: branches/salvatoreingala/Gadgets/backend/Gadget.php
@@ -648,6 +648,8 @@
649649 * Sets the description of preferences for this gadget. If the given array is not valid,
650650 * then internal preference description is set to null.
651651 *
 652+ * Invalidates any previous preference value set with setPrefs().
 653+ *
652654 * @param $prefsDescription mixed an array with new preferences description, or null.
653655 *
654656 */
@@ -657,6 +659,9 @@
658660 } else {
659661 $this->prefsDescription = null;
660662 }
 663+
 664+ //Any previously set of preferences has no meaning now, set back to null
 665+ $this->preferences = null;
661666 }
662667
663668 //Check if a preference is valid, according to description
Index: branches/salvatoreingala/Gadgets/backend/GadgetHooks.php
@@ -236,11 +236,18 @@
237237 }
238238
239239 foreach ( $gadgets as $gadget ) {
240 - if ( $gadget->getPrefs() !== null ) {
241 - //TODO: should remove prefs that equal their default
242 -
243 - $prefsSerialized = serialize( $gadget->getPrefs() );
244 - $options["gadget-{$gadget->getName()}-config"] = $prefsSerialized;
 240+ $prefs = $gadget->getPrefs();
 241+ if ( $prefs !== null ) {
 242+ $prefsDescription = $gadget->getPrefsDescription();
 243+
 244+ //Remove preferences that equal their default
 245+ foreach ( $prefs as $prefName => $value ) {
 246+ if ( $prefsDescription['fields'][$prefName]['default'] === $value ) {
 247+ unset( $prefs[$prefName] );
 248+ }
 249+ }
 250+
 251+ $options["gadget-{$gadget->getName()}-config"] = serialize( $prefs );
245252 }
246253 }
247254

Status & tagging log