MediaWiki
REL1_40
ApiFormatFeedWrapper.php
Go to the documentation of this file.
1
<?php
23
use
MediaWiki\Feed\ChannelFeed
;
24
use
MediaWiki\Feed\FeedItem
;
25
30
class
ApiFormatFeedWrapper
extends
ApiFormatBase
{
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
}
ApiBase\dieDebug
static dieDebug( $method, $message)
Internal code errors should be reported with this method.
Definition
ApiBase.php:1701
ApiBase\getResult
getResult()
Get the result object.
Definition
ApiBase.php:637
ApiFormatBase
This is the abstract base class for API formatters.
Definition
ApiFormatBase.php:33
ApiFormatBase\printText
printText( $text)
Append text to the output buffer.
Definition
ApiFormatBase.php:345
ApiFormatBase\isDisabled
isDisabled()
Whether the printer is disabled.
Definition
ApiFormatBase.php:128
ApiFormatFeedWrapper
This printer is used to wrap an instance of the Feed class.
Definition
ApiFormatFeedWrapper.php:30
ApiFormatFeedWrapper\initPrinter
initPrinter( $unused=false)
This class expects the result data to be in a custom format set by self::setResult() $result['_feed']...
Definition
ApiFormatFeedWrapper.php:76
ApiFormatFeedWrapper\__construct
__construct(ApiMain $main)
Definition
ApiFormatFeedWrapper.php:32
ApiFormatFeedWrapper\getMimeType
getMimeType()
Feed does its own headers.
Definition
ApiFormatFeedWrapper.php:57
ApiFormatFeedWrapper\execute
execute()
This class expects the result data to be in a custom format set by self::setResult() $result['_feed']...
Definition
ApiFormatFeedWrapper.php:99
ApiFormatFeedWrapper\setResult
static setResult( $result, $feed, $feedItems)
Call this method to initialize output data.
Definition
ApiFormatFeedWrapper.php:42
ApiFormatFeedWrapper\canPrintErrors
canPrintErrors()
MediaWiki\Feed\ChannelFeed doesn't give us a method to print errors in a friendly manner,...
Definition
ApiFormatFeedWrapper.php:66
ApiMain
This is the main API class, used for both external and internal processing.
Definition
ApiMain.php:58
MediaWiki\Feed\ChannelFeed
Class to support the outputting of syndication feeds in Atom and RSS format.
Definition
ChannelFeed.php:38
MediaWiki\Feed\FeedItem
A base class for outputting syndication feeds (e.g.
Definition
FeedItem.php:40
includes
api
ApiFormatFeedWrapper.php
Generated on Thu Jun 27 2024 14:02:12 for MediaWiki by
1.10.0