MediaWiki  master
RSSFeed.php
Go to the documentation of this file.
1 <?php
29 class 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 }
RSSFeed\outFooter
outFooter()
Output an RSS 2.0 footer.
Definition: RSSFeed.php:89
RSSFeed\outItem
outItem( $item)
Output an RSS 2.0 item.
Definition: RSSFeed.php:66
RSSFeed\outHeader
outHeader()
Output an RSS 2.0 header.
Definition: RSSFeed.php:47
wfTimestamp
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
Definition: GlobalFunctions.php:1808
ChannelFeed\outXmlHeader
outXmlHeader()
Output the initial XML headers.
Definition: ChannelFeed.php:132
MW_VERSION
const MW_VERSION
The running version of MediaWiki.
Definition: Defines.php:39
FeedItem\getLanguage
getLanguage()
Get the language of this item.
Definition: FeedItem.php:164
FeedItem\getTitle
getTitle()
Get the title of this item; already xml-encoded.
Definition: FeedItem.php:120
PROTO_CURRENT
const PROTO_CURRENT
Definition: Defines.php:211
wfTimestampNow
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
Definition: GlobalFunctions.php:1837
FeedItem\getDescription
getDescription()
Get the description of this item; already xml-encoded.
Definition: FeedItem.php:146
FeedItem\$comments
$comments
Definition: FeedItem.php:47
ChannelFeed
Class to support the outputting of syndication feeds in Atom and RSS format.
Definition: ChannelFeed.php:30
FeedItem\xmlEncode
xmlEncode( $string)
Encode $string so that it can be safely embedded in a XML document.
Definition: FeedItem.php:77
RSSFeed\formatTime
formatTime( $ts)
Format a date given a timestamp.
Definition: RSSFeed.php:37
RSSFeed
Generate an RSS feed.
Definition: RSSFeed.php:29
wfExpandUrl
wfExpandUrl( $url, $defaultProto=PROTO_CURRENT)
Expand a potentially local URL to a fully-qualified URL.
Definition: GlobalFunctions.php:490
FeedItem\getUrlUnescaped
getUrlUnescaped()
Get the URL of this item without any escaping.
Definition: FeedItem.php:137