/** * 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 $messageMemc, $wgFeedCacheTimeout; global $wgSitename, $wgLang; if (!FeedUtils::checkFeedOutput($this->format)) { return; } $timekey = wfMemcKey($this->type, $this->format, 'timestamp'); $optionsHash = md5(serialize($opts->getAllValues())); $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; }
/** * main() */ public function execute($par) { global $wgContLang, $wgFeedClasses, $wgLanguageCode, $wgMemc, $wgOut, $wgGNSMsmaxage; list($params, $categories, $notCategories) = $this->getParams(); // if there's an error parsing the params, bail out and return if (isset($params['error'])) { wfHttpError(500, 'Internal Server Error', $params['error']); return; } // Check to make sure that feed type is supported. if (FeedUtils::checkFeedOutput($params['feed'])) { $msg = wfMessage('feed-' . $params['feed'])->inContentLanguage(); if ($msg->exists()) { // This seems a little icky since // its re-using another message in a // different context. // uses feed-rss and feed-atom messages. $feedType = $msg->text(); } else { $feedType = $wgContLang->uc($params['feed']); } $feed = new $wgFeedClasses[$params['feed']](wfMsgExt('googlenewssitemap_feedtitle', array('parsemag', 'content'), $wgContLang->getLanguageName($wgLanguageCode), $feedType, $wgLanguageCode), wfMsgExt('tagline', array('parsemag', 'content')), Title::newMainPage()->getFullURL()); } else { // FeedUtils outputs an error if wrong feed type. // So nothing else to do at this point return; } $wgOut->setSquidMaxage($wgGNSMsmaxage); $cacheInvalidationInfo = $this->getCacheInvalidationInfo($params, $categories, $notCategories); $cacheKey = $this->getCacheKey($params, $categories, $notCategories); // The way this does caching is based on ChangesFeed::execute. $cached = $this->getCachedVersion($cacheKey, $cacheInvalidationInfo); if ($cached !== false) { $feed->httpHeaders(); echo $cached; echo "<!-- From cache: {$cacheKey} -->"; } else { wfProfileIn(__METHOD__ . '-not-cached'); $res = $this->getCategories($params, $categories, $notCategories); ob_start(); $this->makeFeed($feed, $res); $output = ob_get_contents(); ob_end_flush(); echo "<!-- Not cached. Saved as: {$cacheKey} -->"; $wgMemc->set($cacheKey, array($cacheInvalidationInfo, $output), $this->maxCacheTime); wfProfileOut(__METHOD__ . '-not-cached'); } }
/** * Output a subscription feed listing recent edits to this page. * * @param string $type Feed type */ function feed($type) { if (!FeedUtils::checkFeedOutput($type)) { return; } $request = $this->getRequest(); $feedClasses = $this->context->getConfig()->get('FeedClasses'); /** @var RSSFeed|AtomFeed $feed */ $feed = new $feedClasses[$type]($this->getTitle()->getPrefixedText() . ' - ' . $this->msg('history-feed-title')->inContentLanguage()->text(), $this->msg('history-feed-description')->inContentLanguage()->text(), $this->getTitle()->getFullURL('action=history')); // Get a limit on number of feed entries. Provide a sane default // of 10 if none is defined (but limit to $wgFeedLimit max) $limit = $request->getInt('limit', 10); $limit = min(max($limit, 1), $this->context->getConfig()->get('FeedLimit')); $items = $this->fetchRevisions($limit, 0, self::DIR_NEXT); // Generate feed elements enclosed between header and footer. $feed->outHeader(); if ($items->numRows()) { foreach ($items as $row) { $feed->outItem($this->feedItem($row)); } } else { $feed->outItem($this->feedEmpty()); } $feed->outFooter(); }
/** * Output a subscription feed listing recent edits to this page. * * @param $type String: feed type */ function feed($type) { global $wgFeedClasses, $wgFeedLimit; if (!FeedUtils::checkFeedOutput($type)) { return; } $request = $this->getRequest(); $feed = new $wgFeedClasses[$type]($this->getTitle()->getPrefixedText() . ' - ' . wfMsgForContent('history-feed-title'), wfMsgForContent('history-feed-description'), $this->getTitle()->getFullUrl('action=history')); // Get a limit on number of feed entries. Provide a sane default // of 10 if none is defined (but limit to $wgFeedLimit max) $limit = $request->getInt('limit', 10); if ($limit > $wgFeedLimit || $limit < 1) { $limit = 10; } $items = $this->fetchRevisions($limit, 0, HistoryPage::DIR_NEXT); // Generate feed elements enclosed between header and footer. $feed->outHeader(); if ($items->numRows()) { foreach ($items as $row) { $feed->outItem($this->feedItem($row)); } } else { $feed->outItem($this->feedEmpty()); } $feed->outFooter(); }