fce088c1 |
1 | <?php |
2 | /*************************************************************************** |
3 | * Copyright (C) 2003-2007 Polytechnique.org * |
4 | * http://opensource.polytechnique.org/ * |
5 | * * |
6 | * This program is free software; you can redistribute it and/or modify * |
7 | * it under the terms of the GNU General Public License as published by * |
8 | * the Free Software Foundation; either version 2 of the License, or * |
9 | * (at your option) any later version. * |
10 | * * |
11 | * This program is distributed in the hope that it will be useful, * |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
14 | * GNU General Public License for more details. * |
15 | * * |
16 | * You should have received a copy of the GNU General Public License * |
17 | * along with this program; if not, write to the Free Software * |
18 | * Foundation, Inc., * |
19 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * |
20 | ***************************************************************************/ |
21 | |
22 | require_once 'wiki.inc.php'; |
23 | |
24 | $n = wiki_pagename(); |
25 | if (!$n) { |
26 | pl_redirect(''); |
27 | } |
28 | |
29 | new_skinned_page('core/wiki.tpl'); |
30 | $perms = wiki_get_perms($n); |
31 | |
32 | // Check user perms |
33 | switch (Env::v('action')) { |
34 | case '': case 'search': |
35 | break; |
36 | |
37 | case 'edit': |
38 | wiki_apply_perms($perms[1]); |
39 | break; |
40 | |
41 | default: |
42 | wiki_apply_perms('admin'); |
43 | break; |
44 | } |
45 | |
46 | if ($p = Post::v('setrperms')) { |
47 | wiki_apply_perms('admin'); |
48 | if (wiki_set_perms($n, $p, $perms[1])) { |
49 | $perms = wiki_get_perms($n); |
a7de4ef7 |
50 | $page->trig('Permissions mises à jour'); |
fce088c1 |
51 | } |
52 | } |
53 | |
54 | if ($p = Post::v('setwperms')) { |
55 | wiki_apply_perms('admin'); |
56 | if (wiki_set_perms($n, $perms[0], $p)) { |
57 | $perms = wiki_get_perms($n); |
a7de4ef7 |
58 | $page->trig('Permissions mises à jour'); |
fce088c1 |
59 | } |
60 | } |
61 | |
62 | // Generate cache even if we don't have access rights |
63 | $wiki_cache = wiki_work_dir().'/cache_'.wiki_filename($n).'.tpl'; |
64 | $cache_exists = file_exists($wiki_cache); |
65 | |
66 | if (Env::v('action') || !$cache_exists) { |
3da341b6 |
67 | if ($cache_exists) { |
68 | unlink($wiki_cache); |
c77fed74 |
69 | $files = glob($globals->spoolroot . '/spool/templates_c/*cache_' . wiki_filename($n) . '.tpl*'); |
70 | foreach ($files as $file) { |
71 | unlink($file); |
72 | } |
3da341b6 |
73 | } |
fce088c1 |
74 | |
75 | // we leave pmwiki do whatever it wants and store everything |
76 | ob_start(); |
77 | require_once($globals->spoolroot.'/wiki/pmwiki.php'); |
78 | |
79 | $wikiAll = ob_get_clean(); |
80 | // the pmwiki skin we are using (almost empty) has these keywords: |
81 | $i = strpos($wikiAll, "<!--/HeaderText-->"); |
82 | $j = strpos($wikiAll, "<!--/PageLeftFmt-->", $i); |
83 | } |
84 | |
3da341b6 |
85 | $wiki_exists = file_exists(wiki_work_dir() . '/' . wiki_filename($n)); |
86 | |
fce088c1 |
87 | if (Env::v('action')) { |
88 | $page->assign('xorg_extra_header', substr($wikiAll, 0, $i)); |
89 | $wikiAll = substr($wikiAll, $j); |
90 | } else { |
3da341b6 |
91 | if (!$cache_exists && $wiki_exists) { |
fce088c1 |
92 | $wikiAll = substr($wikiAll, $j); |
93 | wiki_putfile($wiki_cache, $wikiAll); |
3da341b6 |
94 | } elseif ($cache_exists) { |
fce088c1 |
95 | $wikiAll = file_get_contents($wiki_cache); |
3da341b6 |
96 | } elseif (S::has_perms()) { |
97 | $wikiAll = "<p>La page de wiki $n n'existe pas. " |
a7de4ef7 |
98 | . "Il te suffit de <a href='" . str_replace('.', '/', $n) . "?action=edit'>l'éditer</a></p>"; |
3da341b6 |
99 | } else { |
100 | $page->changeTpl('core/404.tpl'); |
fce088c1 |
101 | } |
102 | } |
103 | |
104 | // Check user perms |
105 | wiki_apply_perms($perms[0]); |
106 | |
107 | $page->assign('perms', $perms); |
108 | $page->assign('perms_opts', wiki_perms_options()); |
109 | |
110 | $page->assign('canedit', wiki_may_have_perms($perms[1])); |
111 | $page->assign('has_perms', wiki_may_have_perms('admin')); |
112 | |
113 | $page->assign('wikipage', str_replace('.', '/', $n)); |
3da341b6 |
114 | if ($perms[1] == 'admin' && !Env::v('action') && $wiki_exists) { |
fce088c1 |
115 | $page->assign('pmwiki_cache', $wiki_cache); |
116 | } else { |
117 | $page->assign('pmwiki', $wikiAll); |
118 | $page->assign('text', true); |
119 | } |
120 | $page->addCssLink('wiki.css'); |
121 | $page->addJsLink('wiki.js'); |
122 | |
123 | $page->run(); |
124 | |
a7de4ef7 |
125 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: |
fce088c1 |
126 | ?> |