From 3b962ded10f0e2c0a018c8887c5bdb78bff05641 Mon Sep 17 00:00:00 2001 From: x2003bruneau Date: Mon, 22 Jan 2007 11:31:32 +0000 Subject: [PATCH] Fix encoding issues in wiki page names Generate cache even if the user has not the rigths to see the page (fix wiki_requirepage) git-svn-id: svn+ssh://murphy/home/svn/platal/trunk@1383 839d8a87-29fc-0310-9880-83ba4fa771e5 --- htdocs/xnet.php | 30 +++++++++++++++--------------- htdocs/xorg.php | 42 ++++++++++++++++++++++-------------------- include/wiki.inc.php | 21 ++++++++++++++++----- 3 files changed, 53 insertions(+), 40 deletions(-) diff --git a/htdocs/xnet.php b/htdocs/xnet.php index 410bfe4..1f206a5 100644 --- a/htdocs/xnet.php +++ b/htdocs/xnet.php @@ -42,20 +42,6 @@ if (!$n) { new_skinned_page('core/wiki.tpl'); $perms = wiki_get_perms($n); -switch (Env::v('action')) { - case '': case 'search': - wiki_apply_perms($perms[0]); - break; - - case 'edit': - wiki_apply_perms($perms[1]); - break; - - default: - wiki_apply_perms('admin'); - break; -} - if ($p = Post::v('setrperms')) { wiki_apply_perms('admin'); if (wiki_set_perms($n, $p, $perms[1])) { @@ -72,7 +58,7 @@ if ($p = Post::v('setwperms')) { } } -$wiki_cache = wiki_work_dir().'/cache_'.$n.'.tpl'; +$wiki_cache = wiki_work_dir().'/cache_'.wiki_filename($n).'.tpl'; $cache_exists = file_exists($wiki_cache); if (Env::v('action') || !$cache_exists) { @@ -100,6 +86,20 @@ if (Env::v('action')) { } } +switch (Env::v('action')) { + case '': case 'search': + wiki_apply_perms($perms[0]); + break; + + case 'edit': + wiki_apply_perms($perms[1]); + break; + + default: + wiki_apply_perms('admin'); + break; +} + $page->assign('perms', $perms); $page->assign('perms_opts', wiki_perms_options()); diff --git a/htdocs/xorg.php b/htdocs/xorg.php index 9a40d01..a048312 100644 --- a/htdocs/xorg.php +++ b/htdocs/xorg.php @@ -38,7 +38,7 @@ if (!($path = Env::v('n')) || ($path{0} < 'A' || $path{0} > 'Z')) { require_once 'wiki.inc.php'; -$n = wiki_pagename(); +$n = wiki_pagename(); if (!$n) { pl_redirect(''); } @@ -46,24 +46,6 @@ if (!$n) { new_skinned_page('core/wiki.tpl'); $perms = wiki_get_perms($n); -if (Env::v('display') == 'light') { - $page->assign('simple', true); -} - -switch (Env::v('action')) { - case '': case 'search': - wiki_apply_perms($perms[0]); - break; - - case 'edit': - wiki_apply_perms($perms[1]); - break; - - default: - wiki_apply_perms('admin'); - break; -} - if ($p = Post::v('setrperms')) { wiki_apply_perms('admin'); if (wiki_set_perms($n, $p, $perms[1])) { @@ -80,7 +62,8 @@ if ($p = Post::v('setwperms')) { } } -$wiki_cache = wiki_work_dir().'/cache_'.$n.'.tpl'; +// Generate cache even if we don't have access rights +$wiki_cache = wiki_work_dir().'/cache_'.wiki_filename($n).'.tpl'; $cache_exists = file_exists($wiki_cache); if (Env::v('action') || !$cache_exists) { @@ -108,6 +91,25 @@ if (Env::v('action')) { } } +// Check user perms +switch (Env::v('action')) { + case '': case 'search': + wiki_apply_perms($perms[0]); + break; + + case 'edit': + wiki_apply_perms($perms[1]); + break; + + default: + wiki_apply_perms('admin'); + break; +} + +if (Env::v('display') == 'light') { + $page->assign('simple', true); +} + $page->assign('perms', $perms); $page->assign('perms_opts', wiki_perms_options()); diff --git a/include/wiki.inc.php b/include/wiki.inc.php index 838693e..6ab71a4 100644 --- a/include/wiki.inc.php +++ b/include/wiki.inc.php @@ -19,7 +19,8 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ***************************************************************************/ -function wiki_pagename() { +function wiki_pagename() +{ if (!Get::v('n')) { return null; } @@ -36,7 +37,16 @@ function wiki_pagename() { 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'; } @@ -53,7 +63,7 @@ function wiki_perms_options() { function wiki_get_perms($n) { - $file = wiki_work_dir().'/'.str_replace('/', '.', $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); @@ -73,9 +83,10 @@ function wiki_putfile($f, $s) function wiki_set_perms($n, $pr, $pw) { - $file = wiki_work_dir().'/'.str_replace('/', '.', $n); - if (!file_exists($file)) + $file = wiki_work_dir().'/'.wiki_filename(str_replace('/', '.', $n)); + if (!file_exists($file)) { return false; + } $p = $pr . ':' . $pw; -- 2.1.4