MediaWiki REL1_30
Feed.php
Go to the documentation of this file.
1<?php
38class FeedItem {
40 public $title;
41
43
44 public $url;
45
46 public $date;
47
48 public $author;
49
50 public $uniqueId;
51
52 public $comments;
53
54 public $rssIsPermalink = false;
55
64 function __construct( $title, $description, $url, $date = '', $author = '', $comments = '' ) {
65 $this->title = $title;
66 $this->description = $description;
67 $this->url = $url;
68 $this->uniqueId = $url;
69 $this->date = $date;
70 $this->author = $author;
71 $this->comments = $comments;
72 }
73
80 public function xmlEncode( $string ) {
81 $string = str_replace( "\r\n", "\n", $string );
82 $string = preg_replace( '/[\x00-\x08\x0b\x0c\x0e-\x1f]/', '', $string );
83 return htmlspecialchars( $string );
84 }
85
91 public function getUniqueId() {
92 if ( $this->uniqueId ) {
93 return $this->xmlEncode( wfExpandUrl( $this->uniqueId, PROTO_CURRENT ) );
94 }
95 }
96
103 public function setUniqueId( $uniqueId, $rssIsPermalink = false ) {
104 $this->uniqueId = $uniqueId;
105 $this->rssIsPermalink = $rssIsPermalink;
106 }
107
113 public function getTitle() {
114 return $this->xmlEncode( $this->title );
115 }
116
122 public function getUrl() {
123 return $this->xmlEncode( $this->url );
124 }
125
131 public function getDescription() {
132 return $this->xmlEncode( $this->description );
133 }
134
140 public function getLanguage() {
142 return wfBCP47( $wgLanguageCode );
143 }
144
150 public function getDate() {
151 return $this->date;
152 }
153
159 public function getAuthor() {
160 return $this->xmlEncode( $this->author );
161 }
162
168 public function getComments() {
169 return $this->xmlEncode( $this->comments );
170 }
171
178 public static function stripComment( $text ) {
179 return preg_replace( '/\[\[([^]]*\|)?([^]]+)\]\]/', '\2', $text );
180 }
182}
183
189abstract class ChannelFeed extends FeedItem {
197 abstract public function outHeader();
198
207 abstract public function outItem( $item );
208
216 abstract public function outFooter();
217
226 public function httpHeaders() {
228
229 # We take over from $wgOut, excepting its cache header info
230 $wgOut->disable();
231 $mimetype = $this->contentType();
232 header( "Content-type: $mimetype; charset=UTF-8" );
233
234 // Set a sane filename
235 $exts = MimeMagic::singleton()->getExtensionsForType( $mimetype );
236 $ext = $exts ? strtok( $exts, ' ' ) : 'xml';
237 header( "Content-Disposition: inline; filename=\"feed.{$ext}\"" );
238
239 if ( $wgVaryOnXFP ) {
240 $wgOut->addVaryHeader( 'X-Forwarded-Proto' );
241 }
242 $wgOut->sendCacheControl();
243 }
244
250 private function contentType() {
252
253 $ctype = $wgRequest->getVal( 'ctype', 'application/xml' );
254 $allowedctypes = [
255 'application/xml',
256 'text/xml',
257 'application/rss+xml',
258 'application/atom+xml'
259 ];
260
261 return ( in_array( $ctype, $allowedctypes ) ? $ctype : 'application/xml' );
262 }
263
267 protected function outXmlHeader() {
268 $this->httpHeaders();
269 echo '<?xml version="1.0"?>' . "\n";
270 }
271}
272
278class RSSFeed extends ChannelFeed {
279
286 function formatTime( $ts ) {
287 return gmdate( 'D, d M Y H:i:s \G\M\T', wfTimestamp( TS_UNIX, $ts ) );
288 }
289
293 function outHeader() {
295
296 $this->outXmlHeader();
297 ?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
298 <channel>
299 <title><?php print $this->getTitle() ?></title>
300 <link><?php print wfExpandUrl( $this->getUrl(), PROTO_CURRENT ) ?></link>
301 <description><?php print $this->getDescription() ?></description>
302 <language><?php print $this->getLanguage() ?></language>
303 <generator>MediaWiki <?php print $wgVersion ?></generator>
304 <lastBuildDate><?php print $this->formatTime( wfTimestampNow() ) ?></lastBuildDate>
305<?php
306 }
307
312 function outItem( $item ) {
313 // @codingStandardsIgnoreStart Ignore long lines and formatting issues.
314 ?>
315 <item>
316 <title><?php print $item->getTitle(); ?></title>
317 <link><?php print wfExpandUrl( $item->getUrl(), PROTO_CURRENT ); ?></link>
318 <guid<?php if ( !$item->rssIsPermalink ) { print ' isPermaLink="false"'; } ?>><?php print $item->getUniqueId(); ?></guid>
319 <description><?php print $item->getDescription() ?></description>
320 <?php if ( $item->getDate() ) { ?><pubDate><?php print $this->formatTime( $item->getDate() ); ?></pubDate><?php } ?>
321 <?php if ( $item->getAuthor() ) { ?><dc:creator><?php print $item->getAuthor(); ?></dc:creator><?php }?>
322 <?php if ( $item->getComments() ) { ?><comments><?php print wfExpandUrl( $item->getComments(), PROTO_CURRENT ); ?></comments><?php }?>
323 </item>
324<?php
325 // @codingStandardsIgnoreEnd
326 }
327
331 function outFooter() {
332 ?>
333 </channel>
334</rss><?php
335 }
336}
337
343class AtomFeed extends ChannelFeed {
350 function formatTime( $timestamp ) {
351 // need to use RFC 822 time format at least for rss2.0
352 return gmdate( 'Y-m-d\TH:i:s', wfTimestamp( TS_UNIX, $timestamp ) );
353 }
354
358 function outHeader() {
360
361 $this->outXmlHeader();
362 // @codingStandardsIgnoreStart Ignore long lines and formatting issues.
363 ?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="<?php print $this->getLanguage() ?>">
364 <id><?php print $this->getFeedId() ?></id>
365 <title><?php print $this->getTitle() ?></title>
366 <link rel="self" type="application/atom+xml" href="<?php print wfExpandUrl( $this->getSelfUrl(), PROTO_CURRENT ) ?>"/>
367 <link rel="alternate" type="text/html" href="<?php print wfExpandUrl( $this->getUrl(), PROTO_CURRENT ) ?>"/>
368 <updated><?php print $this->formatTime( wfTimestampNow() ) ?>Z</updated>
369 <subtitle><?php print $this->getDescription() ?></subtitle>
370 <generator>MediaWiki <?php print $wgVersion ?></generator>
371
372<?php
373 // @codingStandardsIgnoreEnd
374 }
375
384 private function getFeedId() {
385 return $this->getSelfUrl();
386 }
387
392 private function getSelfUrl() {
394 return htmlspecialchars( $wgRequest->getFullRequestURL() );
395 }
396
401 function outItem( $item ) {
403 // @codingStandardsIgnoreStart Ignore long lines and formatting issues.
404 ?>
405 <entry>
406 <id><?php print $item->getUniqueId(); ?></id>
407 <title><?php print $item->getTitle(); ?></title>
408 <link rel="alternate" type="<?php print $wgMimeType ?>" href="<?php print wfExpandUrl( $item->getUrl(), PROTO_CURRENT ); ?>"/>
409 <?php if ( $item->getDate() ) { ?>
410 <updated><?php print $this->formatTime( $item->getDate() ); ?>Z</updated>
411 <?php } ?>
412
413 <summary type="html"><?php print $item->getDescription() ?></summary>
414 <?php if ( $item->getAuthor() ) { ?><author><name><?php print $item->getAuthor(); ?></name></author><?php }?>
415 </entry>
416
417<?php /* @todo FIXME: Need to add comments
418 <?php if( $item->getComments() ) { ?><dc:comment><?php print $item->getComments() ?></dc:comment><?php }?>
419 */
420 }
421
425 function outFooter() {?>
426 </feed><?php
427 // @codingStandardsIgnoreEnd
428 }
429}
shown</td >< td > a href
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
$wgLanguageCode
Site language code.
$wgMimeType
The default Content-Type header.
$wgVersion
MediaWiki version number.
$wgVaryOnXFP
Add X-Forwarded-Proto to the Vary and Key headers for API requests and RSS/Atom feeds.
wfBCP47( $code)
Get the normalised IETF language tag See unit test for examples.
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.
$wgOut
Definition Setup.php:827
if(! $wgDBerrorLogTZ) $wgRequest
Definition Setup.php:662
Generate an Atom feed.
Definition Feed.php:343
outItem( $item)
Output a given item.
Definition Feed.php:401
outFooter()
Outputs the footer for Atom 1.0 feed (basically '</feed>').
Definition Feed.php:425
getFeedId()
Atom 1.0 requires a unique, opaque IRI as a unique identifier for every feed we create.
Definition Feed.php:384
formatTime( $timestamp)
Format a date given timestamp.
Definition Feed.php:350
getSelfUrl()
Atom 1.0 requests a self-reference to the feed.
Definition Feed.php:392
outHeader()
Outputs a basic header for Atom 1.0 feeds.
Definition Feed.php:358
Class to support the outputting of syndication feeds in Atom and RSS format.
Definition Feed.php:189
outFooter()
Generate Footer of the feed.
outHeader()
Generate Header of the feed.
contentType()
Return an internet media type to be sent in the headers.
Definition Feed.php:250
httpHeaders()
Setup and send HTTP headers.
Definition Feed.php:226
outItem( $item)
Generate an item.
outXmlHeader()
Output the initial XML headers.
Definition Feed.php:267
A base class for basic support for outputting syndication feeds in RSS and other formats.
Definition Feed.php:38
$description
Definition Feed.php:42
getLanguage()
Get the language of this item.
Definition Feed.php:140
setUniqueId( $uniqueId, $rssIsPermalink=false)
Set the unique id of an item.
Definition Feed.php:103
getDescription()
Get the description of this item; already xml-encoded.
Definition Feed.php:131
$rssIsPermalink
Definition Feed.php:54
getUniqueId()
Get the unique id of this item.
Definition Feed.php:91
getTitle()
Get the title of this item; already xml-encoded.
Definition Feed.php:113
getDate()
Get the date of this item.
Definition Feed.php:150
Title $title
Definition Feed.php:40
static stripComment( $text)
Quickie hack... strip out wikilinks to more legible form from the comment.
Definition Feed.php:178
$author
Definition Feed.php:48
$uniqueId
Definition Feed.php:50
getAuthor()
Get the author of this item; already xml-encoded.
Definition Feed.php:159
xmlEncode( $string)
Encode $string so that it can be safely embedded in a XML document.
Definition Feed.php:80
getComments()
Get the comment of this item; already xml-encoded.
Definition Feed.php:168
$comments
Definition Feed.php:52
__construct( $title, $description, $url, $date='', $author='', $comments='')
Definition Feed.php:64
getUrl()
Get the URL of this item; already xml-encoded.
Definition Feed.php:122
getTitle()
Get the Title object that we'll be acting on, as specified in the WebRequest.
static singleton()
Get an instance of this class.
Definition MimeMagic.php:33
Generate a RSS feed.
Definition Feed.php:278
formatTime( $ts)
Format a date given a timestamp.
Definition Feed.php:286
outHeader()
Output an RSS 2.0 header.
Definition Feed.php:293
outItem( $item)
Output an RSS 2.0 item.
Definition Feed.php:312
outFooter()
Output an RSS 2.0 footer.
Definition Feed.php:331
Represents a title within MediaWiki.
Definition Title.php:39
when a variable name is used in a it is silently declared as a new local masking the global
Definition design.txt:95
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
while(( $__line=Maintenance::readconsole()) !==false) print
Definition eval.php:64
const PROTO_CURRENT
Definition Defines.php:223
Allows to change the fields on the form that will be generated rss
Definition hooks.txt:302
usually copyright or history_copyright This message must be in HTML not wikitext if the section is included from a template to be included in the link
Definition hooks.txt:2991
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:37
Prior to version
This document describes the state of Postgres support in and is fairly well maintained The main code is very well while extensions are very hit and miss it is probably the most supported database after MySQL Much of the work in making MediaWiki database agnostic came about through the work of creating Postgres as and are nearing end of but without copying over all the usage comments General notes on the but these can almost always be programmed around *Although Postgres has a true BOOLEAN type
Definition postgres.txt:36