MediaWiki master
ApiFormatFeedWrapper.php
Go to the documentation of this file.
1<?php
23namespace MediaWiki\Api;
24
27
33
34 public function __construct( ApiMain $main ) {
35 parent::__construct( $main, 'feed' );
36 }
37
44 public static function setResult( $result, $feed, $feedItems ) {
45 // Store output in the Result data.
46 // This way we can check during execution if any error has occurred
47 // Disable size checking for this because we can't continue
48 // cleanly; size checking would cause more problems than it'd
49 // solve
50 $result->addValue( null, '_feed', $feed, ApiResult::NO_VALIDATE );
51 $result->addValue( null, '_feeditems', $feedItems, ApiResult::NO_VALIDATE );
52 }
53
59 public function getMimeType() {
60 return null;
61 }
62
68 public function canPrintErrors() {
69 return false;
70 }
71
78 public function initPrinter( $unused = false ) {
79 parent::initPrinter( $unused );
80
81 if ( $this->isDisabled() ) {
82 return;
83 }
84
85 $data = $this->getResult()->getResultData();
86 if ( isset( $data['_feed'] ) && isset( $data['_feeditems'] ) ) {
88 $feed = $data['_feed'];
89 $feed->httpHeaders();
90 } else {
91 // Error has occurred, print something useful
92 ApiBase::dieDebug( __METHOD__, 'Invalid feed class/item' );
93 }
94 }
95
101 public function execute() {
102 $data = $this->getResult()->getResultData();
103 if ( isset( $data['_feed'] ) && isset( $data['_feeditems'] ) ) {
105 $feed = $data['_feed'];
106 $items = $data['_feeditems'];
107
108 // execute() needs to pass strings to $this->printText, not produce output itself.
109 ob_start();
110 $feed->outHeader();
111 foreach ( $items as & $item ) {
112 $feed->outItem( $item );
113 }
114 $feed->outFooter();
115 $this->printText( ob_get_clean() );
116 } else {
117 // Error has occurred, print something useful
118 ApiBase::dieDebug( __METHOD__, 'Invalid feed class/item' );
119 }
120 }
121}
122
124class_alias( ApiFormatFeedWrapper::class, 'ApiFormatFeedWrapper' );
getResult()
Get the result object.
Definition ApiBase.php:710
static dieDebug( $method, $message)
Internal code errors should be reported with this method.
Definition ApiBase.php:1820
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:78
const NO_VALIDATE
For addValue(), setValue() and similar functions, do not validate data.
Definition ApiResult.php:74
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:40