",$x);
EmitCode("indent",strlen($match[1]));
} else { $x.=$HTMLLineBreak; EmitCode("",0); }
foreach ($InlineReplacements as $pat => $rep)
$x = preg_replace($pat,$rep,$x);
if (preg_match("/^\\s*($lp(\\d+)$lp)\\s*\$/",$x,$match))
$x = str_replace(" img>"," />
",$lpv[$match[2]]);
if (preg_match("/^\\s*($lp(\\d+)$lp).*\\S/",$x,$match))
$x = str_replace($match[1],
str_replace(" img>"," align='left' />",$lpv[$match[2]]), $x);
if (preg_match("/\\S.*($lp(\\d+)$lp)\\s*\$/",$x,$match)) {
$rt = str_replace(" img>"," align='right' />",$lpv[$match[2]]);
if (strstr($rt,"
"," />",$lpv[$1])',$x);
$x = preg_replace("/$lp#$lp/e",'"[".++$refcount."]"',$x);
if ($WikiStylePattern) $x = ApplyStyles($x);
while (preg_match("/$KeepToken(\\d+?)$KeepToken/",$x))
$x = preg_replace("/$KeepToken(\\d+?)$KeepToken/e",'$KPV[$1]',$x);
echo $x,"\n";
}
EmitCode("",0);
EmitCell("","");
}
function PrintWikiPage($pagename,$wikilist=NULL) {
global $PrintWikiPageNotFoundFmt;
if (is_null($wikilist)) $wikilist=$pagename;
$pagelist = preg_split('/\s+/',$wikilist,-1,PREG_SPLIT_NO_EMPTY);
foreach($pagelist as $p) {
if (PageExists($p)) {
$page = RetrieveAuthPage($p,"read",false);
if ($page['text'])
PrintText($pagename,ProcessIncludes($pagename,$page['text']));
return;
}
}
if ($PrintWikiPageNotFoundFmt>'')
print FmtPageName(@$PrintWikiPageNotFoundFmt,array_pop($pagelist));
}
function ProcessIncludes($pagename,$text="") {
global $MaxIncludes,$IncludeBadAnchorFmt,$GroupNamePattern,$PageTitlePattern;
$inclcount=0;
while ($inclcount<$MaxIncludes &&
preg_match("/\\[\\[include:(($GroupNamePattern([\\/.]))?$PageTitlePattern)(#(\\w[-.:\\w]*)?(#(\\w[-.:\\w]*)?)?)?\\]\\]/",$text,$match)) {
list($inclrepl,$inclname,$group,$dot,$a,$aa,$b,$bb) = $match;
if (!$group) $inclname=FmtPageName('$Group.',$pagename).$inclname;
$inclpage = RetrieveAuthPage($inclname,"read",false);
$incltext = $inclpage['text'];
$badanchor = '';
if ($bb && !preg_match('/^\\d+$/',$bb) &&
strpos($incltext,"[[#$bb]]")===false) $badanchor=$bb;
if ($aa && !preg_match('/^\\d+$/',$aa) &&
strpos($incltext,"[[#$aa]]")===false) $badanchor=$aa;
if ($badanchor)
$incltext=FmtPageName(str_replace('$BadAnchor',$badanchor,
$IncludeBadAnchorFmt),$inclname);
if (preg_match('/^\\d+$/',$bb))
$incltext=preg_replace("/^(([^\\n]*\\n)\{0,$bb}).*$/s",'$1',$incltext,1);
elseif ($bb)
$incltext=preg_replace("/[^\\n]*\\[\\[#$bb\\]\\].*$/s",'',$incltext,1);
if (preg_match('/^\\d+$/',$aa)) {
$aa--; $incltext=preg_replace("/^([^\\n]*\\n)\{0,$aa}/s",'',$incltext,1);
if (!$b) $incltext=preg_replace("/\\n.*$/s",'',$incltext);
} elseif ($aa && $b)
$incltext=preg_replace("/^.*?([^\\n]*\\[\\[#$aa\\]\\])/s",'$1',$incltext,1);
elseif ($aa)
$incltext=preg_replace("/^.*?([^\\n]*\\[\\[#$aa\\]\\]( *\\n)?[^\\n]*).*/s",'$1',$incltext,1);
$text = str_replace($inclrepl,$incltext,$text);
$inclcount++;
}
return $text;
}
function ProcessTextDirectives($pagename,$text="") {
global $Text,$GroupHeaderFmt,$GroupFooterFmt,$BrowseDirectives;
if (!$text) $text=$Text;
$text = KeepWikiEscapes($text);
$text = ProcessIncludes($pagename,$text);
if (!strstr($text,"[[nogroupheader]]")) {
$hdname = FmtPageName($GroupHeaderFmt,$pagename);
if ($hdname != $pagename) {
$hdpage=ReadPage($hdname,"");
if ($hdpage['text'] && substr($hdpage['text'],-1,1)!="\n" &&
substr($text,0,1)!="\n") $hdpage['text'] .= "\n";
$text = $hdpage['text'].$text;
}
}
if (!strstr($text,"[[nogroupfooter]]")) {
$hdname = FmtPageName($GroupFooterFmt,$pagename);
if ($hdname != $pagename) {
$hdpage=ReadPage($hdname,"");
if ($hdpage['text'] && substr($hdpage['text'],0,1)!="\n" &&
substr($text,-1,1)!="\n") $text .= "\n";
$text .= $hdpage['text'];
}
}
Lock(0);
foreach($BrowseDirectives as $p=>$s) {
if ($p[0]=='/') $text=preg_replace($p,$s,$text);
else if (strstr($text,$p)) $text = str_replace($p,eval($s),$text);
}
$Text = $text;
}
function HandleBrowse($pagename) {
global $Text,$PageRedirectFmt,$RedirectPattern,
$HandleBrowseFmt,$PageStartFmt,$PageEndFmt;
$page = RetrieveAuthPage($pagename,"read");
if (!$page) { Abort("Invalid page name"); }
$Text = $page['text'];
SetPageVars($pagename,$page,$pagename);
if (@!$_GET['from']) {
$PageRedirectFmt = '';
if (preg_match("/$RedirectPattern/",$Text,$match)) {
$rpage = FmtWikiLink('',$match[1],NULL,'PageName',$pagename);
if (PageExists($rpage)) Redirect($rpage,"\$PageUrl?from=$pagename");
}
}
else $PageRedirectFmt = FmtPageName($PageRedirectFmt,$_GET['from']);
ProcessTextDirectives($pagename);
SDV($HandleBrowseFmt,array(&$PageStartFmt,
&$PageRedirectFmt,'function:PrintText',
&$PageEndFmt));
PrintFmt($pagename,$HandleBrowseFmt);
}
function HandleEdit($pagename) {
global $restore,$preview,$HandleActions,$Text,
$HandleEditFmt,$PageStartFmt,$PageEditFmt,$PagePreviewFmt,$PageEndFmt,
$DiffClassMinor,$PatchFunction;
if (@$_POST['post'])
{ $handle = $HandleActions['post']; return $handle($pagename); }
$page = RetrieveAuthPage($pagename,"edit");
if (!$page) { Abort("?cannot edit $pagename"); }
SetPageVars($pagename,$page,"Edit $pagename");
if ($restore && $PatchFunction) { $text = $PatchFunction($page,$restore); }
else if ($preview) { $text = stripmagic($_POST['text']); }
else { $text = $page['text']; }
$Text = $text;
$DiffClassMinor = '';
if (@$_POST['diffclass']=='minor') $DiffClassMinor="checked='checked'";
SDV($HandleEditFmt,array(&$PageStartFmt,
&$PageEditFmt,&$PagePreviewFmt,
&$PageEndFmt));
PrintFmt($pagename,$HandleEditFmt);
}
function HandlePost($pagename) {
global $WikiDir,$DeleteKeyWord,$RecentChanges,$RCDelimPattern,$Now,
$TimeFmt,$CurrentTime,$PageFileFmt,$DiffKeepDays,$Author,$PostFields,
$DiffFunction,$ChangeSummary;
$CurrentTime = strftime($TimeFmt,$Now);
foreach($PostFields as $k) {
if (isset($_POST[$k]))
$new[$k]=str_replace("\r","",stripmagic($_POST[$k]));
}
Lock(2);
$page = RetrieveAuthPage($pagename,"edit");
if (!$page) { Abort("?cannot post $pagename"); }
$pagename = FmtPageName('$PageName',$pagename);
if ($new['text']==$page['text'])
{ Redirect($pagename); return; }
$diffclass=preg_replace('/\\W/','',@$_POST['diffclass']);
if ($page["time"]>0)
$new["diff:$Now:".$page['time'].":$diffclass"] =
$DiffFunction($new['text'],$page['text']);
$new['author'] = $Author;
$new["author:$Now"] = $Author;
$new["host:$Now"] = $_SERVER['REMOTE_ADDR'];
if ($ChangeSummary) $new["csum:$Now"] = $ChangeSummary;
foreach($new as $k=>$v) {
if ($k=='pagename' || $k=='action') continue;
$page[$k] = $v;
}
$keepgmt = $Now-$DiffKeepDays*86400;
$keys = array_keys($page);
foreach ($keys as $k)
if (preg_match("/^\\w+:(\\d+)/",$k,$match))
if ($match[1] < $keepgmt) unset($page[$k]);
$pagefile = FmtPageName($PageFileFmt,$pagename);
if ($page['text']==$DeleteKeyWord)
{ @rename("$WikiDir/$pagefile","$WikiDir/$pagefile,$Now"); }
else WritePage($pagename,$page);
foreach($RecentChanges as $rcfmt => $pgfmt) {
$rcname=FmtPageName($rcfmt,$pagename); if (!$rcname) continue;
$pgtext=FmtPageName($pgfmt,$pagename); if (!$pgtext) continue;
if (@$seen[$rcname]++) continue;
$rcpage = ReadPage($rcname,"");
$rcelim = preg_quote(preg_replace("/$RCDelimPattern.*$/",' ',$pgtext),'/');
$rcpage['text'] = preg_replace("/[^\n]*$rcelim.*\n/","",$rcpage['text']);
if (!preg_match("/$RCDelimPattern/",$rcpage['text']))
$rcpage['text'] .= "$pgtext\n";
else
$rcpage['text'] = preg_replace("/([^\n]*$RCDelimPattern.*\n)/",
"$pgtext\n$1",$rcpage['text'],1);
WritePage($rcname,$rcpage);
}
Redirect($pagename);
}
function HandleSource($pagename) {
$page = RetrieveAuthPage($pagename,"read");
if (!$page) Abort("?cannot source $pagename");
Lock(0);
header("Content-Type: text/plain");
echo $page['text'];
}
function BasicAuth($pagename,$level,$authprompt=true) {
global $AuthRealmFmt,$AuthDeniedFmt,$DefaultPasswords,
$AllowPassword,$GroupAttributesFmt;
$page = ReadPage($pagename);
if (!$page) { return false; }
@$passwd = $page["passwd$level"];
if ($passwd=="") {
$grouppg = ReadPage(FmtPageName($GroupAttributesFmt,$pagename));
@$passwd = $grouppg["passwd$level"];
}
if (crypt($AllowPassword,$passwd)==$passwd) return $page;
if ($passwd=="") { $passwd=@$DefaultPasswords[$level]; }
if ($passwd=="") return $page;
foreach (array_merge((array)$DefaultPasswords['admin'],(array)$passwd) as $pw)
if (@crypt($_SERVER['PHP_AUTH_PW'],$pw)==$pw) return $page;
if (!$authprompt) return false;
$realm=FmtPageName($AuthRealmFmt,$pagename);
header("WWW-Authenticate: Basic realm=\"$realm\"");
header("Status: 401 Unauthorized");
header("HTTP-Status: 401 Unauthorized");
PrintFmt($pagename,$AuthDeniedFmt);
exit;
}
function RetrieveAuthPage($pagename,$level,$authprompt=true) {
global $AuthFunction;
if (!function_exists($AuthFunction))
Abort("?Invalid AuthFunction specified: $AuthFunction","AuthFunction");
return $AuthFunction($pagename,$level,$authprompt);
}
function PrintAttrForm($pagename) {
global $PageAttributes;
echo FmtPageName("
";
}
function HandleAttr($pagename) {
global $HandleAttrFmt,$PageStartFmt,$PageAttrFmt,$PageEndFmt;
$page = RetrieveAuthPage($pagename,"attr");
if (!$page) { Abort("?unable to read $pagename"); }
SetPageVars($pagename,$page,"Edit $pagename Attributes");
SDV($HandleAttrFmt,array(&$PageStartFmt,
&$PageAttrFmt,'function:PrintAttrForm',
&$PageEndFmt));
PrintFmt($pagename,$HandleAttrFmt);
}
function HandlePostAttr($pagename) {
global $PageAttributes;
$page = RetrieveAuthPage($pagename,"attr");
if (!$page) { Abort("?cannot get $pagename"); }
foreach($PageAttributes as $k=>$v) {
$newpw = $_POST[$k];
if ($newpw=="clear") unset($page[$k]);
else if ($newpw>"") $page[$k]=crypt($newpw);
}
WritePage($pagename,$page);
Redirect($pagename);
exit;
}
?>