MediaWiki master
ApiFormatFeedWrapper.php
Go to the documentation of this file.
1<?php
9namespace MediaWiki\Api;
10
13
19
20 public function __construct( ApiMain $main ) {
21 parent::__construct( $main, 'feed' );
22 }
23
30 public static function setResult( $result, $feed, $feedItems ) {
31 // Store output in the Result data.
32 // This way we can check during execution if any error has occurred
33 // Disable size checking for this because we can't continue
34 // cleanly; size checking would cause more problems than it'd
35 // solve
36 $result->addValue( null, '_feed', $feed, ApiResult::NO_VALIDATE );
37 $result->addValue( null, '_feeditems', $feedItems, ApiResult::NO_VALIDATE );
38 }
39
45 public function getMimeType() {
46 return null;
47 }
48
54 public function canPrintErrors() {
55 return false;
56 }
57
64 public function initPrinter( $unused = false ) {
65 parent::initPrinter( $unused );
66
67 if ( $this->isDisabled() ) {
68 return;
69 }
70
71 $data = $this->getResult()->getResultData();
72 if ( isset( $data['_feed'] ) && isset( $data['_feeditems'] ) ) {
74 $feed = $data['_feed'];
75 '@phan-var ChannelFeed $feed';
76
77 $feed->httpHeaders();
78 } else {
79 // Error has occurred, print something useful
80 ApiBase::dieDebug( __METHOD__, 'Invalid feed class/item' );
81 }
82 }
83
89 public function execute() {
90 $data = $this->getResult()->getResultData();
91 if ( isset( $data['_feed'] ) && isset( $data['_feeditems'] ) ) {
93 $feed = $data['_feed'];
94 $items = $data['_feeditems'];
95
96 '@phan-var ChannelFeed $feed';
97 '@phan-var FeedItem[] $items';
98
99 // execute() needs to pass strings to $this->printText, not produce output itself.
100 ob_start();
101 $feed->outHeader();
102 foreach ( $items as $item ) {
103 $feed->outItem( $item );
104 }
105 $feed->outFooter();
106 $this->printText( ob_get_clean() );
107 } else {
108 // Error has occurred, print something useful
109 ApiBase::dieDebug( __METHOD__, 'Invalid feed class/item' );
110 }
111 }
112}
113
115class_alias( ApiFormatFeedWrapper::class, 'ApiFormatFeedWrapper' );
getResult()
Get the result object.
Definition ApiBase.php:682
static dieDebug( $method, $message)
Internal code errors should be reported with this method.
Definition ApiBase.php:1748
This is the abstract base class for API formatters.
printText( $text)
Append text to the output buffer.
isDisabled()
Whether the printer is disabled.
This printer is used to wrap an instance of the Feed class.
initPrinter( $unused=false)
This class expects the result data to be in a custom format set by self::setResult() $result['_feed']...
execute()
This class expects the result data to be in a custom format set by self::setResult() $result['_feed']...
canPrintErrors()
MediaWiki\Feed\ChannelFeed doesn't give us a method to print errors in a friendly manner,...
static setResult( $result, $feed, $feedItems)
Call this method to initialize output data.
getMimeType()
Feed does its own headers.
This is the main API class, used for both external and internal processing.
Definition ApiMain.php:66
const NO_VALIDATE
For addValue(), setValue() and similar functions, do not validate data.
Definition ApiResult.php:65
Class to support the outputting of syndication feeds in Atom and RSS format.
A base class for outputting syndication feeds (e.g.
Definition FeedItem.php:26