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  public function __construct(
43  $title, $description, $url, $date = '', $author = '', $comments = ''
44  ) {
45  parent::__construct( $title, $description, $url, $date, $author, $comments );
46  $this->templateParser = new TemplateParser();
47  }
48 
56  abstract public function outHeader();
57 
66  abstract public function outItem( $item );
67 
75  abstract public function outFooter();
76 
85  public function httpHeaders() {
86  global $wgOut, $wgVaryOnXFP;
87 
88  # We take over from $wgOut, excepting its cache header info
89  $wgOut->disable();
90  $mimetype = $this->contentType();
91  header( "Content-type: $mimetype; charset=UTF-8" );
92 
93  // Set a sane filename
94  $exts = MediaWiki\MediaWikiServices::getInstance()->getMimeAnalyzer()
95  ->getExtensionsForType( $mimetype );
96  $ext = $exts ? strtok( $exts, ' ' ) : 'xml';
97  header( "Content-Disposition: inline; filename=\"feed.{$ext}\"" );
98 
99  if ( $wgVaryOnXFP ) {
100  $wgOut->addVaryHeader( 'X-Forwarded-Proto' );
101  }
102  $wgOut->sendCacheControl();
103  }
104 
110  private function contentType() {
111  global $wgRequest;
112 
113  $ctype = $wgRequest->getVal( 'ctype', 'application/xml' );
114  $allowedctypes = [
115  'application/xml',
116  'text/xml',
117  'application/rss+xml',
118  'application/atom+xml'
119  ];
120 
121  return ( in_array( $ctype, $allowedctypes ) ? $ctype : 'application/xml' );
122  }
123 
127  protected function outXmlHeader() {
128  $this->httpHeaders();
129  echo '<?xml version="1.0"?>' . "\n";
130  }
131 }
ChannelFeed\contentType
contentType()
Return an internet media type to be sent in the headers.
Definition: ChannelFeed.php:110
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:85
ChannelFeed\outXmlHeader
outXmlHeader()
Output the initial XML headers.
Definition: ChannelFeed.php:127
MediaWiki\MediaWikiServices\getInstance
static getInstance()
Returns the global default instance of the top level service locator.
Definition: MediaWikiServices.php:175
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:2868
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:641
FeedItem\$title
Title $title
Definition: FeedItem.php:35
$wgOut
$wgOut
Definition: Setup.php:779
TemplateParser
Definition: TemplateParser.php:27