MediaWiki master
ChannelFeed.php
Go to the documentation of this file.
1<?php
2
25namespace MediaWiki\Feed;
26
30
37abstract class ChannelFeed extends FeedItem {
38
40 protected $templateParser;
41
53 public function __construct(
54 $title, $description, $url, $date = '', $author = '', $comments = ''
55 ) {
56 parent::__construct( $title, $description, $url, $date, $author, $comments );
57 $this->templateParser = new TemplateParser();
58 }
59
67 abstract public function outHeader();
68
77 abstract public function outItem( $item );
78
86 abstract public function outFooter();
87
96 public function httpHeaders() {
97 global $wgOut;
98 $varyOnXFP = MediaWikiServices::getInstance()->getMainConfig()
100 # We take over from $wgOut, excepting its cache header info
101 $wgOut->disable();
102 $mimetype = $this->contentType();
103 header( "Content-type: $mimetype; charset=UTF-8" );
104
105 // Set a sensible filename
106 $mimeAnalyzer = MediaWikiServices::getInstance()->getMimeAnalyzer();
107 $ext = $mimeAnalyzer->getExtensionFromMimeTypeOrNull( $mimetype ) ?? 'xml';
108 header( "Content-Disposition: inline; filename=\"feed.{$ext}\"" );
109
110 if ( $varyOnXFP ) {
111 $wgOut->addVaryHeader( 'X-Forwarded-Proto' );
112 }
113 $wgOut->sendCacheControl();
114 }
115
123 private function contentType() {
124 global $wgRequest;
125
126 $ctype = $wgRequest->getVal( 'ctype', 'application/xml' );
127 $allowedctypes = [
128 'application/xml',
129 'text/xml',
130 'application/rss+xml',
131 'application/atom+xml'
132 ];
133
134 return ( in_array( $ctype, $allowedctypes ) ? $ctype : 'application/xml' );
135 }
136
140 protected function outXmlHeader() {
141 $this->httpHeaders();
142 echo '<?xml version="1.0"?>' . "\n";
143 }
144}
145
147class_alias( ChannelFeed::class, 'ChannelFeed' );
global $wgRequest
Definition Setup.php:449
if(!defined( 'MW_NO_SESSION') &&MW_ENTRY_POINT !=='cli' $wgOut
Definition Setup.php:570
Class to support the outputting of syndication feeds in Atom and RSS format.
TemplateParser $templateParser
__construct( $title, $description, $url, $date='', $author='', $comments='')
httpHeaders()
Setup and send HTTP headers.
outItem( $item)
Generate an item.
outHeader()
Generate Header of the feed.
outFooter()
Generate Footer of the feed.
outXmlHeader()
Output the initial XML headers.
A base class for outputting syndication feeds (e.g.
Definition FeedItem.php:40
A class containing constants representing the names of configuration variables.
const VaryOnXFP
Name constant for the VaryOnXFP setting, for use with Config::get()
Service locator for MediaWiki core services.
static getInstance()
Returns the global default instance of the top level service locator.