MediaWiki REL1_35
ChannelFeed.php
Go to the documentation of this file.
1<?php
30abstract 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}
$wgVaryOnXFP
Add X-Forwarded-Proto to the Vary and Key headers for API requests and RSS/Atom feeds.
$wgOut
Definition Setup.php:786
if(! $wgDBerrorLogTZ) $wgRequest
Definition Setup.php:643
Class to support the outputting of syndication feeds in Atom and RSS format.
outFooter()
Generate Footer of the feed.
TemplateParser $templateParser
outHeader()
Generate Header of the feed.
__construct( $title, $description, $url, $date='', $author='', $comments='')
Stable to call.
contentType()
Return an internet media type to be sent in the headers.
httpHeaders()
Setup and send HTTP headers.
outItem( $item)
Generate an item.
outXmlHeader()
Output the initial XML headers.
A base class for outputting syndication feeds (e.g.
Definition FeedItem.php:33
Title $title
Definition FeedItem.php:35
if(!is_readable( $file)) $ext
Definition router.php:48