= $start[$i]) ||
(!is_numeric($start[$i]) && preg_match($start[$i], $line)))
$matchstatus[$i] = 1;
if ($matchstatus[$i] == 1) $matched = true;
if (!is_numeric($end[$i]) && preg_match($end[$i], $line))
$matchstatus[$i] = 0;
if (is_numeric($end[$i]) && $curlineno >= $end[$i])
$matchstatus[$i] = 2;
}
return($matched);
}
function WShReplace($opt, $page, $string, $lineno='')
{
if ($string == '') return '';
$find_str = array('PAGENAME', 'PAGELINK');
$repl_str = array($page['filename'], "[[" . $page['filename'] . "]]");
if (is_numeric($lineno)) {
$find_str[] = 'LINENO';
$repl_str[] = $lineno;
}
if (strstr($string, 'PAGETITLE')) {
$find_str[] = 'PAGETITLE';
$repl_str[] = PageVar($page['filename'], '$Title');
}
$string = str_replace($find_str, $repl_str, $string);
return($string);
}
function WikiShNotNow($OverrideActive = false)
{
global $WikiShVars, $WikiShRCPages, $action, $WikiShWriting,
$MXWhileEditing;
static $RCDone = false;
$OKActions = array('browse', 'search', 'approvesites');
if (!$RCDone) {
$OldDfltDbg = $WikiShVars['DEFAULT_DEBUG'];
$OldDbg = $WikiShVars['DEBUGLEVEL'];
$WikiShVars['DEBUGLEVEL'] = $WikiShVars['RC_DEBUG'];
foreach ($WikiShRCPages as $k => $rcpagename) {
if (isset($WikiShVars[$rcpagename])) {
$tmp = $WikiShVars[$rcpagename];
unset($WikiShRCPages[$k]);
MarkupExpression($rcpagename, "(wikish source $tmp)");
}
}
if ($OldDfltDbg == $WikiShVars['DEFAULT_DEBUG'])
$WikiShVars['DEBUGLEVEL'] = $OldDbg;
else
$WikiShVars['DEBUGLEVEL'] = $WikiShVars['DEFAULT_DEBUG'];
$RCDone = true;
}
if ((!$OverrideActive && !$WikiShVars['ACTIVE']) || (!in_array($action, $OKActions) && !$MXWhileEditing) || ($MXWhileEditing && $action != 'edit') || $WikiShWriting) {
return(true);
} else {
return(false);
}
}
function WikiShFmtPagename($pagename, $opt, $tgt)
{
return(MakePageName($pagename, $tgt));
}
function unhtmlspecialchars(&$str)
{
$rplc = array( '<' => '<', '≤' => '<=', '>' => '>', '≥' => '>=',
' ' => ' ', '&' => '&');
$str = str_replace(array_keys($rplc), array_values($rplc), $str);
return($str);
}
function WikiShTextSection($text, $sections, &$pre, &$post, $args = NULL)
{
$args = (array)$args;
$npat = '[[:alpha:]][-\\w*]*';
if (!preg_match("/#($npat)?(\\.\\.)?(#($npat)?)?/", $sections, $match))
return $text;
@list($x, $aa, $dots, $b, $bb) = $match;
if (!$dots && !$b) $bb = $npat;
if ($aa) {
$pos = strpos($text, "[[#$aa]]"); if ($pos === false) return false;
if (@$args['anchors'])
while ($pos > 0 && $text[$pos-1] != "\n") $pos--;
else $pos += strlen("[[#$aa]]");
$pre = substr($text, 0, $pos);
$text = substr($text, $pos);
}
if ($bb) {
$post = $text;
$text = preg_replace("/(\n)[^\n]*\\[\\[#$bb\\]\\](.*)$/s", '$1', $text, 1);
$post = substr($post, strlen($text));
}
return $text;
}
function WikiShParseCode($code, $SuppressKeep = false)
{
global $KeepToken, $KPV, $MarkupExpr;
$rpat = "/$KeepToken(\\d+P)$KeepToken/e";
$rrep = '$KPV[\'$1\']';
$func = "ParseCode";
$newlines = array();
$codelines = explode("\n", $code);
foreach ($codelines as $line) {
if ($SuppressKeep) {
$line = preg_replace('/(([\'"]).*?\\2)/e', "Keep(PSS('$1'),'P')", $line);
} else {
$line = preg_replace('/([\'"])(.*?)\\1/e', "Keep(PSS('$2'),'P')", $line);
$line = preg_replace('/\\(\\W/e', "Keep(PSS('$2'),'P')", $line);
}
$line = preg_replace("/(?:^|\s)\s*#.*$/", "", $line);
if ($SuppressKeep) {
$line = preg_replace($rpat, $rrep, $line);
}
if ($line && !preg_match("/^\s*$/", $line))
$newlines[] = $line;
}
$newcode = implode(";", $newlines);
$newcode = preg_replace("/;*$/", "", $newcode) . ';';
return($newcode);
}
function WikiShStdErr($pagename, $opt, $text)
{
global $MessagesFmt;
SDV($opt['stderr'], 'echo');
switch ($opt['stderr']) {
case 'messages':
if (is_array($text)) {
$MessagesFmt[] = "" . print_r($text,true) . "
\n";
} else {
$MessagesFmt[] = $text . "\n";
}
break;
case 'echo':
if (is_array($text)) {
echo "" . print_r($text,true) . "
\n";
} else {
echo $text . "
\n";
}
break;
case 'nul':
case 'null':
case '/dev/null':
break;
default:
echo "ERROR: Unhandled stderr=$opt[stderr]
\n";
}
}
if (!function_exists("wdbg")) {
function wdbg($printlevel, $text, $txt2 = '', $txt3 = '')
{
global $MessagesFmt, $WikiShVars;
if ($printlevel<$WikiShVars['DEBUGLEVEL']) return;
foreach (array($text, $txt2, $txt3) as $txt) {
if ($txt == '')
break;
elseif (is_array($text)) {
$MessagesFmt[] = "" . print_r($text,true) . "
" . ($newline ? "\n" : "");
} else {
$suffix = "";
for ($i = 4-$printlevel; $i > 0; $i--) {
$prefix .= "- ";
$suffix .= "
";
}
$prefix .= "- ";
$MessagesFmt[] = $prefix . $text . $suffix . "\n";
}
}
}
}
$MarkupExpr["wikish_devtest"] = 'WikiShDevTest($pagename, @$argp, @$args)';
function WikiShDevTest($page, $opts, $args)
{
global $WikiShVars, $InputValues, $FmtV, $foo;
echo "PRE: " . print_r($opts,true) . "
\n";
}
function WikiShMatchPageName($page, $pat, $allowslash = false)
{
$MatchedInclusive = false;
foreach((array)$pat as $p) {
if (!$p) continue;
switch ($p{0}) {
case '/':
if (preg_match($p, $page))
$MatchedInclusive = true;
continue;
case '!':
if (preg_match($p, $page))
return(false);
continue;
default:
if ($allowslash)
list($inclp, $exclp) = GlobToPCRE($p);
else
list($inclp, $exclp) = GlobToPCRE(str_replace('/', '.', $p));
if ($exclp && preg_match("/$exclp/i", $page))
return(false);
if ($inclp && preg_match("/$inclp/i", $page))
$MatchedInclusive = true;
}
}
return $MatchedInclusive;
}
function WikiShGlobToPCRE($pat, $anchor_beg=false, $anchor_end=false, $greedy=true) {
$pat = preg_quote($pat, '/');
$pat = str_replace(array('\\*',
'\\?', '\\[', '\\]', '\\^'),
array('.*' . ($greedy?'':'?'),
'.', '[', ']', '^'), $pat);
$incl = array();
foreach(preg_split('/,+\s?/', $pat, -1, PREG_SPLIT_NO_EMPTY) as $p) {
$incl[] = ($anchor_beg?'^':'') . "$p" . ($anchor_end?'$':'');
}
return (implode('|', $incl));
}