MediaWiki  master
AtomFeed.php
Go to the documentation of this file.
1 <?php
29 class AtomFeed extends ChannelFeed {
36  function formatTime( $timestamp ) {
37  if ( $timestamp ) {
38  // need to use RFC 822 time format at least for rss2.0
39  return gmdate( 'Y-m-d\TH:i:s', wfTimestamp( TS_UNIX, $timestamp ) );
40  }
41  }
42 
46  function outHeader() {
47  global $wgVersion;
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  'language' => $this->xmlEncode( $this->getLanguage() ),
53  'feedID' => $this->getFeedId(),
54  'title' => $this->getTitle(),
55  'url' => $this->xmlEncode( wfExpandUrl( $this->getUrlUnescaped(), PROTO_CURRENT ) ),
56  'selfUrl' => $this->getSelfUrl(),
57  'timestamp' => $this->xmlEncode( $this->formatTime( wfTimestampNow() ) ),
58  'description' => $this->getDescription(),
59  'version' => $this->xmlEncode( $wgVersion ),
60  ];
61  print $this->templateParser->processTemplate( 'AtomHeader', $templateParams );
62  }
63 
72  private function getFeedId() {
73  return $this->getSelfUrl();
74  }
75 
80  private function getSelfUrl() {
81  global $wgRequest;
82  return htmlspecialchars( $wgRequest->getFullRequestURL() );
83  }
84 
89  function outItem( $item ) {
90  global $wgMimeType;
91  // Manually escaping rather than letting Mustache do it because Mustache
92  // uses htmlentities, which does not work with XML
93  $templateParams = [
94  "uniqueID" => $item->getUniqueID(),
95  "title" => $item->getTitle(),
96  "mimeType" => $this->xmlEncode( $wgMimeType ),
97  "url" => $this->xmlEncode( wfExpandUrl( $item->getUrlUnescaped(), PROTO_CURRENT ) ),
98  "date" => $this->xmlEncode( $this->formatTime( $item->getDate() ) ),
99  "description" => $item->getDescription(),
100  "author" => $item->getAuthor()
101  ];
102  print $this->templateParser->processTemplate( 'AtomItem', $templateParams );
103  }
104 
108  function outFooter() {
109  print "</feed>";
110  }
111 }
outXmlHeader()
Output the initial XML headers.
outFooter()
Outputs the footer for Atom 1.0 feed (basically &#39;</feed>&#39;).
Definition: AtomFeed.php:108
getUrlUnescaped()
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
$wgVersion
MediaWiki version number.
$wgMimeType
The default Content-Type header.
wfExpandUrl( $url, $defaultProto=PROTO_CURRENT)
Expand a potentially local URL to a fully-qualified URL.
const PROTO_CURRENT
Definition: Defines.php:202
getSelfUrl()
Atom 1.0 requests a self-reference to the feed.
Definition: AtomFeed.php:80
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
formatTime( $timestamp)
Format a date given timestamp, if one is given.
Definition: AtomFeed.php:36
getLanguage()
Get the language of this item.
Definition: FeedItem.php:162
outItem( $item)
Output a given item.
Definition: AtomFeed.php:89
Generate an Atom feed.
Definition: AtomFeed.php:29
outHeader()
Outputs a basic header for Atom 1.0 feeds.
Definition: AtomFeed.php:46
getTitle()
Get the title of this item; already xml-encoded.
Definition: FeedItem.php:118
if(! $wgDBerrorLogTZ) $wgRequest
Definition: Setup.php:728
getFeedId()
Atom 1.0 requires a unique, opaque IRI as a unique identifier for every feed we create.
Definition: AtomFeed.php:72
getDescription()
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