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 * Generate an Atom feed.
29 class AtomFeed
extends ChannelFeed
{
31 * Format a date given timestamp, if one is given.
33 * @param string|int|null $timestamp
36 function formatTime( $timestamp ) {
38 // need to use RFC 822 time format at least for rss2.0
39 return gmdate( 'Y-m-d\TH:i:s', wfTimestamp( TS_UNIX
, $timestamp ) );
44 * Outputs a basic header for Atom 1.0 feeds.
46 function outHeader() {
48 $this->outXmlHeader();
49 // Manually escaping rather than letting Mustache do it because Mustache
50 // uses htmlentities, which does not work with XML
52 'language' => $this->xmlEncode( $this->getLanguage() ),
53 'feedID' => $this->getFeedId(),
54 'title' => $this->getTitle(),
55 'url' => $this->xmlEncode( wfExpandUrl( $this->getUrlUnescaped(), PROTO_CURRENT
) ),
56 'selfUrl' => $this->getSelfUrl(),
57 'timestamp' => $this->xmlEncode( $this->formatTime( wfTimestampNow() ) ),
58 'description' => $this->getDescription(),
59 'version' => $this->xmlEncode( $wgVersion ),
61 print $this->templateParser
->processTemplate( 'AtomHeader', $templateParams );
65 * Atom 1.0 requires a unique, opaque IRI as a unique identifier
66 * for every feed we create. For now just use the URL, but who
67 * can tell if that's right? If we put options on the feed, do we
68 * have to change the id? Maybe? Maybe not.
72 private function getFeedId() {
73 return $this->getSelfUrl();
77 * Atom 1.0 requests a self-reference to the feed.
80 private function getSelfUrl() {
82 return htmlspecialchars( $wgRequest->getFullRequestURL() );
86 * Output a given item.
87 * @param FeedItem $item
89 function outItem( $item ) {
91 // Manually escaping rather than letting Mustache do it because Mustache
92 // uses htmlentities, which does not work with XML
94 "uniqueID" => $item->getUniqueID(),
95 "title" => $item->getTitle(),
96 "mimeType" => $this->xmlEncode( $wgMimeType ),
97 "url" => $this->xmlEncode( wfExpandUrl( $item->getUrlUnescaped(), PROTO_CURRENT
) ),
98 "date" => $this->xmlEncode( $this->formatTime( $item->getDate() ) ),
99 "description" => $item->getDescription(),
100 "author" => $item->getAuthor()
102 print $this->templateParser
->processTemplate( 'AtomItem', $templateParams );
106 * Outputs the footer for Atom 1.0 feed (basically '\</feed\>').
108 function outFooter() {