require_once 'wiki.inc.php';
if ($n = wiki_pagename()) {
- $wiki_template = wiki_work_dir().'/cache_'.$n.'.tpl';
- $tmpfile_exists = file_exists($wiki_template);
+ $wiki_cache = wiki_work_dir().'/cache_'.$n.'.tpl';
+ $cache_exists = file_exists($wiki_cache);
- if (Env::get('action') || !$tmpfile_exists) {
- if ($tmpfile_exists) {
- @unlink($wiki_template);
- }
+ if (Env::get('action') || !$cache_exists) {
+ @unlink($wiki_cache);
// we leave pmwiki do whatever it wants and store everything
ob_start();
}
if (Env::get('action')) {
- // clean old tmp files
- wiki_clean_tmp();
-
- // create new tmp files with editing page from wiki engine
$page->assign('xorg_extra_header', substr($wikiAll, 0, $i));
$wikiAll = substr($wikiAll, $j);
- $wiki_template = wiki_create_tmp($wikiAll);
} else {
- if (!$tmpfile_exists) {
- $f = fopen($wiki_template, 'w');
+ if (!$cache_exists) {
+ $f = fopen($wiki_cache, 'w');
$wikiAll = substr($wikiAll, $j);
fputs($f, $wikiAll);
fclose($f);
} else {
- $wikiAll = file_get_contents($wiki_template);
+ $wikiAll = file_get_contents($wiki_cache);
}
}
}
$page->assign('pmwiki', $wikiAll);
-wiki_assign_auth();
+$page->assign('has_perms', S::has_perms());
$page->addCssLink('css/wiki.css');
$page->run();
function wiki_clear_all_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_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_assign_auth() {
- global $page;
- $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());
+ system('rm -f '.wiki_work_dir().'/cache_*');
}
?>