MediaWiki REL1_34
ChannelFeed.php
Go to the documentation of this file.
1<?php
29abstract class ChannelFeed extends FeedItem {
30
32 protected $templateParser;
33
42 function __construct( $title, $description, $url, $date = '', $author = '', $comments = '' ) {
43 parent::__construct( $title, $description, $url, $date, $author, $comments );
44 $this->templateParser = new TemplateParser();
45 }
46
54 abstract public function outHeader();
55
64 abstract public function outItem( $item );
65
73 abstract public function outFooter();
74
83 public function httpHeaders() {
84 global $wgOut, $wgVaryOnXFP;
85
86 # We take over from $wgOut, excepting its cache header info
87 $wgOut->disable();
88 $mimetype = $this->contentType();
89 header( "Content-type: $mimetype; charset=UTF-8" );
90
91 // Set a sane filename
92 $exts = MediaWiki\MediaWikiServices::getInstance()->getMimeAnalyzer()
93 ->getExtensionsForType( $mimetype );
94 $ext = $exts ? strtok( $exts, ' ' ) : 'xml';
95 header( "Content-Disposition: inline; filename=\"feed.{$ext}\"" );
96
97 if ( $wgVaryOnXFP ) {
98 $wgOut->addVaryHeader( 'X-Forwarded-Proto' );
99 }
100 $wgOut->sendCacheControl();
101 }
102
108 private function contentType() {
109 global $wgRequest;
110
111 $ctype = $wgRequest->getVal( 'ctype', 'application/xml' );
112 $allowedctypes = [
113 'application/xml',
114 'text/xml',
115 'application/rss+xml',
116 'application/atom+xml'
117 ];
118
119 return ( in_array( $ctype, $allowedctypes ) ? $ctype : 'application/xml' );
120 }
121
125 protected function outXmlHeader() {
126 $this->httpHeaders();
127 echo '<?xml version="1.0"?>' . "\n";
128 }
129}
$wgVaryOnXFP
Add X-Forwarded-Proto to the Vary and Key headers for API requests and RSS/Atom feeds.
$wgOut
Definition Setup.php:885
if(! $wgDBerrorLogTZ) $wgRequest
Definition Setup.php:751
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='')
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