MediaWiki master
ChannelFeed.php
Go to the documentation of this file.
1<?php
2
11namespace MediaWiki\Feed;
12
16
23abstract class ChannelFeed extends FeedItem {
24
26 protected $templateParser;
27
38 public function __construct(
39 $title, $description, $url, $date = '', $author = '', $comments = ''
40 ) {
41 parent::__construct( $title, $description, $url, $date, $author, $comments );
42 $this->templateParser = new TemplateParser();
43 }
44
52 abstract public function outHeader();
53
62 abstract public function outItem( $item );
63
71 abstract public function outFooter();
72
81 public function httpHeaders() {
82 global $wgOut;
83 $varyOnXFP = MediaWikiServices::getInstance()->getMainConfig()
85 # We take over from $wgOut, excepting its cache header info
86 $wgOut->disable();
87 $mimetype = $this->contentType();
88 header( "Content-type: $mimetype; charset=UTF-8" );
89 // @todo Maybe set a CSP header here at some point as defense in depth.
90 // need to figure out how that interacts with browser display of article
91 // snippets.
92
93 // Set a sensible filename
94 $mimeAnalyzer = MediaWikiServices::getInstance()->getMimeAnalyzer();
95 $ext = $mimeAnalyzer->getExtensionFromMimeTypeOrNull( $mimetype ) ?? 'xml';
96 header( "Content-Disposition: inline; filename=\"feed.{$ext}\"" );
97
98 if ( $varyOnXFP ) {
99 $wgOut->addVaryHeader( 'X-Forwarded-Proto' );
100 }
101 $wgOut->sendCacheControl();
102 }
103
111 private function contentType() {
112 global $wgRequest;
113
114 $ctype = $wgRequest->getVal( 'ctype', 'application/xml' );
115 $allowedctypes = [
116 'application/xml',
117 'text/xml',
118 'application/rss+xml',
119 'application/atom+xml'
120 ];
121
122 return ( in_array( $ctype, $allowedctypes ) ? $ctype : 'application/xml' );
123 }
124
128 protected function outXmlHeader() {
129 $this->httpHeaders();
130 echo '<?xml version="1.0"?>' . "\n";
131 }
132}
global $wgRequest
Definition Setup.php:434
if(MW_ENTRY_POINT==='index') if(!defined( 'MW_NO_SESSION') &&MW_ENTRY_POINT !=='cli' $wgOut
Definition Setup.php:551
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:26
Handles compiling Mustache templates into PHP rendering functions.
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.