***************************************************************************/
require_once 'xorg.inc.php';
+require_once 'wiki.inc.php';
-new_skinned_page('wiki.tpl');
-if (!S::identified()) {
- XorgSession::doAuth();
+require_once dirname(__FILE__).'/../classes/Platal.php';
+require_once dirname(__FILE__).'/../classes/PLModule.php';
+
+$n = wiki_pagename();
+if (!$n) {
+ pl_redirect('');
}
-require_once 'wiki.inc.php';
+new_skinned_page('wiki.tpl');
+
+switch (Env::get('action')) {
+ case '':
+ list($r) = get_perms($n);
+ wiki_apply_perms($r);
+ break;
-if ($n = wiki_pagename()) {
- $wiki_cache = wiki_work_dir().'/cache_'.$n.'.tpl';
- $cache_exists = file_exists($wiki_cache);
+ case 'edit':
+ list(, $e) = get_perms($n);
+ wiki_apply_perms($e);
+ break;
- if (Env::get('action') || !$cache_exists) {
- @unlink($wiki_cache);
+ default:
+ wiki_apply_perms('admin');
+ break;
+}
- // we leave pmwiki do whatever it wants and store everything
- ob_start();
- require_once($globals->spoolroot.'/wiki/pmwiki.php');
+$wiki_cache = wiki_work_dir().'/cache_'.$n.'.tpl';
+$cache_exists = file_exists($wiki_cache);
- $wikiAll = ob_get_clean();
- // the pmwiki skin we are using (almost empty) has these keywords:
- $i = strpos($wikiAll, "<!--/HeaderText-->");
- $j = strpos($wikiAll, "<!--/PageLeftFmt-->", $i);
- }
+if (Env::get('action') || !$cache_exists) {
+ @unlink($wiki_cache);
+
+ // we leave pmwiki do whatever it wants and store everything
+ ob_start();
+ require_once($globals->spoolroot.'/wiki/pmwiki.php');
- if (Env::get('action')) {
- $page->assign('xorg_extra_header', substr($wikiAll, 0, $i));
+ $wikiAll = ob_get_clean();
+ // the pmwiki skin we are using (almost empty) has these keywords:
+ $i = strpos($wikiAll, "<!--/HeaderText-->");
+ $j = strpos($wikiAll, "<!--/PageLeftFmt-->", $i);
+}
+
+if (Env::get('action')) {
+ $page->assign('xorg_extra_header', substr($wikiAll, 0, $i));
+ $wikiAll = substr($wikiAll, $j);
+} else {
+ if (!$cache_exists) {
+ $f = fopen($wiki_cache, 'w');
$wikiAll = substr($wikiAll, $j);
+ fputs($f, $wikiAll);
+ fclose($f);
} else {
- if (!$cache_exists) {
- $f = fopen($wiki_cache, 'w');
- $wikiAll = substr($wikiAll, $j);
- fputs($f, $wikiAll);
- fclose($f);
- } else {
- $wikiAll = file_get_contents($wiki_cache);
- }
+ $wikiAll = file_get_contents($wiki_cache);
}
-
- $page->assign('wikipage', str_replace('.', '/', $n));
}
+$page->assign('wikipage', str_replace('.', '/', $n));
$page->assign('pmwiki', $wikiAll);
$page->assign('has_perms', S::has_perms());
$page->addCssLink('css/wiki.css');
system('rm -f '.wiki_work_dir().'/cache_*');
}
+function get_perms($n)
+{
+ $file = wiki_work_dir().'/'.str_replace('/', '.', $n);
+ $lines = explode("\n", file_get_contents($file));
+ foreach ($lines as $line) {
+ list($k, $v) = explode('=', $line, 2);
+ if ($k == 'platal_perms') {
+ return explode(':', $v);
+ }
+ }
+ return array('logged', 'admin');
+}
+
+function wiki_apply_perms($perm) {
+ global $page, $platal;
+
+ switch ($perm) {
+ case 'public':
+ return;
+
+ case 'logged':
+ if (!XorgSession::doAuthCookie()) {
+ $platal = new Platal();
+ $platal->force_login($page);
+ }
+ return;
+
+ default:
+ if (!XorgSession::doAuth()) {
+ $platal = new Platal();
+ $platal->force_login($page);
+ }
+ if ($perm == 'admin') {
+ check_perms();
+ }
+ return;
+ }
+}
+
?>