MediaWiki REL1_33
ChangesFeed.php
Go to the documentation of this file.
1<?php
25
33
38 public function __construct( $format, $type ) {
39 $this->format = $format;
40 $this->type = $type;
41 }
42
51 public function getFeedObject( $title, $description, $url ) {
53
54 if ( !isset( $wgFeedClasses[$this->format] ) ) {
55 return false;
56 }
57
58 if ( !array_key_exists( $this->format, $wgFeedClasses ) ) {
59 // falling back to atom
60 $this->format = 'atom';
61 }
62
63 $feedTitle = "$wgSitename - {$title} [$wgLanguageCode]";
64 return new $wgFeedClasses[$this->format](
65 $feedTitle, htmlspecialchars( $description ), $url );
66 }
67
79 public function execute( $feed, $rows, $lastmod, $opts ) {
81
82 if ( !FeedUtils::checkFeedOutput( $this->format ) ) {
83 return null;
84 }
85
86 $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
87 $optionsHash = md5( serialize( $opts->getAllValues() ) ) . $wgRenderHashAppend;
88 $timekey = $cache->makeKey(
89 $this->type, $this->format, $wgLang->getCode(), $optionsHash, 'timestamp' );
90 $key = $cache->makeKey( $this->type, $this->format, $wgLang->getCode(), $optionsHash );
91
92 FeedUtils::checkPurge( $timekey, $key );
93
99 $cachedFeed = $this->loadFromCache( $lastmod, $timekey, $key );
100 if ( is_string( $cachedFeed ) ) {
101 wfDebug( "RC: Outputting cached feed\n" );
102 $feed->httpHeaders();
103 echo $cachedFeed;
104 } else {
105 wfDebug( "RC: rendering new feed and caching it\n" );
106 ob_start();
107 self::generateFeed( $rows, $feed );
108 $cachedFeed = ob_get_contents();
109 ob_end_flush();
110 $this->saveToCache( $cachedFeed, $timekey, $key );
111 }
112 return true;
113 }
114
122 public function saveToCache( $feed, $timekey, $key ) {
123 $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
124 $cache->set( $key, $feed, $cache::TTL_DAY );
125 $cache->set( $timekey, wfTimestamp( TS_MW ), $cache::TTL_DAY );
126 }
127
136 public function loadFromCache( $lastmod, $timekey, $key ) {
138
139 $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
140 $feedLastmod = $cache->get( $timekey );
141
142 if ( ( $wgFeedCacheTimeout > 0 ) && $feedLastmod ) {
150 $feedAge = time() - wfTimestamp( TS_UNIX, $feedLastmod );
151 $feedLastmodUnix = wfTimestamp( TS_UNIX, $feedLastmod );
152 $lastmodUnix = wfTimestamp( TS_UNIX, $lastmod );
153
154 if ( $feedAge < $wgFeedCacheTimeout || $feedLastmodUnix > $lastmodUnix ) {
155 wfDebug( "RC: loading feed from cache ($key; $feedLastmod; $lastmod)...\n" );
156 if ( $feedLastmodUnix < $lastmodUnix ) {
157 $wgOut->setLastModified( $feedLastmod ); // T23916
158 }
159 return $cache->get( $key );
160 } else {
161 wfDebug( "RC: cached feed timestamp check failed ($feedLastmod; $lastmod)\n" );
162 }
163 }
164 return false;
165 }
166
172 public static function generateFeed( $rows, &$feed ) {
173 $items = self::buildItems( $rows );
174 $feed->outHeader();
175 foreach ( $items as $item ) {
176 $feed->outItem( $item );
177 }
178 $feed->outFooter();
179 }
180
186 public static function buildItems( $rows ) {
187 $items = [];
188
189 # Merge adjacent edits by one user
190 $sorted = [];
191 $n = 0;
192 foreach ( $rows as $obj ) {
193 if ( $obj->rc_type == RC_EXTERNAL ) {
194 continue;
195 }
196
197 if ( $n > 0 &&
198 $obj->rc_type == RC_EDIT &&
199 $obj->rc_namespace >= 0 &&
200 $obj->rc_cur_id == $sorted[$n - 1]->rc_cur_id &&
201 $obj->rc_user_text == $sorted[$n - 1]->rc_user_text ) {
202 $sorted[$n - 1]->rc_last_oldid = $obj->rc_last_oldid;
203 } else {
204 $sorted[$n] = $obj;
205 $n++;
206 }
207 }
208
209 foreach ( $sorted as $obj ) {
210 $title = Title::makeTitle( $obj->rc_namespace, $obj->rc_title );
211 $talkpage = MWNamespace::hasTalkNamespace( $obj->rc_namespace )
212 ? $title->getTalkPage()->getFullURL()
213 : '';
214
215 // Skip items with deleted content (avoids partially complete/inconsistent output)
216 if ( $obj->rc_deleted ) {
217 continue;
218 }
219
220 if ( $obj->rc_this_oldid ) {
221 $url = $title->getFullURL( [
222 'diff' => $obj->rc_this_oldid,
223 'oldid' => $obj->rc_last_oldid,
224 ] );
225 } else {
226 // log entry or something like that.
227 $url = $title->getFullURL();
228 }
229
230 $items[] = new FeedItem(
231 $title->getPrefixedText(),
232 FeedUtils::formatDiff( $obj ),
233 $url,
234 $obj->rc_timestamp,
235 ( $obj->rc_deleted & Revision::DELETED_USER )
236 ? wfMessage( 'rev-deleted-user' )->escaped() : $obj->rc_user_text,
238 );
239 }
240
241 return $items;
242 }
243}
serialize()
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two and(2) offer you this license which gives you legal permission to copy
$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:880
$wgLang
Definition Setup.php:875
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:80
static checkFeedOutput( $type)
Check whether feeds can be used and that $type is a valid feed type.
Definition FeedUtils.php:57
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:39
MediaWikiServices is the service locator for the application scope of MediaWiki.
const DELETED_USER
Definition Revision.php:48
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:2818
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:154
const RC_EDIT
Definition Defines.php:151
$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 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:30