Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 25 |
|
0.00% |
0 / 6 |
CRAP | |
0.00% |
0 / 1 |
| ApiFormatFeedWrapper | |
0.00% |
0 / 24 |
|
0.00% |
0 / 6 |
156 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setResult | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| getMimeType | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| canPrintErrors | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| initPrinter | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
20 | |||
| execute | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
20 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * Copyright © 2006 Yuri Astrakhan "<Firstname><Lastname>@gmail.com" |
| 4 | * |
| 5 | * @license GPL-2.0-or-later |
| 6 | * @file |
| 7 | */ |
| 8 | |
| 9 | namespace MediaWiki\Api; |
| 10 | |
| 11 | use MediaWiki\Feed\ChannelFeed; |
| 12 | use MediaWiki\Feed\FeedItem; |
| 13 | |
| 14 | /** |
| 15 | * This printer is used to wrap an instance of the Feed class |
| 16 | * @ingroup API |
| 17 | */ |
| 18 | class ApiFormatFeedWrapper extends ApiFormatBase { |
| 19 | |
| 20 | public function __construct( ApiMain $main ) { |
| 21 | parent::__construct( $main, 'feed' ); |
| 22 | } |
| 23 | |
| 24 | /** |
| 25 | * Call this method to initialize output data. See execute() |
| 26 | * @param ApiResult $result |
| 27 | * @param ChannelFeed $feed An instance of one of the $wgFeedClasses classes |
| 28 | * @param FeedItem[] $feedItems |
| 29 | */ |
| 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 | |
| 40 | /** |
| 41 | * Feed does its own headers |
| 42 | * |
| 43 | * @return null |
| 44 | */ |
| 45 | public function getMimeType() { |
| 46 | return null; |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * MediaWiki\Feed\ChannelFeed doesn't give us a method to print errors in a friendly |
| 51 | * manner, so just punt errors to the default printer. |
| 52 | * @return bool |
| 53 | */ |
| 54 | public function canPrintErrors() { |
| 55 | return false; |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * This class expects the result data to be in a custom format set by self::setResult() |
| 60 | * $result['_feed'] - an instance of one of the $wgFeedClasses classes |
| 61 | * $result['_feeditems'] - an array of MediaWiki\Feed\FeedItem instances |
| 62 | * @param bool $unused |
| 63 | */ |
| 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'] ) ) { |
| 73 | /** @var ChannelFeed $feed */ |
| 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 | |
| 84 | /** |
| 85 | * This class expects the result data to be in a custom format set by self::setResult() |
| 86 | * $result['_feed'] - an instance of one of the $wgFeedClasses classes |
| 87 | * $result['_feeditems'] - an array of MediaWiki\Feed\FeedItem instances |
| 88 | */ |
| 89 | public function execute() { |
| 90 | $data = $this->getResult()->getResultData(); |
| 91 | if ( isset( $data['_feed'] ) && isset( $data['_feeditems'] ) ) { |
| 92 | /** @var ChannelFeed $feed */ |
| 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 | |
| 114 | /** @deprecated class alias since 1.43 */ |
| 115 | class_alias( ApiFormatFeedWrapper::class, 'ApiFormatFeedWrapper' ); |