Index: trunk/extensions/Gadgets/Gadgets.php |
— | — | @@ -28,11 +28,24 @@ |
29 | 29 | $wgHooks['RenderPreferencesForm'][] = 'wfGadgetsRenderPreferencesForm'; |
30 | 30 | $wgHooks['ResetPreferences'][] = 'wfGadgetsResetPreferences'; |
31 | 31 | $wgHooks['BeforePageDisplay'][] = 'wfGadgetsBeforePageDisplay'; |
| 32 | +$wgHooks['ArticleSave'][] = 'wfGadgetsArticleSave'; |
32 | 33 | $wgHooks['LoadAllMessages'][] = "loadGadgetsI18n"; |
33 | 34 | |
34 | 35 | $wgAutoloadClasses['SpecialGadgets'] = dirname( __FILE__ ) . '/SpecialGadgets.php'; |
35 | 36 | $wgSpecialPages['Gadgets'] = 'SpecialGadgets'; |
36 | 37 | |
| 38 | +function wfGadgetsArticleSave( &$article ) { |
| 39 | + //purge from cache if need be |
| 40 | + $title =& $article->mTitle; |
| 41 | + if( $title->getNamespace() == NS_MEDIAWIKI && $title->getText() == 'Gadgets-definition' ) { |
| 42 | + global $wgMemc, $wgDBname; |
| 43 | + $key = "$wgDBname:gadgets-definition"; |
| 44 | + $wgMemc->delete( $key ); |
| 45 | + wfDebug("wfGadgetsArticleSave: MediaWiki:Gadgets-definition edited, cache entry $key purged\n"); |
| 46 | + } |
| 47 | + return true; |
| 48 | +} |
| 49 | + |
37 | 50 | function wfLoadGadgets() { |
38 | 51 | static $gadgets = NULL; |
39 | 52 | |
— | — | @@ -54,9 +67,15 @@ |
55 | 68 | |
56 | 69 | function wfLoadGadgetsStructured() { |
57 | 70 | global $wgContLang, $wgCapitalLinks; |
| 71 | + global $wgMemc, $wgDBname; |
58 | 72 | |
59 | 73 | static $gadgets = NULL; |
| 74 | + if ( $gadgets !== NULL ) return $gadgets; |
60 | 75 | |
| 76 | + $key = "$wgDBname:gadgets-definition"; |
| 77 | + |
| 78 | + //cached? |
| 79 | + $gadgets = $wgMemc->get( $key ); |
61 | 80 | if ( $gadgets !== NULL ) return $gadgets; |
62 | 81 | |
63 | 82 | $g = wfMsgForContentNoTrans( "Gadgets-definition" ); |
— | — | @@ -91,6 +110,10 @@ |
92 | 111 | } |
93 | 112 | } |
94 | 113 | |
| 114 | + //cache for a while. gets purged automatically when MediaWiki:Gadgets-definition is edited |
| 115 | + $wgMemc->set( $key, $gadgets, 900 ); |
| 116 | + wfDebug("wfLoadGadgetsStructured: MediaWiki:Gadgets-definition parsed, cache entry $key updated\n"); |
| 117 | + |
95 | 118 | return $gadgets; |
96 | 119 | } |
97 | 120 | |