MediaWiki master
ApiFormatFeedWrapper.php
Go to the documentation of this file.
1<?php
25
31
32 public function __construct( ApiMain $main ) {
33 parent::__construct( $main, 'feed' );
34 }
35
42 public static function setResult( $result, $feed, $feedItems ) {
43 // Store output in the Result data.
44 // This way we can check during execution if any error has occurred
45 // Disable size checking for this because we can't continue
46 // cleanly; size checking would cause more problems than it'd
47 // solve
48 $result->addValue( null, '_feed', $feed, ApiResult::NO_VALIDATE );
49 $result->addValue( null, '_feeditems', $feedItems, ApiResult::NO_VALIDATE );
50 }
51
57 public function getMimeType() {
58 return null;
59 }
60
66 public function canPrintErrors() {
67 return false;
68 }
69
76 public function initPrinter( $unused = false ) {
77 parent::initPrinter( $unused );
78
79 if ( $this->isDisabled() ) {
80 return;
81 }
82
83 $data = $this->getResult()->getResultData();
84 if ( isset( $data['_feed'] ) && isset( $data['_feeditems'] ) ) {
86 $feed = $data['_feed'];
87 $feed->httpHeaders();
88 } else {
89 // Error has occurred, print something useful
90 ApiBase::dieDebug( __METHOD__, 'Invalid feed class/item' );
91 }
92 }
93
99 public function execute() {
100 $data = $this->getResult()->getResultData();
101 if ( isset( $data['_feed'] ) && isset( $data['_feeditems'] ) ) {
103 $feed = $data['_feed'];
104 $items = $data['_feeditems'];
105
106 // execute() needs to pass strings to $this->printText, not produce output itself.
107 ob_start();
108 $feed->outHeader();
109 foreach ( $items as & $item ) {
110 $feed->outItem( $item );
111 }
112 $feed->outFooter();
113 $this->printText( ob_get_clean() );
114 } else {
115 // Error has occurred, print something useful
116 ApiBase::dieDebug( __METHOD__, 'Invalid feed class/item' );
117 }
118 }
119}
static dieDebug( $method, $message)
Internal code errors should be reported with this method.
Definition ApiBase.php:1777
getResult()
Get the result object.
Definition ApiBase.php:671
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']...
getMimeType()
Feed does its own headers.
execute()
This class expects the result data to be in a custom format set by self::setResult() $result['_feed']...
static setResult( $result, $feed, $feedItems)
Call this method to initialize output data.
canPrintErrors()
MediaWiki\Feed\ChannelFeed doesn't give us a method to print errors in a friendly manner,...
This is the main API class, used for both external and internal processing.
Definition ApiMain.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:40