MediaWiki 1.41.2
AtomFeed.php
Go to the documentation of this file.
1<?php
2
26
29
35class AtomFeed extends ChannelFeed {
42 private function formatTime( $timestamp ) {
43 if ( $timestamp ) {
44 // need to use RFC 822 time format at least for rss2.0
45 return gmdate( 'Y-m-d\TH:i:s', (int)wfTimestamp( TS_UNIX, $timestamp ) );
46 }
47 return null;
48 }
49
53 public function outHeader() {
54 $this->outXmlHeader();
55 // Manually escaping rather than letting Mustache do it because Mustache
56 // uses htmlentities, which does not work with XML
57 $templateParams = [
58 'language' => $this->xmlEncode( $this->getLanguage() ),
59 'feedID' => $this->getFeedId(),
60 'title' => $this->getTitle(),
61 'url' => $this->xmlEncode( wfExpandUrl( $this->getUrlUnescaped(), PROTO_CURRENT ) ),
62 'selfUrl' => $this->getSelfUrl(),
63 'timestamp' => $this->xmlEncode( $this->formatTime( wfTimestampNow() ) ),
64 'description' => $this->getDescription(),
65 'version' => $this->xmlEncode( MW_VERSION ),
66 ];
67 print $this->templateParser->processTemplate( 'AtomHeader', $templateParams );
68 }
69
78 private function getFeedId() {
79 return $this->getSelfUrl();
80 }
81
86 private function getSelfUrl() {
87 global $wgRequest;
88 return htmlspecialchars( $wgRequest->getFullRequestURL() );
89 }
90
95 public function outItem( $item ) {
96 $mimeType = MediaWikiServices::getInstance()->getMainConfig()
98 // Manually escaping rather than letting Mustache do it because Mustache
99 // uses htmlentities, which does not work with XML
100 $templateParams = [
101 "uniqueID" => $item->getUniqueID(),
102 "title" => $item->getTitle(),
103 "mimeType" => $this->xmlEncode( $mimeType ),
104 "url" => $this->xmlEncode( wfExpandUrl( $item->getUrlUnescaped(), PROTO_CURRENT ) ),
105 "date" => $this->xmlEncode( $this->formatTime( $item->getDate() ) ),
106 "description" => $item->getDescription(),
107 "author" => $item->getAuthor()
108 ];
109 print $this->templateParser->processTemplate( 'AtomItem', $templateParams );
110 }
111
115 public function outFooter() {
116 print "</feed>";
117 }
118}
119
123class_alias( AtomFeed::class, 'AtomFeed' );
const PROTO_CURRENT
Definition Defines.php:196
const MW_VERSION
The running version of MediaWiki.
Definition Defines.php:36
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 using $wgServer (or one of its alternatives).
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
global $wgRequest
Definition Setup.php:414
Generate an Atom feed.
Definition AtomFeed.php:35
outFooter()
Outputs the footer for Atom 1.0 feed (basically '</feed>').
Definition AtomFeed.php:115
outHeader()
Outputs a basic header for Atom 1.0 feeds.
Definition AtomFeed.php:53
outItem( $item)
Output a given item.
Definition AtomFeed.php:95
Class to support the outputting of syndication feeds in Atom and RSS format.
outXmlHeader()
Output the initial XML headers.
getUrlUnescaped()
Get the URL of this item without any escaping.
Definition FeedItem.php:144
getTitle()
Get the title of this item; already xml-encoded.
Definition FeedItem.php:127
getDescription()
Get the description of this item; already xml-encoded.
Definition FeedItem.php:153
getLanguage()
Get the language of this item.
Definition FeedItem.php:171
xmlEncode( $string)
Encode $string so that it can be safely embedded in a XML document.
Definition FeedItem.php:84
A class containing constants representing the names of configuration variables.
const MimeType
Name constant for the MimeType setting, for use with Config::get()
Service locator for MediaWiki core services.
static getInstance()
Returns the global default instance of the top level service locator.