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 }
AtomFeed\getFeedId
getFeedId()
Atom 1.0 requires a unique, opaque IRI as a unique identifier for every feed we create.
Definition: AtomFeed.php:72
AtomFeed\outHeader
outHeader()
Outputs a basic header for Atom 1.0 feeds.
Definition: AtomFeed.php:46
$wgMimeType
$wgMimeType
The default Content-Type header.
Definition: DefaultSettings.php:3261
wfTimestamp
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
Definition: GlobalFunctions.php:1871
$wgVersion
$wgVersion
MediaWiki version number.
Definition: DefaultSettings.php:75
AtomFeed
Generate an Atom feed.
Definition: AtomFeed.php:29
AtomFeed\outFooter
outFooter()
Outputs the footer for Atom 1.0 feed (basically '</feed>').
Definition: AtomFeed.php:108
PROTO_CURRENT
const PROTO_CURRENT
Definition: Defines.php:202
AtomFeed\getSelfUrl
getSelfUrl()
Atom 1.0 requests a self-reference to the feed.
Definition: AtomFeed.php:80
wfTimestampNow
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
Definition: GlobalFunctions.php:1900
AtomFeed\formatTime
formatTime( $timestamp)
Format a date given timestamp, if one is given.
Definition: AtomFeed.php:36
getTitle
getTitle()
Definition: RevisionSearchResultTrait.php:74
$wgRequest
if(! $wgDBerrorLogTZ) $wgRequest
Definition: Setup.php:729
AtomFeed\outItem
outItem( $item)
Output a given item.
Definition: AtomFeed.php:89
wfExpandUrl
wfExpandUrl( $url, $defaultProto=PROTO_CURRENT)
Expand a potentially local URL to a fully-qualified URL.
Definition: GlobalFunctions.php:491