r110148 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r110147‎ | r110148 | r110149 >
Date:17:13, 27 January 2012
Author:maxsem
Status:ok (Comments)
Tags:
Comment:
Purge cache upon changs to feed messages
Modified paths:
  • /trunk/extensions/FeaturedFeeds/FeaturedFeeds.body.php (modified) (history)
  • /trunk/extensions/FeaturedFeeds/FeaturedFeeds.php (modified) (history)

Diff [purge]

Index: trunk/extensions/FeaturedFeeds/FeaturedFeeds.body.php
@@ -18,7 +18,7 @@
1919 return $cache[$langCode];
2020 }
2121
22 - $key = wfMemcKey( 'featured-feeds', $langCode );
 22+ $key = self::getCacheKey( $langCode );
2323 $feeds = $wgMemc->get( $key );
2424
2525 if ( !$feeds ) {
@@ -30,6 +30,35 @@
3131 }
3232
3333 /**
 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+ /**
3463 * Adds feeds to the page header
3564 *
3665 * @param OutputPage $out
@@ -80,25 +109,47 @@
81110 }
82111
83112 /**
 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+ /**
84145 * @param $langCode string
85146 * @return array
86147 * @throws MWException
87148 */
88149 private static function getFeedsInternal( $langCode ) {
89 - global $wgFeaturedFeeds, $wgFeaturedFeedsDefaults, $wgContLang;
 150+ global $wgContLang;
90151
91152 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();
103154
104155 $feeds = array();
105156 $requestedLang = Language::factory( $langCode );
Index: trunk/extensions/FeaturedFeeds/FeaturedFeeds.php
@@ -32,6 +32,7 @@
3333
3434 $wgAPIModules['featuredfeed'] = 'ApiFeaturedFeeds';
3535
 36+$wgHooks['ArticleSaveComplete'][] = 'FeaturedFeeds::articleSaveComplete';
3637 $wgHooks['BeforePageDisplay'][] = 'FeaturedFeeds::beforePageDisplay';
3738 $wgHooks['SkinTemplateOutputPageBeforeExec'][] = 'FeaturedFeeds::skinTemplateOutputPageBeforeExec';
3839

Sign-offs

UserFlagDate
Awjrichardsinspected21:33, 27 January 2012
😂inspected22:03, 27 January 2012
Reedyinspected14:21, 3 February 2012

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r110087Bug 33977 - check for invalid timestampsmaxsem21:58, 26 January 2012

Comments

#Comment by Krinkle (talk | contribs)   02:21, 27 February 2012

This wasn't merged yet (I see no follow-ups). If that is the case, do we still need it? 1.19 was branched after this so it'll be in 1.19.0 and already is in 1.19wmf1. Untagging for now, feel free to re-tag.

Status & tagging log