xref: /dokuwiki/feed.php (revision 8788dbbd585b42284320d64cc932f3c875eab6b2)
1<?php
2
3/**
4 * XML feed export
5 *
6 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
7 * @author     Andreas Gohr <andi@splitbrain.org>
8 *
9 * @global array $conf
10 * @global Input $INPUT
11 */
12
13use dokuwiki\Feed\FeedCreator;
14use dokuwiki\Feed\FeedCreatorOptions;
15use dokuwiki\Cache\Cache;
16use dokuwiki\ChangeLog\MediaChangeLog;
17use dokuwiki\ChangeLog\PageChangeLog;
18use dokuwiki\Extension\AuthPlugin;
19use dokuwiki\Extension\Event;
20use dokuwiki\Search\FulltextSearch;
21
22if (!defined('DOKU_INC')) define('DOKU_INC', __DIR__ . '/');
23require_once(DOKU_INC . 'inc/init.php');
24
25//close session
26session_write_close();
27
28//feed disabled?
29if (!actionOK('rss')) {
30    http_status(404);
31    echo '<error>RSS feed is disabled.</error>';
32    exit;
33}
34
35$options = new FeedCreatorOptions();
36
37// we only cache the recent cache, but do so based on dynamic parameters
38// other modes are never cached and always created on the fly
39$cache = null;
40$cacheKey = $options->getCacheKey([
41    $INPUT->server->str('REMOTE_USER'),
42    $INPUT->server->str('HTTP_HOST'),
43    $INPUT->server->str('SERVER_PORT'),
44]);
45if ($cacheKey !== null) {
46    $cache = new Cache($cacheKey, '.feed');
47
48    // prepare cache depends
49    $depends['files'] = getConfigFiles('main');
50    $depends['age'] = $conf['rss_update'];
51    $depends['purge'] = $INPUT->bool('purge');
52}
53
54// check cacheage and deliver if nothing has changed since last
55// time or the update interval has not passed, also handles conditional requests
56header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
57header('Pragma: public');
58header('Content-Type: ' . $options->getMimeType());
59header('X-Robots-Tag: noindex');
60if ($cache?->useCache($depends)) {
61    http_conditionalRequest($cache->getTime());
62    if ($conf['allowdebug']) header("X-CacheUsed: $cache->cache");
63    echo $cache->retrieveCache();
64    exit;
65} else {
66    http_conditionalRequest(time());
67}
68
69// create new feed
70try {
71    $feed = (new FeedCreator($options))->build();
72    $cache?->storeCache($feed);
73    echo $feed;
74} catch (Exception $e) {
75    http_status(500);
76    echo '<error>' . hsc($e->getMessage()) . '</error>';
77    exit;
78}
79