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