MediaWiki REL1_39
ChannelFeed.php
Go to the documentation of this file.
1<?php
2
27
34abstract class ChannelFeed extends FeedItem {
35
37 protected $templateParser;
38
50 public function __construct(
51 $title, $description, $url, $date = '', $author = '', $comments = ''
52 ) {
53 parent::__construct( $title, $description, $url, $date, $author, $comments );
54 $this->templateParser = new TemplateParser();
55 }
56
64 abstract public function outHeader();
65
74 abstract public function outItem( $item );
75
83 abstract public function outFooter();
84
93 public function httpHeaders() {
94 global $wgOut;
95 $varyOnXFP = MediaWikiServices::getInstance()->getMainConfig()
96 ->get( MainConfigNames::VaryOnXFP );
97 # We take over from $wgOut, excepting its cache header info
98 $wgOut->disable();
99 $mimetype = $this->contentType();
100 header( "Content-type: $mimetype; charset=UTF-8" );
101
102 // Set a sensible filename
103 $mimeAnalyzer = MediaWikiServices::getInstance()->getMimeAnalyzer();
104 $ext = $mimeAnalyzer->getExtensionFromMimeTypeOrNull( $mimetype ) ?? 'xml';
105 header( "Content-Disposition: inline; filename=\"feed.{$ext}\"" );
106
107 if ( $varyOnXFP ) {
108 $wgOut->addVaryHeader( 'X-Forwarded-Proto' );
109 }
110 $wgOut->sendCacheControl();
111 }
112
120 private function contentType() {
121 global $wgRequest;
122
123 $ctype = $wgRequest->getVal( 'ctype', 'application/xml' );
124 $allowedctypes = [
125 'application/xml',
126 'text/xml',
127 'application/rss+xml',
128 'application/atom+xml'
129 ];
130
131 return ( in_array( $ctype, $allowedctypes ) ? $ctype : 'application/xml' );
132 }
133
137 protected function outXmlHeader() {
138 $this->httpHeaders();
139 echo '<?xml version="1.0"?>' . "\n";
140 }
141}
global $wgRequest
Definition Setup.php:377
if(!defined( 'MW_NO_SESSION') &&! $wgCommandLineMode $wgOut
Definition Setup.php:497
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='')
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:36
Title $title
Definition FeedItem.php:38
A class containing constants representing the names of configuration variables.
Service locator for MediaWiki core services.
if(!is_readable( $file)) $ext
Definition router.php:48