MediaWiki REL1_39
AtomFeed.php
Go to the documentation of this file.
1<?php
2
27
33class AtomFeed extends ChannelFeed {
40 private function formatTime( $timestamp ) {
41 if ( $timestamp ) {
42 // need to use RFC 822 time format at least for rss2.0
43 return gmdate( 'Y-m-d\TH:i:s', (int)wfTimestamp( TS_UNIX, $timestamp ) );
44 }
45 return null;
46 }
47
51 public function outHeader() {
52 $this->outXmlHeader();
53 // Manually escaping rather than letting Mustache do it because Mustache
54 // uses htmlentities, which does not work with XML
55 $templateParams = [
56 'language' => $this->xmlEncode( $this->getLanguage() ),
57 'feedID' => $this->getFeedId(),
58 'title' => $this->getTitle(),
59 'url' => $this->xmlEncode( wfExpandUrl( $this->getUrlUnescaped(), PROTO_CURRENT ) ),
60 'selfUrl' => $this->getSelfUrl(),
61 'timestamp' => $this->xmlEncode( $this->formatTime( wfTimestampNow() ) ),
62 'description' => $this->getDescription(),
63 'version' => $this->xmlEncode( MW_VERSION ),
64 ];
65 print $this->templateParser->processTemplate( 'AtomHeader', $templateParams );
66 }
67
76 private function getFeedId() {
77 return $this->getSelfUrl();
78 }
79
84 private function getSelfUrl() {
85 global $wgRequest;
86 return htmlspecialchars( $wgRequest->getFullRequestURL() );
87 }
88
93 public function outItem( $item ) {
94 $mimeType = MediaWikiServices::getInstance()->getMainConfig()
95 ->get( MainConfigNames::MimeType );
96 // Manually escaping rather than letting Mustache do it because Mustache
97 // uses htmlentities, which does not work with XML
98 $templateParams = [
99 "uniqueID" => $item->getUniqueID(),
100 "title" => $item->getTitle(),
101 "mimeType" => $this->xmlEncode( $mimeType ),
102 "url" => $this->xmlEncode( wfExpandUrl( $item->getUrlUnescaped(), PROTO_CURRENT ) ),
103 "date" => $this->xmlEncode( $this->formatTime( $item->getDate() ) ),
104 "description" => $item->getDescription(),
105 "author" => $item->getAuthor()
106 ];
107 print $this->templateParser->processTemplate( 'AtomItem', $templateParams );
108 }
109
113 public function outFooter() {
114 print "</feed>";
115 }
116}
const PROTO_CURRENT
Definition Defines.php:198
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.
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
global $wgRequest
Definition Setup.php:377
Generate an Atom feed.
Definition AtomFeed.php:33
outItem( $item)
Output a given item.
Definition AtomFeed.php:93
outFooter()
Outputs the footer for Atom 1.0 feed (basically '</feed>').
Definition AtomFeed.php:113
outHeader()
Outputs a basic header for Atom 1.0 feeds.
Definition AtomFeed.php:51
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:167
getDescription()
Get the description of this item; already xml-encoded.
Definition FeedItem.php:149
getTitle()
Get the title of this item; already xml-encoded.
Definition FeedItem.php:123
xmlEncode( $string)
Encode $string so that it can be safely embedded in a XML document.
Definition FeedItem.php:80
getUrlUnescaped()
Get the URL of this item without any escaping.
Definition FeedItem.php:140
A class containing constants representing the names of configuration variables.
Service locator for MediaWiki core services.
while(( $__line=Maintenance::readconsole()) !==false) print
Definition eval.php:69