Triki Wiki / 2020-09-17 15:49:25
The Wiki that you are currently reading is an instance of the Triki Wiki by Tim Reeves (details). Triki Wiki is a nice, simple, elegant, file-based, PHP-implemented Wiki, perfect to run on a A1200. It installed nicely, just unzip its archive and set some parameters in the file config.php. It requires some fine-tuning when installing the FCKEditor v2.6.11 and improving its visual display: all fun in PHP .
There was a strange bug with the uploading-related PHP functions, such as move_upload_file(), which would result into corrupted POST-uploaded files. It turns out that the problem was due to an interaction between thttpd and the IXEmul library v63.1. The problem disappeared when downgrading to v48.3 .
I recently implemented an extension for Triki Wiki, which makes it easy to implement such extensions! , to cache the HTML pages generated from the Wiki pages. This extension greatly speeds up the serving of the pages. Below, I explain my extension, which source code is freely available here.
plugin-db-cache.php
Source Code |
Comments |
require("default-db.php");
function isNodeInCache($title) {
global $nodedir;
// blacklist the title
if (blacklistTitle($title)) {
return false;
}
$wikiFile = $nodedir.$title.".wiki";
$cacheFile = $nodedir.$title.".cache";
if (file_exists($wikiFile) &&
file_exists($cacheFile) &&
filemtime($wikiFile) < filemtime($cacheFile)) {
return TRUE;
}
return FALSE;
}
function saveNodeContentsInCache($title, $node) {
global $nodedir;
// open the file
$file = fopen($nodedir.$title.".cache", "w");
if ($file === false) return false;
// and lock it
flock($file, LOCK_EX);
// write content
fwrite($file, $node);
// finish
flock($file, LOCK_UN);
}
function getNodeContentsFromCache($title) {
global $nodedir;
if (!isNodeInCache($title)) return false;
// open the file
$file = fopen($nodedir.$title.".cache", "r");
if ($file === false) return false;
// and lock it
flock($file, LOCK_SH);
// read content
$html = fread($file, 65535);
$html = rtrim($html);
// finish
flock($file, LOCK_UN);
fclose($file);
return $html;
} |
This method is used in parse.php to check whether a cached HTML file exists or not when a Wiki page is requested.
This function saved the HTML generated by Triki Wiki when parsing a Wiki page.
This function returns the content of the HTML cache file when it exists.
|
|