MediaWiki  1.23.15
Feed.php
Go to the documentation of this file.
1 <?php
38 class FeedItem {
42  var $title;
43 
45  var $url;
46  var $date;
47  var $author;
48  var $uniqueId;
49  var $comments;
50  var $rssIsPermalink = false;
51 
62  function __construct( $title, $description, $url, $date = '', $author = '', $comments = '' ) {
63  $this->title = $title;
64  $this->description = $description;
65  $this->url = $url;
66  $this->uniqueId = $url;
67  $this->date = $date;
68  $this->author = $author;
69  $this->comments = $comments;
70  }
71 
78  public function xmlEncode( $string ) {
79  $string = str_replace( "\r\n", "\n", $string );
80  $string = preg_replace( '/[\x00-\x08\x0b\x0c\x0e-\x1f]/', '', $string );
81  return htmlspecialchars( $string );
82  }
83 
89  public function getUniqueId() {
90  if ( $this->uniqueId ) {
91  return $this->xmlEncode( $this->uniqueId );
92  }
93  }
94 
101  public function setUniqueId( $uniqueId, $rssIsPermalink = false ) {
102  $this->uniqueId = $uniqueId;
103  $this->rssIsPermalink = $rssIsPermalink;
104  }
105 
111  public function getTitle() {
112  return $this->xmlEncode( $this->title );
113  }
114 
120  public function getUrl() {
121  return $this->xmlEncode( $this->url );
122  }
123 
129  public function getDescription() {
130  return $this->xmlEncode( $this->description );
131  }
132 
138  public function getLanguage() {
139  global $wgLanguageCode;
140  return $wgLanguageCode;
141  }
142 
148  public function getDate() {
149  return $this->date;
150  }
151 
157  public function getAuthor() {
158  return $this->xmlEncode( $this->author );
159  }
160 
166  public function getComments() {
167  return $this->xmlEncode( $this->comments );
168  }
169 
176  public static function stripComment( $text ) {
177  return preg_replace( '/\[\[([^]]*\|)?([^]]+)\]\]/', '\2', $text );
178  }
180 }
181 
186 abstract class ChannelFeed extends FeedItem {
195  abstract public function outHeader();
196 
205  abstract public function outItem( $item );
206 
214  abstract public function outFooter();
215 
224  public function httpHeaders() {
225  global $wgOut, $wgVaryOnXFP;
226 
227  # We take over from $wgOut, excepting its cache header info
228  $wgOut->disable();
229  $mimetype = $this->contentType();
230  header( "Content-type: $mimetype; charset=UTF-8" );
231  if ( $wgVaryOnXFP ) {
232  $wgOut->addVaryHeader( 'X-Forwarded-Proto' );
233  }
234  $wgOut->sendCacheControl();
235 
236  }
237 
244  function contentType() {
245  global $wgRequest;
246  $ctype = $wgRequest->getVal( 'ctype', 'application/xml' );
247  $allowedctypes = array( 'application/xml', 'text/xml', 'application/rss+xml', 'application/atom+xml' );
248  return ( in_array( $ctype, $allowedctypes ) ? $ctype : 'application/xml' );
249  }
250 
256  function outXmlHeader() {
257  global $wgStylePath, $wgStyleVersion;
258 
259  $this->httpHeaders();
260  echo '<?xml version="1.0"?>' . "\n";
261  echo '<?xml-stylesheet type="text/css" href="' .
262  htmlspecialchars( wfExpandUrl( "$wgStylePath/common/feed.css?$wgStyleVersion", PROTO_CURRENT ) ) .
263  '"?' . ">\n";
264  }
265 }
266 
272 class RSSFeed extends ChannelFeed {
273 
280  function formatTime( $ts ) {
281  return gmdate( 'D, d M Y H:i:s \G\M\T', wfTimestamp( TS_UNIX, $ts ) );
282  }
283 
287  function outHeader() {
288  global $wgVersion;
289 
290  $this->outXmlHeader();
291  ?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
292  <channel>
293  <title><?php print $this->getTitle() ?></title>
294  <link><?php print wfExpandUrl( $this->getUrl(), PROTO_CURRENT ) ?></link>
295  <description><?php print $this->getDescription() ?></description>
296  <language><?php print $this->getLanguage() ?></language>
297  <generator>MediaWiki <?php print $wgVersion ?></generator>
298  <lastBuildDate><?php print $this->formatTime( wfTimestampNow() ) ?></lastBuildDate>
299 <?php
300  }
301 
306  function outItem( $item ) {
307  ?>
308  <item>
309  <title><?php print $item->getTitle(); ?></title>
310  <link><?php print wfExpandUrl( $item->getUrl(), PROTO_CURRENT ); ?></link>
311  <guid<?php if ( !$item->rssIsPermalink ) { print ' isPermaLink="false"'; } ?>><?php print $item->getUniqueId(); ?></guid>
312  <description><?php print $item->getDescription() ?></description>
313  <?php if ( $item->getDate() ) { ?><pubDate><?php print $this->formatTime( $item->getDate() ); ?></pubDate><?php } ?>
314  <?php if ( $item->getAuthor() ) { ?><dc:creator><?php print $item->getAuthor(); ?></dc:creator><?php }?>
315  <?php if ( $item->getComments() ) { ?><comments><?php print wfExpandUrl( $item->getComments(), PROTO_CURRENT ); ?></comments><?php }?>
316  </item>
317 <?php
318  }
319 
323  function outFooter() {
324  ?>
325  </channel>
326 </rss><?php
327  }
328 }
329 
335 class AtomFeed extends ChannelFeed {
340  function formatTime( $ts ) {
341  // need to use RFC 822 time format at least for rss2.0
342  return gmdate( 'Y-m-d\TH:i:s', wfTimestamp( TS_UNIX, $ts ) );
343  }
344 
348  function outHeader() {
349  global $wgVersion;
350 
351  $this->outXmlHeader();
352  ?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="<?php print $this->getLanguage() ?>">
353  <id><?php print $this->getFeedId() ?></id>
354  <title><?php print $this->getTitle() ?></title>
355  <link rel="self" type="application/atom+xml" href="<?php print wfExpandUrl( $this->getSelfUrl(), PROTO_CURRENT ) ?>"/>
356  <link rel="alternate" type="text/html" href="<?php print wfExpandUrl( $this->getUrl(), PROTO_CURRENT ) ?>"/>
357  <updated><?php print $this->formatTime( wfTimestampNow() ) ?>Z</updated>
358  <subtitle><?php print $this->getDescription() ?></subtitle>
359  <generator>MediaWiki <?php print $wgVersion ?></generator>
360 
361 <?php
362  }
363 
373  function getFeedId() {
374  return $this->getSelfUrl();
375  }
376 
382  function getSelfUrl() {
383  global $wgRequest;
384  return htmlspecialchars( $wgRequest->getFullRequestURL() );
385  }
386 
391  function outItem( $item ) {
392  global $wgMimeType;
393  ?>
394  <entry>
395  <id><?php print $item->getUniqueId(); ?></id>
396  <title><?php print $item->getTitle(); ?></title>
397  <link rel="alternate" type="<?php print $wgMimeType ?>" href="<?php print wfExpandUrl( $item->getUrl(), PROTO_CURRENT ); ?>"/>
398  <?php if ( $item->getDate() ) { ?>
399  <updated><?php print $this->formatTime( $item->getDate() ); ?>Z</updated>
400  <?php } ?>
401 
402  <summary type="html"><?php print $item->getDescription() ?></summary>
403  <?php if ( $item->getAuthor() ) { ?><author><name><?php print $item->getAuthor(); ?></name></author><?php }?>
404  </entry>
405 
406 <?php /* @todo FIXME: Need to add comments
407  <?php if( $item->getComments() ) { ?><dc:comment><?php print $item->getComments() ?></dc:comment><?php }?>
408  */
409  }
410 
414  function outFooter() {?>
415  </feed><?php
416  }
417 }
FeedItem
A base class for basic support for outputting syndication feeds in RSS and other formats.
Definition: Feed.php:38
FeedItem\getUniqueId
getUniqueId()
Get the unique id of this item.
Definition: Feed.php:88
AtomFeed\getFeedId
print $this getFeedId() print $this getTitle() print wfExpandUrl($this->getSelfUrl(), PROTO_CURRENT) print wfExpandUrl($this->getUrl(), PROTO_CURRENT) print $this formatTime(wfTimestampNow()) print $this getDescription() print $wgVersion getFeedId()
Atom 1.0 requires a unique, opaque IRI as a unique identifier for every feed we create.
Definition: Feed.php:372
FeedItem\$url
$url
Definition: Feed.php:44
AtomFeed\outHeader
outHeader()
Outputs a basic header for Atom 1.0 feeds.
Definition: Feed.php:347
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
FeedItem\$description
$description
Definition: Feed.php:43
FeedItem\$rssIsPermalink
$rssIsPermalink
Definition: Feed.php:49
MediaWiki\getTitle
getTitle()
Get the Title object that we'll be acting on, as specified in the WebRequest.
Definition: Wiki.php:138
wfTimestamp
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
Definition: GlobalFunctions.php:2530
AtomFeed
Generate an Atom feed.
Definition: Feed.php:334
FeedItem\getLanguage
getLanguage()
Get the language of this item.
Definition: Feed.php:137
FeedItem\stripComment
static stripComment( $text)
Quickie hack...
Definition: Feed.php:175
outXmlHeader
outXmlHeader()
Output the initial XML headers with a stylesheet for legibility if someone finds it in a browser.
Definition: Feed.php:330
FeedItem\getTitle
getTitle()
Get the title of this item; already xml-encoded.
Definition: Feed.php:110
title
to move a page</td >< td > &*You are moving the page across *A non empty talk page already exists under the new or *You uncheck the box below In those you will have to move or merge the page manually if desired</td >< td > be sure to &You are responsible for making sure that links continue to point where they are supposed to go Note that the page will &a page at the new title
Definition: All_system_messages.txt:2703
FeedItem\getAuthor
getAuthor()
Get the author of this item; already xml-encoded.
Definition: Feed.php:156
contentType
contentType()
Return an internet media type to be sent in the headers.
Definition: Feed.php:318
$wgOut
$wgOut
Definition: Setup.php:582
PROTO_CURRENT
const PROTO_CURRENT
Definition: Defines.php:270
FeedItem\$date
$date
Definition: Feed.php:45
FeedItem\getDate
getDate()
Get the title of this item.
Definition: Feed.php:147
version
Prior to version
Definition: maintenance.txt:1
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
AtomFeed\getSelfUrl
getSelfUrl()
Atom 1.0 requests a self-reference to the feed.
Definition: Feed.php:381
wfTimestampNow
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
Definition: GlobalFunctions.php:2561
outHeader
outHeader()
Generate Header of the feed.
Definition: Feed.php:286
outItem
outItem( $item)
Generate an item.
Definition: Feed.php:305
FeedItem\setUniqueId
setUniqueId( $uniqueId, $rssIsPermalink=false)
set the unique id of an item
Definition: Feed.php:100
FeedItem\getDescription
getDescription()
Get the description of this item; already xml-encoded.
Definition: Feed.php:128
httpHeaders
httpHeaders()
Setup and send HTTP headers.
Definition: Feed.php:298
FeedItem\getUrl
getUrl()
Get the URL of this item; already xml-encoded.
Definition: Feed.php:119
type
ChannelFeed FeedItem xml stylesheet type
Definition: Feed.php:260
FeedItem\$comments
$comments
Definition: Feed.php:48
FeedItem\__construct
__construct( $title, $description, $url, $date='', $author='', $comments='')
Constructor.
Definition: Feed.php:61
AtomFeed\outFooter
if( $item->getDate()) print $item getDescription() if( $item->getAuthor()) outFooter()
Outputs the footer for Atom 1.0 feed (basically '</feed>').
Definition: Feed.php:413
Title
Represents a title within MediaWiki.
Definition: Title.php:35
TS_UNIX
const TS_UNIX
Unix time - the number of seconds since 1970-01-01 00:00:00 UTC.
Definition: GlobalFunctions.php:2473
FeedItem\xmlEncode
xmlEncode( $string)
Encode $string so that it can be safely embedded in a XML document.
Definition: Feed.php:77
outFooter
outFooter()
Generate Footer of the feed.
Definition: Feed.php:322
FeedItem\$author
$author
Definition: Feed.php:46
AtomFeed\formatTime
formatTime( $ts)
Definition: Feed.php:339
name
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at name
Definition: design.txt:12
FeedItem\$title
Title $title
Definition: Feed.php:41
FeedItem\getComments
getComments()
Get the comment of this item; already xml-encoded.
Definition: Feed.php:165
AtomFeed\outItem
outItem( $item)
Output a given item.
Definition: Feed.php:390
href
shown</td >< td > a href
Definition: All_system_messages.txt:2674
wfExpandUrl
wfExpandUrl( $url, $defaultProto=PROTO_CURRENT)
Expand a potentially local URL to a fully-qualified URL.
Definition: GlobalFunctions.php:544
MediaWiki
The MediaWiki class is the helper class for the index.php entry point.
Definition: Wiki.php:28
FeedItem\$uniqueId
$uniqueId
Definition: Feed.php:47