MediaWiki
master
Toggle main menu visibility
RSSFeed.php
Go to the documentation of this file.
1
<?php
9
10
namespace
MediaWiki\Feed;
11
12
use Wikimedia\Timestamp\TimestampFormat as TS;
13
19
class
RSSFeed
extends
ChannelFeed
{
20
27
private
function
formatTime( $ts ) {
28
if
( $ts ) {
29
return
gmdate(
'D, d M Y H:i:s \G\M\T'
, (
int
)
wfTimestamp
( TS::UNIX, $ts ) );
30
}
31
return
null
;
32
}
33
38
public
function
outputHeader
( $output ): void {
39
$this->
outputXmlHeader
( $output );
40
// Manually escaping rather than letting Mustache do it because Mustache
41
// uses htmlentities, which does not work with XML
42
$templateParams = [
43
'title'
=> $this->
getTitle
(),
44
'url'
=> $this->
xmlEncode
(
45
$this->urlUtils->expand( $this->getUrlUnescaped(),
PROTO_CURRENT
) ??
''
46
),
47
'description'
=> $this->
getDescription
(),
48
'language'
=> $this->
xmlEncode
( $this->
getLanguage
() ),
49
'version'
=> $this->
xmlEncode
(
MW_VERSION
),
50
'timestamp'
=> $this->
xmlEncode
( $this->formatTime(
wfTimestampNow
() ) )
51
];
52
print $this->templateParser->processTemplate(
'RSSHeader'
, $templateParams );
53
}
54
59
public
function
outputItem
(
FeedItem
$item, $output ): void {
60
// Manually escaping rather than letting Mustache do it because Mustache
61
// uses htmlentities, which does not work with XML
62
$templateParams = [
63
"title"
=> $item->
getTitle
(),
64
"url"
=> $this->
xmlEncode
(
65
$this->urlUtils->expand( $item->
getUrlUnescaped
(),
PROTO_CURRENT
) ??
''
66
),
67
"permalink"
=> $item->rssIsPermalink,
68
"uniqueID"
=> $item->
getUniqueID
(),
69
"description"
=> $item->
getDescription
(),
70
"date"
=> $this->
xmlEncodeNullable
( $this->formatTime( $item->
getDate
() ) ),
71
"author"
=> $item->
getAuthor
()
72
];
73
$comments
= $item->
getCommentsUnescaped
();
74
if
(
$comments
) {
75
$commentsEscaped = $this->
xmlEncode
(
76
$this->urlUtils->expand(
$comments
,
PROTO_CURRENT
) ??
''
77
);
78
$templateParams[
"comments"
] = $commentsEscaped;
79
}
80
print $this->templateParser->processTemplate(
'RSSItem'
, $templateParams );
81
}
82
87
public
function
outputFooter
( $output ): void {
88
print
"</channel></rss>"
;
89
}
90
}
PROTO_CURRENT
const PROTO_CURRENT
Definition
Defines.php:222
MW_VERSION
const MW_VERSION
The running version of MediaWiki.
Definition
Defines.php:23
wfTimestampNow
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
Definition
GlobalFunctions.php:1057
wfTimestamp
wfTimestamp( $outputtype=TS::UNIX, $ts=0)
Get a timestamp string in one of various formats.
Definition
GlobalFunctions.php:1025
MediaWiki\Feed\ChannelFeed
Class to support the outputting of syndication feeds in Atom and RSS format.
Definition
ChannelFeed.php:26
MediaWiki\Feed\ChannelFeed\outputXmlHeader
outputXmlHeader( $output)
Output the initial XML headers.
Definition
ChannelFeed.php:132
MediaWiki\Feed\FeedItem
A base class for outputting syndication feeds (e.g.
Definition
FeedItem.php:26
MediaWiki\Feed\FeedItem\$comments
string $comments
Definition
FeedItem.php:46
MediaWiki\Feed\FeedItem\getUrlUnescaped
getUrlUnescaped()
Get the URL of this item without any escaping.
Definition
FeedItem.php:155
MediaWiki\Feed\FeedItem\getUniqueID
getUniqueID()
Get the unique id of this item; already xml-encoded.
Definition
FeedItem.php:102
MediaWiki\Feed\FeedItem\xmlEncodeNullable
xmlEncodeNullable(?string $string)
Encode $string so that it can be safely embedded in a XML document, returning null if $string was nul...
Definition
FeedItem.php:93
MediaWiki\Feed\FeedItem\getDate
getDate()
Get the date of this item.
Definition
FeedItem.php:193
MediaWiki\Feed\FeedItem\getTitle
getTitle()
Get the title of this item; already xml-encoded.
Definition
FeedItem.php:138
MediaWiki\Feed\FeedItem\getAuthor
getAuthor()
Get the author of this item; already xml-encoded.
Definition
FeedItem.php:202
MediaWiki\Feed\FeedItem\getDescription
getDescription()
Get the description of this item; already xml-encoded.
Definition
FeedItem.php:164
MediaWiki\Feed\FeedItem\getLanguage
getLanguage()
Get the language of this item.
Definition
FeedItem.php:182
MediaWiki\Feed\FeedItem\getCommentsUnescaped
getCommentsUnescaped()
Get the comment of this item without any escaping.
Definition
FeedItem.php:229
MediaWiki\Feed\FeedItem\xmlEncode
xmlEncode( $string)
Encode $string so that it can be safely embedded in a XML document.
Definition
FeedItem.php:81
MediaWiki\Feed\RSSFeed
Generate an RSS feed.
Definition
RSSFeed.php:19
MediaWiki\Feed\RSSFeed\outputItem
outputItem(FeedItem $item, $output)
Output an RSS 2.0 item Generate an item.Example: print "<item>...</item>"; to override 1....
Definition
RSSFeed.php:59
MediaWiki\Feed\RSSFeed\outputFooter
outputFooter( $output)
Output an RSS 2.0 footer Generate Footer of the feed.Example: print "</feed>"; to override 1....
Definition
RSSFeed.php:87
MediaWiki\Feed\RSSFeed\outputHeader
outputHeader( $output)
Output an RSS 2.0 header Generate Header of the feed.Example: print "<feed>"; to override 1....
Definition
RSSFeed.php:38
includes
Feed
RSSFeed.php
Generated on
for MediaWiki by
1.18.0