Here is the Chalisque network wiki source in all its glory!

w.css

html { background-color: white; }
* { font-family: inherit; }
body { 
  font-family: "Palatino", "URW Palladio", "TexGyrePagella", serif; 
  font-size: 12pt;
}
blockquote{
	line-height: 1.1em;
}
body {
  margin: 12px; padding: 12px;
}
span.extwiki {
  color: #292;
  font-size: 0.7em;
}
pre.fbox {
  font-family: "Courier New", monospace;
  white-space: pre-wrap;
  padding: 0.5em;
  padding-left: 2em;
  overflow: wrap;
  color: black;
}
pre.box {
  white-space: pre-wrap;
  padding: 0.5em;
  padding-left: 2em;
  overflow: wrap;
  color: black;
}
pre.cbox {
  font-family: "Courier New", monospace;
  white-space: pre-wrap;
  padding: 0.5em;
  overflow: wrap;
  background-color: #ffd;
  color: black;
  border: 1px solid black;
  border-right-width: 2px;
  border-bottom-width: 2px;
  box-shadow: 7px 4px 11px #272727;
}
pre.pobox {
  white-space: pre-wrap;
  padding: 0.2em;
  padding-left: 2em;
  overflow: wrap;
  line-height: 1.5em;
}
pre.cpobox {
  white-space: pre-wrap;
  padding: 0.2em;
  overflow: wrap;
  line-height: 1.5em;
  text-align: center;
}
div.prbox {
  padding: 0.5em;
  overflow: wrap;
  line-height: 1.1em;
}
textarea {
  font-family: "Courier New", fixed;
  font-size: 12pt;
}
a { Color: #006699; }
a:visited { Color: #990066; }
h1, h2, h3, h4, h5, h6 { font-weight: bold; }
h1 { Font-size: 1.6em; }
h2 { Font-size: 1.5em; }
h3 { Font-size: 1.4em; }
h4 { Font-size: 1.3em; }
h5 { Font-size: 1.2em; }
h6 { Font-size: 1.1em; }

div.main {
	Position: relative;
	Padding-top: 4em;
}
div.header{
	position: relative;
}

div#gotobar {
	Position: absolute;
	width: 100%;
	Top: 0; Left: 0;
	padding-top: 1em;
	padding-bottom: 0.7em;
	border-bottom: 1px solid black;
}
div#gotobar ul {
	List-style: none;
	Margin: 0; Padding: 0;
}
div#gotobar li { Float: left; Margin-right: 1ex; }
div#gotobar a { Display: block; }
div#gotobar span {
	position: absolute;
	top: 0em;
	padding-left: 2em;
}

div#actionbar { padding-top: 0.3em; line-height: 1.5em; }
div#actionbar div { Float: right; }

div.article table { Margin: 1em auto; }
div.article th, div.article td {
	Margin: 0; Padding: 0.5em;
	Border: 1px solid #808080;
	Border-collapse: collapse;
}
div.article th {
	Color: #ffffff;
	Background-color: #808080;
}
div.article hr { Color: #808080; }

div.footer {
	Margin-top: 1em;
	Border-top: 1px solid black;
}

a.rss {
	Background-color: orange;
	Color: white;
	Font-size: 0.7em;
	Font-weight: bold;
	Text-decoration: none;
	Padding: 0.15em;
	Border-radius: 0.15em;
}
.ky {
	visibility: hidden;
	width: 0px;
	margin-right: -0.8ex;
	position: relative;
	bottom: 0.5em;
	color: black;
	font-size: 0.8em;
}
span#ckmsg {
	font-style: italic;
}
a.hid { color: inherit; text-decoration: none; }
a.hid:followed { color: inherit; text-decoration: none; }
code {
  background-color: #ddb;
  font-family: "Courier New", "Courier", "Droid Sans Mono", monospace;
}
a {
	text-decoration: none;
}
a:hover {
	text-decoration: underline;
}
#linkhelp {
position: absolute;
background-color: #eec;
}

w.js

// This was written years ago, is cryptic, and needs
// a rewrite into modern Javascript with modern browser
// facilities. One of these days I'll get round to it,
// but as it is, it works for its intended function.
function db(x) {
document.querySelector("h1").innerHTML=x;
}
function lh(x) {
var a = document.getElementById("linkhelp");
var y = window.scrollY;
a.innerHTML = x;
a.style.top = y+"px";
}
var kh = {
  es: false,
  q: null,
  u: null,
  v: 0,
  a: function(o,a,b) { //utility1
    o.addEventListener(a,b); //W3C
  },
  c: null,
  z: function(a,b) {
    kh.a(window,a,b);
  },
  b: "http://thewikiman.allsup.co/",
  d: function(c) { //domfetch macro
    return kh.e("key"+c);
  },
  e: function(c) { //domfetch
    return document.getElementById(c);
  },
  hb: function(m) {
    document.getElementById("hintbox").innerHTML=m;
  },
  f: null,
  s: null,
  l: function(e) { //keyup
    var a = e.keyCode;
    if( a == 91 ) { kh.appl=false; return false; }
    if ( a == 16 ) {
      kh.x("hidden");
    }
  },
        lm: 0,
  eso: null,
  esc: function(x) { // escape
      var i, j = kh.eso.length;
      for( i=0; i<j; i++ ) {
        kh.eso[i].setAttribute("es",x);
      }
  },
  appl: false,
  hbd:"(QuiKeys)",
  curx:0,
  cure:null,
  curs:function(x) {
     if(kh.cure != null) kh.cure.style.backgroundColor = "inherit";
     kh.cure=x;
     lh(x.attributes['href'].value);
     kh.cure.style.backgroundColor = "#ff7";
     kh.cure.scrollIntoView();
  },
  curgo:function() {
     if(kh.cure != null) kh.cure.click();
  },
  cur:function(a) { // first run only
    var x = document.querySelectorAll("div.article a");
    var l = x.length;
    if(a == 39) { kh.curx = 0; kh.curs(x[kh.curx]); }
    else if(a == 37) { kh.curx = l-1; kh.curs(x[kh.curx]); }
    else return;
    kh.cur = kh.curn;
    return true;
  },
  curn:function(a) {
    var x = document.querySelectorAll("div.article a");
    var l = x.length;
    switch(a) {
    case 37: // left
        kh.curx = (kh.curx+l-1)%l;
        kh.curs(x[kh.curx]);
        break;
    case 39: // right
        kh.curx = (kh.curx+1)%l;
        kh.curs(x[kh.curx]);
        break;
    case 38: // up -- ignore since this does scroll
        break;
    case 40: // down -- ignore since this does scroll
        break;
    }
    return true;
  },
  k: function(e) { //keydown
    var a = e.keyCode;
    if ( a == 16 ) {
      kh.x("visible");
    } else {
      var c = String.fromCharCode(a).toLowerCase();
      var b;
      if( 32 == a ) {
        e.preventDefault();
        return kh.curgo();
      }
      if( 37 <= a && a <= 40 ) return kh.cur(a);
      if( a < 48 || a > 90) return true; // basic filter
      b = kh.d(c);
      if(b == null) { return true; }
      if(e.altKey || e.ctrlKey || e.metaKey) return true;
      var c = b.attributes;
      var d = c.getNamedItem("kh");
      var x;
      if(d && (x = d.value) == "h") {
        var w = c.getNamedItem("href");
        var l = w.value;
        e.preventDefault();
        window.location=l;
        return false;
      } 
      return true;
    }
  },
  w: function(t) {
    if( kh.f ) kh.f.innerHTML = t;
  },
  x: function(v) {
    var i, j = kh.s.length;
    for( i=0; i<j; i++ ) {
      kh.s[i].style.visibility=v;
    }
  },
  y: function(e) {
    var a = e.keyCode;
    if(e.altKey || e.ctrlKey || e.metaKey ) return true; /* ignore if ctrl or alt */
    if( this.es == false ) {
      if( a == 27 ) { this.es = true; return false; }
    } else {
      this.es = false;
      return true;
    }
    if( ( e.key === undefined && a == 223 ) || e.key == "`" ) {
      e.preventDefault();
      document.getElementById("editor-in-chieftain").click();
      return false;
    }
  },
  m: function(e) { //macro
    return false;
  },
  i: function() { //init
    if( document.body.className == "edit" ) {
      kh.c = document.getElementById("local-subeditor");
      kh.a(window,'keydown',kh.y);
      kh.c.focus();
    } else {
      kh.z('keydown',kh.k);
      kh.z('keyup',kh.l);
    }
    kh.f = kh.e("flibble");
    kh.q = document.querySelectorAll('[kh]');
    if( kh.q ) {
      var i, j = kh.q.length;
      kh.s = document.getElementsByClassName("ky");
      kh.eso = document.querySelectorAll('[es]');
      for( i=0; i<j; i++ ) {
        var r = kh.q[i].id.substr(3);
        kh.q[i].outerHTML+="<span class='ky'>"+r+"</span>";
      }
    }
  }
};
window.addEventListener('load',kh.i,false); //W3C

w.php

<?php

define('HOMEPAGE', 'OldSchoolWiki'); // Must be a WikiWord, see below.
define('DOMAIN','domain.name.net');
define('PAGE_DIR', 'pages'); // Should not end with a slash.
define('SITE_TITLE','OldSchoolWiki');

include('pw.php');
include("wiki.php");

?>

multi_replace.php

<?php

function multi_replace($patterns,$input) {
  // needed since /e is no longer supported
  $fs = array_keys($patterns);
  $rs = array_values($patterns);
  $l = count($fs);
  $t = $input;
  for($i=0;$i<$l;$i++) {
    $f = $fs[$i];
    $r = $rs[$i];
    if( substr($f,-1) == "e" ) {
      $f = substr($f,0,strlen($f)-1); # drop last char
      $rr = "return ".preg_replace('/\$(\d)/','\$m[$1]',$r);
      $fn = create_function("\$m",$rr);
      $t = preg_replace_callback($f,$fn,$t);
    } else {
      $t = preg_replace($f,$r,$t);
    }
  }
  return $t;
}

?>

pw.php

<?php

// use cookies so as not to require the password _every_ time
define('CHALNET_DOMAIN','.chalisque.net');
define('PASSWORD', 'PasswordGoesHere');
define('SUGAR','AndSpice'); 
define('COOKIENAME','IWantAcookie');
define('COOKIE_DUR',60*60*2); // 2 hrs before password is needed again

$date = date("Y_m_d");
$hash = hash("sha256",SUGAR.$date,true);
$cookie_value = base64_encode($hash);
    
function gen_cookie($w) {
  $a = $w.SUGAR;
  $c = $w."=".base64_encode(md5($a,true));
  return $c;
}

function set_cookie($c) {
  return setcookie(COOKIENAME,$c,time()+COOKIE_DUR,"/",CHALNET_DOMAIN,false,false);
}
$perr="";
$auth_ok = false;
$pw = $_POST['password'];
$ck = $_COOKIE[COOKIENAME];
# allow password-free updates for a COOKIE_DUR seconds after successful update
if($ck == $cookie_value) {
  set_cookie($cookie_value);
  $auth_ok=true;
} else if($pw == PASSWORD) {
  set_cookie($cookie_value);
  $auth_ok = true;
}
function auth() {
    global $perr,$ck,$auth_ok;
    if($auth_ok) {
      return true;
    } else {
      return null;
    }
}

?>

dot.htaccess

RewriteEngine on
RewriteRule ^/?$ /w.php [L]
RewriteRule ^(([A-Z]+[a-z0-9_-]*){2,})$ /w.php?$1 [L]
RewriteRule ^edit/(([A-Z]+[a-z0-9_-]*){2,})$ /w.php?$1&action=edit [L]
RewriteRule ^index$ /w.php?action=index [L]
RewriteRule ^rc$ /w.php?action=rc [L]

wiki.php

<?php
// Original copyright
// WabiSabi - a fast experimental wiki engine
// 2009-2012 Felix Plesoianu <felix@plesoianu.ro>
// If you are asking what license this software is released under,
// you are asking the wrong question.

// Chalisque.net wikis
// 2013-2021 John Allsup
// Public Domain, or whatever license Felix meant above

include('multi_replace.php');

define('TX1',time());

define('GOTOBAR', "*$_0\n*WikiLicense");
define('DATE_FORMAT', 'D d M Y, H:i:s'); // Must be valid for date().
define('TIMEZONE', 'UTC'); // See http://www.php.net/manual/en/timezones.php

define('URL', '[a-z\\+]+://[\\w\\.-]+(:\\d+)?/[\\w$-.+!*\'(),\\?#%&;=~:\\/]*');
// Must not contain dots or slashes, it's a security risk!
define('WIKIWORD', '(([A-Z]+[a-z0-9_-]*){2,})');
define('WIKIWORDEXT', '(([A-Z]+[a-z0-9_-]*){2,})\[([a-zA-Z0-9])\]');

$action = isset($_GET['action']) ? $_GET['action'] : 'view';

$perr="";
$wiki_template = <<<WIKI_TPL
<!DOCTYPE html>
<html>
 <head>
  <title>\$page_title | \$site_title</title>
  <link rel="stylesheet" type="text/css" title="wiki" href="/w.css">
  <link rel="stylesheet" type="text/css" title="wiki" href="/wpr.css" media="print">
  <link rel="alternate" type="application/x-wiki" title="Edit this page" href="/edit/\$page_name">
  <meta http-equiv="Content-type" content="text/html; charset=utf-8">
  <script src="/w.js"></script>
  \$head
 </head>

 <body\$bodyadd>
 <div class="header" role="banner" es="b"><h1>\$page_title</h1></div>
 <div class="main">
 <div class="article" role="main">\$page_text</div>
 <div id="gotobar" class="screenonly" role="navigation">\$gotobar</div>
 </div>
 <div class="footer screenonly">
 <div id="actionbar" role="navigation">
 <div>
<a href="/rc">Recent changes</a> 
<a href="/index">Index</a> 
\$actions</div>
 Last modified: \$last_mod<br /><span id="ckmsg">By
 <a href="/edit/\$page_name" class="hid" id="key0" kh="h" rel="nofollow">modifying pages</a>,
or otherwise entering a correct password, you indicate that you accept cookies: if you do not want cookies, do not modify pages here.</span>
   </div>
   <div id="footer" role="banner" class="screenonly">\$footer</div>
  </div>
 <div id="linkhelp" class="screenonly"></div>
 </body>
</html>
WIKI_TPL;

$edit_template = <<<EDIT_TPL
<div id="editing-suite">
<form method="post">
 <div id="input1"><input type="hidden" name="page_name" value="\$page_name">
 <textarea name="page_text" id="local-subeditor" cols="80" rows="25">\$page_text</textarea></div>
 <div id="input2">
 <label>Password <input name="password"></label>
 <input type="submit" name="save" value="Save" id="editor-in-chieftain">
 <input type="submit" name="preview" value="Preview">
 <a href="/\$page_name">Cancel</a><span id="editbgcopyright"></span></div>
</form>
</div>
EDIT_TPL;

$saved_template = 'Page saved. <a href="/$page_name" id="key1" kh="h">See the new version.</a>';

$wiki_patterns = array(
	'/^\\{\\{\\{(\w*)(\s|$)(.*?)\\}\\}\\}/mse' => 'wiki_preserve("<pre class=\"$1box\">$3</pre>");', # pre with class
	'/^\\[\\[\\[(\w*)(\s|$)(.*?)\\]\\]\\]/mse' => 'wiki_preserve("<div class=\"$1box\">$3</div>");', # div with class
	'/\s*==+\s*$/m' => '', # =='s at the end of a line get deleted
	'/^======(.*)/m' => '<h6>$1</h6>', # headings
	'/^=====(.*)/m' => '<h5>$1</h5>',
	'/^====(.*)/m' => '<h4>$1</h4>',
	'/^===(.*)/m' => '<h3>$1</h3>',
	'/^==(.*)/m' => '<h2>$1</h2>',
	'/^\s*$/m' => '<p>', # blank lines delimit paragraphs
	'/^----+/m' => "<hr>\n", # ----'s for rules
	'/^:(.*)/m' => '<blockquote>$1</blockquote>',
	'/^\\*\\*(.*?)\\*\\*/' => '<b>$1</b>', # bold at start of line takes precedence over bulleted lists
	'/^\\*+(.*)/m' => '<ul><li>$1</li></ul>', # bulleted lists
	'/^#+(.*)/m' => '<ol><li>$1</li></ol>', # numbered lists
	'/^;([^:]+):(.*)/m' => '<dl><dt>$1</dt><dd>$2</dd></dl>', # description lists
	'!(</ul>\s<ul>)|(</ol>\s<ol>)|(</dl>\s<dl>)!m' => "\n", # merge adjacent lists
	'/\\{\\{\\{(.*?\\}*)\\}\\}\\}/e' => 'wiki_preserve("<code>$1</code>");', # inline code
	'/^\\{\\|(.*?)\\|\\}/mse'
		=> '"<table><tr>".wiki_render_table("$1")."</tr></table>";', # table
    # these are for inter wiki links
    # firstly those where the visible text is not the wikiword, both with and without hotkeys
    '|\[w:([a-z]+)/(' . WIKIWORD . ') (\\w.+?)\[([a-z0-9])\]\]|e'
        => 'wiki_preserve("<a href=\"http://$1.chalisque.net/$3\" id=\"key".strtolower("$6")."\" kh=\"h\"><span class=\"extwiki\">$1</span>$5</a>");', 
    '|\[w:([a-z]+)/(' . WIKIWORD . ') (\\w.+?)\]|e'
        => 'wiki_preserve("<a href=\"http://$1.chalisque.net/$3\"><span class=\"extwiki\">$1</span>$5</a>");',
    # Then conventional wikiwords (of the form w:wikisubdomain/WikiWord) again with and without hotkeys
    '|w:([a-z]+)/('.WIKIWORDEXT.')|e' 
      => 'wiki_preserve("<a href=\"http://$2.chalisque.net/$3\" id=\"key".strtolower("$4")."\" kh=\"h\"><span class=\"extwiki\">$2/</span>$3</a>");', # inter wiki links (with shortcut keys)
    '|w:([a-z]+)/('.WIKIWORD.')|e' 
      => 'wiki_preserve("<a href=\"http://$1.chalisque.net/$3\"><span class=\"extwiki\">$1/</span>$3</a>");', # inter wiki links
    '|\{\{(' . URL . ')(.*?)\}\}|e'
        => 'wiki_preserve("<img src=\"$1\" alt=\"$3\" />");', # images
    # these next pattern allow intra wiki links which are not the same as the linked to WikiWord
    # [WikiWordOne hello world] ==> <a href='/WikiWordOne'>hello world</a>
    # and similar for wikiwords with shortcut keys
    # first where the visible text is not the WikiWord, with and without shortcut keys
    '|\[(' . WIKIWORD . ') (\\w.+?)\[([a-z0-9])\]\]|e'
        => 'wiki_preserve("<a href=\"/$1\" id=\"key".strtolower("$5")."\" kh=\"h\">$4</a>");', 
    '|\[(' . WIKIWORD . ') (\\w.+?)\]|e'
        => 'wiki_preserve("<a href=\"/$1\">$4</a>");',
    # the same but for URLs
    '|\[(' . URL . ')(.+?)\[([a-z0-9])\]\]|e'
        => 'wiki_preserve("<a href=\"$1\" id=\"key".strtolower("$4")."\" kh=\"h\">$3</a>");',
    '|\[(' . URL . ')(.+?)\]|e'
        => 'wiki_preserve("<a href=\"$1\">$3</a>");',
    # turn urls into links (no shortcut key facility here)
    '|(' . URL . ')|e' => 'wiki_preserve("<a href=\"$1\">$1</a>");',
    # usual wikiwords 
	  '|' . WIKIWORDEXT . '|e' => 'wiki_preserve("<a href=\"/$1\" id=\"key".strtolower("$3")."\" kh=\"h\">$1</a>");',
	  '/' . WIKIWORD . '/' => '<a href="/$1">$1</a>',
  # formatting:
	'/\\*\\*(.*?)\\*\\*/' => '<b>$1</b>', # bold
	'|//(.*?)//|' => '<i>$1</i>', # italic
	'/\\\\\\\\/' => "<br>\n", # line break (<br/>)
	'/\\^\\^(.*?)\\^\\^/' => '<sup>$1</sup>', # superscript
	'/,,(.*?),,/' => '<sub>$1</sub>'); # subscript

$wiki_table_patterns = array(
	'/^\s*\\|-/m' => '</tr><tr>',
	'/^\s*\\|\\+(.*)/m' => '<th>$1</th>',
	'/^\s*\\|(.*)/m' => '<td>$1</td>');

$preserved_strings = array();

function wiki_preserve($text) {
	global $preserved_strings;
	$gensym = '_' . count($preserved_strings);
	$preserved_strings[$gensym] = $text;
	return "\$$gensym";
}

function wiki_render($text, $patterns = array()) {
	global $preserved_strings;
	$preserved_strings = array();
	$tmp = preg_replace_callback(
		'/<<(\w+)(.*?)>>/', 'wiki_plugin', $text);
    $tmp = multi_replace($patterns, htmlspecialchars($tmp, ENT_QUOTES, "UTF-8"));
	return tpl_render($tmp, $preserved_strings);
}

function wiki_render_table($text) {
	global $wiki_table_patterns;
  return multi_replace($patterns, $text);
}

function wiki_plugin($matches) {
	$fn = 'wiki_plugin_' . $matches[1];
	return function_exists($fn) ? $fn($matches[2]) : $matches[0];
}

function wiki_plugin_include($text) {
	$text = trim($text);
	if (!preg_match('/^' . WIKIWORD . '$/', $text))
		return '';
	else if ($text == page_name())
		return ''; // avoid recursive reading
	else
  {
    $tt = preg_replace_callback('/<<(\w+)(.*?)>>/', 'wiki_plugin', page_retrieve($text));
    return $tt;
  }
}

function wiki_plugin_title($text) {
	$GLOBALS['tpl_vars']['page_title'] = trim($text); return '';
}

function wiki_plugin_home($text) {
	return wiki_preserve('<a href="/' . HOMEPAGE . '" rel="home">Home</a>');
}

function tpl_render($text, $tpl_vars) {
  return preg_replace_callback("/\\$(\\w+)/",function($m) use (&$tpl_vars) {
  return isset($tpl_vars[$m[1]]) ? $tpl_vars[$m[1]] : "";}, $text);
}

function tpl_render_editbox($page_text) {
	global $edit_template, $page_name;
	return tpl_render($edit_template, array(
		'page_name' => $page_name,
		'page_text' => htmlspecialchars(
			$page_text, ENT_QUOTES, "UTF-8")));
}
$ms = array();
function page_name() {
	global $ms;
	$ww = '/^(' . WIKIWORD . ')(&|$)/';
	if (isset($_GET['page'])) {
		if (preg_match($ww, $_GET['page'])) {
			return $_GET['page'];
		} else {
			return HOMEPAGE;
		}
	} else if (preg_match($ww, $_SERVER['QUERY_STRING'],$ms)) {
		return $ms[1];
	} else {
		return HOMEPAGE;
	}
}

$tx1 = 0;
function page_retrieve($page_name) {
  $fn = PAGE_DIR . "/$page_name.txt";
  if( file_exists($fn) ) {
    $a = file_get_contents($fn);
    $i = strrpos($a,"%TIME");
    if( $i ) {
      if( preg_match("/%TIME=\d+$/",$a,$m,0,$i) ) {
        $a = substr($a,0,$i);
      }
    }
    $a = jda_prepend_toc_if_requested($a);
    return $a;
  } else { return ""; }
}
function extract_time($a) {
  global $tx1;
  if(preg_match("/%TIME=(\d+)\s*$/s",$a,$m)) {
    $b = substr($a,0,strlen($a)-strlen($m[0]));
    $tx1 = $m[1];
  } else $b = $a;
  return $b;
}
function strip_time($a) {
  global $tx1;
  if(preg_match("/%TIME=(\d+)\s*$/s",$a,$m)) {
    $b = substr($a,0,strlen($a)-strlen($m[0]));
  } else $b = $a;
  return $b;
}

function page_save() {
	global $perr;
    $perr="";
	if (!preg_match('/^' . WIKIWORD . '$/', $_POST['page_name'])) {
		$perr = "Invalid page name"; return false; }
	if (strlen($_POST['page_text']) < 6) { $perr = "Too short"; return false; }
    $wh = auth();
    if(is_null($wh)) {
        if(strcmp($perr,"")==0) {
            $perr = "Big security bloke says no entry! (He has a thing about people from $_SERVER[REMOTE_ADDR])"; return false;
        }
        # else message already set.
        return false;
    }
    if (preg_match("/\\d{9,}$/",$_POST['page_name'])) {
        $perr = "Invalid page name, cannot save."; return false;
    }
	if ($_POST['page_text'] == $GLOBALS['raw_page_text']) {
		$perr = "No changes"; return false;
    }
	$basename = PAGE_DIR . '/' . $_POST['page_name'];
    $x = $_POST['page_text']."%TIME=".TX1;
    file_put_contents($basename.TX1.'.txt',$x);
	@copy($basename . '.txt', $basename . '.last.txt');
	$r = @file_put_contents($basename . '.txt', $x);
    $sn = $_SERVER['SERVER_NAME'];
    $ip = $_SERVER['REMOTE_ADDR'];
    $pn = $_POST['page_name'];
    $le = date("Y-m-d H:i:s")." ip=$ip site=$sn page=$pn pw=$pw\n";
    $wfnd = "../writes/".date("Y-m-d").".txt";
    @file_put_contents($wfnd,$le,FILE_APPEND);
    return $r;
}

function page_list($pattern) {
	$oldcwd = getcwd();
	chdir(PAGE_DIR);
	$pages = @glob($pattern);
	if (!$pages) $pages = array();
	$mtimes = array_map('filemtime', $pages);
	chdir($oldcwd);
	return array_combine($pages, $mtimes);
}

function page_list_format($page_list) {
	$output = "<ol>\n";
	foreach ($page_list as $fname => $mtime) {
		$tstr = date(DATE_FORMAT, $mtime);
		$pname = substr($fname, 0, -4);
		$output .= "<li><a href=\"/$pname\">$pname</a> ($tstr)</li>\n";
	}
	$output .= "</ol>\n";
	return $output;
}

function revert_magic_quotes() {
	if (get_magic_quotes_gpc())
		$_POST['page_text'] = stripslashes($_POST['page_text']);
}

function wiki_action_edit(&$tpl_vars) {
	global $saved_template, $wiki_patterns, $raw_page_text;
	global $perr;
	if (isset($_POST['save'])) {
		revert_magic_quotes();
		if (page_save()) {
			$GLOBALS['tpl_vars']['bodyadd'] = " class='view'";
			$tpl_vars['page_text'] =
				tpl_render($saved_template, $tpl_vars);
		} else {
			$GLOBALS['tpl_vars']['bodyadd'] = " class='edit'";
			if( ! is_string($a) ) $a = "Save failed ($perr)";
			$tpl_vars['page_text'] = $a . '<br />'
				. tpl_render_editbox($_POST['page_text']);
		}
	} else if (isset($_POST['preview'])) {
		$GLOBALS['tpl_vars']['bodyadd'] = " class='edit'";
		revert_magic_quotes();
		$tpl_vars['page_text'] = 'Preview:<br>'
			. wiki_render($_POST['page_text'], $wiki_patterns)
			. tpl_render_editbox($_POST['page_text']);
	} else {
		$GLOBALS['tpl_vars']['bodyadd'] = " class='edit'";
		$tpl_vars['page_text'] = tpl_render_editbox($raw_page_text);
	}
}

// index
function match_backup_filename($filename) {
  return preg_match("/\\d{9,}.txt$/",$filename);
}
function match_nonbackup_filename($filename) {
  return !match_backup_filename($filename);
}

function wiki_action_index(&$tpl_vars) {
	$page_list = page_list('*.txt');
	$tpl_vars['page_title'] = 'Index';
	$tpl_vars['page_text'] = index_list_format($page_list);
}

function index_list_format($page_list) {
	$output = "<ol>\n";
  $page_names = array_keys($page_list);
	foreach ($page_names as $fname) {
    if( match_backup_filename($fname) ) continue;
    if( preg_match("/.last.txt$/",$fname) ) continue;
    $wikiword = preg_replace("/.txt$/","",$fname);
		$output .= "<li><a href=\"/$wikiword\">$wikiword</a></li>\n";
	}
	$output .= "</ol>\n";
	return $output;
}

function wiki_action_rc(&$tpl_vars) {
	$pagemtimes = page_list('*.txt');
	arsort($pagemtimes);
	$pagemtimes = array_slice($pagemtimes, 0, 50);
	$tpl_vars['page_title'] = 'Recent changes';
	$tpl_vars['page_text'] = page_list_format($pagemtimes);
}

function wiki_action_view(&$tpl_vars) {
	global $page_name,$raw_page_text, $wiki_patterns;
	if($page_name == CSS_FILE) {
		$raw_page_text = "{{{\n".$raw_page_text."\n
"; } $GLOBALS['tpl_vars']['bodyadd'] = " class='view'"; ['page_text'] = wiki_render(, ); }

function jda_prepend_toc_if_requested() { global ; if( !preg_match("/^#contents
s/",) || == "edit") { return ; }

= strpos(,"\n"); if( == false ) { return "#contents??"; } = substr(,+1);

= explode("\n",); = 7; = null; foreach( as ) { if( preg_match("/^(==+)([^=].*)?$/",,) ) { = [1]; = ltrim([2]); = strlen(); = min(,); } } if( == 7 ) { return ; } = array(0,0,0,0,0,0); = array();

foreach( as ) { if( preg_match("/^(==+)([^=].*)?$/",,) ) { = [1]; = ltrim([2]); = strlen() - ; [] ++; for( = + 1; < 6; ++) { [] = 0; # reset subcounters } = implode(".",array_slice(,0,+1)); array_push(," "); } }

= implode("\n",); return "\n$toc\n\n----\n"; }

date_default_timezone_set(TIMEZONE); = page_name(); = page_retrieve(); = extract_time(); if (empty()) = "Page does not exist yet."; if( strcmp(,'GoToBar') != 0) = strip_time(page_retrieve('GoToBar')); if (empty()) = GOTOBAR;

= array( 'site_title' => SITE_TITLE, 'page_name' => , 'page_title' => strtr(, '_', ' '), 'last_mod' => date(DATE_FORMAT, @filemtime(PAGE_DIR . "/.txt")), 'password' => PASSWORD, 'pwxt' => 'py', 'home_page' => HOMEPAGE, 'gotobar' => wiki_render(, ), 'actions' => '', 'footer' => '', 'head' => '');

foreach (glob('plugins/*.php') as ) @include();

= 'wiki_action_' . ; if (!function_exists()) = 'wiki_action_view'; ();

header('Content-type: text/html; charset=utf-8'); print tpl_render(, )."\n"; ?> }}}