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