1) $opt['n'] = true;
$opt['u'] = true; // default to a sinple timestamp
}
SDV($opt['table'], false);
if ($opt['table']) {
$opt['sep'] = '||';
$opt['line_prefix'] = '||';
$opt['line_suffix'] = '||';
}
SDV($opt['line_prefix'], '');
SDV($opt['line_suffix'], '');
SDV($opt['sep'], ',');
if ($opt['t']) SDV($opt['fmt'], '%Y-%m-%d %T');
SDV($opt['count'], 0); // unlimited
$rtn = '';
if (isset($opt['start'])) {
if (!preg_match('/^\d+$/', $opt['start'])) {
$old = $opt['start'];
$opt['start'] = strtotime($opt['start']);
if ($opt['start'] == 0)
$rtn .= "ERROR: start=\"$old\" timestamp did not convert\n";
}
} else $opt['start'] = 0;
if (isset($opt['end'])) {
if (!preg_match('/^\d+$/', $opt['end'])) {
$old = $opt['end'];
$opt['end'] = strtotime($opt['end']);
if ($opt['end'] == 0)
$rtn .= "ERROR: end=\"$old\" timestamp did not convert\n";
}
} else $opt['end'] = 0;
#echo "opts=".print_r($opt, true)."
\n";
foreach ($args as $pn) {
#echo "phList: Processing pn=$pn
\n";
$pn = MakePageName($pagename, $pn);
$page = RetrieveAuthPage($pn, 'read');
$x['author'] = $x['diff'] = $x['host'] = $x['csum'] = $time = '';
$cnt = 1;
foreach ($page as $k => $v) {
#echo "phList: Processing k=$k
\n";
if (preg_match("/^(author|diff|host|csum):(\d+)(?::\d+:)?$/", $k, $m)) {
#echo "phList: found element=".print_r($m,true)."
\n";
if ($opt['count'] && $cnt >= $opt['count']) continue;
if ($opt['start'] > $m[2]) continue;
if ($opt['end'] && $opt['end'] < $m[2]) continue;
if ($m[2] != $time) {
if ($time) {
$line = PageHistLine($pn, $opt, $x, $time);
if ($opt['links']) {
$line = "[[$pn?asof=$time|$line]]";
}
$rtn .=($rtn?"\n":"").$opt['line_prefix'].$line.$opt['line_suffix'];
$cnt++;
}
$time = $m[2];
$x['author'] = $x['diff'] = $x['host'] = $x['csum'] = '';
}
$x[$m[1]] = $v;
}
}
if ($time) {
$line = PageHistLine($pn, $opt, $x, $time);
if ($opt['links']) {
$line = "[[$pn?asof=$time|$line]]";
}
$rtn .=($rtn?"\n":"").$opt['line_prefix'].$line.$opt['line_suffix'];
}
}
if (defined('WikiSh')) return(wshPostProcess($pagename, $opt, (array)$rtn));
else return($rtn);
}
function PageHistLine($pn, $opt, $x, $time)
{
$mysep = '';
if ($opt['n']) {
$rtn .= $mysep . $pn;
$mysep = $opt['sep'];
}
if ($opt['a']) {
$rtn .= $mysep . $x['author'];
$mysep = $opt['sep'];
}
if ($opt['u']) {
$rtn .= $mysep . $time;
$mysep = $opt['sep'];
}
if ($opt['fmt']) {
$tmp = str_replace(array('{name}', '{author}', '{host}', '{desc}', '{diff}'),
array($pn, $x['author'],$x['host'],$x['csum'],$x['diff']),
strftime($opt['fmt'], $time));
$rtn .= $mysep . $tmp;
$mysep = $opt['sep'];
}
if ($opt['h']) {
$rtn .= $mysep . $x['host'];
$mysep = $opt['sep'];
}
if ($opt['l']) {
#echo "Looking in $x[diff] for %0a - found ".substr_count($x['diff'], "\n")."
\n";
$rtn .= $mysep . substr_count($x['diff'], "\n");
$mysep = $opt['sep'];
}
if ($opt['s']) {
$rtn .= $mysep . strlen($x['diff']);
$mysep = $opt['sep'];
}
if ($opt['d']) {
$rtn .= $mysep . $x['csum'];
$mysep = $opt['sep'];
}
return($rtn);
}
class PageHistStore extends PageStore {
function read($pagename, $since=0) {
global $action, $PageHistActions, $PageHistIgnorePages;
SDV($PageHistActions, array('browse', 'source'));
if (!in_array($pagename, (array)@$PageHistIgnorePages) && in_array($action, $PageHistActions) && $_REQUEST['asof']) {
if (preg_match('/^\\d+$/', $_REQUEST['asof']))
$asof = $_REQUEST['asof'];
else
$asof = strtotime($_REQUEST['asof']);
$since = $asof;
}
$page = parent::read($pagename, $since);
if (in_array($pagename, (array)@$PageHistIgnorePages) || !in_array($action, $PageHistActions)) return ($page);
if (!$page) return ($page);
if ($asof)
$page['text'] = RestorePage($pagename, $page, $junk, 'diff:'.$asof.':99999');
return($page);
}
}
# Work with links so that they will get the ?asof=timestamp as part of the
# link target
if ($_REQUEST['asof'])
$LinkFunctions['<:page>'] = 'phLinkPage';
function phLinkPage($pagename,$imap,$path,$alt,$txt,$fmt=NULL) {
if ($path && strpos($path, 'asof=') == false)
$path .= '?asof=' . $_REQUEST['asof'];
return(LinkPage($pagename, $imap, $path, $alt, $txt, $fmt));
}