MediaWiki REL1_35
AtomFeed.php
Go to the documentation of this file.
1<?php
29class AtomFeed extends ChannelFeed {
36 private 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 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 '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( MW_VERSION ),
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 public 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 public function outFooter() {
109 print "</feed>";
110 }
111}
$wgMimeType
The default Content-Type header.
const MW_VERSION
The running version of MediaWiki.
Definition Defines.php:40
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.
if(! $wgDBerrorLogTZ) $wgRequest
Definition Setup.php:643
Generate an Atom feed.
Definition AtomFeed.php:29
outItem( $item)
Output a given item.
Definition AtomFeed.php:89
outFooter()
Outputs the footer for Atom 1.0 feed (basically '</feed>').
Definition AtomFeed.php:108
getFeedId()
Atom 1.0 requires a unique, opaque IRI as a unique identifier for every feed we create.
Definition AtomFeed.php:72
formatTime( $timestamp)
Format a date given timestamp, if one is given.
Definition AtomFeed.php:36
getSelfUrl()
Atom 1.0 requests a self-reference to the feed.
Definition AtomFeed.php:80
outHeader()
Outputs a basic header for Atom 1.0 feeds.
Definition AtomFeed.php:47
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:164
getDescription()
Get the description of this item; already xml-encoded.
Definition FeedItem.php:146
getTitle()
Get the title of this item; already xml-encoded.
Definition FeedItem.php:120
xmlEncode( $string)
Encode $string so that it can be safely embedded in a XML document.
Definition FeedItem.php:77
getUrlUnescaped()
Get the URL of this item without any escaping.
Definition FeedItem.php:137
while(( $__line=Maintenance::readconsole()) !==false) print
Definition eval.php:64
const PROTO_CURRENT
Definition Defines.php:212