示例#1
0
 /**
  * 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;
 }
	/**
	 * Execute the feed driver, generating the syndication feed and printing
	 * the results.
	 */
	public function execute() {
		global $wgOut;

		if ( !$this->checkFeedOutput() )
			return;

		$feed = $this->getFeedObject();

		if ( !$feed ) {
			wfHttpError( 404, "Not found",
				"There is no such wikilog feed available from this site." );
			return;
		}

		list( $timekey, $feedkey ) = $this->getCacheKeys();
		FeedUtils::checkPurge( $timekey, $feedkey );

		if ( $feed->isCacheable() ) {
			# Check if client cache is ok.
			if ( $wgOut->checkLastModified( $feed->getUpdated() ) ) {
				# Client cache is fresh. OutputPage takes care of sending
				# the appropriate headers, nothing else to do.
				return;
			}

			# Try to load the feed from our cache.
			$cached = $this->loadFromCache( $feed->getUpdated(), $timekey, $feedkey );

			if ( is_string( $cached ) ) {
				wfDebug( __METHOD__ . ": Outputting cached feed\n" );
				$feed->httpHeaders();
				echo $cached;
			} else {
				wfDebug( __METHOD__ . ": rendering new feed and caching it\n" );
				ob_start();
				$this->printFeed( $feed );
				$cached = ob_get_contents();
				ob_end_flush();
				$this->saveToCache( $cached, $timekey, $feedkey );
			}
		} else {
			# This feed is not cacheable.
			$this->printFeed( $feed );
		}
	}