MediaWiki REL1_35
RSSFeed.php
Go to the documentation of this file.
1<?php
29class RSSFeed extends ChannelFeed {
30
37 private function formatTime( $ts ) {
38 if ( $ts ) {
39 return gmdate( 'D, d M Y H:i:s \G\M\T', wfTimestamp( TS_UNIX, $ts ) );
40 }
41 return null;
42 }
43
47 public 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
51 $templateParams = [
52 'title' => $this->getTitle(),
53 'url' => $this->xmlEncode( wfExpandUrl( $this->getUrlUnescaped(), PROTO_CURRENT ) ),
54 'description' => $this->getDescription(),
55 'language' => $this->xmlEncode( $this->getLanguage() ),
56 'version' => $this->xmlEncode( MW_VERSION ),
57 'timestamp' => $this->xmlEncode( $this->formatTime( wfTimestampNow() ) )
58 ];
59 print $this->templateParser->processTemplate( 'RSSHeader', $templateParams );
60 }
61
66 public function outItem( $item ) {
67 // Manually escaping rather than letting Mustache do it because Mustache
68 // uses htmlentities, which does not work with XML
69 $templateParams = [
70 "title" => $item->getTitle(),
71 "url" => $this->xmlEncode( wfExpandUrl( $item->getUrlUnescaped(), PROTO_CURRENT ) ),
72 "permalink" => $item->rssIsPermalink,
73 "uniqueID" => $item->getUniqueID(),
74 "description" => $item->getDescription(),
75 "date" => $this->xmlEncode( $this->formatTime( $item->getDate() ) ),
76 "author" => $item->getAuthor()
77 ];
78 $comments = $item->getCommentsUnescaped();
79 if ( $comments ) {
80 $commentsEscaped = $this->xmlEncode( wfExpandUrl( $comments, PROTO_CURRENT ) );
81 $templateParams["comments"] = $commentsEscaped;
82 }
83 print $this->templateParser->processTemplate( 'RSSItem', $templateParams );
84 }
85
89 public function outFooter() {
90 print "</channel></rss>";
91 }
92}
const MW_VERSION
The running version of MediaWiki.
Definition Defines.php:40
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.
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.
getLanguage()
Get the language of this item.
Definition FeedItem.php:164
getDescription()
Get the description of this item; already xml-encoded.
Definition FeedItem.php:146
getTitle()
Get the title of this item; already xml-encoded.
Definition FeedItem.php:120
xmlEncode( $string)
Encode $string so that it can be safely embedded in a XML document.
Definition FeedItem.php:77
getUrlUnescaped()
Get the URL of this item without any escaping.
Definition FeedItem.php:137
Generate an RSS feed.
Definition RSSFeed.php:29
formatTime( $ts)
Format a date given a timestamp.
Definition RSSFeed.php:37
outHeader()
Output an RSS 2.0 header.
Definition RSSFeed.php:47
outItem( $item)
Output an RSS 2.0 item.
Definition RSSFeed.php:66
outFooter()
Output an RSS 2.0 footer.
Definition RSSFeed.php:89
while(( $__line=Maintenance::readconsole()) !==false) print
Definition eval.php:64
const PROTO_CURRENT
Definition Defines.php:212