with your question(s) and I'll provide explanations (and add comments) that answer them. */ error_reporting(E_ALL ^ E_NOTICE); StopWatch('PmWiki'); @ini_set('magic_quotes_runtime', 0); @ini_set('magic_quotes_sybase', 0); if (ini_get('register_globals')) foreach($_REQUEST as $k=>$v) { if (preg_match('/^(GLOBALS|_SERVER|_GET|_POST|_COOKIE|_FILES|_ENV|_REQUEST|_SESSION|FarmD|WikiDir)$/i', $k)) exit(); ${$k}=''; unset(${$k}); } $UnsafeGlobals = array_keys($GLOBALS); $GCount=0; $FmtV=array(); SDV($FarmD,dirname(__FILE__)); SDV($WorkDir,'wiki.d'); define('PmWiki',1); if (preg_match('/\\w\\w:/', $FarmD)) exit(); @include_once("$FarmD/scripts/version.php"); $GroupPattern = '[[:upper:]][\\w]*(?:-\\w+)*'; $NamePattern = '[[:upper:]\\d][\\w]*(?:-\\w+)*'; $BlockPattern = 'form|div|table|t[rdh]|p|[uo]l|d[ltd]|h[1-6r]|pre|blockquote'; $WikiWordPattern = '[[:upper:]][[:alnum:]]*(?:[[:upper:]][[:lower:]0-9]|[[:lower:]0-9][[:upper:]])[[:alnum:]]*'; $WikiDir = new PageStore('wiki.d/{$FullName}'); $WikiLibDirs = array(&$WikiDir,new PageStore('$FarmD/wikilib.d/{$FullName}')); $LocalDir = 'local'; $InterMapFiles = array("$FarmD/scripts/intermap.txt", "$FarmD/local/farmmap.txt", '$SiteGroup.InterMap', 'local/localmap.txt'); $Newline = "\263"; # deprecated, 2.0.0 $KeepToken = "\235\235"; $Now=time(); define('READPAGE_CURRENT', $Now+604800); $TimeFmt = '%B %d, %Y, at %I:%M %p'; $MessagesFmt = array(); $BlockMessageFmt = "
','','
',0), 'indent' => array("','','',0), 'table' => array("
'.htmlspecialchars(print_r($x, true)).''; } function PSS($x) { return str_replace('\\"','"',$x); } function PVS($x) { return preg_replace("/\n[^\\S\n]*(?=\n)/", "\n<:vspace>", $x); } function PZZ($x,$y='') { return ''; } function PRR($x=NULL) { if ($x || is_null($x)) $GLOBALS['RedoMarkupLine']++; return $x; } function PUE($x) { return preg_replace('/[\\x80-\\xff \'"]/e', "'%'.dechex(ord('$0'))", $x); } function PQA($x) { $out = ''; if (preg_match_all('/([a-zA-Z]+)\\s*=\\s*("[^"]*"|\'[^\']*\'|\\S*)/', $x, $attr, PREG_SET_ORDER)) { foreach($attr as $a) { if (preg_match('/^on/i', $a[1])) continue; $out .= $a[1] . '=' . preg_replace( '/^(?![\'"]).*$/e', "\"'\".str_replace(\"'\", ''', PSS('$0')).\"'\"", $a[2]) . ' '; } } return $out; } function SDV(&$v,$x) { if (!isset($v)) $v=$x; } function SDVA(&$var,$val) { foreach($val as $k=>$v) if (!isset($var[$k])) $var[$k]=$v; } function IsEnabled(&$var,$f=0) { return (isset($var)) ? $var : $f; } function SetTmplDisplay($var, $val) { NoCache(); $GLOBALS['TmplDisplay'][$var] = $val; } function NoCache($x = '') { $GLOBALS['NoHTMLCache'] |= 1; return $x; } function ParseArgs($x) { $z = array(); preg_match_all('/([-+]|(?>(\\w+)[:=]))?("[^"]*"|\'[^\']*\'|\\S+)/', $x, $terms, PREG_SET_ORDER); foreach($terms as $t) { $v = preg_replace('/^([\'"])?(.*)\\1$/', '$2', $t[3]); if ($t[2]) { $z['#'][] = $t[2]; $z[$t[2]] = $v; } else { $z['#'][] = $t[1]; $z[$t[1]][] = $v; } $z['#'][] = $v; } return $z; } function StopWatch($x) { global $StopWatch, $EnableStopWatch; if (!$EnableStopWatch) return; static $wstart = 0, $ustart = 0; list($usec,$sec) = explode(' ',microtime()); $wtime = ($sec+$usec); if (!$wstart) $wstart = $wtime; if ($EnableStopWatch != 2) { $StopWatch[] = sprintf("%05.2f %s", $wtime-$wstart, $x); return; } $dat = getrusage(); $utime = ($dat['ru_utime.tv_sec']+$dat['ru_utime.tv_usec']/1000000); if (!$ustart) $ustart=$utime; $StopWatch[] = sprintf("%05.2f %05.2f %s", $wtime-$wstart, $utime-$ustart, $x); } ## AsSpaced converts a string with WikiWords into a spaced version ## of that string. (It can be overridden via $AsSpacedFunction.) function AsSpaced($text) { $text = preg_replace("/([[:lower:]\\d])([[:upper:]])/", '$1 $2', $text); $text = preg_replace('/(?$dir/ directory before it can continue. You can create the directory manually by executing the following commands on your server:
mkdir $parent/$dir\n chmod 777 $parent/$dirThen, reload this page."; $safemode = ini_get('safe_mode'); if (!$safemode) $msg .= "
chmod 2777 $parenton your server and following this link. Afterwards you can restore the permissions to their current setting by executing
chmod $perms $parent."; Abort($msg); } ## fixperms attempts to correct permissions on a file or directory ## so that both PmWiki and the account (current dir) owner can manipulate it function fixperms($fname, $add = 0) { clearstatcache(); if (!file_exists($fname)) Abort('no such file'); $bp = 0; if (fileowner($fname)!=@fileowner('.')) $bp = (is_dir($fname)) ? 007 : 006; if (filegroup($fname)==@filegroup('.')) $bp <<= 3; $bp |= $add; if ($bp && (fileperms($fname) & $bp) != $bp) @chmod($fname,fileperms($fname)|$bp); } ## MatchPageNames function MatchPageNames($pagelist, $pat) { $pagelist = (array)$pagelist; foreach((array)$pat as $p) { if (count($pagelist) < 1) break; switch ($p{0}) { case '/': $pagelist = preg_grep($p, $pagelist); continue; case '!': $pagelist = array_diff($pagelist, preg_grep($p, $pagelist)); continue; default: $p = preg_quote($p, '/'); $p = str_replace(array('/', '\\*', '\\?', '\\[', '\\]', '\\^'), array('.', '.*', '.', '[', ']', '^'), $p); $excl = array(); $incl = array(); foreach(preg_split('/[\\s,]+/', $p, -1, PREG_SPLIT_NO_EMPTY) as $q) { if ($q{0} == '-' || $q{0} == '!') $excl[] = '^'.substr($q, 1).'$'; else $incl[] = "^$q$"; } if ($excl) $pagelist = array_diff($pagelist, preg_grep('/' . join('|', $excl) . '/i', $pagelist)); if ($incl) $pagelist = preg_grep('/' . join('|', $incl) . '/i', $pagelist); } } return $pagelist; } function FixGlob($x, $rep = '$1*.$2') { return preg_replace('/([\\s,][-!]?)([^.\\s,]+)(?=[\\s,])/', $rep, " $x "); } ## ResolvePageName "normalizes" a pagename based on the current ## settings of $DefaultPage and $PagePathFmt. It's normally used ## during initialization to fix up any missing or partial pagenames. function ResolvePageName($pagename) { global $DefaultPage, $DefaultGroup, $DefaultName, $GroupPattern, $NamePattern, $EnableFixedUrlRedirect; SDV($DefaultPage, "$DefaultGroup.$DefaultName"); $pagename = preg_replace('!([./][^./]+)\\.html$!', '$1', $pagename); if ($pagename == '') return $DefaultPage; $p = MakePageName($DefaultPage, $pagename); if (!preg_match("/^($GroupPattern)[.\\/]($NamePattern)$/i", $p)) Abort("?invalid page name"); if (preg_match("/^($GroupPattern)[.\\/]($NamePattern)$/i", $pagename)) return $p; if (IsEnabled($EnableFixedUrlRedirect, 1) && $p && (PageExists($p) || preg_match('/[\\/.]/', $pagename))) { Redirect($p); exit(); } return MakePageName($DefaultPage, "$pagename.$pagename"); } ## MakePageName is used to convert a string into a valid pagename. ## If no group is supplied, then it uses $PagePathFmt to look ## for the page in other groups, or else uses the group of the ## pagename passed as an argument. function MakePageName($basepage,$x) { global $MakePageNameFunction, $PageNameChars, $PagePathFmt, $MakePageNamePatterns; if (@$MakePageNameFunction) return $MakePageNameFunction($basepage,$x); SDV($PageNameChars,'-[:alnum:]'); SDV($MakePageNamePatterns, array( "/'/" => '', # strip single-quotes "/[^$PageNameChars]+/" => ' ', # convert everything else to space "/((^|[^-\\w])\\w)/e" => "strtoupper('$1')", "/ /" => '')); $m = preg_split('/[.\\/]/', $x); if (count($m)<1 || count($m)>2 || $m[0]=='') return ''; if ($m[1] > '') { $group = preg_replace(array_keys($MakePageNamePatterns), array_values($MakePageNamePatterns), $m[0]); $name = preg_replace(array_keys($MakePageNamePatterns), array_values($MakePageNamePatterns), $m[1]); return "$group.$name"; } $name = preg_replace(array_keys($MakePageNamePatterns), array_values($MakePageNamePatterns), $m[0]); if (count($m)>1) { $basepage = "$name.$name"; } foreach((array)$PagePathFmt as $pg) { $pn = FmtPageName(str_replace('$1',$name,$pg),$basepage); if (PageExists($pn)) return $pn; } $group=preg_replace('/[\\/.].*$/','',$basepage); return "$group.$name"; } ## PCache caches basic information about a page and its attributes-- ## usually everything except page text and page history. This makes ## for quicker access to certain values in PageVar below. function PCache($pagename, $page) { global $PCache; foreach($page as $k=>$v) if ($k!='text' && strpos($k,':')===false) $PCache[$pagename][$k]=$v; } ## SetProperty saves a page property into $PCache. For convenience ## it returns the $value of the property just set. If $sep is supplied, ## then $value is appended to the current property (with $sep as ## as separator) instead of replacing it. function SetProperty($pagename, $prop, $value, $sep = NULL) { global $PCache, $KeepToken; NoCache(); $prop = "=p_$prop"; $value = preg_replace("/$KeepToken(\\d.*?)$KeepToken/e", "\$GLOBALS['KPV']['$1']", $value); if (!is_null($sep) && isset($PCache[$pagename][$prop])) $value = $PCache[$pagename][$prop] . $sep . $value; $PCache[$pagename][$prop] = $value; return $value; } function PageVar($pagename, $var, $pn = '') { global $Cursor, $PCache, $FmtPV, $AsSpacedFunction, $ScriptUrl, $EnablePathInfo; if ($var == '$ScriptUrl') return PUE($ScriptUrl); if ($pn) { $pn = isset($Cursor[$pn]) ? $Cursor[$pn] : MakePageName($pagename, $pn); } else $pn = $pagename; if ($pn == '') return ''; if (preg_match('/^(.+)[.\\/]([^.\\/]+)$/', $pn, $match) && !isset($PCache[$pn]['time']) && (!@$FmtPV[$var] || strpos($FmtPV[$var], '$page') !== false)) { $page = ReadPage($pn, READPAGE_CURRENT); PCache($pn, $page); } @list($d, $group, $name) = $match; $page = &$PCache[$pn]; if (@$FmtPV[$var]) return eval("return ({$FmtPV[$var]});"); return ''; } ## FmtPageName handles $[internationalization] and $Variable ## substitutions in strings based on the $pagename argument. function FmtPageName($fmt, $pagename) { # Perform $-substitutions on $fmt relative to page given by $pagename global $GroupPattern, $NamePattern, $EnablePathInfo, $ScriptUrl, $GCount, $UnsafeGlobals, $FmtV, $FmtP, $FmtPV, $PCache, $AsSpacedFunction; if (strpos($fmt,'$')===false) return $fmt; $fmt = preg_replace('/\\$([A-Z]\\w*Fmt)\\b/e','$GLOBALS[\'$1\']',$fmt); $fmt = preg_replace('/\\$\\[(?>([^\\]]+))\\]/e',"XL(PSS('$1'))",$fmt); $fmt = str_replace('{$ScriptUrl}', '$ScriptUrl', $fmt); $fmt = preg_replace('/\\{(\\$[A-Z]\\w+)\\}/e', "PageVar(\$pagename, '$1')", $fmt); if (strpos($fmt,'$')===false) return $fmt; if ($FmtP) $fmt = preg_replace(array_keys($FmtP), array_values($FmtP), $fmt); static $pv, $pvpat; if ($pv != count($FmtPV)) { $pvpat = str_replace('$', '\\$', implode('|', array_keys($FmtPV))); $pv = count($FmtPV); } $fmt = preg_replace("/(?:$pvpat)\\b/e", "PageVar(\$pagename, '$0')", $fmt); $fmt = preg_replace('!\\$ScriptUrl/([^?#\'"\\s<>]+)!e', (@$EnablePathInfo) ? "'$ScriptUrl/'.PUE('$1')" : "'$ScriptUrl?n='.str_replace('/','.',PUE('$1'))", $fmt); if (strpos($fmt,'$')===false) return $fmt; static $g; if ($GCount != count($GLOBALS)+count($FmtV)) { $g = array(); foreach($GLOBALS as $n=>$v) { if (is_array($v) || is_object($v) || isset($FmtV["\$$n"]) || in_array($n,$UnsafeGlobals)) continue; $g["\$$n"] = $v; } $GCount = count($GLOBALS)+count($FmtV); krsort($g); reset($g); } $fmt = str_replace(array_keys($g),array_values($g),$fmt); $fmt = preg_replace('/(?>(\\$[[:alpha:]]\\w+))/e', "isset(\$FmtV['$1']) ? \$FmtV['$1'] : '$1'", $fmt); return $fmt; } ## The XL functions provide translation tables for $[i18n] strings ## in FmtPageName(). function XL($key) { global $XL,$XLLangs; foreach($XLLangs as $l) if (isset($XL[$l][$key])) return $XL[$l][$key]; return $key; } function XLSDV($lang,$a) { global $XL; foreach($a as $k=>$v) { if (!isset($XL[$lang][$k])) $XL[$lang][$k]=$v; } } function XLPage($lang,$p) { global $TimeFmt,$XLLangs,$FarmD; $page = ReadPage($p, READPAGE_CURRENT); if (!$page) return; $text = preg_replace("/=>\\s*\n/",'=> ',@$page['text']); foreach(explode("\n",$text) as $l) if (preg_match('/^\\s*[\'"](.+?)[\'"]\\s*=>\\s*[\'"](.+)[\'"]/',$l,$match)) $xl[stripslashes($match[1])] = stripslashes($match[2]); if (isset($xl)) { if (@$xl['xlpage-i18n']) { $i18n = preg_replace('/[^-\\w]/','',$xl['xlpage-i18n']); include_once("$FarmD/scripts/xlpage-$i18n.php"); } if (@$xl['Locale']) setlocale(LC_ALL,$xl['Locale']); if (@$xl['TimeFmt']) $TimeFmt=$xl['TimeFmt']; array_unshift($XLLangs,$lang); XLSDV($lang,$xl); } } ## CmpPageAttr is used with uksort to order a page's elements with ## the latest items first. This can make some operations more efficient. function CmpPageAttr($a, $b) { @list($x, $agmt) = explode(':', $a); @list($x, $bgmt) = explode(':', $b); if ($agmt != $bgmt) return ($agmt==0 || $bgmt==0) ? $agmt - $bgmt : $bgmt - $agmt; return strcmp($a, $b); } ## class PageStore holds objects that store pages via the native ## filesystem. class PageStore { var $dirfmt; var $iswrite; function PageStore($d='$WorkDir/$FullName', $w=0) { $this->dirfmt=$d; $this->iswrite=$w; } function pagefile($pagename) { global $FarmD; $dfmt = $this->dirfmt; if ($pagename > '') { $pagename = str_replace('/', '.', $pagename); if ($dfmt == 'wiki.d/{$FullName}') # optimizations for return "wiki.d/$pagename"; # standard locations if ($dfmt == '$FarmD/wikilib.d/{$FullName}') # return "$FarmD/wikilib.d/$pagename"; # if ($dfmt == 'wiki.d/{$Group}/{$FullName}') return preg_replace('/([^.]+).*/', 'wiki.d/$1/$0', $pagename); } return FmtPageName($dfmt, $pagename); } function read($pagename, $since=0) { $newline = ''; $urlencoded = false; $pagefile = $this->pagefile($pagename); if ($pagefile && ($fp=@fopen($pagefile, "r"))) { while (!feof($fp)) { $line = fgets($fp, 4096); while (substr($line, -1, 1) != "\n" && !feof($fp)) { $line .= fgets($fp, 4096); } $line = rtrim($line); if ($urlencoded) $line = urldecode(str_replace('+', '%2b', $line)); @list($k,$v) = explode('=', $line, 2); if (!$k) continue; if ($k == 'version') { $ordered = (strpos($v, 'ordered=1') !== false); $urlencoded = (strpos($v, 'urlencoded=1') !== false); if (strpos($v, 'pmwiki-0.')!==false) $newline="\262"; } if ($k == 'newline') { $newline = $v; continue; } if ($since > 0 && preg_match('/:(\\d+)/', $k, $m) && $m[1] < $since) { if ($ordered) break; continue; } if ($newline) $v = str_replace($newline, "\n", $v); $page[$k] = $v; } fclose($fp); } return @$page; } function write($pagename,$page) { global $Now, $Version; $page['name'] = $pagename; $page['time'] = $Now; $page['host'] = $_SERVER['REMOTE_ADDR']; $page['agent'] = @$_SERVER['HTTP_USER_AGENT']; $page['rev'] = @$page['rev']+1; unset($page['version']); unset($page['newline']); uksort($page, 'CmpPageAttr'); $s = false; $pagefile = $this->pagefile($pagename); $dir = dirname($pagefile); mkdirp($dir); if (!file_exists("$dir/.htaccess") && $fp = @fopen("$dir/.htaccess", "w")) { fwrite($fp, "Order Deny,Allow\nDeny from all\n"); fclose($fp); } if ($pagefile && ($fp=fopen("$pagefile,new","w"))) { $r0 = array('%', "\n", '<'); $r1 = array('%25', '%0a', '%3c'); $x = "version=$Version ordered=1 urlencoded=1\n"; $s = true && fputs($fp, $x); $sz = strlen($x); foreach($page as $k=>$v) if ($k > '' && $k{0} != '=') { $x = str_replace($r0, $r1, "$k=$v") . "\n"; $s = $s && fputs($fp, $x); $sz += strlen($x); } $s = fclose($fp) && $s; $s = $s && (filesize("$pagefile,new") > $sz * 0.95); if (file_exists($pagefile)) $s = $s && unlink($pagefile); $s = $s && rename("$pagefile,new", $pagefile); } $s && fixperms($pagefile); if (!$s) Abort("Cannot write page to $pagename ($pagefile)...changes not saved"); PCache($pagename, $page); } function exists($pagename) { if (!$pagename) return false; $pagefile = $this->pagefile($pagename); return ($pagefile && file_exists($pagefile)); } function delete($pagename) { global $Now; $pagefile = $this->pagefile($pagename); @rename($pagefile,"$pagefile,del-$Now"); } function ls($pats=NULL) { global $GroupPattern, $NamePattern; StopWatch("PageStore::ls begin {$this->dir}"); $pats=(array)$pats; array_push($pats, "/^$GroupPattern\.$NamePattern$/"); $dir = $this->pagefile('$Group.$Name'); $dirlist = array(preg_replace('!/*[^/]*\\$.*$!','',$dir)); $out = array(); while (count($dirlist)>0) { $dir = array_shift($dirlist); $dfp = @opendir($dir); if (!$dfp) { continue; } $o = array(); while ( ($pagefile = readdir($dfp)) !== false) { if ($pagefile{0} == '.') continue; if (is_dir("$dir/$pagefile")) { array_push($dirlist,"$dir/$pagefile"); continue; } $o[] = $pagefile; } closedir($dfp); StopWatch("PageStore::ls merge {$this->dir}"); $out = array_merge($out, MatchPageNames($o, $pats)); } StopWatch("PageStore::ls end {$this->dir}"); return $out; } } function ReadPage($pagename, $since=0) { # read a page from the appropriate directories given by $WikiReadDirsFmt. global $WikiLibDirs,$Now; foreach ($WikiLibDirs as $dir) { $page = $dir->read($pagename, $since); if ($page) break; } if (@!$page) $page['ctime'] = $Now; if (@!$page['time']) $page['time'] = $Now; return $page; } function WritePage($pagename,$page) { global $WikiLibDirs,$WikiDir,$LastModFile; $WikiDir->iswrite = 1; for($i=0; $i
$msg
We are sorry for any inconvenience.
"; exit; } function Redirect($pagename,$urlfmt='$PageUrl') { # redirect the browser to $pagename global $EnableRedirect,$RedirectDelay; SDV($RedirectDelay,0); clearstatcache(); #if (!PageExists($pagename)) $pagename=$DefaultPage; $pageurl = FmtPageName($urlfmt,$pagename); if (IsEnabled($EnableRedirect,1) && (!isset($_REQUEST['redirect']) || $_REQUEST['redirect'])) { header("Location: $pageurl"); header("Content-type: text/html"); echo "($[redirected from] {\$FullName})
\$HTMLVSpace\n"); if (@!$_GET['from']) { $opt['redirect'] = 1; $PageRedirectFmt = ''; } else $PageRedirectFmt = FmtPageName($PageRedirectFmt, $_GET['from']); if (@$EnableHTMLCache && !$NoHTMLCache && $PageCacheFile && @filemtime($PageCacheFile) > $LastModTime) { list($ctext) = unserialize(file_get_contents($PageCacheFile)); $FmtV['$PageText'] = "$ctext"; $IsHTMLCached = 1; } else { $IsHTMLCached = 0; $text = '(:groupheader:)'.@$text.'(:groupfooter:)'; $t1 = time(); $FmtV['$PageText'] = MarkupToHTML($pagename, $text, $opt); if (@$EnableHTMLCache > 0 && !$NoHTMLCache && $PageCacheFile && (time() - $t1 + 1) >= $EnableHTMLCache) { $fp = @fopen("$PageCacheFile,new", "x"); if ($fp) { fwrite($fp, serialize(array($FmtV['$PageText']))); fclose($fp); rename("$PageCacheFile,new", $PageCacheFile); } } } SDV($HandleBrowseFmt,array(&$PageStartFmt, &$PageRedirectFmt, '$PageText', &$PageEndFmt)); PrintFmt($pagename,$HandleBrowseFmt); } # EditTemplate allows a site administrator to pre-populate new pages # with the contents of another page. function EditTemplate($pagename, &$page, &$new) { global $EditTemplatesFmt; if (@$new['text'] > '') return; if (@$_REQUEST['template'] && PageExists($_REQUEST['template'])) { $p = RetrieveAuthPage($_REQUEST['template'], 'read', false, READPAGE_CURRENT); if ($p['text'] > '') $new['text'] = $p['text']; return; } foreach((array)$EditTemplatesFmt as $t) { $p = RetrieveAuthPage(FmtPageName($t,$pagename), 'read', false, READPAGE_CURRENT); if (@$p['text'] > '') { $new['text'] = $p['text']; return; } } } # RestorePage handles returning to the version of text as of # the version given by $restore or $_REQUEST['restore']. function RestorePage($pagename,&$page,&$new,$restore=NULL) { if (is_null($restore)) $restore=@$_REQUEST['restore']; if (!$restore) return; $t = $page['text']; $nl = (substr($t,-1)=="\n"); $t = explode("\n",$t); if ($nl) array_pop($t); krsort($page); reset($page); foreach($page as $k=>$v) { if ($k<$restore) break; if (strncmp($k, 'diff:', 5) != 0) continue; foreach(explode("\n",$v) as $x) { if (preg_match('/^(\\d+)(,(\\d+))?([adc])(\\d+)/',$x,$match)) { $a1 = $a2 = $match[1]; if ($match[3]) $a2=$match[3]; $b1 = $match[5]; if ($match[4]=='d') array_splice($t,$b1,$a2-$a1+1); if ($match[4]=='c') array_splice($t,$b1-1,$a2-$a1+1); continue; } if (strncmp($x,'< ',2) == 0) { $nlflag=true; continue; } if (preg_match('/^> (.*)$/',$x,$match)) { $nlflag=false; array_splice($t,$b1-1,0,$match[1]); $b1++; } if ($x=='\\ No newline at end of file') $nl=$nlflag; } } if ($nl) $t[]=''; $new['text']=implode("\n",$t); return $new['text']; } ## ReplaceOnSave performs any text replacements (held in $ROSPatterns) ## on the new text prior to saving the page. function ReplaceOnSave($pagename,&$page,&$new) { global $EnablePost, $ROSPatterns; if (!$EnablePost) return; foreach((array)$ROSPatterns as $pat=>$repfmt) $new['text'] = preg_replace($pat,FmtPageName($repfmt,$pagename),$new['text']); } function SaveAttributes($pagename,&$page,&$new) { global $EnablePost, $LinkTargets, $SaveAttrPatterns, $PCache, $SaveProperties; if (!$EnablePost) return; $text = preg_replace(array_keys($SaveAttrPatterns), array_values($SaveAttrPatterns), $new['text']); $html = MarkupToHTML($pagename,$text); $new['targets'] = implode(',',array_keys((array)$LinkTargets)); $p = & $PCache[$pagename]; foreach((array)$SaveProperties as $k) { if (@$p["=p_$k"]) $new[$k] = $p["=p_$k"]; else unset($new[$k]); } unset($new['excerpt']); } function PostPage($pagename, &$page, &$new) { global $DiffKeepDays, $DiffFunction, $DeleteKeyPattern, $EnablePost, $Now, $Author, $WikiDir, $IsPagePosted; SDV($DiffKeepDays,3650); SDV($DeleteKeyPattern,"^\\s*delete\\s*$"); $IsPagePosted = false; if ($EnablePost) { $new["author"]=@$Author; $new["author:$Now"] = @$Author; $new["host:$Now"] = $_SERVER['REMOTE_ADDR']; $diffclass = preg_replace('/\\W/','',@$_POST['diffclass']); if ($page["time"]>0 && function_exists(@$DiffFunction)) $new["diff:$Now:{$page['time']}:$diffclass"] = $DiffFunction($new['text'],@$page['text']); $keepgmt = $Now-$DiffKeepDays * 86400; $keys = array_keys($new); foreach($keys as $k) if (preg_match("/^\\w+:(\\d+)/",$k,$match) && $match[1]<$keepgmt) unset($new[$k]); if (preg_match("/$DeleteKeyPattern/",$new['text'])) $WikiDir->delete($pagename); else WritePage($pagename,$new); $IsPagePosted = true; } } function PostRecentChanges($pagename,&$page,&$new) { global $IsPagePosted, $RecentChangesFmt, $RCDelimPattern, $RCLinesMax; if (!$IsPagePosted) return; foreach($RecentChangesFmt 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); if (@$RCLinesMax > 0) $rcpage['text'] = implode("\n", array_slice( explode("\n", $rcpage['text'], $RCLinesMax + 1), 0, $RCLinesMax)); WritePage($rcname, $rcpage); } } function PreviewPage($pagename,&$page,&$new) { global $IsPageSaved, $FmtV; if (@$_POST['preview']) { $text = '(:groupheader:)'.$new['text'].'(:groupfooter:)'; $FmtV['$PreviewText'] = MarkupToHTML($pagename,$text); } } function HandleEdit($pagename, $auth = 'edit') { global $IsPagePosted, $EditFields, $ChangeSummary, $EditFunctions, $EnablePost, $FmtV, $Now, $EditRedirectFmt, $PageEditForm, $HandleEditFmt, $PageStartFmt, $PageEditFmt, $PageEndFmt; SDV($EditRedirectFmt, '$FullName'); if (@$_POST['cancel']) { Redirect(FmtPageName($EditRedirectFmt, $pagename)); return; } Lock(2); $IsPagePosted = false; $page = RetrieveAuthPage($pagename, $auth, true); if (!$page) Abort("?cannot edit $pagename"); PCache($pagename,$page); $new = $page; foreach((array)$EditFields as $k) if (isset($_POST[$k])) $new[$k]=str_replace("\r",'',stripmagic($_POST[$k])); $new['csum'] = $ChangeSummary; if ($ChangeSummary) $new["csum:$Now"] = $ChangeSummary; $EnablePost &= preg_grep('/^post/', array_keys(@$_POST)); foreach((array)$EditFunctions as $fn) $fn($pagename,$page,$new); Lock(0); if ($IsPagePosted && !@$_POST['postedit']) { Redirect(FmtPageName($EditRedirectFmt, $pagename)); return; } $FmtV['$DiffClassMinor'] = (@$_POST['diffclass']=='minor') ? "checked='checked'" : ''; $FmtV['$EditText'] = str_replace('$','$',htmlspecialchars(@$new['text'],ENT_NOQUOTES)); $FmtV['$EditBaseTime'] = $Now; if (@$PageEditForm) { $form = ReadPage(FmtPageName($PageEditForm, $pagename), READPAGE_CURRENT); $FmtV['$EditForm'] = MarkupToHTML($pagename, $form['text']); } SDV($PageEditFmt, "$[EnterAttributes]