diff options
author | Brad Jorsch <bjorsch@wikimedia.org> | 2014-10-22 12:00:48 -0400 |
---|---|---|
committer | Brad Jorsch <bjorsch@wikimedia.org> | 2014-10-22 13:13:11 -0400 |
commit | e80638ccff7ac1cb2976902f4b8c54e45849e9e5 (patch) | |
tree | 537d1ef815ed7edb453a4c405e3ffcb3af6461e7 /includes/api/ApiFormatFeedWrapper.php | |
parent | 379669ac65d9eb6637415a2f7c382e0a1b114623 (diff) | |
download | mediawikicore-e80638ccff7ac1cb2976902f4b8c54e45849e9e5.tar.gz mediawikicore-e80638ccff7ac1cb2976902f4b8c54e45849e9e5.zip |
API: Fix ApiFormatFeedWrapper
With recent changes to the API, directly outputting text from execute()
in ApiFormatBase subclasses doesn't work anymore. Adjust
ApiFormatFeedWrapper for this new situation, and also handle headers in
initPrinter() where that belongs.
Bug: 72359
Change-Id: I4e4a2386858da6d87169deabaca763eeeacefbe9
Diffstat (limited to 'includes/api/ApiFormatFeedWrapper.php')
-rw-r--r-- | includes/api/ApiFormatFeedWrapper.php | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/includes/api/ApiFormatFeedWrapper.php b/includes/api/ApiFormatFeedWrapper.php index 92600067f181..3f53ed43d329 100644 --- a/includes/api/ApiFormatFeedWrapper.php +++ b/includes/api/ApiFormatFeedWrapper.php @@ -82,17 +82,41 @@ class ApiFormatFeedWrapper extends ApiFormatBase { * $result['_feed'] - an instance of one of the $wgFeedClasses classes * $result['_feeditems'] - an array of FeedItem instances */ + public function initPrinter( $unused = false ) { + parent::initPrinter( $unused ); + + if ( $this->isDisabled() ) { + return; + } + + $data = $this->getResultData(); + if ( isset( $data['_feed'] ) && isset( $data['_feeditems'] ) ) { + $data['_feed']->httpHeaders(); + } else { + // Error has occurred, print something useful + ApiBase::dieDebug( __METHOD__, 'Invalid feed class/item' ); + } + } + + /** + * 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']; + // execute() needs to pass strings to $this->printText, not produce output itself. + ob_start(); $feed->outHeader(); foreach ( $items as & $item ) { $feed->outItem( $item ); } $feed->outFooter(); + $this->printText( ob_get_clean() ); } else { // Error has occurred, print something useful ApiBase::dieDebug( __METHOD__, 'Invalid feed class/item' ); |