From f6ce9a8820cbf644dc2f9ae47b3d03d8ea6a4243 Mon Sep 17 00:00:00 2001 From: x2000habouzit Date: Sat, 22 Jul 2006 16:09:57 +0000 Subject: [PATCH] refactor wiki.php *again*. implement our simple permissions level checks. now will have to implement things to modify them git-svn-id: svn+ssh://murphy/home/svn/platal/trunk@563 839d8a87-29fc-0310-9880-83ba4fa771e5 --- htdocs/wiki.php | 75 +++++++++++++++++++++++++++----------------- include/wiki.inc.php | 39 +++++++++++++++++++++++ include/xorg/session.inc.php | 6 ++-- 3 files changed, 89 insertions(+), 31 deletions(-) diff --git a/htdocs/wiki.php b/htdocs/wiki.php index c702d7a..1d0963e 100644 --- a/htdocs/wiki.php +++ b/htdocs/wiki.php @@ -20,48 +20,65 @@ ***************************************************************************/ 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, ""); - $j = strpos($wikiAll, "", $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, ""); + $j = strpos($wikiAll, "", $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'); diff --git a/include/wiki.inc.php b/include/wiki.inc.php index 6f9c83c..000690e 100644 --- a/include/wiki.inc.php +++ b/include/wiki.inc.php @@ -46,4 +46,43 @@ function wiki_clear_all_cache() 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; + } +} + ?> diff --git a/include/xorg/session.inc.php b/include/xorg/session.inc.php index df30806..841bbd1 100644 --- a/include/xorg/session.inc.php +++ b/include/xorg/session.inc.php @@ -146,10 +146,10 @@ class XorgSession * * @param page the calling page (by reference) */ - function doAuthCookie(&$page) + function doAuthCookie() { if (S::logged()) { - return; + return true; } if (Env::has('username') and Env::has('response')) { @@ -159,6 +159,8 @@ class XorgSession if ($r = try_cookie()) { return XorgSession::doAuth(($r > 0)); } + + return false; } // }}} -- 2.1.4