Reference Count Results");
SDV($RefCountTimeFmt," %Y-%b-%d %H:%M");
SDV($HandleActions['refcount'], 'HandleRefCount');
function PrintRefCount($pagename) {
global $GroupPattern,$NamePattern,$PageRefCountFmt,$RefCountTimeFmt;
$pagelist = ListPages();
$grouplist = array();
foreach($pagelist as $pname) {
if (!preg_match("/^($GroupPattern)[\\/.]($NamePattern)$/",$pname,$m))
continue;
$grouplist[$m[1]]=$m[1];
}
asort($grouplist);
$grouplist = array_merge(array('all' => 'all groups'),$grouplist);
$wlist = array('all','missing','existing','orphaned');
$tlist = isset($_REQUEST['tlist']) ? $_REQUEST['tlist'] : array('all');
$flist = isset($_REQUEST['flist']) ? $_REQUEST['flist'] : array('all');
$whichrefs = @$_REQUEST['whichrefs'];
$showrefs = @$_REQUEST['showrefs'];
$submit = @$_REQUEST['submit'];
echo FmtPageName($PageRefCountFmt,$pagename);
echo "
";
if ($submit) {
foreach($pagelist as $pname) {
$ref = array();
$page = ReadPage($pname, READPAGE_CURRENT);
if (!$page) continue;
$tref[$pname]['time'] = $page['time'];
if (!in_array('all',$flist) &&
!in_array(FmtPageName('$Group',$pname),$flist)) continue;
$rc = preg_match('/RecentChanges$/',$pname);
foreach(explode(',',@$page['targets']) as $r) {
if ($r=='') continue;
if ($rc) @$tref[$r]['rc']++;
else { @$tref[$r]['page']++; @$pref[$r][$pname]++; }
}
}
uasort($tref,'RefCountCmp');
echo "
| Referring pages |
Name / Time | All | R.C. |
";
reset($tref);
foreach($tref as $p=>$c) {
if (!in_array('all',$tlist) &&
!in_array(FmtPageName('$Group',$p),$tlist)) continue;
if ($whichrefs=='missing' && PageExists($p)) continue;
elseif ($whichrefs=='existing' && !PageExists($p)) continue;
elseif ($whichrefs=='orphaned' &&
(@$tref[$p]['page']>0 || !PageExists($p))) continue;
echo "",LinkPage($pagename, '', $p, '', $p);
if (@$tref[$p]['time']) echo strftime($RefCountTimeFmt,$tref[$p]['time']);
if ($showrefs && is_array(@$pref[$p])) {
foreach($pref[$p] as $pr=>$pc)
echo "", LinkPage($pagename, '', $pr, '', $pr);
}
echo " | ";
echo "",@$tref[$p]['page']+0," | ";
echo "",@$tref[$p]['rc']+0," | ";
echo "
";
}
echo "
";
}
}
function RefCountCmp($ua,$ub) {
if (@($ua['page']!=$ub['page'])) return @($ub['page']-$ua['page']);
if (@($ua['rc']!=$ub['rc'])) return @($ub['rc']-$ua['rc']);
return @($ub['time']-$ua['time']);
}
function HandleRefCount($pagename, $auth='read') {
global $HandleRefCountFmt,$PageStartFmt,$PageEndFmt;
$page = RetrieveAuthPage($pagename, $auth, true, READPAGE_CURRENT);
if (!$page) Abort('?unauthorized');
PCache($pagename, $page);
SDV($HandleRefCountFmt,array(&$PageStartFmt,
'function:PrintRefCount',&$PageEndFmt));
PrintFmt($pagename,$HandleRefCountFmt);
}