Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 29
0.00% covered (danger)
0.00%
0 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
RSSFeed
0.00% covered (danger)
0.00%
0 / 28
0.00% covered (danger)
0.00%
0 / 4
42
0.00% covered (danger)
0.00%
0 / 1
 formatTime
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
6
 outHeader
0.00% covered (danger)
0.00%
0 / 10
0.00% covered (danger)
0.00%
0 / 1
2
 outItem
0.00% covered (danger)
0.00%
0 / 14
0.00% covered (danger)
0.00%
0 / 1
6
 outFooter
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2/**
3 * Copyright © 2004 Brooke Vibber <bvibber@wikimedia.org>
4 * https://www.mediawiki.org/
5 *
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.
10 *
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.
15 *
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
20 *
21 * @file
22 */
23
24namespace MediaWiki\Feed;
25
26/**
27 * Generate an RSS feed.
28 *
29 * @ingroup Feed
30 */
31class RSSFeed extends ChannelFeed {
32
33    /**
34     * Format a date given a timestamp. If a timestamp is not given, nothing is returned
35     *
36     * @param string|int|null $ts Timestamp
37     * @return string|null Date string
38     */
39    private function formatTime( $ts ) {
40        if ( $ts ) {
41            return gmdate( 'D, d M Y H:i:s \G\M\T', (int)wfTimestamp( TS_UNIX, $ts ) );
42        }
43        return null;
44    }
45
46    /**
47     * Output an RSS 2.0 header
48     */
49    public function outHeader() {
50        $this->outXmlHeader();
51        // Manually escaping rather than letting Mustache do it because Mustache
52        // uses htmlentities, which does not work with XML
53        $templateParams = [
54            'title' => $this->getTitle(),
55            'url' => $this->xmlEncode( wfExpandUrl( $this->getUrlUnescaped(), PROTO_CURRENT ) ),
56            'description' => $this->getDescription(),
57            'language' => $this->xmlEncode( $this->getLanguage() ),
58            'version' => $this->xmlEncode( MW_VERSION ),
59            'timestamp' => $this->xmlEncode( $this->formatTime( wfTimestampNow() ) )
60        ];
61        print $this->templateParser->processTemplate( 'RSSHeader', $templateParams );
62    }
63
64    /**
65     * Output an RSS 2.0 item
66     * @param FeedItem $item Item to be output
67     */
68    public function outItem( $item ) {
69        // Manually escaping rather than letting Mustache do it because Mustache
70        // uses htmlentities, which does not work with XML
71        $templateParams = [
72            "title" => $item->getTitle(),
73            "url" => $this->xmlEncode( wfExpandUrl( $item->getUrlUnescaped(), PROTO_CURRENT ) ),
74            "permalink" => $item->rssIsPermalink,
75            "uniqueID" => $item->getUniqueID(),
76            "description" => $item->getDescription(),
77            "date" => $this->xmlEncode( $this->formatTime( $item->getDate() ) ),
78            "author" => $item->getAuthor()
79        ];
80        $comments = $item->getCommentsUnescaped();
81        if ( $comments ) {
82            $commentsEscaped = $this->xmlEncode( wfExpandUrl( $comments, PROTO_CURRENT ) );
83            $templateParams["comments"] = $commentsEscaped;
84        }
85        print $this->templateParser->processTemplate( 'RSSItem', $templateParams );
86    }
87
88    /**
89     * Output an RSS 2.0 footer
90     */
91    public function outFooter() {
92        print "</channel></rss>";
93    }
94}
95
96/** @deprecated class alias since 1.40 */
97class_alias( RSSFeed::class, 'RSSFeed' );