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
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
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:794
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