phpdocumentor comments placeholders
[lhc/web/wiklou.git] / includes / Feed.php
1 <?php
2 # Basic support for outputting syndication feeds in RSS, other formats
3 #
4 # Copyright (C) 2004 Brion Vibber <brion@pobox.com>
5 # http://www.mediawiki.org/
6 #
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License along
18 # with this program; if not, write to the Free Software Foundation, Inc.,
19 # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 # http://www.gnu.org/copyleft/gpl.html
21
22 /**
23 * Contain a feed class as well as classes to build rss / atom ... feeds
24 */
25
26 /**
27 * Available feeds objects
28 */
29 $wgFeedClasses = array(
30 'rss' => 'RSSFeed',
31 'atom' => 'AtomFeed',
32 );
33
34 /**
35 * @todo document
36 */
37 class FeedItem {
38 /**@#+
39 * @var string
40 * @access private
41 */
42 var $Title = 'Wiki';
43 var $Description = '';
44 var $Url = '';
45 var $Date = '';
46 var $Author = '';
47 /**@#-*/
48
49 /**
50 * @todo document
51 */
52 function FeedItem( $Title, $Description, $Url, $Date = '', $Author = '', $Comments = '' ) {
53 $this->Title = $Title;
54 $this->Description = $Description;
55 $this->Url = $Url;
56 $this->Date = $Date;
57 $this->Author = $Author;
58 $this->Comments = $Comments;
59 }
60
61 /**
62 * @static
63 * @todo document
64 */
65 function xmlEncode( $string ) {
66 global $wgInputEncoding, $wgLang;
67 $string = str_replace( "\r\n", "\n", $string );
68 if( strcasecmp( $wgInputEncoding, 'utf-8' ) != 0 ) {
69 $string = $wgLang->iconv( $wgInputEncoding, 'utf-8', $string );
70 }
71 return htmlspecialchars( $string );
72 }
73
74 /**
75 * @todo document
76 */
77 function getTitle() { return $this->xmlEncode( $this->Title ); }
78 /**
79 * @todo document
80 */
81 function getUrl() { return $this->xmlEncode( $this->Url ); }
82 /**
83 * @todo document
84 */
85 function getDescription() { return $this->xmlEncode( $this->Description ); }
86 /**
87 * @todo document
88 */
89 function getLanguage() {
90 global $wgLanguageCode;
91 return $wgLanguageCode;
92 }
93 /**
94 * @todo document
95 */
96 function getDate() { return $this->Date; }
97 /**
98 * @todo document
99 */
100 function getAuthor() { return $this->xmlEncode( $this->Author ); }
101 /**
102 * @todo document
103 */
104 function getComments() { return $this->xmlEncode( $this->Comments ); }
105 }
106
107 /**
108 * @todo document
109 */
110 class ChannelFeed extends FeedItem {
111 /**@#+
112 * Abstract function, override!
113 */
114
115 /**
116 * @todo document
117 */
118 function outHeader() {
119 # print "<feed>";
120 }
121
122 /**
123 * @todo document
124 */
125 function outItem( $item ) {
126 # print "<item>...</item>";
127 }
128
129 /**
130 * @todo document
131 */
132 function outFooter() {
133 # print "</feed>";
134 }
135
136 /**
137 * @todo document
138 */
139 function outXmlHeader( $mimetype='application/xml' ) {
140 global $wgServer, $wgStylePath, $wgOut;
141
142 # We take over from $wgOut, excepting its cache header info
143 $wgOut->disable();
144 header( "Content-type: $mimetype; charset=UTF-8" );
145 $wgOut->sendCacheControl();
146
147 print '<' . '?xml version="1.0" encoding="utf-8"?' . ">\n";
148 print '<' . '?xml-stylesheet type="text/css" href="' .
149 htmlspecialchars( "$wgServer$wgStylePath/feed.css" ) . '"?' . ">\n";
150 }
151 /**@#-*/
152 }
153
154 /**
155 * Generate a RSS feed
156 * @todo document
157 */
158 class RSSFeed extends ChannelFeed {
159
160 /**
161 * @todo document
162 */
163 function formatTime( $ts ) {
164 return gmdate( 'D, d M Y H:i:s \G\M\T', wfTimestamp2Unix( $ts ) );
165 }
166
167 /**
168 * @todo document
169 */
170 function outHeader() {
171 global $wgVersion;
172
173 $this->outXmlHeader();
174 ?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
175 <channel>
176 <title><?php print $this->getTitle() ?></title>
177 <link><?php print $this->getUrl() ?></link>
178 <description><?php print $this->getDescription() ?></description>
179 <language><?php print $this->getLanguage() ?></language>
180 <generator>MediaWiki <?php print $wgVersion ?></generator>
181 <lastBuildDate><?php print $this->formatTime( wfTimestampNow() ) ?></lastBuildDate>
182 <?php
183 }
184
185 /**
186 * @todo document
187 */
188 function outItem( $item ) {
189 ?>
190 <item>
191 <title><?php print $item->getTitle() ?></title>
192 <link><?php print $item->getUrl() ?></link>
193 <description><?php print $item->getDescription() ?></description>
194 <?php if( $item->getDate() ) { ?><pubDate><?php print $this->formatTime( $item->getDate() ) ?></pubDate><?php } ?>
195 <?php if( $item->getAuthor() ) { ?><dc:creator><?php print $item->getAuthor() ?></dc:creator><?php }?>
196 <?php if( $item->getComments() ) { ?><comments><?php print $item->getComments() ?></comments><?php }?>
197 </item>
198 <?php
199 }
200
201 /**
202 * @todo document
203 */
204 function outFooter() {
205 ?>
206 </channel>
207 </rss><?php
208 }
209 }
210
211 /**
212 * Generate an Atom feed
213 * @todo document
214 */
215 class AtomFeed extends ChannelFeed {
216 /**
217 * @todo document
218 */
219 function formatTime( $ts ) {
220 // need to use RFC 822 time format at least for rss2.0
221 return gmdate( 'Y-m-d\TH:i:s', wfTimestamp2Unix( $ts ) );
222 }
223
224 /**
225 * @todo document
226 */
227 function outHeader() {
228 global $wgVersion, $wgOut;
229
230 $this->outXmlHeader();
231 ?><feed version="0.3" xml:lang="<?php print $this->getLanguage() ?>">
232 <title><?php print $this->getTitle() ?></title>
233 <link rel="alternate" type="text/html" href="<?php print $this->getUrl() ?>"/>
234 <modified><?php print $this->formatTime( wfTimestampNow() ) ?>Z</modified>
235 <tagline><?php print $this->getDescription() ?></tagline>
236 <generator>MediaWiki <?php print $wgVersion ?></generator>
237
238 <?php
239 }
240
241 /**
242 * @todo document
243 */
244 function outItem( $item ) {
245 global $wgMimeType;
246 ?>
247 <entry>
248 <title><?php print $item->getTitle() ?></title>
249 <link rel="alternate" type="<?php print $wgMimeType ?>" href="<?php print $item->getUrl() ?>"/>
250 <?php if( $item->getDate() ) { ?>
251 <modified><?php print $this->formatTime( $item->getDate() ) ?>Z</modified>
252 <issued><?php print $this->formatTime( $item->getDate() ) ?></issued>
253 <created><?php print $this->formatTime( $item->getDate() ) ?>Z</created><?php } ?>
254
255 <summary type="text/plain"><?php print $item->getDescription() ?></summary>
256 <?php if( $item->getAuthor() ) { ?><author><name><?php print $item->getAuthor() ?></name><!-- <url></url><email></email> --></author><?php }?>
257 <comment>foobar</comment>
258 </entry>
259
260 <?php /* FIXME need to add comments
261 <?php if( $item->getComments() ) { ?><dc:comment><?php print $item->getComments() ?></dc:comment><?php }?>
262 */
263 }
264
265 /**
266 * @todo document
267 */
268 function outFooter() {?>
269 </feed><?php
270 }
271 }
272
273 ?>