MediaWiki REL1_34
RSSFeed.php
Go to the documentation of this file.
1<?php
29class RSSFeed extends ChannelFeed {
30
37 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 }
42
46 function outHeader() {
47 global $wgVersion;
48
49 $this->outXmlHeader();
50 // Manually escaping rather than letting Mustache do it because Mustache
51 // uses htmlentities, which does not work with XML
52 $templateParams = [
53 'title' => $this->getTitle(),
54 'url' => $this->xmlEncode( wfExpandUrl( $this->getUrlUnescaped(), PROTO_CURRENT ) ),
55 'description' => $this->getDescription(),
56 'language' => $this->xmlEncode( $this->getLanguage() ),
57 'version' => $this->xmlEncode( $wgVersion ),
58 'timestamp' => $this->xmlEncode( $this->formatTime( wfTimestampNow() ) )
59 ];
60 print $this->templateParser->processTemplate( 'RSSHeader', $templateParams );
61 }
62
67 function outItem( $item ) {
68 // Manually escaping rather than letting Mustache do it because Mustache
69 // uses htmlentities, which does not work with XML
70 $templateParams = [
71 "title" => $item->getTitle(),
72 "url" => $this->xmlEncode( wfExpandUrl( $item->getUrlUnescaped(), PROTO_CURRENT ) ),
73 "permalink" => $item->rssIsPermalink,
74 "uniqueID" => $item->getUniqueID(),
75 "description" => $item->getDescription(),
76 "date" => $this->xmlEncode( $this->formatTime( $item->getDate() ) ),
77 "author" => $item->getAuthor()
78 ];
79 $comments = $item->getCommentsUnescaped();
80 if ( $comments ) {
81 $commentsEscaped = $this->xmlEncode( wfExpandUrl( $comments, PROTO_CURRENT ) );
82 $templateParams["comments"] = $commentsEscaped;
83 }
84 print $this->templateParser->processTemplate( 'RSSItem', $templateParams );
85 }
86
90 function outFooter() {
91 print "</channel></rss>";
92 }
93}
$wgVersion
MediaWiki version number.
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:162
getDescription()
Get the description of this item; already xml-encoded.
Definition FeedItem.php:144
getTitle()
Get the title of this item; already xml-encoded.
Definition FeedItem.php:118
xmlEncode( $string)
Encode $string so that it can be safely embedded in a XML document.
Definition FeedItem.php:75
getUrlUnescaped()
Get the URL of this item without any escaping.
Definition FeedItem.php:135
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:46
outItem( $item)
Output an RSS 2.0 item.
Definition RSSFeed.php:67
outFooter()
Output an RSS 2.0 footer.
Definition RSSFeed.php:90
while(( $__line=Maintenance::readconsole()) !==false) print
Definition eval.php:64
const PROTO_CURRENT
Definition Defines.php:211