Non significant spaces suck.
[platal.git] / include / wiki / engine.php
index 8455e44..dfd587f 100644 (file)
@@ -28,9 +28,13 @@ if (!$n) {
 
 new_skinned_page('core/wiki.tpl');
 $perms = wiki_get_perms($n);
+$feed  = false;
 
 // Check user perms
 switch (Env::v('action')) {
+  case 'rss': case 'atom': case 'sdf': case 'dc':
+    wiki_apply_feed_perms($perms[0]);
+    $feed = true;
   case '': case 'search':
     break;
 
@@ -47,7 +51,7 @@ if ($p = Post::v('setrperms')) {
     wiki_apply_perms('admin');
     if (wiki_set_perms($n, $p, $perms[1])) {
         $perms = wiki_get_perms($n);
-        $page->trig('Permissions mises à jour');
+        $page->trig('Permissions mises à jour');
     }
 }
 
@@ -55,17 +59,20 @@ if ($p = Post::v('setwperms')) {
     wiki_apply_perms('admin');
     if (wiki_set_perms($n, $perms[0], $p)) {
         $perms = wiki_get_perms($n);
-        $page->trig('Permissions mises à jour');
+        $page->trig('Permissions mises à jour');
     }
 }
 
 // Generate cache even if we don't have access rights
 $wiki_cache   = wiki_work_dir().'/cache_'.wiki_filename($n).'.tpl';
 $cache_exists = file_exists($wiki_cache);
-
 if (Env::v('action') || !$cache_exists) {
-    if ($cache_exists) {
+    if ($cache_exists && !$feed) {
         unlink($wiki_cache);
+        $files = glob($globals->spoolroot . '/spool/templates_c/*cache_' . wiki_filename($n) . '.tpl*');
+        foreach ($files as $file) {
+            unlink($file);
+        }
     }
 
     // we leave pmwiki do whatever it wants and store everything
@@ -73,6 +80,8 @@ if (Env::v('action') || !$cache_exists) {
     require_once($globals->spoolroot.'/wiki/pmwiki.php');
 
     $wikiAll = ob_get_clean();
+    pl_clear_errors();
+
     // the pmwiki skin we are using (almost empty) has these keywords:
     $i = strpos($wikiAll, "<!--/HeaderText-->");
     $j = strpos($wikiAll, "<!--/PageLeftFmt-->", $i);
@@ -80,7 +89,14 @@ if (Env::v('action') || !$cache_exists) {
 
 $wiki_exists = file_exists(wiki_work_dir() . '/' . wiki_filename($n));
 
-if (Env::v('action')) {
+if ($feed) {
+    $wikiAll = str_replace('dc:contributor', 'author', $wikiAll);
+    $wikiAll = preg_replace('!<author>.*?\..*?\.(\d{4})\|(.*?)</author>!u', '<author>$2 (X$1)</author>', $wikiAll);
+    $wikiAll = str_replace('<link>./', '<link>' . $globals->baseurl . '/' . $platal->ns, $wikiAll);
+    echo $wikiAll;
+    pl_clear_errors();
+    exit;
+} elseif (Env::v('action')) {
     $page->assign('xorg_extra_header', substr($wikiAll, 0, $i));
     $wikiAll = substr($wikiAll, $j);
 } else {
@@ -91,7 +107,7 @@ if (Env::v('action')) {
         $wikiAll = file_get_contents($wiki_cache);
     } elseif (S::has_perms()) {
         $wikiAll = "<p>La page de wiki $n n'existe pas. "
-                 . "Il te suffit de <a href='" . str_replace('.', '/', $n) . "?action=edit'>l'éditer</a></p>";
+                 . "Il te suffit de <a href='" . str_replace('.', '/', $n) . "?action=edit'>l'éditer</a></p>";
     } else {
         $page->changeTpl('core/404.tpl');
     }
@@ -107,7 +123,7 @@ $page->assign('canedit',    wiki_may_have_perms($perms[1]));
 $page->assign('has_perms',  wiki_may_have_perms('admin'));
 
 $page->assign('wikipage', str_replace('.', '/', $n));
-if ($perms[1] == 'admin' && !Env::v('action') && $wiki_exists) {
+if (!$feed && $perms[1] == 'admin' && !Env::v('action') && $wiki_exists) {
     $page->assign('pmwiki_cache', $wiki_cache);
 } else {
     $page->assign('pmwiki',   $wikiAll);
@@ -115,7 +131,15 @@ if ($perms[1] == 'admin' && !Env::v('action') && $wiki_exists) {
 }
 $page->addCssLink('wiki.css');
 $page->addJsLink('wiki.js');
+if (!Env::v('action')) {
+    $url = '/' . str_replace('.', '/', $n) . '?action=rss';
+    if (S::logged()) {
+        $url .= '&user=' . S::v('forlife') . '&hash=' . S::v('core_rss_hash');
+    }
+    $page->setRssLink($n, $url);
+}
 
 $page->run();
 
+// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
 ?>