MediaWiki  master
Go to the documentation of this file.
1 <?php
29 class RSSFeed extends ChannelFeed {
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  }
46  function outHeader() {
47  global $wgVersion;
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  }
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  }
90  function outFooter() {
91  print "</channel></rss>";
92  }
93 }
Output an RSS 2.0 header.
Definition: RSSFeed.php:46
Output the initial XML headers.
Generate an RSS feed.
Definition: RSSFeed.php:29
Get the URL of this item without any escaping.
Definition: FeedItem.php:135
Class to support the outputting of syndication feeds in Atom and RSS format.
Definition: ChannelFeed.php:29
MediaWiki version number.
Output an RSS 2.0 footer.
Definition: RSSFeed.php:90
wfExpandUrl( $url, $defaultProto=PROTO_CURRENT)
Expand a potentially local URL to a fully-qualified URL.
Definition: Defines.php:202
outItem( $item)
Output an RSS 2.0 item.
Definition: RSSFeed.php:67
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
Convenience function; returns MediaWiki timestamp for the present time.
formatTime( $ts)
Format a date given a timestamp.
Definition: RSSFeed.php:37
Get the language of this item.
Definition: FeedItem.php:162
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
Get the title of this item; already xml-encoded.
Definition: FeedItem.php:118
Get the description of this item; already xml-encoded.
Definition: FeedItem.php:144
xmlEncode( $string)
Encode $string so that it can be safely embedded in a XML document.
Definition: FeedItem.php:75