From 89232034976e2987f136d6afe75b4038aa66f987 Mon Sep 17 00:00:00 2001 From: x2000habouzit Date: Sat, 22 Jul 2006 17:05:50 +0000 Subject: [PATCH] and now we have a permission system for our Wiki, that is understandable and simple. yay git-svn-id: svn+ssh://murphy/home/svn/platal/trunk@565 839d8a87-29fc-0310-9880-83ba4fa771e5 --- htdocs/wiki.php | 22 ++++++++++++++++++---- include/wiki.inc.php | 34 ++++++++++++++++++++++++++++++++-- templates/wiki.tpl | 6 ++++-- 3 files changed, 54 insertions(+), 8 deletions(-) diff --git a/htdocs/wiki.php b/htdocs/wiki.php index ab25fbc..39bb47a 100644 --- a/htdocs/wiki.php +++ b/htdocs/wiki.php @@ -31,7 +31,7 @@ if (!$n) { } new_skinned_page('wiki.tpl'); -$perms = get_perms($n); +$perms = wiki_get_perms($n); switch (Env::get('action')) { case '': @@ -47,6 +47,22 @@ switch (Env::get('action')) { break; } +if ($p = Post::get('setrperms')) { + wiki_apply_perms('admin'); + if (wiki_set_perms($n, $p, $perms[1])) { + $perms = wiki_get_perms($n); + $page->trig('Permissions mises à jour'); + } +} + +if ($p = Post::get('setwperms')) { + wiki_apply_perms('admin'); + if (wiki_set_perms($n, $perms[0], $p)) { + $perms = wiki_get_perms($n); + $page->trig('Permissions mises à jour'); + } +} + $wiki_cache = wiki_work_dir().'/cache_'.$n.'.tpl'; $cache_exists = file_exists($wiki_cache); @@ -68,10 +84,8 @@ if (Env::get('action')) { $wikiAll = substr($wikiAll, $j); } else { if (!$cache_exists) { - $f = fopen($wiki_cache, 'w'); $wikiAll = substr($wikiAll, $j); - fputs($f, $wikiAll); - fclose($f); + wiki_putfile($wiki_cache, $wikiAll); } else { $wikiAll = file_get_contents($wiki_cache); } diff --git a/include/wiki.inc.php b/include/wiki.inc.php index 7e69dd2..3b441bc 100644 --- a/include/wiki.inc.php +++ b/include/wiki.inc.php @@ -46,10 +46,10 @@ function wiki_clear_all_cache() system('rm -f '.wiki_work_dir().'/cache_*'); } -function get_perms($n) +function wiki_get_perms($n) { $file = wiki_work_dir().'/'.str_replace('/', '.', $n); - $lines = explode("\n", file_get_contents($file)); + $lines = explode("\n", @file_get_contents($file)); foreach ($lines as $line) { list($k, $v) = explode('=', $line, 2); if ($k == 'platal_perms') { @@ -59,6 +59,36 @@ function get_perms($n) return array('logged', 'admin'); } +function wiki_putfile($f, $s) +{ + $fp = fopen($f, 'w'); + fputs($fp, $s); + fclose($fp); +} + +function wiki_set_perms($n, $pr, $pw) +{ + $file = wiki_work_dir().'/'.str_replace('/', '.', $n); + if (!file_exists($file)) + return false; + + $p = $pr . ':' . $pw; + + $lines = explode("\n", file_get_contents($file)); + foreach ($lines as $i => $line) { + list($k, $v) = explode('=', $line, 2); + if ($k == 'platal_perms') { + $lines[$i] = 'platal_perms='.$p; + wiki_putfile($file, join("\n", $lines)); + return true; + } + } + + array_splice($lines, 1, 0, array('platal_perms='.$p)); + wiki_putfile($file, join("\n", $lines)); + return true; +} + function wiki_may_have_perms($perm) { switch ($perm) { case 'public': return true; diff --git a/templates/wiki.tpl b/templates/wiki.tpl index 0c679a4..0f7a85e 100644 --- a/templates/wiki.tpl +++ b/templates/wiki.tpl @@ -20,12 +20,13 @@ {* *} {**************************************************************************} +{if $canedit || $has_perms}
Voir la page {if $has_perms} - {html_options options=$perms_opts selected=$perms[0]} {/if} @@ -34,7 +35,7 @@ Éditer {if $has_perms} - {html_options options=$perms_opts selected=$perms[1]} {else} @@ -52,5 +53,6 @@ {/if}
+{/if} {$pmwiki|smarty:nodefaults} -- 2.1.4