MediaWiki  master
ChannelFeed.php
Go to the documentation of this file.
1 <?php
30 abstract class ChannelFeed extends FeedItem {
31 
33  protected $templateParser;
34 
46  public function __construct(
47  $title, $description, $url, $date = '', $author = '', $comments = ''
48  ) {
49  parent::__construct( $title, $description, $url, $date, $author, $comments );
50  $this->templateParser = new TemplateParser();
51  }
52 
60  abstract public function outHeader();
61 
70  abstract public function outItem( $item );
71 
79  abstract public function outFooter();
80 
89  public function httpHeaders() {
90  global $wgOut, $wgVaryOnXFP;
91 
92  # We take over from $wgOut, excepting its cache header info
93  $wgOut->disable();
94  $mimetype = $this->contentType();
95  header( "Content-type: $mimetype; charset=UTF-8" );
96 
97  // Set a sane filename
98  $mimeAnalyzer = MediaWiki\MediaWikiServices::getInstance()->getMimeAnalyzer();
99  $ext = $mimeAnalyzer->getExtensionFromMimeTypeOrNull( $mimetype ) ?? 'xml';
100  header( "Content-Disposition: inline; filename=\"feed.{$ext}\"" );
101 
102  if ( $wgVaryOnXFP ) {
103  $wgOut->addVaryHeader( 'X-Forwarded-Proto' );
104  }
105  $wgOut->sendCacheControl();
106  }
107 
115  private function contentType() {
116  global $wgRequest;
117 
118  $ctype = $wgRequest->getVal( 'ctype', 'application/xml' );
119  $allowedctypes = [
120  'application/xml',
121  'text/xml',
122  'application/rss+xml',
123  'application/atom+xml'
124  ];
125 
126  return ( in_array( $ctype, $allowedctypes ) ? $ctype : 'application/xml' );
127  }
128 
132  protected function outXmlHeader() {
133  $this->httpHeaders();
134  echo '<?xml version="1.0"?>' . "\n";
135  }
136 }
ChannelFeed\contentType
contentType()
Return an internet media type to be sent in the headers.
Definition: ChannelFeed.php:115
FeedItem
A base class for outputting syndication feeds (e.g.
Definition: FeedItem.php:33
ChannelFeed\outItem
outItem( $item)
Generate an item.
FeedItem\$url
$url
Definition: FeedItem.php:39
FeedItem\$description
$description
Definition: FeedItem.php:37
ChannelFeed\__construct
__construct( $title, $description, $url, $date='', $author='', $comments='')
Stable to call.
Definition: ChannelFeed.php:46
ChannelFeed\httpHeaders
httpHeaders()
Setup and send HTTP headers.
Definition: ChannelFeed.php:89
ChannelFeed\outXmlHeader
outXmlHeader()
Output the initial XML headers.
Definition: ChannelFeed.php:132
MediaWiki\MediaWikiServices\getInstance
static getInstance()
Returns the global default instance of the top level service locator.
Definition: MediaWikiServices.php:186
ChannelFeed\$templateParser
TemplateParser $templateParser
Definition: ChannelFeed.php:33
FeedItem\$date
$date
Definition: FeedItem.php:41
$wgVaryOnXFP
$wgVaryOnXFP
Add X-Forwarded-Proto to the Vary and Key headers for API requests and RSS/Atom feeds.
Definition: DefaultSettings.php:2898
FeedItem\$comments
$comments
Definition: FeedItem.php:47
ChannelFeed
Class to support the outputting of syndication feeds in Atom and RSS format.
Definition: ChannelFeed.php:30
ChannelFeed\outFooter
outFooter()
Generate Footer of the feed.
ChannelFeed\outHeader
outHeader()
Generate Header of the feed.
$ext
if(!is_readable( $file)) $ext
Definition: router.php:48
FeedItem\$author
$author
Definition: FeedItem.php:43
$wgRequest
if(! $wgDBerrorLogTZ) $wgRequest
Definition: Setup.php:644
FeedItem\$title
Title $title
Definition: FeedItem.php:35
$wgOut
$wgOut
Definition: Setup.php:781
TemplateParser
Definition: TemplateParser.php:27