r91026 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r91025‎ | r91026 | r91027 >
Date:22:20, 28 June 2011
Author:salvatoreingala
Status:deferred
Tags:
Comment:
- Fixed bug on GadgetHooks::articleSaveComplete()
- Implemented getModifiedTime() method on gadget modules and on GadgetsGlobalModule
Modified paths:
  • /branches/salvatoreingala/Gadgets/backend/Gadget.php (modified) (history)
  • /branches/salvatoreingala/Gadgets/backend/GadgetHooks.php (modified) (history)
  • /branches/salvatoreingala/Gadgets/backend/GadgetResourceLoaderModule.php (modified) (history)
  • /branches/salvatoreingala/Gadgets/ui/GadgetsMainModule.php (modified) (history)

Diff [purge]

Index: branches/salvatoreingala/Gadgets/backend/Gadget.php
@@ -32,6 +32,7 @@
3333 $requiredRights = array(),
3434 $onByDefault = false,
3535 $category,
 36+ $mTime = null, //upper bound on last modification time; UNIX timestamp
3637 $prefsDescription = null,
3738 $preferences = null;
3839
@@ -52,6 +53,11 @@
5354 $gadget->name = trim( str_replace(' ', '_', $m[1] ) );
5455 $gadget->definition = $definition;
5556
 57+ //Could be made more precise using per-gadget info; an upper bound suffices.
 58+ //Since the list is reloaded every time gadget definitions or gadget preference descriptions
 59+ //are changed, 'now' is an upper bound.
 60+ $gadget->mTime = wfTimestamp( TS_UNIX );
 61+
5662 //Parse gadget options
5763 $options = trim( $m[2], ' []' );
5864 foreach ( preg_split( '/\s*\|\s*/', $options, -1, PREG_SPLIT_NO_EMPTY ) as $option ) {
@@ -236,6 +242,16 @@
237243 }
238244
239245 /**
 246+ * Returns an upper bound on the modification time of the gadget.
 247+ * Used by GadgetResourceLoaderModule to compute its own mTime.
 248+ *
 249+ * @return String the UNIX timestamp of this gadget's modificaton time.
 250+ */
 251+ public function getModifiedTime() {
 252+ return $this->mTime;
 253+ }
 254+
 255+ /**
240256 * Returns list of scripts that don't support ResourceLoader
241257 * @return Array
242258 */
Index: branches/salvatoreingala/Gadgets/backend/GadgetHooks.php
@@ -27,10 +27,15 @@
2828 //or if a Mediawiki:Gadget-foo.preferences was edited
2929 $title = $article->mTitle;
3030 if( $title->getNamespace() == NS_MEDIAWIKI ) {
31 - if ( $title->getText() == 'Gadgets-definition'
32 - || preg_match( '/Gadget-([a-zA-Z](?:[-_:.\w\d ]*[a-zA-Z0-9])?)-config/', $title->getText() ) )
33 - {
 31+ if ( $title->getText() == 'Gadgets-definition' ) {
3432 Gadget::loadStructuredList( $text );
 33+ } elseif ( preg_match( '/Gadget-([a-zA-Z](?:[-_:.\w\d ]*[a-zA-Z0-9])?)\.preferences/', $title->getText() ) ) {
 34+ $msg = wfMessage( 'Gadgets-definition' );
 35+ if ( $msg->exists() ) {
 36+ Gadget::loadStructuredList( $msg->plain() );
 37+ } else {
 38+ Gadget::loadStructuredList( '' );
 39+ }
3540 }
3641 }
3742 return true;
Index: branches/salvatoreingala/Gadgets/backend/GadgetResourceLoaderModule.php
@@ -74,12 +74,10 @@
7575 return $header . parent::getScript( $context ) . $footer;
7676 }
7777
78 -
79 - //TODO: should depend on last modification time of gadget's configuration page, also
8078 public function getModifiedTime( ResourceLoaderContext $context ) {
81 - $touched = RequestContext::getMain()->getUser()->getTouched();
82 -
83 - return max( parent::getModifiedTime( $context ), wfTimestamp( TS_UNIX, $touched ) );
 79+ $touched = wfTimestamp( TS_UNIX, RequestContext::getMain()->getUser()->getTouched() );
 80+ $gadgetMTime = $this->gadget->getModifiedTime();
 81+ return max( parent::getModifiedTime( $context ), $touched, $gadgetMTime );
8482 }
8583 }
8684
Index: branches/salvatoreingala/Gadgets/ui/GadgetsMainModule.php
@@ -17,18 +17,24 @@
1818 * Class implementing the ext.gadgets module. Required by ext.gadgets.preferences.
1919 */
2020 class GadgetsMainModule extends ResourceLoaderModule {
21 - //TODO: should override getModifiedTime()
2221
 22+ public function getModifiedTime( ResourceLoaderContext $context ) {
 23+ $gadgets = Gadget::loadList();
 24+
 25+ $m = 0;
 26+ foreach ( $gadgets as $gadget ) {
 27+ $m = max( $m, $gadget->getModifiedTime() );
 28+ }
 29+ return $m;
 30+ }
 31+
2332 public function getScript( ResourceLoaderContext $context ) {
2433 $configurableGadgets = array();
25 - $gadgetsList = Gadget::loadStructuredList();
 34+ $gadgets = Gadget::loadList();
2635
27 - foreach ( $gadgetsList as $section => $gadgets ) {
28 - foreach ( $gadgets as $gadgetName => $gadget ) {
29 - $prefs = $gadget->getPrefsDescription();
30 - if ( $prefs !== null ) {
31 - $configurableGadgets[] = $gadget->getName();
32 - }
 36+ foreach ( $gadgets as $gadget ) {
 37+ if ( $gadget->getPrefsDescription() !== null ) {
 38+ $configurableGadgets[] = $gadget->getName();
3339 }
3440 }
3541

Status & tagging log