3 * Copyright © 2004 Brion Vibber <brion@pobox.com>
4 * https://www.mediawiki.org/
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 * http://www.gnu.org/copyleft/gpl.html
25 * Class to support the outputting of syndication feeds in Atom and RSS format.
29 abstract class ChannelFeed
extends FeedItem
{
31 /** @var TemplateParser */
32 protected $templateParser;
35 * @param string|Title $title Feed's title
36 * @param string $description
37 * @param string $url URL uniquely designating the feed.
38 * @param string $date Feed's date
39 * @param string $author Author's user name
40 * @param string $comments
42 function __construct( $title, $description, $url, $date = '', $author = '', $comments = '' ) {
43 parent
::__construct( $title, $description, $url, $date, $author, $comments );
44 $this->templateParser
= new TemplateParser();
48 * Generate Header of the feed
54 abstract public function outHeader();
60 * print "<item>...</item>";
62 * @param FeedItem $item
64 abstract public function outItem( $item );
67 * Generate Footer of the feed
73 abstract public function outFooter();
76 * Setup and send HTTP headers. Don't send any content;
77 * content might end up being cached and re-sent with
78 * these same headers later.
80 * This should be called from the outHeader() method,
81 * but can also be called separately.
83 public function httpHeaders() {
84 global $wgOut, $wgVaryOnXFP;
86 # We take over from $wgOut, excepting its cache header info
88 $mimetype = $this->contentType();
89 header( "Content-type: $mimetype; charset=UTF-8" );
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}\"" );
98 $wgOut->addVaryHeader( 'X-Forwarded-Proto' );
100 $wgOut->sendCacheControl();
104 * Return an internet media type to be sent in the headers.
108 private function contentType() {
111 $ctype = $wgRequest->getVal( 'ctype', 'application/xml' );
115 'application/rss+xml',
116 'application/atom+xml'
119 return ( in_array( $ctype, $allowedctypes ) ?
$ctype : 'application/xml' );
123 * Output the initial XML headers.
125 protected function outXmlHeader() {
126 $this->httpHeaders();
127 echo '<?xml version="1.0"?>' . "\n";