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
__construct( $title, $description, $url, $date='', $author='', $comments='')
Definition: ChannelFeed.php:42
static getInstance()
Returns the global default instance of the top level service locator.
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.
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
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:785
$wgOut
Definition: Setup.php:936
outItem( $item)
Generate an item.