MediaWiki master
ChannelFeed.php
Go to the documentation of this file.
1<?php
2
25namespace MediaWiki\Feed;
26
31
38abstract class ChannelFeed extends FeedItem {
39
41 protected $templateParser;
42
54 public function __construct(
55 $title, $description, $url, $date = '', $author = '', $comments = ''
56 ) {
57 parent::__construct( $title, $description, $url, $date, $author, $comments );
58 $this->templateParser = new TemplateParser();
59 }
60
68 abstract public function outHeader();
69
78 abstract public function outItem( $item );
79
87 abstract public function outFooter();
88
97 public function httpHeaders() {
98 global $wgOut;
99 $varyOnXFP = MediaWikiServices::getInstance()->getMainConfig()
101 # We take over from $wgOut, excepting its cache header info
102 $wgOut->disable();
103 $mimetype = $this->contentType();
104 header( "Content-type: $mimetype; charset=UTF-8" );
105
106 // Set a sensible filename
107 $mimeAnalyzer = MediaWikiServices::getInstance()->getMimeAnalyzer();
108 $ext = $mimeAnalyzer->getExtensionFromMimeTypeOrNull( $mimetype ) ?? 'xml';
109 header( "Content-Disposition: inline; filename=\"feed.{$ext}\"" );
110
111 if ( $varyOnXFP ) {
112 $wgOut->addVaryHeader( 'X-Forwarded-Proto' );
113 }
114 $wgOut->sendCacheControl();
115 }
116
124 private function contentType() {
125 global $wgRequest;
126
127 $ctype = $wgRequest->getVal( 'ctype', 'application/xml' );
128 $allowedctypes = [
129 'application/xml',
130 'text/xml',
131 'application/rss+xml',
132 'application/atom+xml'
133 ];
134
135 return ( in_array( $ctype, $allowedctypes ) ? $ctype : 'application/xml' );
136 }
137
141 protected function outXmlHeader() {
142 $this->httpHeaders();
143 echo '<?xml version="1.0"?>' . "\n";
144 }
145}
146
148class_alias( ChannelFeed::class, 'ChannelFeed' );
global $wgRequest
Definition Setup.php:415
if(!defined( 'MW_NO_SESSION') &&MW_ENTRY_POINT !=='cli') $wgOut
Definition Setup.php:536
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.
Represents a title within MediaWiki.
Definition Title.php:78