5 public $format, $type, $titleMsg, $descMsg;
7 public function __construct( $format, $type ) {
8 $this->format
= $format;
12 public function getFeedObject( $title, $description ) {
13 global $wgSitename, $wgContLanguageCode, $wgFeedClasses, $wgTitle;
14 $feedTitle = "$wgSitename - {$title} [$wgContLanguageCode]";
16 return new $wgFeedClasses[$this->format
](
17 $feedTitle, htmlspecialchars( $description ), $wgTitle->getFullUrl() );
20 public function execute( $feed, $rows, $limit = 0 , $hideminor = false, $lastmod = false ) {
21 global $messageMemc, $wgFeedCacheTimeout;
22 global $wgFeedClasses, $wgTitle, $wgSitename, $wgContLanguageCode;
24 if ( !FeedUtils
::checkFeedOutput( $this->format
) ) {
28 $timekey = wfMemcKey( $this->type
, $this->format
, 'timestamp' );
29 $key = wfMemcKey( $this->type
, $this->format
, 'limit', $limit, 'minor', $hideminor );
31 FeedUtils
::checkPurge($timekey, $key);
34 * Bumping around loading up diffs can be pretty slow, so where
35 * possible we want to cache the feed output so the next visitor
38 $cachedFeed = $this->loadFromCache( $lastmod, $timekey, $key );
39 if( is_string( $cachedFeed ) ) {
40 wfDebug( "RC: Outputting cached feed\n" );
44 wfDebug( "RC: rendering new feed and caching it\n" );
46 self
::generateFeed( $rows, $feed );
47 $cachedFeed = ob_get_contents();
49 $this->saveToCache( $cachedFeed, $timekey, $key );
54 public function saveToCache( $feed, $timekey, $key ) {
56 $expire = 3600 * 24; # One day
57 $messageMemc->set( $key, $feed );
58 $messageMemc->set( $timekey, wfTimestamp( TS_MW
), $expire );
61 public function loadFromCache( $lastmod, $timekey, $key ) {
62 global $wgFeedCacheTimeout, $messageMemc;
63 $feedLastmod = $messageMemc->get( $timekey );
65 if( ( $wgFeedCacheTimeout > 0 ) && $feedLastmod ) {
67 * If the cached feed was rendered very recently, we may
68 * go ahead and use it even if there have been edits made
69 * since it was rendered. This keeps a swarm of requests
70 * from being too bad on a super-frequently edited wiki.
73 $feedAge = time() - wfTimestamp( TS_UNIX
, $feedLastmod );
74 $feedLastmodUnix = wfTimestamp( TS_UNIX
, $feedLastmod );
75 $lastmodUnix = wfTimestamp( TS_UNIX
, $lastmod );
77 if( $feedAge < $wgFeedCacheTimeout ||
$feedLastmodUnix > $lastmodUnix) {
78 wfDebug( "RC: loading feed from cache ($key; $feedLastmod; $lastmod)...\n" );
79 return $messageMemc->get( $key );
81 wfDebug( "RC: cached feed timestamp check failed ($feedLastmod; $lastmod)\n" );
89 * @param $rows Database resource with recentchanges rows
90 * @param $feed Feed object
92 public static function generateFeed( $rows, &$feed ) {
93 wfProfileIn( __METHOD__
);
97 # Merge adjacent edits by one user
100 foreach( $rows as $obj ) {
102 $obj->rc_namespace
>= 0 &&
103 $obj->rc_cur_id
== $sorted[$n-1]->rc_cur_id
&&
104 $obj->rc_user_text
== $sorted[$n-1]->rc_user_text
) {
105 $sorted[$n-1]->rc_last_oldid
= $obj->rc_last_oldid
;
112 foreach( $sorted as $obj ) {
113 $title = Title
::makeTitle( $obj->rc_namespace
, $obj->rc_title
);
114 $talkpage = $title->getTalkPage();
115 $item = new FeedItem(
116 $title->getPrefixedText(),
117 FeedUtils
::formatDiff( $obj ),
118 $title->getFullURL( 'diff=' . $obj->rc_this_oldid
. '&oldid=prev' ),
120 ($obj->rc_deleted
& Revision
::DELETED_USER
) ?
wfMsgHtml('rev-deleted-user') : $obj->rc_user_text
,
121 $talkpage->getFullURL()
123 $feed->outItem( $item );
126 wfProfileOut( __METHOD__
);