X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=include%2Fwiki.inc.php;h=1a5717e8cddbd138a5f97d36102022fcce3a55d6;hb=493b6abebf3d6c35691f66fd1bfdc063efaab576;hp=dbb7810fba128e492bb3acfe3ec0ea6b8d54cdc7;hpb=06a5e65b3b7109cee962cdf323660ab8086b5b89;p=platal.git diff --git a/include/wiki.inc.php b/include/wiki.inc.php index dbb7810..1a5717e 100644 --- a/include/wiki.inc.php +++ b/include/wiki.inc.php @@ -1,6 +1,6 @@ baseurl.'/'.$a.'/'.$b); + pl_redirect($a.'/'.$b); } -function wiki_work_dir() { +function wiki_filename($s) +{ + if (@iconv('utf-8', 'utf-8', $s) == $s) { + return utf8_decode($s); + } + return $s; +} + +function wiki_work_dir() +{ global $globals; return $globals->spoolroot.'/spool/wiki.d'; } function wiki_clear_all_cache() { - system("rm -f ".wiki_work_dir()."/cache_*"); + system('rm -f '.wiki_work_dir().'/cache_*'); } -// editing pages are not static but used templates too, so we used -// temp template files containing result from wiki -function wiki_create_tmp($content) { - $tmpfile = tempnam(wiki_work_dir(), "temp_"); - $f = fopen($tmpfile, 'w'); - fputs($f, $content); - fclose($f); - return $tmpfile; +function wiki_perms_options() { + return array('public' => 'Public', 'logged' => 'Connecté', + 'mdp' => 'Authentifié', 'admin' => 'Admin'); } -function wiki_clean_tmp() { - // clean old tmp files (more than one hour) - $wiki_work_dir = wiki_work_dir(); - $dh = opendir(wiki_work_dir()); - $time = time(); - while (($file = readdir($dh)) !== false) { - if (strpos($file, 'temp_') === 0) { - $created = filectime($wiki_work_dir.'/'.$file); - if ($time-$created > 60 * 60) - @unlink($wiki_work_dir.'/'.$file); +function wiki_get_perms($n) +{ + $file = wiki_work_dir().'/'.wiki_filename(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_assign_auth() { - global $page, $wiki_auths; - $page->assign('true', true); - $page->assign('public', true); - $page->assign('logged', S::logged()); - $page->assign('identified', S::identified()); - $page->assign('has_perms', S::has_perms()); +function wiki_putfile($f, $s) +{ + $fp = fopen($f, 'w'); + fputs($fp, $s); + fclose($fp); } -// cannot be in a function because pmwiki use all vars as if it was globals -if ($n = wiki_pagename()) { - $wiki_template = wiki_work_dir().'/cache_'.$n.'.tpl'; - $tmpfile_exists = file_exists($wiki_template); +function wiki_set_perms($n, $pr, $pw) +{ + $file = wiki_work_dir().'/'.wiki_filename(str_replace('/', '.', $n)); + if (!file_exists($file)) { + return false; + } + + $p = $pr . ':' . $pw; - if (Env::get('action') || !$tmpfile_exists) { - if ($tmpfile_exists) { - @unlink($wiki_template); - $page->clear_compiled_tpl($wiki_template); + $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; } + } - // we leave pmwiki do whatever it wants and store everything - ob_start(); - require_once($globals->spoolroot.'/wiki/pmwiki.php'); + array_splice($lines, 1, 0, array('platal_perms='.$p)); + wiki_putfile($file, join("\n", $lines)); + return true; +} - $wikiAll = ob_get_clean(); - // the pmwiki skin we are using (almost empty) has these keywords: - $i = strpos($wikiAll, ""); - $j = strpos($wikiAll, "", $i); +function wiki_may_have_perms($perm) { + switch ($perm) { + case 'public': return true; + case 'logged': return S::logged(); + case 'mdp': return S::logged(); + default: return S::has_perms(); } +} + +function wiki_apply_perms($perm) { + global $page, $platal, $globals; + + switch ($perm) { + case 'public': + return; + + case 'logged': + if (!call_user_func(array($globals->session, 'doAuthCookie'))) { + $platal = empty($GLOBALS['IS_XNET_SITE']) ? new Platal() : new Xnet(); + $platal->force_login($page); + } + return; - if (Env::get('action')) { - // clean old tmp files - wiki_clean_tmp(); - $page->assign('xorg_extra_header', substr($wikiAll, 0, $i)); - - // create new tmp files with editing page from wiki engine - $wiki_template = wiki_create_tmp(substr($wikiAll, $j)); - } else { - if (!$tmpfile_exists) { - $f = fopen($wiki_template, 'w'); - fputs($f, substr($wikiAll, $j)); - fclose($f); + default: + if (!call_user_func(array($globals->session, 'doAuth'))) { + $platal = empty($GLOBALS['IS_XNET_SITE']) ? new Platal() : new Xnet(); + $platal->force_login($page); } + if ($perm == 'admin') { + check_perms(); + } + return; } } + +function wiki_require_page($pagename) +{ + global $globals; + $pagename_slashes = str_replace('.','/',$pagename); + $pagename_dots = str_replace('/','.',$pagename); + if (is_file(wiki_work_dir().'/cache_'.$pagename_dots.'.tpl')) return; + system('wget '.$globals->baseurl.'/'.$pagename_slashes.' -O /dev/null'); +} + +// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: ?>