+
+/**
+ * This printer is used to wrap an instance of the Feed class
+ * @ingroup API
+ */
+class ApiFormatFeedWrapper extends ApiFormatBase {
+
+ public function __construct( $main ) {
+ parent :: __construct( $main, 'feed' );
+ }
+
+ /**
+ * Call this method to initialize output data. See execute()
+ * @param $result ApiResult
+ * @param $feed object an instance of one of the $wgFeedClasses classes
+ * @param $feedItems array of FeedItem objects
+ */
+ public static function setResult( $result, $feed, $feedItems ) {
+ // Store output in the Result data.
+ // This way we can check during execution if any error has occured
+ // Disable size checking for this because we can't continue
+ // cleanly; size checking would cause more problems than it'd
+ // solve
+ $result->disableSizeCheck();
+ $result->addValue( null, '_feed', $feed );
+ $result->addValue( null, '_feeditems', $feedItems );
+ $result->enableSizeCheck();
+ }
+
+ /**
+ * Feed does its own headers
+ */
+ public function getMimeType() {
+ return null;
+ }
+
+ /**
+ * Optimization - no need to sanitize data that will not be needed
+ */
+ public function getNeedsRawData() {
+ return true;
+ }
+
+ /**
+ * This class expects the result data to be in a custom format set by self::setResult()
+ * $result['_feed'] - an instance of one of the $wgFeedClasses classes
+ * $result['_feeditems'] - an array of FeedItem instances
+ */
+ public function execute() {
+ $data = $this->getResultData();
+ if ( isset ( $data['_feed'] ) && isset ( $data['_feeditems'] ) ) {
+ $feed = $data['_feed'];
+ $items = $data['_feeditems'];
+
+ $feed->outHeader();
+ foreach ( $items as & $item )
+ $feed->outItem( $item );
+ $feed->outFooter();
+ } else {
+ // Error has occured, print something useful
+ ApiBase::dieDebug( __METHOD__, 'Invalid feed class/item' );
+ }
+ }
+
+ public function getVersion() {
+ return __CLASS__ . ': $Id$';
+ }
+}
\ No newline at end of file