MediaWiki  master
ChannelFeed.php
Go to the documentation of this file.
1 <?php
2 
27 
34 abstract class ChannelFeed extends FeedItem {
35 
37  protected $templateParser;
38 
50  public function __construct(
51  $title, $description, $url, $date = '', $author = '', $comments = ''
52  ) {
53  parent::__construct( $title, $description, $url, $date, $author, $comments );
54  $this->templateParser = new TemplateParser();
55  }
56 
64  abstract public function outHeader();
65 
74  abstract public function outItem( $item );
75 
83  abstract public function outFooter();
84 
93  public function httpHeaders() {
94  global $wgOut;
95  $varyOnXFP = MediaWikiServices::getInstance()->getMainConfig()
96  ->get( MainConfigNames::VaryOnXFP );
97  # We take over from $wgOut, excepting its cache header info
98  $wgOut->disable();
99  $mimetype = $this->contentType();
100  header( "Content-type: $mimetype; charset=UTF-8" );
101 
102  // Set a sensible filename
103  $mimeAnalyzer = MediaWikiServices::getInstance()->getMimeAnalyzer();
104  $ext = $mimeAnalyzer->getExtensionFromMimeTypeOrNull( $mimetype ) ?? 'xml';
105  header( "Content-Disposition: inline; filename=\"feed.{$ext}\"" );
106 
107  if ( $varyOnXFP ) {
108  $wgOut->addVaryHeader( 'X-Forwarded-Proto' );
109  }
110  $wgOut->sendCacheControl();
111  }
112 
120  private function contentType() {
121  global $wgRequest;
122 
123  $ctype = $wgRequest->getVal( 'ctype', 'application/xml' );
124  $allowedctypes = [
125  'application/xml',
126  'text/xml',
127  'application/rss+xml',
128  'application/atom+xml'
129  ];
130 
131  return ( in_array( $ctype, $allowedctypes ) ? $ctype : 'application/xml' );
132  }
133 
137  protected function outXmlHeader() {
138  $this->httpHeaders();
139  echo '<?xml version="1.0"?>' . "\n";
140  }
141 }
global $wgRequest
Definition: Setup.php:366
if(!defined( 'MW_NO_SESSION') &&! $wgCommandLineMode) $wgOut
Definition: Setup.php:486
Class to support the outputting of syndication feeds in Atom and RSS format.
Definition: ChannelFeed.php:34
outFooter()
Generate Footer of the feed.
TemplateParser $templateParser
Definition: ChannelFeed.php:37
outHeader()
Generate Header of the feed.
__construct( $title, $description, $url, $date='', $author='', $comments='')
Definition: ChannelFeed.php:50
contentType()
Return an internet media type to be sent in the headers.
httpHeaders()
Setup and send HTTP headers.
Definition: ChannelFeed.php:93
outItem( $item)
Generate an item.
outXmlHeader()
Output the initial XML headers.
A base class for outputting syndication feeds (e.g.
Definition: FeedItem.php:36
$description
Definition: FeedItem.php:40
Title $title
Definition: FeedItem.php:38
A class containing constants representing the names of configuration variables.
MediaWikiServices is the service locator for the application scope of MediaWiki.
if(!is_readable( $file)) $ext
Definition: router.php:48