Reference Count Results
");
SDV($RefCountTimeFmt," %Y-%b-%d %H:%M");
SDV($HandleActions['refcount'],'HandleRefCount');
function PrintRefCount() {
global $WikiLibDirs,$WikiDir,$GroupNamePattern,$PageTitlePattern,
$PageRefCountFmt,$WikiWordPattern,$FreeLinkPattern,$UrlPathPattern,
$WikiPageExistsFmt, $WikiPageCreateFmt, $WikiPageCreateSpaceFmt,
$RefCountTimeFmt,$InterMapUrls,$LinkPatterns;
if (!isset($WikiLibDirs)) $WikiLibDirs = array($WikiDir,"wikilib.d");
$grouplist = array('all' => ' all groups');
foreach($WikiLibDirs as $d) {
$dp = opendir($d);
if (!$dp) continue;
while (($pagename = readdir($dp))!==false) {
if (!preg_match("/^($GroupNamePattern)\.$PageTitlePattern\$/",$pagename,
$match)) continue;
$pagelist[$pagename] = $pagename;
$grouplist[$match[1]] = $match[1];
}
closedir($dp);
}
asort($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'];
$WikiPageExistsFmt = "\$LinkText";
$WikiPageCreateFmt =
"\$LinkText?";
$WikiPageCreateSpaceFmt = $WikiPageCreateFmt;
echo FmtPageName($PageRefCountFmt,NULL);
echo "
";
if ($submit) {
ksort($LinkPatterns);
foreach($LinkPatterns as $n=>$a)
foreach($a as $p=>$r) $linkpats[$p]=$r;
foreach($pagelist as $pagename) {
$ref=array();
$page = ReadPage($pagename); Lock(0);
if (!$page) continue;
$tref[$pagename]['time'] = $page['time'];
if (!in_array('all',$flist) &&
!in_array(FmtPageName('$Group',$pagename),$flist)) continue;
$text = preg_replace("/\\[\\=.*?\\=\\]/s",' ',$page['text']);
foreach($linkpats as $p=>$r)
$text = preg_replace("/\\[\\[($p)(\\s*.*?)?\\]\\]/",'$1',$text);
$text = preg_replace("/\\w+:($UrlPathPattern)/",' ',$text);
$text = preg_replace("/\\$$WikiWordPattern/",' ',$text);
$text = preg_replace("/\\[\\[#[A-Za-z][-.:\\w]*?\\]\\]/",' ',$text);
foreach($InterMapUrls as $mapid=>$mapurl) {
$text = preg_replace("/\\b$mapid:($UrlPathPattern)/",' ',$text);
}
if (!preg_match_all("/(($GroupNamePattern)[\\/.])?(($WikiWordPattern)|($FreeLinkPattern))/",$text,$match)) continue;
for($i=0;$i$c) {
@$tref[$r]['tot'] += $c;
if ($rc) @$tref[$r]['rc']++;
else { @$tref[$r]['page']++; @$pref[$r][$pagename]++; }
}
}
uasort($tref,'RefCountCmp');
echo "
| Referring pages | Total |
Name / Time | All | R.C. | Refs |
";
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 "",FmtWikiLink('',$p,NULL);
if (@$tref[$p]['time']) echo strftime($RefCountTimeFmt,$tref[$p]['time']);
if ($showrefs && is_array(@$pref[$p])) {
foreach($pref[$p] as $pr=>$pc) echo "",FmtWikiLink('',$pr,NULL);
}
echo " | ";
echo "",
FmtPageName("",$p),@$tref[$p]['page']+0," | ";
echo "",@$tref[$p]['rc']," | ";
echo "",@$tref[$p]['tot']," | ";
echo "
";
}
echo "
";
}
EndHTML();
}
function RefCountCmp($ua,$ub) {
if (@($ua['page']!=$ub['page'])) return @($ub['page']-$ua['page']);
if (@($ua['rc']!=$ub['rc'])) return @($ub['rc']-$ua['rc']);
if (@($ua['tot']!=$ub['tot'])) return @($ub['tot']-$ua['tot']);
return @($ub['time']-$ua['time']);
}
function HandleRefCount($pagename) {
global $HandleRefCountFmt,$PageStartFmt,$PageEndFmt;
$page = array('timefmt'=>@$GLOBALS['CurrentTime'],
'author'=>@$GLOBALS['Author']);
SetPageVars($pagename,$page,"Reference Counts");
SDV($HandleRefCountFmt,array(&$PageStartFmt,
'function:PrintRefCount',&$PageEndFmt));
PrintFmt($pagename,$HandleRefCountFmt);
}
?>