3 * Copyright © 2006 Yuri Astrakhan "<Firstname><Lastname>@gmail.com"
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
24 * This printer is used to wrap an instance of the Feed class
27 class ApiFormatFeedWrapper
extends ApiFormatBase
{
29 public function __construct( ApiMain
$main ) {
30 parent
::__construct( $main, 'feed' );
34 * Call this method to initialize output data. See execute()
35 * @param ApiResult $result
36 * @param object $feed An instance of one of the $wgFeedClasses classes
37 * @param array $feedItems Array of FeedItem objects
39 public static function setResult( $result, $feed, $feedItems ) {
40 // Store output in the Result data.
41 // This way we can check during execution if any error has occurred
42 // Disable size checking for this because we can't continue
43 // cleanly; size checking would cause more problems than it'd
45 $result->addValue( null, '_feed', $feed, ApiResult
::NO_VALIDATE
);
46 $result->addValue( null, '_feeditems', $feedItems, ApiResult
::NO_VALIDATE
);
50 * Feed does its own headers
54 public function getMimeType() {
59 * ChannelFeed doesn't give us a method to print errors in a friendly
60 * manner, so just punt errors to the default printer.
63 public function canPrintErrors() {
68 * This class expects the result data to be in a custom format set by self::setResult()
69 * $result['_feed'] - an instance of one of the $wgFeedClasses classes
70 * $result['_feeditems'] - an array of FeedItem instances
73 public function initPrinter( $unused = false ) {
74 parent
::initPrinter( $unused );
76 if ( $this->isDisabled() ) {
80 $data = $this->getResult()->getResultData();
81 if ( isset( $data['_feed'] ) && isset( $data['_feeditems'] ) ) {
82 /** @var ChannelFeed $feed */
83 $feed = $data['_feed'];
86 // Error has occurred, print something useful
87 ApiBase
::dieDebug( __METHOD__
, 'Invalid feed class/item' );
92 * This class expects the result data to be in a custom format set by self::setResult()
93 * $result['_feed'] - an instance of one of the $wgFeedClasses classes
94 * $result['_feeditems'] - an array of FeedItem instances
96 public function execute() {
97 $data = $this->getResult()->getResultData();
98 if ( isset( $data['_feed'] ) && isset( $data['_feeditems'] ) ) {
99 /** @var ChannelFeed $feed */
100 $feed = $data['_feed'];
101 $items = $data['_feeditems'];
103 // execute() needs to pass strings to $this->printText, not produce output itself.
106 foreach ( $items as & $item ) {
107 $feed->outItem( $item );
110 $this->printText( ob_get_clean() );
112 // Error has occurred, print something useful
113 ApiBase
::dieDebug( __METHOD__
, 'Invalid feed class/item' );