Main Page | Namespace List | Class Hierarchy | Class List | File List | Class Members | File Members | Related Pages

Feed.php

Go to the documentation of this file.
00001 <?php 00002 # Basic support for outputting syndication feeds in RSS, other formats 00003 # 00004 # Copyright (C) 2004 Brion Vibber <brion@pobox.com> 00005 # http://www.mediawiki.org/ 00006 # 00007 # This program is free software; you can redistribute it and/or modify 00008 # it under the terms of the GNU General Public License as published by 00009 # the Free Software Foundation; either version 2 of the License, or 00010 # (at your option) any later version. 00011 # 00012 # This program is distributed in the hope that it will be useful, 00013 # but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 # GNU General Public License for more details. 00016 # 00017 # You should have received a copy of the GNU General Public License along 00018 # with this program; if not, write to the Free Software Foundation, Inc., 00019 # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00020 # http://www.gnu.org/copyleft/gpl.html 00021 00022 $wgFeedClasses = array( 00023 'rss' => 'RSSFeed', 00024 'atom' => 'AtomFeed', 00025 ); 00026 00027 class FeedItem { 00028 var $Title = 'Wiki'; 00029 var $Description = ''; 00030 var $Url = ''; 00031 var $Date = ''; 00032 var $Author = ''; 00033 00034 function FeedItem( $Title, $Description, $Url, $Date = '', $Author = '', $Comments = '' ) { 00035 $this->Title = $Title; 00036 $this->Description = $Description; 00037 $this->Url = $Url; 00038 $this->Date = $Date; 00039 $this->Author = $Author; 00040 $this->Comments = $Comments; 00041 } 00042 00043 /* Static... */ 00044 function xmlEncode( $string ) { 00045 global $wgInputEncoding, $wgLang; 00046 $string = str_replace( "\r\n", "\n", $string ); 00047 if( strcasecmp( $wgInputEncoding, 'utf-8' ) != 0 ) { 00048 $string = $wgLang->iconv( $wgInputEncoding, 'utf-8', $string ); 00049 } 00050 return htmlspecialchars( $string ); 00051 } 00052 function getTitle() { 00053 return $this->xmlEncode( $this->Title ); 00054 } 00055 function getUrl() { 00056 return $this->xmlEncode( $this->Url ); 00057 } 00058 function getDescription() { 00059 return $this->xmlEncode( $this->Description ); 00060 } 00061 function getLanguage() { 00062 global $wgLanguageCode; 00063 return $wgLanguageCode; 00064 } 00065 function getDate() { 00066 return $this->Date; 00067 } 00068 function getAuthor() { 00069 return $this->xmlEncode( $this->Author ); 00070 } 00071 function getComments() { 00072 return $this->xmlEncode( $this->Comments ); 00073 } 00074 } 00075 00076 class ChannelFeed extends FeedItem { 00077 /* Abstract functions, override! */ 00078 function outHeader() { 00079 # print "<feed>"; 00080 } 00081 function outItem( $item ) { 00082 # print "<item>...</item>"; 00083 } 00084 function outFooter() { 00085 # print "</feed>"; 00086 } 00087 00088 function outXmlHeader( $mimetype='application/xml' ) { 00089 global $wgServer, $wgStylePath, $wgOut; 00090 00091 # We take over from $wgOut, excepting its cache header info 00092 $wgOut->disable(); 00093 header( "Content-type: $mimetype; charset=UTF-8" ); 00094 $wgOut->sendCacheControl(); 00095 00096 print '<' . '?xml version="1.0" encoding="utf-8"?' . ">\n"; 00097 print '<' . '?xml-stylesheet type="text/css" href="' . 00098 htmlspecialchars( "$wgServer$wgStylePath/feed.css" ) . '"?' . ">\n"; 00099 } 00100 } 00101 00102 class RSSFeed extends ChannelFeed { 00103 00104 function formatTime( $ts ) { 00105 return gmdate( 'D, d M Y H:i:s \G\M\T', wfTimestamp2Unix( $ts ) ); 00106 } 00107 00108 function outHeader() { 00109 global $wgVersion; 00110 00111 $this->outXmlHeader(); 00112 ?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"> 00113 <channel> 00114 <title><?php print $this->getTitle() ?></title> 00115 <link><?php print $this->getUrl() ?></link> 00116 <description><?php print $this->getDescription() ?></description> 00117 <language><?php print $this->getLanguage() ?></language> 00118 <generator>MediaWiki <?php print $wgVersion ?></generator> 00119 <lastBuildDate><?php print $this->formatTime( wfTimestampNow() ) ?></lastBuildDate> 00120 <?php 00121 } 00122 00123 function outItem( $item ) { 00124 ?> 00125 <item> 00126 <title><?php print $item->getTitle() ?></title> 00127 <link><?php print $item->getUrl() ?></link> 00128 <description><?php print $item->getDescription() ?></description> 00129 <?php if( $item->getDate() ) { ?><pubDate><?php print $this->formatTime( $item->getDate() ) ?></pubDate><?php } ?> 00130 <?php if( $item->getAuthor() ) { ?><dc:creator><?php print $item->getAuthor() ?></dc:creator><?php }?> 00131 <?php if( $item->getComments() ) { ?><comments><?php print $item->getComments() ?></comments><?php }?> 00132 </item> 00133 <?php 00134 } 00135 00136 function outFooter() { 00137 ?> 00138 </channel> 00139 </rss><?php 00140 } 00141 } 00142 00143 class AtomFeed extends ChannelFeed { 00144 function formatTime( $ts ) { 00145 // need to use RFC 822 time format at least for rss2.0 00146 return gmdate( 'Y-m-d\TH:i:s', wfTimestamp2Unix( $ts ) ); 00147 } 00148 00149 function outHeader() { 00150 global $wgVersion, $wgOut; 00151 00152 $this->outXmlHeader(); 00153 ?><feed version="0.3" xml:lang="<?php print $this->getLanguage() ?>"> 00154 <title><?php print $this->getTitle() ?></title> 00155 <link rel="alternate" type="text/html" href="<?php print $this->getUrl() ?>"/> 00156 <modified><?php print $this->formatTime( wfTimestampNow() ) ?>Z</modified> 00157 <tagline><?php print $this->getDescription() ?></tagline> 00158 <generator>MediaWiki <?php print $wgVersion ?></generator> 00159 00160 <?php 00161 } 00162 00163 function outItem( $item ) { 00164 global $wgMimeType; 00165 ?> 00166 <entry> 00167 <title><?php print $item->getTitle() ?></title> 00168 <link rel="alternate" type="<?php print $wgMimeType ?>" href="<?php print $item->getUrl() ?>"/> 00169 <?php if( $item->getDate() ) { ?> 00170 <modified><?php print $this->formatTime( $item->getDate() ) ?>Z</modified> 00171 <issued><?php print $this->formatTime( $item->getDate() ) ?></issued> 00172 <created><?php print $this->formatTime( $item->getDate() ) ?>Z</created><?php } ?> 00173 00174 <summary type="text/plain"><?php print $item->getDescription() ?></summary> 00175 <?php if( $item->getAuthor() ) { ?><author><name><?php print $item->getAuthor() ?></name><!-- <url></url><email></email> --></author><?php }?> 00176 <comment>foobar</comment> 00177 </entry> 00178 00179 <?php /* FIXME need to add comments 00180 <?php if( $item->getComments() ) { ?><dc:comment><?php print $item->getComments() ?></dc:comment><?php }?> 00181 */ 00182 } 00183 00184 function outFooter() {?> 00185 </feed><?php 00186 } 00187 } 00188 00189 ?>

Generated on Tue Jun 29 23:40:03 2004 for Mediawiki by doxygen 1.3.7