| 1 |
<?php |
| 2 |
|
| 3 |
> |
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
namespace MediaWiki\Feed; |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
class RSSFeed extends ChannelFeed { |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
private function formatTime( $ts ) { |
| 40 |
if ( $ts ) { |
| 41 |
return gmdate( 'D, d M Y H:i:s \G\M\T', (int)wfTimestamp( TS_UNIX, $ts ) ); |
| 42 |
} |
| 43 |
return null; |
| 44 |
} |
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
public function outHeader() { |
| 50 |
$this->outXmlHeader(); |
| 51 |
|
| 52 |
|
| 53 |
$templateParams = [ |
| 54 |
'title' => $this->getTitle(), |
| 55 |
'url' => $this->xmlEncode( |
| 56 |
$this->urlUtils->expand( $this->getUrlUnescaped(), PROTO_CURRENT ) ?? '' |
| 57 |
), |
| 58 |
'description' => $this->getDescription(), |
| 59 |
'language' => $this->xmlEncode( $this->getLanguage() ), |
| 60 |
'version' => $this->xmlEncode( MW_VERSION ), |
| 61 |
'timestamp' => $this->xmlEncode( $this->formatTime( wfTimestampNow() ) ) |
| 62 |
]; |
| 63 |
print $this->templateParser->processTemplate( 'RSSHeader', $templateParams ); |
| 64 |
} |
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
public function outItem( $item ) { |
| 71 |
|
| 72 |
|
| 73 |
$templateParams = [ |
| 74 |
"title" => $item->getTitle(), |
| 75 |
"url" => $this->xmlEncode( |
| 76 |
$this->urlUtils->expand( $item->getUrlUnescaped(), PROTO_CURRENT ) ?? '' |
| 77 |
), |
| 78 |
"permalink" => $item->rssIsPermalink, |
| 79 |
"uniqueID" => $item->getUniqueID(), |
| 80 |
"description" => $item->getDescription(), |
| 81 |
"date" => $this->xmlEncodeNullable( $this->formatTime( $item->getDate() ) ), |
| 82 |
"author" => $item->getAuthor() |
| 83 |
]; |
| 84 |
$comments = $item->getCommentsUnescaped(); |
| 85 |
if ( $comments ) { |
| 86 |
$commentsEscaped = $this->xmlEncode( |
| 87 |
$this->urlUtils->expand( $comments, PROTO_CURRENT ) ?? '' |
| 88 |
); |
| 89 |
$templateParams["comments"] = $commentsEscaped; |
| 90 |
} |
| 91 |
print $this->templateParser->processTemplate( 'RSSItem', $templateParams ); |
| 92 |
} |
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
public function outFooter() { |
| 98 |
print "</channel></rss>"; |
| 99 |
} |
| 100 |
} |
| 101 |
|
| 102 |
|
| 103 |
class_alias( RSSFeed::class, 'RSSFeed' ); |