MediaWiki REL1_41
RSSFeed.php
Go to the documentation of this file.
1<?php
24namespace MediaWiki\Feed;
25
31class RSSFeed extends ChannelFeed {
32
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
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
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
91 public function outFooter() {
92 print "</channel></rss>";
93 }
94}
95
99class_alias( RSSFeed::class, 'RSSFeed' );
const PROTO_CURRENT
Definition Defines.php:196
const MW_VERSION
The running version of MediaWiki.
Definition Defines.php:36
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
wfExpandUrl( $url, $defaultProto=PROTO_CURRENT)
Expand a potentially local URL to a fully-qualified URL using $wgServer (or one of its alternatives).
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
Class to support the outputting of syndication feeds in Atom and RSS format.
outXmlHeader()
Output the initial XML headers.
getUrlUnescaped()
Get the URL of this item without any escaping.
Definition FeedItem.php:144
getTitle()
Get the title of this item; already xml-encoded.
Definition FeedItem.php:127
getDescription()
Get the description of this item; already xml-encoded.
Definition FeedItem.php:153
getLanguage()
Get the language of this item.
Definition FeedItem.php:171
xmlEncode( $string)
Encode $string so that it can be safely embedded in a XML document.
Definition FeedItem.php:84
Generate an RSS feed.
Definition RSSFeed.php:31
outFooter()
Output an RSS 2.0 footer.
Definition RSSFeed.php:91
outItem( $item)
Output an RSS 2.0 item.
Definition RSSFeed.php:68
outHeader()
Output an RSS 2.0 header.
Definition RSSFeed.php:49