| 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 |
|
| 25 |
namespace MediaWiki\Feed; |
| 26 |
|
| 27 |
use MediaWiki\MainConfigNames; |
| 28 |
use MediaWiki\MediaWikiServices; |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
class AtomFeed extends ChannelFeed { |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
private function formatTime( $timestamp ) { |
| 43 |
if ( $timestamp ) { |
| 44 |
|
| 45 |
return gmdate( 'Y-m-d\TH:i:s', (int)wfTimestamp( TS_UNIX, $timestamp ) ); |
| 46 |
} |
| 47 |
return null; |
| 48 |
} |
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
public function outHeader() { |
| 54 |
$this->outXmlHeader(); |
| 55 |
|
| 56 |
|
| 57 |
$templateParams = [ |
| 58 |
'language' => $this->xmlEncode( $this->getLanguage() ), |
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
'feedID' => $this->getSelfUrl(), |
| 64 |
'title' => $this->getTitle(), |
| 65 |
'url' => $this->xmlEncode( |
| 66 |
$this->urlUtils->expand( $this->getUrlUnescaped(), PROTO_CURRENT ) ?? '' |
| 67 |
), |
| 68 |
'selfUrl' => $this->getSelfUrl(), |
| 69 |
'timestamp' => $this->xmlEncode( $this->formatTime( wfTimestampNow() ) ), |
| 70 |
'description' => $this->getDescription(), |
| 71 |
'version' => $this->xmlEncode( MW_VERSION ), |
| 72 |
]; |
| 73 |
print $this->templateParser->processTemplate( 'AtomHeader', $templateParams ); |
| 74 |
} |
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
private function getSelfUrl() { |
| 82 |
global $wgRequest; |
| 83 |
return htmlspecialchars( $wgRequest->getFullRequestURL() ); |
| 84 |
} |
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
public function outItem( $item ) { |
| 92 |
$mimeType = MediaWikiServices::getInstance()->getMainConfig() |
| 93 |
->get( MainConfigNames::MimeType ); |
| 94 |
|
| 95 |
|
| 96 |
$templateParams = [ |
| 97 |
"uniqueID" => $item->getUniqueID(), |
| 98 |
"title" => $item->getTitle(), |
| 99 |
"mimeType" => $this->xmlEncode( $mimeType ), |
| 100 |
"url" => $this->xmlEncode( |
| 101 |
$this->urlUtils->expand( $item->getUrlUnescaped(), PROTO_CURRENT ) ?? '' |
| 102 |
), |
| 103 |
"date" => $this->xmlEncodeNullable( $this->formatTime( $item->getDate() ) ), |
| 104 |
"description" => $item->getDescription(), |
| 105 |
"author" => $item->getAuthor() |
| 106 |
]; |
| 107 |
print $this->templateParser->processTemplate( 'AtomItem', $templateParams ); |
| 108 |
} |
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
public function outFooter() { |
| 114 |
print "</feed>"; |
| 115 |
} |
| 116 |
} |
| 117 |
|
| 118 |
|
| 119 |
class_alias( AtomFeed::class, 'AtomFeed' ); |