MediaWiki  1.34.0
RSSFeed.php
Go to the documentation of this file.
1 <?php
29 class 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 }
RSSFeed\outFooter
outFooter()
Output an RSS 2.0 footer.
Definition: RSSFeed.php:90
RSSFeed\outItem
outItem( $item)
Output an RSS 2.0 item.
Definition: RSSFeed.php:67
RSSFeed\outHeader
outHeader()
Output an RSS 2.0 header.
Definition: RSSFeed.php:46
wfTimestamp
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
Definition: GlobalFunctions.php:1869
$wgVersion
$wgVersion
MediaWiki version number.
Definition: DefaultSettings.php:75
PROTO_CURRENT
const PROTO_CURRENT
Definition: Defines.php:202
wfTimestampNow
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
Definition: GlobalFunctions.php:1898
getTitle
getTitle()
Definition: RevisionSearchResultTrait.php:74
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:491