and now we have a permission system for our Wiki, that is understandable
authorx2000habouzit <x2000habouzit@839d8a87-29fc-0310-9880-83ba4fa771e5>
Sat, 22 Jul 2006 17:05:50 +0000 (17:05 +0000)
committerx2000habouzit <x2000habouzit@839d8a87-29fc-0310-9880-83ba4fa771e5>
Sat, 22 Jul 2006 17:05:50 +0000 (17:05 +0000)
and simple. yay

git-svn-id: svn+ssh://murphy/home/svn/platal/trunk@565 839d8a87-29fc-0310-9880-83ba4fa771e5

htdocs/wiki.php
include/wiki.inc.php
templates/wiki.tpl

index ab25fbc..39bb47a 100644 (file)
@@ -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);
     }
index 7e69dd2..3b441bc 100644 (file)
@@ -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;
index 0c679a4..0f7a85e 100644 (file)
 {*                                                                        *}
 {**************************************************************************}
 
+{if $canedit || $has_perms}
 <table class='wiki' cellspacing='0' cellpadding='0'>
   <tr>
     <td>
       <a href='{$wikipage}'>Voir la page</a>
       {if $has_perms}
-      <select>
+      <select onchange="dynpostkv('{$wikipage}', 'setrperms', this.value)">
       {html_options options=$perms_opts selected=$perms[0]}
       </select>
       {/if}
@@ -34,7 +35,7 @@
     <td>
       <a href='{$wikipage}?action=edit'>Éditer</a>
       {if $has_perms}
-      <select>
+      <select onchange="dynpostkv('{$wikipage}', 'setwperms', this.value)">
       {html_options options=$perms_opts selected=$perms[1]}
       </select>
       {else}
@@ -52,5 +53,6 @@
     {/if}
   </tr>
 </table>
+{/if}
 
 {$pmwiki|smarty:nodefaults}