<?php
+/**
+ * Feed to Special:RecentChanges and Special:RecentChangesLiked
+ *
+ * @ingroup Feed
+ */
class ChangesFeed {
-
public $format, $type, $titleMsg, $descMsg;
+ /**
+ * Constructor
+ *
+ * @param $format String: feed's format (either 'rss' or 'atom')
+ * @param $type String: type of feed (for cache keys)
+ */
public function __construct( $format, $type ) {
$this->format = $format;
$this->type = $type;
}
- public function getFeedObject( $title, $description ) {
- global $wgSitename, $wgContLanguageCode, $wgFeedClasses, $wgTitle;
- $feedTitle = "$wgSitename - {$title} [$wgContLanguageCode]";
- if( !isset($wgFeedClasses[$this->format] ) )
+ /**
+ * Get a ChannelFeed subclass object to use
+ *
+ * @param $title String: feed's title
+ * @param $description String: feed's description
+ * @param $url String: url of origin page
+ * @return ChannelFeed subclass or false on failure
+ */
+ public function getFeedObject( $title, $description, $url ) {
+ global $wgSitename, $wgLanguageCode, $wgFeedClasses;
+
+ if ( !isset( $wgFeedClasses[$this->format] ) ) {
return false;
+ }
+
+ $feedTitle = "$wgSitename - {$title} [$wgLanguageCode]";
return new $wgFeedClasses[$this->format](
- $feedTitle, htmlspecialchars( $description ), $wgTitle->getFullUrl() );
+ $feedTitle, htmlspecialchars( $description ), $url );
}
- public function execute( $feed, $rows, $limit=0, $hideminor=false, $lastmod=false, $target='', $namespace='' ) {
- global $messageMemc, $wgFeedCacheTimeout;
- global $wgSitename, $wgLang;
+ /**
+ * Generates feed's content
+ *
+ * @param $feed ChannelFeed subclass object (generally the one returned by getFeedObject())
+ * @param $rows ResultWrapper object with rows in recentchanges table
+ * @param $lastmod Integer: timestamp of the last item in the recentchanges table (only used for the cache key)
+ * @param $opts FormOptions as in SpecialRecentChanges::getDefaultOptions()
+ * @return null or true
+ */
+ public function execute( $feed, $rows, $lastmod, $opts ) {
+ global $wgLang, $wgRenderHashAppend;
if ( !FeedUtils::checkFeedOutput( $this->format ) ) {
return;
}
- $timekey = wfMemcKey( $this->type, $this->format, 'timestamp' );
- $key = wfMemcKey( $this->type, $this->format, $limit, $hideminor, $target, $wgLang->getCode(), $namespace );
+ $optionsHash = md5( serialize( $opts->getAllValues() ) ) . $wgRenderHashAppend;
+ $timekey = wfMemcKey( $this->type, $this->format, $wgLang->getCode(), $optionsHash, 'timestamp' );
+ $key = wfMemcKey( $this->type, $this->format, $wgLang->getCode(), $optionsHash );
- FeedUtils::checkPurge($timekey, $key);
+ FeedUtils::checkPurge( $timekey, $key );
/*
* Bumping around loading up diffs can be pretty slow, so where
return true;
}
+ /**
+ * Save to feed result to $messageMemc
+ *
+ * @param $feed String: feed's content
+ * @param $timekey String: memcached key of the last modification
+ * @param $key String: memcached key of the content
+ */
public function saveToCache( $feed, $timekey, $key ) {
global $messageMemc;
$expire = 3600 * 24; # One day
$messageMemc->set( $timekey, wfTimestamp( TS_MW ), $expire );
}
+ /**
+ * Try to load the feed result from $messageMemc
+ *
+ * @param $lastmod Integer: timestamp of the last item in the recentchanges table
+ * @param $timekey String: memcached key of the last modification
+ * @param $key String: memcached key of the content
+ * @return feed's content on cache hit or false on cache miss
+ */
public function loadFromCache( $lastmod, $timekey, $key ) {
- global $wgFeedCacheTimeout, $messageMemc;
+ global $wgFeedCacheTimeout, $wgOut, $messageMemc;
+
$feedLastmod = $messageMemc->get( $timekey );
if( ( $wgFeedCacheTimeout > 0 ) && $feedLastmod ) {
if( $feedAge < $wgFeedCacheTimeout || $feedLastmodUnix > $lastmodUnix) {
wfDebug( "RC: loading feed from cache ($key; $feedLastmod; $lastmod)...\n" );
+ if ( $feedLastmodUnix < $lastmodUnix ) {
+ $wgOut->setLastModified( $feedLastmod ); // bug 21916
+ }
return $messageMemc->get( $key );
} else {
wfDebug( "RC: cached feed timestamp check failed ($feedLastmod; $lastmod)\n" );
}
/**
- * Generate the feed items given a row from the database.
- * @param $rows Database resource with recentchanges rows
- * @param $feed Feed object
- */
+ * Generate the feed items given a row from the database.
+ * @param $rows DatabaseBase resource with recentchanges rows
+ * @param $feed Feed object
+ */
public static function generateFeed( $rows, &$feed ) {
wfProfileIn( __METHOD__ );
wfProfileOut( __METHOD__ );
}
-}
\ No newline at end of file
+}