Index: trunk/extensions/FeaturedFeeds/FeaturedFeeds.body.php |
— | — | @@ -18,7 +18,7 @@ |
19 | 19 | return $cache[$langCode]; |
20 | 20 | } |
21 | 21 | |
22 | | - $key = wfMemcKey( 'featured-feeds', $langCode ); |
| 22 | + $key = self::getCacheKey( $langCode ); |
23 | 23 | $feeds = $wgMemc->get( $key ); |
24 | 24 | |
25 | 25 | if ( !$feeds ) { |
— | — | @@ -30,6 +30,35 @@ |
31 | 31 | } |
32 | 32 | |
33 | 33 | /** |
| 34 | + * Returns cache key for a given language |
| 35 | + * @param String $langCode: Feed language code |
| 36 | + * @return String |
| 37 | + */ |
| 38 | + private static function getCacheKey( $langCode ) { |
| 39 | + return wfMemcKey( 'featured-feeds', $langCode ); |
| 40 | + } |
| 41 | + |
| 42 | + /** |
| 43 | + * Returns fully prepared feed definitions |
| 44 | + * @return Array |
| 45 | + */ |
| 46 | + private static function getFeedDefinitions() { |
| 47 | + global $wgFeaturedFeeds, $wgFeaturedFeedsDefaults; |
| 48 | + $feedDefs = $wgFeaturedFeeds; |
| 49 | + wfRunHooks( 'FeaturedFeeds::getFeeds', array( &$feedDefs ) ); |
| 50 | + |
| 51 | + // fill defaults |
| 52 | + foreach ( $feedDefs as $name => $opts ) { |
| 53 | + foreach ( $wgFeaturedFeedsDefaults as $setting => $value ) { |
| 54 | + if ( !isset( $opts[$setting] ) ) { |
| 55 | + $feedDefs[$name][$setting] = $value; |
| 56 | + } |
| 57 | + } |
| 58 | + } |
| 59 | + return $feedDefs; |
| 60 | + } |
| 61 | + |
| 62 | + /** |
34 | 63 | * Adds feeds to the page header |
35 | 64 | * |
36 | 65 | * @param OutputPage $out |
— | — | @@ -80,25 +109,47 @@ |
81 | 110 | } |
82 | 111 | |
83 | 112 | /** |
| 113 | + * Purges cache on message edit |
| 114 | + * |
| 115 | + * @param Article $article |
| 116 | + */ |
| 117 | + public static function articleSaveComplete( $article ) { |
| 118 | + global $wgFeaturedFeeds, $wgMemc, $wgLanguageCode; |
| 119 | + $title = $article->getTitle(); |
| 120 | + // Although message names are configurable and can be set not to start with 'Ffeed', we |
| 121 | + // make a shortcut here to avoid running these checks on every NS_MEDIAWIKI edit |
| 122 | + if ( $title->getNamespace() == NS_MEDIAWIKI && strpos( $title->getText(), 'Ffeed-' ) === 0 ) { |
| 123 | + $baseTitle = Title::makeTitle( NS_MEDIAWIKI, $title->getBaseText() ); |
| 124 | + $messages = array( 'page', 'title', 'short-title', 'description', 'entryName' ); |
| 125 | + foreach ( self::getFeedDefinitions() as $feed ) { |
| 126 | + foreach ( $messages as $msgType ) { |
| 127 | + $nt = Title::makeTitleSafe( NS_MEDIAWIKI, $feed[$msgType] ); |
| 128 | + if ( $nt->equals( $baseTitle ) ) { |
| 129 | + wfDebug( "FeaturedFeeds-related page {$title->getFullText()} edited, purging cache\n" ); |
| 130 | + $wgMemc->delete( self::getCacheKey( $wgLanguageCode ) ); |
| 131 | + $lang = $title->getSubpageText(); |
| 132 | + // Sorry, users of multilingual feeds, we can't purge cache for every possible language |
| 133 | + if ( $lang != $baseTitle->getText() ) { |
| 134 | + $wgMemc->delete( $lang ); |
| 135 | + } |
| 136 | + return true; |
| 137 | + } |
| 138 | + } |
| 139 | + } |
| 140 | + } |
| 141 | + return true; |
| 142 | + } |
| 143 | + |
| 144 | + /** |
84 | 145 | * @param $langCode string |
85 | 146 | * @return array |
86 | 147 | * @throws MWException |
87 | 148 | */ |
88 | 149 | private static function getFeedsInternal( $langCode ) { |
89 | | - global $wgFeaturedFeeds, $wgFeaturedFeedsDefaults, $wgContLang; |
| 150 | + global $wgContLang; |
90 | 151 | |
91 | 152 | wfProfileIn( __METHOD__ ); |
92 | | - $feedDefs = $wgFeaturedFeeds; |
93 | | - wfRunHooks( 'FeaturedFeeds::getFeeds', array( &$feedDefs ) ); |
94 | | - |
95 | | - // fill defaults |
96 | | - foreach ( $feedDefs as $name => $opts ) { |
97 | | - foreach ( $wgFeaturedFeedsDefaults as $setting => $value ) { |
98 | | - if ( !isset( $opts[$setting] ) ) { |
99 | | - $feedDefs[$name][$setting] = $value; |
100 | | - } |
101 | | - } |
102 | | - } |
| 153 | + $feedDefs = self::getFeedDefinitions(); |
103 | 154 | |
104 | 155 | $feeds = array(); |
105 | 156 | $requestedLang = Language::factory( $langCode ); |
Index: trunk/extensions/FeaturedFeeds/FeaturedFeeds.php |
— | — | @@ -32,6 +32,7 @@ |
33 | 33 | |
34 | 34 | $wgAPIModules['featuredfeed'] = 'ApiFeaturedFeeds'; |
35 | 35 | |
| 36 | +$wgHooks['ArticleSaveComplete'][] = 'FeaturedFeeds::articleSaveComplete'; |
36 | 37 | $wgHooks['BeforePageDisplay'][] = 'FeaturedFeeds::beforePageDisplay'; |
37 | 38 | $wgHooks['SkinTemplateOutputPageBeforeExec'][] = 'FeaturedFeeds::skinTemplateOutputPageBeforeExec'; |
38 | 39 | |