123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323 |
- <?php
- class FeedItem {
-
- var $Title = 'Wiki';
- var $Description = '';
- var $Url = '';
- var $Date = '';
- var $Author = '';
-
-
- function __construct( $Title, $Description, $Url, $Date = '', $Author = '', $Comments = '' ) {
- $this->Title = $Title;
- $this->Description = $Description;
- $this->Url = $Url;
- $this->Date = $Date;
- $this->Author = $Author;
- $this->Comments = $Comments;
- }
- public function xmlEncode( $string ) {
- $string = str_replace( "\r\n", "\n", $string );
- $string = preg_replace( '/[\x00-\x08\x0b\x0c\x0e-\x1f]/', '', $string );
- return htmlspecialchars( $string );
- }
- public function getTitle() {
- return $this->xmlEncode( $this->Title );
- }
- public function getUrl() {
- return $this->xmlEncode( $this->Url );
- }
- public function getDescription() {
- return $this->xmlEncode( $this->Description );
- }
- public function getLanguage() {
- global $wgContLanguageCode;
- return $wgContLanguageCode;
- }
- public function getDate() {
- return $this->Date;
- }
- public function getAuthor() {
- return $this->xmlEncode( $this->Author );
- }
- public function getComments() {
- return $this->xmlEncode( $this->Comments );
- }
-
-
- public static function stripComment( $text ) {
- return preg_replace( '/\[\[([^]]*\|)?([^]]+)\]\]/', '\2', $text );
- }
-
- }
- class ChannelFeed extends FeedItem {
-
-
- function outHeader() {
-
- }
-
- function outItem( $item ) {
-
- }
-
- function outFooter() {
-
- }
-
-
- function httpHeaders() {
- global $wgOut;
-
- $wgOut->disable();
- $mimetype = $this->contentType();
- header( "Content-type: $mimetype; charset=UTF-8" );
- $wgOut->sendCacheControl();
- }
-
- function contentType() {
- global $wgRequest;
- $ctype = $wgRequest->getVal('ctype','application/xml');
- $allowedctypes = array('application/xml','text/xml','application/rss+xml','application/atom+xml');
- return (in_array($ctype, $allowedctypes) ? $ctype : 'application/xml');
- }
-
- function outXmlHeader() {
- global $wgStylePath, $wgStyleVersion;
- $this->httpHeaders();
- echo '<?xml version="1.0"?>' . "\n";
- echo '<?xml-stylesheet type="text/css" href="' .
- htmlspecialchars( wfExpandUrl( "$wgStylePath/common/feed.css?$wgStyleVersion" ) ) .
- '"?' . ">\n";
- }
- }
- class RSSFeed extends ChannelFeed {
-
- function formatTime( $ts ) {
- return gmdate( 'D, d M Y H:i:s \G\M\T', wfTimestamp( TS_UNIX, $ts ) );
- }
-
- function outHeader() {
- global $wgVersion;
- $this->outXmlHeader();
- ?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
- <channel>
- <title><?php print $this->getTitle() ?></title>
- <link><?php print $this->getUrl() ?></link>
- <description><?php print $this->getDescription() ?></description>
- <language><?php print $this->getLanguage() ?></language>
- <generator>MediaWiki <?php print $wgVersion ?></generator>
- <lastBuildDate><?php print $this->formatTime( wfTimestampNow() ) ?></lastBuildDate>
- <?php
- }
-
- function outItem( $item ) {
- ?>
- <item>
- <title><?php print $item->getTitle() ?></title>
- <link><?php print $item->getUrl() ?></link>
- <description><?php print $item->getDescription() ?></description>
- <?php if( $item->getDate() ) { ?><pubDate><?php print $this->formatTime( $item->getDate() ) ?></pubDate><?php } ?>
- <?php if( $item->getAuthor() ) { ?><dc:creator><?php print $item->getAuthor() ?></dc:creator><?php }?>
- <?php if( $item->getComments() ) { ?><comments><?php print $item->getComments() ?></comments><?php }?>
- </item>
- <?php
- }
-
- function outFooter() {
- ?>
- </channel>
- </rss><?php
- }
- }
- class AtomFeed extends ChannelFeed {
-
- function formatTime( $ts ) {
-
- return gmdate( 'Y-m-d\TH:i:s', wfTimestamp( TS_UNIX, $ts ) );
- }
-
- function outHeader() {
- global $wgVersion;
- $this->outXmlHeader();
- ?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="<?php print $this->getLanguage() ?>">
- <id><?php print $this->getFeedId() ?></id>
- <title><?php print $this->getTitle() ?></title>
- <link rel="self" type="application/atom+xml" href="<?php print $this->getSelfUrl() ?>"/>
- <link rel="alternate" type="text/html" href="<?php print $this->getUrl() ?>"/>
- <updated><?php print $this->formatTime( wfTimestampNow() ) ?>Z</updated>
- <subtitle><?php print $this->getDescription() ?></subtitle>
- <generator>MediaWiki <?php print $wgVersion ?></generator>
- <?php
- }
-
- function getFeedId() {
- return $this->getSelfUrl();
- }
-
- function getSelfUrl() {
- global $wgRequest;
- return htmlspecialchars( $wgRequest->getFullRequestURL() );
- }
-
- function outItem( $item ) {
- global $wgMimeType;
- ?>
- <entry>
- <id><?php print $item->getUrl() ?></id>
- <title><?php print $item->getTitle() ?></title>
- <link rel="alternate" type="<?php print $wgMimeType ?>" href="<?php print $item->getUrl() ?>"/>
- <?php if( $item->getDate() ) { ?>
- <updated><?php print $this->formatTime( $item->getDate() ) ?>Z</updated>
- <?php } ?>
- <summary type="html"><?php print $item->getDescription() ?></summary>
- <?php if( $item->getAuthor() ) { ?><author><name><?php print $item->getAuthor() ?></name></author><?php }?>
- </entry>
- <?php
- }
-
- function outFooter() {?>
- </feed><?php
- }
- }
|