Merge pull request #4167 from dokuwiki-translate/lang_update_800_1706385011
[dokuwiki.git] / feed.php
blobe45f36524b5fbc0279bb086731c6852311534923
1 <?php
3 /**
4 * XML feed export
6 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
7 * @author Andreas Gohr <andi@splitbrain.org>
9 * @global array $conf
10 * @global Input $INPUT
13 use dokuwiki\Feed\FeedCreatorOptions;
14 use dokuwiki\Cache\Cache;
15 use dokuwiki\ChangeLog\MediaChangeLog;
16 use dokuwiki\ChangeLog\PageChangeLog;
17 use dokuwiki\Extension\AuthPlugin;
18 use dokuwiki\Extension\Event;
20 if (!defined('DOKU_INC')) define('DOKU_INC', __DIR__ . '/');
21 require_once(DOKU_INC . 'inc/init.php');
23 //close session
24 session_write_close();
26 //feed disabled?
27 if (!actionOK('rss')) {
28 http_status(404);
29 echo '<error>RSS feed is disabled.</error>';
30 exit;
33 $options = new FeedCreatorOptions();
35 // the feed is dynamic - we need a cache for each combo
36 // (but most people just use the default feed so it's still effective)
37 $key = implode('$', [
38 $options->getCacheKey(),
39 $INPUT->server->str('REMOTE_USER'),
40 $INPUT->server->str('HTTP_HOST'),
41 $INPUT->server->str('SERVER_PORT')
42 ]);
43 $cache = new Cache($key, '.feed');
45 // prepare cache depends
46 $depends['files'] = getConfigFiles('main');
47 $depends['age'] = $conf['rss_update'];
48 $depends['purge'] = $INPUT->bool('purge');
50 // check cacheage and deliver if nothing has changed since last
51 // time or the update interval has not passed, also handles conditional requests
52 header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
53 header('Pragma: public');
54 header('Content-Type: ' . $options->get('mime_type'));
55 header('X-Robots-Tag: noindex');
56 if ($cache->useCache($depends)) {
57 http_conditionalRequest($cache->getTime());
58 if ($conf['allowdebug']) header("X-CacheUsed: $cache->cache");
59 echo $cache->retrieveCache();
60 exit;
61 } else {
62 http_conditionalRequest(time());
65 // create new feed
66 try {
67 $feed = (new \dokuwiki\Feed\FeedCreator($options))->build();
68 $cache->storeCache($feed);
69 echo $feed;
70 } catch (Exception $e) {
71 http_status(500);
72 echo '<error>' . hsc($e->getMessage()) . '</error>';
73 exit;