Updated the checktrans.php script to be a little more modern and to
[mediawiki.git] / includes / Feed.php
blob3ac7fe3392f7114390a7bcd36ee308ef455a8b38
1 <?php
2 # $Id$
3 # Basic support for outputting syndication feeds in RSS, other formats
4 #
5 # Copyright (C) 2004 Brion Vibber <brion@pobox.com>
6 # http://www.mediawiki.org/
7 #
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License along
19 # with this program; if not, write to the Free Software Foundation, Inc.,
20 # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 # http://www.gnu.org/copyleft/gpl.html
23 /**
24 * Contain a feed class as well as classes to build rss / atom ... feeds
25 * Available feeds are defined in Defines.php
26 * @package MediaWiki
30 /**
31 * @todo document
32 * @package MediaWiki
34 class FeedItem {
35 /**#@+
36 * @var string
37 * @access private
39 var $Title = 'Wiki';
40 var $Description = '';
41 var $Url = '';
42 var $Date = '';
43 var $Author = '';
44 /**#@-*/
46 /**
47 * @todo document
49 function FeedItem( $Title, $Description, $Url, $Date = '', $Author = '', $Comments = '' ) {
50 $this->Title = $Title;
51 $this->Description = $Description;
52 $this->Url = $Url;
53 $this->Date = $Date;
54 $this->Author = $Author;
55 $this->Comments = $Comments;
58 /**
59 * @static
60 * @todo document
62 function xmlEncode( $string ) {
63 global $wgInputEncoding, $wgContLang;
64 $string = str_replace( "\r\n", "\n", $string );
65 if( strcasecmp( $wgInputEncoding, 'utf-8' ) != 0 ) {
66 $string = $wgContLang->iconv( $wgInputEncoding, 'utf-8', $string );
68 return htmlspecialchars( $string );
71 /**
72 * @todo document
74 function getTitle() { return $this->xmlEncode( $this->Title ); }
75 /**
76 * @todo document
78 function getUrl() { return $this->xmlEncode( $this->Url ); }
79 /**
80 * @todo document
82 function getDescription() { return $this->xmlEncode( $this->Description ); }
83 /**
84 * @todo document
86 function getLanguage() {
87 global $wgContLanguageCode;
88 return $wgContLanguageCode;
90 /**
91 * @todo document
93 function getDate() { return $this->Date; }
94 /**
95 * @todo document
97 function getAuthor() { return $this->xmlEncode( $this->Author ); }
98 /**
99 * @todo document
101 function getComments() { return $this->xmlEncode( $this->Comments ); }
105 * @todo document
106 * @package MediaWiki
108 class ChannelFeed extends FeedItem {
109 /**#@+
110 * Abstract function, override!
111 * @abstract
115 * Generate Header of the feed
117 function outHeader() {
118 # print "<feed>";
122 * Generate an item
123 * @param $item
125 function outItem( $item ) {
126 # print "<item>...</item>";
130 * Generate Footer of the feed
132 function outFooter() {
133 # print "</feed>";
135 /**#@-*/
138 * @todo document
139 * @param string $mimetype (optional) type of output
141 function outXmlHeader( $mimetype='application/xml' ) {
142 global $wgServer, $wgStylePath, $wgOut;
144 # We take over from $wgOut, excepting its cache header info
145 $wgOut->disable();
146 header( "Content-type: $mimetype; charset=UTF-8" );
147 $wgOut->sendCacheControl();
149 print '<' . '?xml version="1.0" encoding="utf-8"?' . ">\n";
150 print '<' . '?xml-stylesheet type="text/css" href="' .
151 htmlspecialchars( "$wgServer$wgStylePath/feed.css" ) . '"?' . ">\n";
156 * Generate a RSS feed
157 * @todo document
158 * @package MediaWiki
160 class RSSFeed extends ChannelFeed {
163 * Format a date given a timestamp
164 * @param integer $ts Timestamp
165 * @return string Date string
167 function formatTime( $ts ) {
168 return gmdate( 'D, d M Y H:i:s \G\M\T', wfTimestamp( TS_UNIX, $ts ) );
172 * Ouput an RSS 2.0 header
174 function outHeader() {
175 global $wgVersion;
177 $this->outXmlHeader();
178 ?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
179 <channel>
180 <title><?php print $this->getTitle() ?></title>
181 <link><?php print $this->getUrl() ?></link>
182 <description><?php print $this->getDescription() ?></description>
183 <language><?php print $this->getLanguage() ?></language>
184 <generator>MediaWiki <?php print $wgVersion ?></generator>
185 <lastBuildDate><?php print $this->formatTime( wfTimestampNow() ) ?></lastBuildDate>
186 <?php
190 * Output an RSS 2.0 item
191 * @param FeedItem item to be output
193 function outItem( $item ) {
195 <item>
196 <title><?php print $item->getTitle() ?></title>
197 <link><?php print $item->getUrl() ?></link>
198 <description><?php print $item->getDescription() ?></description>
199 <?php if( $item->getDate() ) { ?><pubDate><?php print $this->formatTime( $item->getDate() ) ?></pubDate><?php } ?>
200 <?php if( $item->getAuthor() ) { ?><dc:creator><?php print $item->getAuthor() ?></dc:creator><?php }?>
201 <?php if( $item->getComments() ) { ?><comments><?php print $item->getComments() ?></comments><?php }?>
202 </item>
203 <?php
207 * Ouput an RSS 2.0 footer
209 function outFooter() {
211 </channel>
212 </rss><?php
217 * Generate an Atom feed
218 * @todo document
219 * @package MediaWiki
221 class AtomFeed extends ChannelFeed {
223 * @todo document
225 function formatTime( $ts ) {
226 // need to use RFC 822 time format at least for rss2.0
227 return gmdate( 'Y-m-d\TH:i:s', wfTimestamp( TS_UNIX, $ts ) );
231 * @todo document
233 function outHeader() {
234 global $wgVersion, $wgOut;
236 $this->outXmlHeader();
237 ?><feed version="0.3" xml:lang="<?php print $this->getLanguage() ?>">
238 <title><?php print $this->getTitle() ?></title>
239 <link rel="alternate" type="text/html" href="<?php print $this->getUrl() ?>"/>
240 <modified><?php print $this->formatTime( wfTimestampNow() ) ?>Z</modified>
241 <tagline><?php print $this->getDescription() ?></tagline>
242 <generator>MediaWiki <?php print $wgVersion ?></generator>
244 <?php
248 * @todo document
250 function outItem( $item ) {
251 global $wgMimeType;
253 <entry>
254 <title><?php print $item->getTitle() ?></title>
255 <link rel="alternate" type="<?php print $wgMimeType ?>" href="<?php print $item->getUrl() ?>"/>
256 <?php if( $item->getDate() ) { ?>
257 <modified><?php print $this->formatTime( $item->getDate() ) ?>Z</modified>
258 <issued><?php print $this->formatTime( $item->getDate() ) ?></issued>
259 <created><?php print $this->formatTime( $item->getDate() ) ?>Z</created><?php } ?>
261 <summary type="text/plain"><?php print $item->getDescription() ?></summary>
262 <?php if( $item->getAuthor() ) { ?><author><name><?php print $item->getAuthor() ?></name><!-- <url></url><email></email> --></author><?php }?>
263 <comment>foobar</comment>
264 </entry>
266 <?php /* FIXME need to add comments
267 <?php if( $item->getComments() ) { ?><dc:comment><?php print $item->getComments() ?></dc:comment><?php }?>
272 * @todo document
274 function outFooter() {?>
275 </feed><?php