From 2907d4014c8e6c437e0d9252b6a65dbaedf53212 Mon Sep 17 00:00:00 2001 From: x2001corpet Date: Wed, 28 Dec 2005 08:56:25 +0000 Subject: [PATCH] wiki => smarty git-svn-id: svn+ssh://murphy/home/svn/platal/trunk@179 839d8a87-29fc-0310-9880-83ba4fa771e5 --- Makefile | 7 ++- hooks/wiki.inc.php | 1 + htdocs/css/wiki.css | 11 +++++ htdocs/wiki.php | 96 ++++++++++++++++++++++++++++++++++---- install.d/wiki/empty/empty.tmpl | 1 - plugins/pmwiki.config.php | 4 +- plugins/pmwiki.platalAuth.php | 101 ++++++++++++++++++++++++++++++++++------ plugins/pmwiki.platalSkin.php | 17 ------- 8 files changed, 193 insertions(+), 45 deletions(-) diff --git a/Makefile b/Makefile index 02e5c01..1d5123b 100644 --- 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 diff --git a/hooks/wiki.inc.php b/hooks/wiki.inc.php index de52f3e..3d799c9 100644 --- a/hooks/wiki.inc.php +++ b/hooks/wiki.inc.php @@ -27,6 +27,7 @@ class WikiConfig { var $mwiki_enable = true; var $wikidir = ""; + var $workdir = "wiki.d"; } // }}} diff --git a/htdocs/css/wiki.css b/htdocs/css/wiki.css index 0c63e9a..f298536 100644 --- a/htdocs/css/wiki.css +++ b/htdocs/css/wiki.css @@ -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; } + diff --git a/htdocs/wiki.php b/htdocs/wiki.php index bca07b3..7c5ee5b 100644 --- a/htdocs/wiki.php +++ b/htdocs/wiki.php @@ -20,21 +20,101 @@ ***************************************************************************/ 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, ""); - $j = strpos($wikiAll, "", $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, ""); + $j = strpos($wikiAll, "", $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', "\n"); +assign_auth(); $page->addCssLink('css/wiki.css'); $page->run(); diff --git a/install.d/wiki/empty/empty.tmpl b/install.d/wiki/empty/empty.tmpl index 566059c..51f6f38 100644 --- a/install.d/wiki/empty/empty.tmpl +++ b/install.d/wiki/empty/empty.tmpl @@ -2,5 +2,4 @@ - diff --git a/plugins/pmwiki.config.php b/plugins/pmwiki.config.php index 00b9d9d..3f561c6 100644 --- a/plugins/pmwiki.config.php +++ b/plugins/pmwiki.config.php @@ -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'; diff --git a/plugins/pmwiki.platalAuth.php b/plugins/pmwiki.platalAuth.php index 3d9d94c..cbff96a 100644 --- a/plugins/pmwiki.platalAuth.php +++ b/plugins/pmwiki.platalAuth.php @@ -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'] = + ""; + +// impossible to see the diff without the source because of the smarty tags +$DiffShow['source'] = 'y'; +$DiffSourceFmt = ''; + +$DiffStartFmt = "{literal}
\$DiffTime \$[by] \$DiffAuthor
"; +$DiffEndFmt = "
{/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; } diff --git a/plugins/pmwiki.platalSkin.php b/plugins/pmwiki.platalSkin.php index 7ac74be..963aeba 100644 --- a/plugins/pmwiki.platalSkin.php +++ b/plugins/pmwiki.platalSkin.php @@ -8,27 +8,10 @@ Markup('[[~platal', '<[[~', '/\[\[~([^|\]]*)\|([^\]]*)\]\]/e', 'PreserveText("=", \'$2\', "")'); -// add conditions for request vars -// (:request topic:) then (:if topic top:) will test $_REQUEST['topic'] == 'top' -Markup('requestVars', '\\[\\[#([A-Za-z][-.:\\w]*))\\]\\]/e', "Keep(\"\",'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', '