X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=includes%2Fchanges%2FChangesFeed.php;h=4d00fbc543fcc360ac48fcf6fb96d1cea51de6bc;hp=df964e0a2b0fc38e1ca2dca91d97bc325c813c56;hb=c5a438e9deaef5bcb6bd85ce38e3ec34337698a2;hpb=03cd9495a4dac1c1cda738d52e74b553b977beb8 diff --git a/includes/changes/ChangesFeed.php b/includes/changes/ChangesFeed.php index df964e0a2b..4d00fbc543 100644 --- a/includes/changes/ChangesFeed.php +++ b/includes/changes/ChangesFeed.php @@ -20,23 +20,19 @@ * @file */ -use Wikimedia\Rdbms\ResultWrapper; - /** - * Feed to Special:RecentChanges and Special:RecentChangesLiked + * Feed to Special:RecentChanges and Special:RecentChangesLinked. * * @ingroup Feed */ class ChangesFeed { - public $format, $type, $titleMsg, $descMsg; + private $format; /** * @param string $format Feed's format (either 'rss' or 'atom') - * @param string $type Type of feed (for cache keys) */ - public function __construct( $format, $type ) { + public function __construct( $format ) { $this->format = $format; - $this->type = $type; } /** @@ -64,118 +60,6 @@ class ChangesFeed { $feedTitle, htmlspecialchars( $description ), $url ); } - /** - * Generates feed's content - * - * @param ChannelFeed $feed ChannelFeed subclass object (generally the one returned - * by getFeedObject()) - * @param ResultWrapper $rows ResultWrapper object with rows in recentchanges table - * @param int $lastmod Timestamp of the last item in the recentchanges table (only - * used for the cache key) - * @param FormOptions $opts As in SpecialRecentChanges::getDefaultOptions() - * @return null|bool True or null - */ - public function execute( $feed, $rows, $lastmod, $opts ) { - global $wgLang, $wgRenderHashAppend; - - if ( !FeedUtils::checkFeedOutput( $this->format ) ) { - return null; - } - - $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 ); - - /** - * Bumping around loading up diffs can be pretty slow, so where - * possible we want to cache the feed output so the next visitor - * gets it quick too. - */ - $cachedFeed = $this->loadFromCache( $lastmod, $timekey, $key ); - if ( is_string( $cachedFeed ) ) { - wfDebug( "RC: Outputting cached feed\n" ); - $feed->httpHeaders(); - echo $cachedFeed; - } else { - wfDebug( "RC: rendering new feed and caching it\n" ); - ob_start(); - self::generateFeed( $rows, $feed ); - $cachedFeed = ob_get_contents(); - ob_end_flush(); - $this->saveToCache( $cachedFeed, $timekey, $key ); - } - return true; - } - - /** - * Save to feed result to cache - * - * @param string $feed Feed's content - * @param string $timekey Memcached key of the last modification - * @param string $key Memcached key of the content - */ - public function saveToCache( $feed, $timekey, $key ) { - $cache = ObjectCache::getMainWANInstance(); - $cache->set( $key, $feed, $cache::TTL_DAY ); - $cache->set( $timekey, wfTimestamp( TS_MW ), $cache::TTL_DAY ); - } - - /** - * Try to load the feed result from cache - * - * @param int $lastmod Timestamp of the last item in the recentchanges table - * @param string $timekey Memcached key of the last modification - * @param string $key Memcached key of the content - * @return string|bool Feed's content on cache hit or false on cache miss - */ - public function loadFromCache( $lastmod, $timekey, $key ) { - global $wgFeedCacheTimeout, $wgOut; - - $cache = ObjectCache::getMainWANInstance(); - $feedLastmod = $cache->get( $timekey ); - - if ( ( $wgFeedCacheTimeout > 0 ) && $feedLastmod ) { - /** - * If the cached feed was rendered very recently, we may - * go ahead and use it even if there have been edits made - * since it was rendered. This keeps a swarm of requests - * from being too bad on a super-frequently edited wiki. - */ - - $feedAge = time() - wfTimestamp( TS_UNIX, $feedLastmod ); - $feedLastmodUnix = wfTimestamp( TS_UNIX, $feedLastmod ); - $lastmodUnix = wfTimestamp( TS_UNIX, $lastmod ); - - if ( $feedAge < $wgFeedCacheTimeout || $feedLastmodUnix > $lastmodUnix ) { - wfDebug( "RC: loading feed from cache ($key; $feedLastmod; $lastmod)...\n" ); - if ( $feedLastmodUnix < $lastmodUnix ) { - $wgOut->setLastModified( $feedLastmod ); // T23916 - } - return $cache->get( $key ); - } else { - wfDebug( "RC: cached feed timestamp check failed ($feedLastmod; $lastmod)\n" ); - } - } - return false; - } - - /** - * Generate the feed items given a row from the database, printing the feed. - * @param object $rows IDatabase resource with recentchanges rows - * @param ChannelFeed &$feed - */ - public static function generateFeed( $rows, &$feed ) { - $items = self::buildItems( $rows ); - $feed->outHeader(); - foreach ( $items as $item ) { - $feed->outItem( $item ); - } - $feed->outFooter(); - } - /** * Generate the feed items given a row from the database. * @param object $rows IDatabase resource with recentchanges rows @@ -206,7 +90,7 @@ class ChangesFeed { foreach ( $sorted as $obj ) { $title = Title::makeTitle( $obj->rc_namespace, $obj->rc_title ); - $talkpage = MWNamespace::canTalk( $obj->rc_namespace ) + $talkpage = MWNamespace::hasTalkNamespace( $obj->rc_namespace ) ? $title->getTalkPage()->getFullURL() : '';