Index: branches/salvatoreingala/Gadgets/backend/Gadget.php |
— | — | @@ -32,6 +32,7 @@ |
33 | 33 | $requiredRights = array(), |
34 | 34 | $onByDefault = false, |
35 | 35 | $category, |
| 36 | + $mTime = null, //upper bound on last modification time; UNIX timestamp |
36 | 37 | $prefsDescription = null, |
37 | 38 | $preferences = null; |
38 | 39 | |
— | — | @@ -52,6 +53,11 @@ |
53 | 54 | $gadget->name = trim( str_replace(' ', '_', $m[1] ) ); |
54 | 55 | $gadget->definition = $definition; |
55 | 56 | |
| 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 | + |
56 | 62 | //Parse gadget options |
57 | 63 | $options = trim( $m[2], ' []' ); |
58 | 64 | foreach ( preg_split( '/\s*\|\s*/', $options, -1, PREG_SPLIT_NO_EMPTY ) as $option ) { |
— | — | @@ -236,6 +242,16 @@ |
237 | 243 | } |
238 | 244 | |
239 | 245 | /** |
| 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 | + /** |
240 | 256 | * Returns list of scripts that don't support ResourceLoader |
241 | 257 | * @return Array |
242 | 258 | */ |
Index: branches/salvatoreingala/Gadgets/backend/GadgetHooks.php |
— | — | @@ -27,10 +27,15 @@ |
28 | 28 | //or if a Mediawiki:Gadget-foo.preferences was edited |
29 | 29 | $title = $article->mTitle; |
30 | 30 | 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' ) { |
34 | 32 | 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 | + } |
35 | 40 | } |
36 | 41 | } |
37 | 42 | return true; |
Index: branches/salvatoreingala/Gadgets/backend/GadgetResourceLoaderModule.php |
— | — | @@ -74,12 +74,10 @@ |
75 | 75 | return $header . parent::getScript( $context ) . $footer; |
76 | 76 | } |
77 | 77 | |
78 | | - |
79 | | - //TODO: should depend on last modification time of gadget's configuration page, also |
80 | 78 | 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 ); |
84 | 82 | } |
85 | 83 | } |
86 | 84 | |
Index: branches/salvatoreingala/Gadgets/ui/GadgetsMainModule.php |
— | — | @@ -17,18 +17,24 @@ |
18 | 18 | * Class implementing the ext.gadgets module. Required by ext.gadgets.preferences. |
19 | 19 | */ |
20 | 20 | class GadgetsMainModule extends ResourceLoaderModule { |
21 | | - //TODO: should override getModifiedTime() |
22 | 21 | |
| 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 | + |
23 | 32 | public function getScript( ResourceLoaderContext $context ) { |
24 | 33 | $configurableGadgets = array(); |
25 | | - $gadgetsList = Gadget::loadStructuredList(); |
| 34 | + $gadgets = Gadget::loadList(); |
26 | 35 | |
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(); |
33 | 39 | } |
34 | 40 | } |
35 | 41 | |