wiki => smarty
authorx2001corpet <x2001corpet@839d8a87-29fc-0310-9880-83ba4fa771e5>
Wed, 28 Dec 2005 08:56:25 +0000 (08:56 +0000)
committerx2001corpet <x2001corpet@839d8a87-29fc-0310-9880-83ba4fa771e5>
Wed, 28 Dec 2005 08:56:25 +0000 (08:56 +0000)
git-svn-id: svn+ssh://murphy/home/svn/platal/trunk@179 839d8a87-29fc-0310-9880-83ba4fa771e5

Makefile
hooks/wiki.inc.php
htdocs/css/wiki.css
htdocs/wiki.php
install.d/wiki/empty/empty.tmpl
plugins/pmwiki.config.php
plugins/pmwiki.platalAuth.php
plugins/pmwiki.platalSkin.php

index 02e5c01..1d5123b 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -65,10 +65,9 @@ wiki/pub/skins/empty:
 get-wiki:
        @if ! test -d wiki; then                                          \
            wget http://www.pmwiki.org/pub/pmwiki/pmwiki-latest.tgz;      \
-           echo "¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯"; \
-           echo "now please untar pmwiki into wiki/ and run make again"; \
-           echo "_____________________________________________________"; \
-           exit 1;                                                       \
+           tar -xzvf pmwiki-latest.tgz;                                  \
+           rm pmwiki-latest.tgz;                                         \
+           mv pmwiki-* wiki;                                             \
        fi
 
 build-wiki: wiki/local/farmconfig.php wiki/pub/skins/empty spool/wiki.d
index de52f3e..3d799c9 100644 (file)
@@ -27,6 +27,7 @@ class WikiConfig
 {
     var $mwiki_enable   = true;
     var $wikidir       = "";
+    var $workdir        = "wiki.d";
 }
 
 // }}}
index 0c63e9a..f298536 100644 (file)
@@ -22,3 +22,14 @@ table.quickref td    {
     border-top: 1px dotted #aaaaaa;
 }
 
+#text { width:800px; }
+.diffbox { border:1px #999999 solid; margin-top:1.33em; }
+.diffauthor { font-weight:bold; }
+.diffchangesum { font-weight:bold; }
+.difftime { font-family:verdana,sans-serif; font-size:66%; background-color:#dddddd; }
+.difftype { clear:both; font-family:verdana,sans-serif; font-size:66%; font-weight:bold; }
+.diffadd { border-left:5px #99ff99 solid; padding-left:5px; }
+.diffdel { border-left:5px #ffff99 solid; padding-left:5px; }
+.diffrestore { clear:both; font-family:verdana,sans-serif; font-size:66%; margin:1.5em 0px; }
+a.varlink { text-decoration:none; }
+    
index bca07b3..7c5ee5b 100644 (file)
  ***************************************************************************/
 
 require_once("xorg.inc.php");
+
+// this page is to create a smarty template page from a wiki file
+// the wiki engine used is pmwiki.
+// the templates created are stored in wiki.d/cache_wikiword.tpl
+
+// some page can be seen by everybody (public), but to validate a password
+// if we arrive here before setting new access we need to try an auth
 new_skinned_page('wiki.tpl', Env::has('response') ? AUTH_MDP : AUTH_PUBLIC);
 
+function assign_auth()
+{
+    global $page;
+    $page->assign('logged', logged());
+    $page->assign('identified', identified());
+    $page->assign('has_perms', has_perms());
+    $page->assign('public', true);
+    $page->assign('wiki_admin', has_perms() && identified());
+}
+
 if ($globals->wiki->wikidir) {
-    ob_start();
-    require_once(dirname(dirname(__FILE__)).'/'.$globals->wiki->wikidir.'/pmwiki.php');
+       // the wiki keword is given in the n var
+       if ($n = Env::get('n', false))
+       {
+         // Get the correcti wiki keywords
+         $n = str_replace('/', '.', $n);
+         $keywords = explode('.', $n);
+         $count = count($keywords);
+         if ($count == 1)
+           $n = $keywords[0].".".$keywords[0];
+         else
+           $n = $keywords[$count - 2].".".$keywords[$count - 1];
+         if (($urln = str_replace('.', '/', $n)) != Env::get('n') &&
+               $n != Env::get('n'))
+         {
+           header("Location: ".$globals->baseurl.'/'.$urln);
+           die();
+         }
+         $_REQUEST['n'] = $n;
+           
+         $dir_wiki_tmp = '../spool/wiki.d/';
+         $short_tpl = $dir_wiki_tmp.'cache_'.$n.'.tpl';
+         $dir_tpl = $globals->spoolroot.'templates/'.$dir_wiki_tmp;
+         $tpl = $globals->spoolroot.'templates/'.$short_tpl;
+         $tmpfile_exists = file_exists($tpl);
 
-    $wikiAll = ob_get_clean();
-    $i = strpos($wikiAll, "<!--/HeaderText-->");
-    $j = strpos($wikiAll, "<!--/PageLeftFmt-->", $i);
+         // don't recreate the tpl if it already exists
+         if (Env::get('action') || !$tmpfile_exists)
+         {
+           // we leave pmwiki do whatever it wants and store everything
+           ob_start();
+           require_once(dirname(dirname(__FILE__)).'/'.$globals->wiki->wikidir.'/pmwiki.php');
 
-    $page->assign('xorg_extra_header', substr($wikiAll, 0, $i));
-    $page->assign('menu-pmwiki', substr($wikiAll, $i, $j-$i));
-    $page->assign('pmwiki', substr($wikiAll, $j));
+           $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'))
+         {
+           // clean old tmp files (more than one hour)
+           $dh = opendir($dir_wiki_tmp);
+           $time = time();
+           while (($file = readdir($dh)) !== false)
+           {
+             if (strpos($file, 'temp_') === 0)
+             {
+               $created = filectime($dir_wiki_tmp.$file);
+               if ($time-$created > 60 * 60)
+                 unlink($dir_wiki_tmp.$file);
+             }
+           }
+         
+           $page->assign('xorg_extra_header', substr($wikiAll, 0, $i));
+           $tmp_tpl = tempnam($dir_tpl, "temp_");
+           $f = fopen($tmp_tpl, 'w');
+           fputs($f, substr($wikiAll, $j));
+           fclose($f);
+           new_skinned_page($tmp_tpl, AUTH_PUBLIC);
+           if ($tmpfile_exists)
+             unlink($tpl);
+         } else {
+           if (!$tmpfile_exists)
+           {
+               $f = fopen($tpl, 'w');
+               fputs($f, substr($wikiAll, $j));
+               fclose($f);
+           }
+           new_skinned_page($short_tpl, AUTH_PUBLIC);
+         } 
+       }
 }
 
+$page->assign('xorg_extra_header', "<script type='text/JavaScript'>\n<!--\nNix={map:null,convert:function(a){Nix.init();var s='';for(i=0;i<a.length;i++){var b=a.charAt(i);s+=((b>='A'&&b<='Z')||(b>='a'&&b<='z')?Nix.map[b]:b);}return s;},init:function(){if(Nix.map!=null)return;var map=new Array();var s='abcdefghijklmnopqrstuvwxyz';for(i=0;i<s.length;i++)map[s.charAt(i)]=s.charAt((i+13)%26);for(i=0;i<s.length;i++)map[s.charAt(i).toUpperCase()]=s.charAt((i+13)%26).toUpperCase();Nix.map=map;},decode:function(a){document.write(Nix.convert(a));}}\n//-->\n</script>\n");
+assign_auth();
 $page->addCssLink('css/wiki.css');
 
 $page->run();
index 566059c..51f6f38 100644 (file)
@@ -2,5 +2,4 @@
 <!--/HeaderText-->
 <!--PageLeftFmt-->
 <!--/PageLeftFmt-->
-<!--wiki: $SiteGroup.PageActions -->
 <!--PageText-->
index 00b9d9d..3f561c6 100644 (file)
@@ -2,8 +2,8 @@
 
 $ScriptUrl       = $globals->baseurl;
 $UploadUrlFmt    = $ScriptUrl."/uploads";
-$WorkDir         = '../spool/wiki.d';
-$WikiDir         = new PageStore('$FarmD/../spool/wiki.d/$FullName');
+$WorkDir         = $globals->wiki->workdir;
+$WikiDir         = new PageStore('$FarmD/'.$WorkDir.'/$FullName');
 $PubDirUrl       = $globals->baseurl.'/wiki';
 $InterMapFiles[] = $globals->spoolroot.'plugins/pmwiki.intermap.txt';
 
index 3d9d94c..cbff96a 100644 (file)
@@ -8,12 +8,32 @@ $Conditions['has_perms']   = has_perms();
 $Conditions['public']      = 'true';
 $Conditions['only_public'] = !identified();
 
-function authPerms($pagename, $key, $could=false)
+$HandleAuth['diff'] = 'edit';
+$HandleAuth['source'] = 'edit';
+
+$InputTags['e_textarea'][':html'] =
+ "<textarea \$InputFormArgs 
+    onkeydown='if (event.keyCode==27) event.returnValue=false;' 
+    >{literal}\$EditText{/literal}</textarea>";
+
+// impossible to see the diff without the source because of the smarty tags
+$DiffShow['source'] = 'y';
+$DiffSourceFmt = '';
+
+$DiffStartFmt = "{literal}<div class='diffbox'><div class='difftime'>\$DiffTime \$[by] <span class='diffauthor' title='\$DiffHost'>\$DiffAuthor</span></div>";
+$DiffEndFmt = "</div>{/literal}";
+
+// compute permissions based on the permission string (key)
+// if could is true, compute permission that could be enabled with a mdp
+// if smarty is true, return a string to insert in a smarty if tag
+// otherwise return true or false
+function authPerms($pagename, $key, $could=false, $smarty=false)
 {
     $words = explode(' ', $key);
-    $auth  = false;
+    $auth  = $smarty?"":false;
     $and   = false;
     foreach ($words as $word) {
+       if (strpos($word, '@') === 0) $word = substr($word,1);
         $iauth = false;
         if ($word == 'and:') {
             $and = true;
@@ -25,17 +45,43 @@ function authPerms($pagename, $key, $could=false)
         if ($cond == 'identified' && $could) {
             $cond = 'logged';
         }
-        $iauth = CondText($pagename, 'if '.$cond.' '.$param, true);
+       if ($smarty)
+          $iauth = '$'.$cond.($param?(' eq "'.$param.'"'):'');
+       else
+       {
+          if (strpos($cond, "smarty.") === 0)
+          {
+             $vars = explode('.', $cond);
+             $iauth = false;
+             switch ($vars[1])
+             {
+               case 'session':$iauth = Session::get($vars[2]) == $param; break;
+               case 'request':$iauth = Env::get($vars[2]) == $param; break;
+             }
+          }
+           else $iauth = CondText($pagename, 'if '.$cond.' '.$param, true);
+       }
+
         if ($and) {
-            $auth &= $iauth;
+           if ($smarty)
+             $auth = ($auth?"($auth) and ":"").$iauth;
+           else
+              $auth &= $iauth;
         } else {
-            $auth |= $iauth;
+           if ($smarty)
+             $auth = ($auth?"($auth) or ":"").$iauth;
+           else
+              $auth |= $iauth;
         }
         $and = false;
     }
+    if ($smarty)
+       $auth = "($auth) or \$wiki_admin";
     return $auth;
 }
 
+// try to find the best permission for a given page and a given level of auth
+// in order: page > group > site
 function TryAllAuths($pagename, $level, $page_read, $group_read)
 {
     global $DefaultPasswords;
@@ -51,6 +97,15 @@ function TryAllAuths($pagename, $level, $page_read, $group_read)
     return array('none', '');
 }
 
+function auth_pmwiki_to_smarty($text, $pass)
+{
+    $ifc = authPerms("", $pass, false, true);
+    if (!$ifc) return "";
+    return "{if $ifc}\n".$text."{/if}";
+}
+
+// for read pages: will come only once so we have to be careful
+// and translate any auth from the wiki to smarty auth
 function AuthPlatal($pagename, $level, $authprompt, $since)
 {
     global $Conditions;
@@ -70,20 +125,39 @@ function AuthPlatal($pagename, $level, $authprompt, $since)
         $pwsources[$l] = $from;
     }
 
-    if (!isset($Conditions['canedit'])) {
-        $Conditions['canedit'] = authPerms($pagename, $passwds['edit'], true);
-    }
-    if (!isset($Conditions['canattr'])) {
-        $Conditions['canattr'] = authPerms($pagename, $passwds['attr'], true);
-    }
-
-    if (authPerms($pagename, $passwds[$level]))
+    $canedit = authPerms($pagename, $passwds['edit'], true, true);
+    $canattr = authPerms($pagename, $passwds['attr'], true, true);
+    $panel  = "{if ($canedit) or ($canattr)}\n";
+    $panel .= ">>frame<<\n";
+    $panel .= "[[{\$FullName} |Voir la page]]\\\\\n";
+    $panel .= "{if ($canedit)}\n";
+    $panel .= "[[{\$FullName}?action=edit |Editer]]\\\\\n";
+    $panel .= "[[{\$FullName}?action=diff |Historique]]\\\\\n";
+    $panel .= "[[{\$FullName}?action=upload |Upload]]\\\\\n";
+    $panel .= "{/if}{if ($canattr)}\n";
+    $panel .= "[[{\$FullName}?action=attr |Droits]]\\\\\n";
+    $panel .= "[[{\$Group}/GroupAttributes?action=attr|Droits du groupe]]\\\\\n";
+    $panel .= "{/if}\n";
+    $panel .= ">><<\n";
+    $panel .= "{/if}\n";
+  
+    if (((identifed() && has_perms()) || authPerms($pagename, $passwds[$level]))
     {
         $page_read['=passwd'] = $passwds;
         $page_read['=pwsource'] = $pwsources;
+       // if try to read, add the permission limitation as a smarty if tag
+       if ($level == 'read')
+       {
+         $page_read['text'] = auth_pmwiki_to_smarty($page_read['text'], $passwds['read']);
+         $page_read['text'] = $panel.$page_read['text'];
+       }
+//     print_r($page_read); die();
         return $page_read;
     }
 
+    // if we arrive here, the user doesn't have enough permission to access page
+
+    // maybe it is because he is not identified
     if ($authprompt && !identified())
     {
         new_skinned_page('wiki.tpl', AUTH_MDP); 
@@ -96,6 +170,7 @@ function AuthPlatal($pagename, $level, $authprompt, $since)
     } else {
         $page->trig("Tu n'as pas le droit d'accéder à ce service");
     }
+    $page->run();
     // don't return false or pmwiki will send an exit breaking smarty page
     return 1;
 }
index 7ac74be..963aeba 100644 (file)
@@ -8,27 +8,10 @@ Markup('[[~platal', '<[[~', '/\[\[~([^|\]]*)\|([^\]]*)\]\]/e',
     'PreserveText("=", \'<a href="'.$globals->baseurl
     .'/fiche.php?user=$1" class="popup2">$2</a>\', "")');
 
-// add conditions for request vars
-// (:request topic:) then (:if topic top:) will test $_REQUEST['topic'] == 'top'
-Markup('requestVars', '<if', '/\(:request ([a-z_]+)( ([a-z_]+))?:\)/ie', 'RequestToCond("$1", "$3")');
-
 ## [[#anchor]] in standard XHTML
 Markup('[[#','<[[','/(?>\\[\\[#([A-Za-z][-.:\\w]*))\\]\\]/e',
   "Keep(\"<a id='$1'></a>\",'L')");
   
-function RequestToCond($var, $default)
-{
-    global $Conditions;
-    $Conditions[$var] = '(!$condparm && !isset($_REQUEST["'.$var
-        .'"])) || $_REQUEST["'.$var.'"]==$condparm';
-    if ($default) {
-        $Conditions[$var] .= ' || "'.$default.'" == $_REQUEST["'.$var.'"]';
-    }
-}
-
-// add access to session vars
-Markup('sessionvars', 'inline', '/\(:session ([a-z_]+):\)/ie', 'Session::get("$1")');
-
 Markup('tablebicol', '<block', '/\(:tablebicol ?([a-z_]+)?:\)/e', 'doBicol("$1")');
 Markup('pairrows', '_end', '/class=\'pair\_pmwiki\_([0-9]+)\'/e', 
     "($1 == 1)?'':('class=\"'.(($1 % 2 == 0)?'impair':'pair').'\"')");