MediaWiki REL1_32
ChangesFeed.php
Go to the documentation of this file.
1<?php
24
32
37 public function __construct( $format, $type ) {
38 $this->format = $format;
39 $this->type = $type;
40 }
41
50 public function getFeedObject( $title, $description, $url ) {
52
53 if ( !isset( $wgFeedClasses[$this->format] ) ) {
54 return false;
55 }
56
57 if ( !array_key_exists( $this->format, $wgFeedClasses ) ) {
58 // falling back to atom
59 $this->format = 'atom';
60 }
61
62 $feedTitle = "$wgSitename - {$title} [$wgLanguageCode]";
63 return new $wgFeedClasses[$this->format](
64 $feedTitle, htmlspecialchars( $description ), $url );
65 }
66
78 public function execute( $feed, $rows, $lastmod, $opts ) {
80
81 if ( !FeedUtils::checkFeedOutput( $this->format ) ) {
82 return null;
83 }
84
85 $cache = ObjectCache::getMainWANInstance();
86 $optionsHash = md5( serialize( $opts->getAllValues() ) ) . $wgRenderHashAppend;
87 $timekey = $cache->makeKey(
88 $this->type, $this->format, $wgLang->getCode(), $optionsHash, 'timestamp' );
89 $key = $cache->makeKey( $this->type, $this->format, $wgLang->getCode(), $optionsHash );
90
91 FeedUtils::checkPurge( $timekey, $key );
92
98 $cachedFeed = $this->loadFromCache( $lastmod, $timekey, $key );
99 if ( is_string( $cachedFeed ) ) {
100 wfDebug( "RC: Outputting cached feed\n" );
101 $feed->httpHeaders();
102 echo $cachedFeed;
103 } else {
104 wfDebug( "RC: rendering new feed and caching it\n" );
105 ob_start();
106 self::generateFeed( $rows, $feed );
107 $cachedFeed = ob_get_contents();
108 ob_end_flush();
109 $this->saveToCache( $cachedFeed, $timekey, $key );
110 }
111 return true;
112 }
113
121 public function saveToCache( $feed, $timekey, $key ) {
122 $cache = ObjectCache::getMainWANInstance();
123 $cache->set( $key, $feed, $cache::TTL_DAY );
124 $cache->set( $timekey, wfTimestamp( TS_MW ), $cache::TTL_DAY );
125 }
126
135 public function loadFromCache( $lastmod, $timekey, $key ) {
137
138 $cache = ObjectCache::getMainWANInstance();
139 $feedLastmod = $cache->get( $timekey );
140
141 if ( ( $wgFeedCacheTimeout > 0 ) && $feedLastmod ) {
149 $feedAge = time() - wfTimestamp( TS_UNIX, $feedLastmod );
150 $feedLastmodUnix = wfTimestamp( TS_UNIX, $feedLastmod );
151 $lastmodUnix = wfTimestamp( TS_UNIX, $lastmod );
152
153 if ( $feedAge < $wgFeedCacheTimeout || $feedLastmodUnix > $lastmodUnix ) {
154 wfDebug( "RC: loading feed from cache ($key; $feedLastmod; $lastmod)...\n" );
155 if ( $feedLastmodUnix < $lastmodUnix ) {
156 $wgOut->setLastModified( $feedLastmod ); // T23916
157 }
158 return $cache->get( $key );
159 } else {
160 wfDebug( "RC: cached feed timestamp check failed ($feedLastmod; $lastmod)\n" );
161 }
162 }
163 return false;
164 }
165
171 public static function generateFeed( $rows, &$feed ) {
172 $items = self::buildItems( $rows );
173 $feed->outHeader();
174 foreach ( $items as $item ) {
175 $feed->outItem( $item );
176 }
177 $feed->outFooter();
178 }
179
185 public static function buildItems( $rows ) {
186 $items = [];
187
188 # Merge adjacent edits by one user
189 $sorted = [];
190 $n = 0;
191 foreach ( $rows as $obj ) {
192 if ( $obj->rc_type == RC_EXTERNAL ) {
193 continue;
194 }
195
196 if ( $n > 0 &&
197 $obj->rc_type == RC_EDIT &&
198 $obj->rc_namespace >= 0 &&
199 $obj->rc_cur_id == $sorted[$n - 1]->rc_cur_id &&
200 $obj->rc_user_text == $sorted[$n - 1]->rc_user_text ) {
201 $sorted[$n - 1]->rc_last_oldid = $obj->rc_last_oldid;
202 } else {
203 $sorted[$n] = $obj;
204 $n++;
205 }
206 }
207
208 foreach ( $sorted as $obj ) {
209 $title = Title::makeTitle( $obj->rc_namespace, $obj->rc_title );
210 $talkpage = MWNamespace::canTalk( $obj->rc_namespace )
211 ? $title->getTalkPage()->getFullURL()
212 : '';
213
214 // Skip items with deleted content (avoids partially complete/inconsistent output)
215 if ( $obj->rc_deleted ) {
216 continue;
217 }
218
219 if ( $obj->rc_this_oldid ) {
220 $url = $title->getFullURL( [
221 'diff' => $obj->rc_this_oldid,
222 'oldid' => $obj->rc_last_oldid,
223 ] );
224 } else {
225 // log entry or something like that.
226 $url = $title->getFullURL();
227 }
228
229 $items[] = new FeedItem(
230 $title->getPrefixedText(),
231 FeedUtils::formatDiff( $obj ),
232 $url,
233 $obj->rc_timestamp,
234 ( $obj->rc_deleted & Revision::DELETED_USER )
235 ? wfMessage( 'rev-deleted-user' )->escaped() : $obj->rc_user_text,
236 $talkpage
237 );
238 }
239
240 return $items;
241 }
242}
serialize()
$wgLanguageCode
Site language code.
$wgFeedCacheTimeout
Minimum timeout for cached Recentchanges feed, in seconds.
$wgRenderHashAppend
Append a configured value to the parser cache and the sitenotice key so that they can be kept separat...
$wgSitename
Name of the site.
$wgFeedClasses
Available feeds objects.
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
$wgOut
Definition Setup.php:915
$wgLang
Definition Setup.php:910
Feed to Special:RecentChanges and Special:RecentChangesLiked.
execute( $feed, $rows, $lastmod, $opts)
Generates feed's content.
getFeedObject( $title, $description, $url)
Get a ChannelFeed subclass object to use.
static generateFeed( $rows, &$feed)
Generate the feed items given a row from the database, printing the feed.
saveToCache( $feed, $timekey, $key)
Save to feed result to cache.
static buildItems( $rows)
Generate the feed items given a row from the database.
__construct( $format, $type)
loadFromCache( $lastmod, $timekey, $key)
Try to load the feed result from cache.
A base class for basic support for outputting syndication feeds in RSS and other formats.
Definition Feed.php:38
static formatDiff( $row)
Format a diff for the newsfeed.
Definition FeedUtils.php:79
static checkFeedOutput( $type)
Check whether feeds can be used and that $type is a valid feed type.
Definition FeedUtils.php:56
static checkPurge( $timekey, $key)
Check whether feed's cache should be cleared; for changes feeds If the feed should be purged; $timeke...
Definition FeedUtils.php:38
const DELETED_USER
Definition Revision.php:49
Result wrapper for grabbing data queried from an IDatabase object.
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults also a ContextSource after deleting those rows but within the same transaction $rows
Definition hooks.txt:2857
either a unescaped string or a HtmlArmor object after in associative array form externallinks including delete and has completed for all link tables whether this was an auto creation use $formDescriptor instead default is conds Array Extra conditions for the No matching items in log is displayed if loglist is empty msgKey Array If you want a nice box with a set this to the key of the message First element is the message additional optional elements are parameters for the key that are processed with wfMessage() -> params() ->parseAsBlock() - offset Set to overwrite offset parameter in $wgRequest set to '' to unset offset - wrap String Wrap the message in html(usually something like "&lt;div ...>$1&lt;/div>"). - flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException':Called before an exception(or PHP error) is logged. This is meant for integration with external error aggregation services
const RC_EXTERNAL
Definition Defines.php:145
const RC_EDIT
Definition Defines.php:142
$cache
Definition mcc.php:33
This document describes the state of Postgres support in and is fairly well maintained The main code is very well while extensions are very hit and miss it is probably the most supported database after MySQL Much of the work in making MediaWiki database agnostic came about through the work of creating Postgres as and are nearing end of but without copying over all the usage comments General notes on the but these can almost always be programmed around *Although Postgres has a true BOOLEAN type
Definition postgres.txt:36