MediaWiki  1.34.0
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 }
FeedItem
A base class for outputting syndication feeds (e.g.
Definition: FeedItem.php:33
MediaWiki\MediaWikiServices\getInstance
static getInstance()
Returns the global default instance of the top level service locator.
Definition: MediaWikiServices.php:138
$wgVaryOnXFP
$wgVaryOnXFP
Add X-Forwarded-Proto to the Vary and Key headers for API requests and RSS/Atom feeds.
Definition: DefaultSettings.php:2761
$title
$title
Definition: testCompression.php:34
$templateParser
$templateParser
Definition: NoLocalSettings.php:47
FeedItem\__construct
__construct( $title, $description, $url, $date='', $author='', $comments='')
Definition: FeedItem.php:59
$ext
if(!is_readable( $file)) $ext
Definition: router.php:48
$wgRequest
if(! $wgDBerrorLogTZ) $wgRequest
Definition: Setup.php:752
$wgOut
$wgOut
Definition: Setup.php:886