Blame
Date:
Thu Jan 27 05:00:26 2022 UTC
Message:
Daily backup
001
2021-12-17
jrmu
<?php if (!defined('PmWiki')) exit();
002
2021-12-17
jrmu
/* Copyright 2004-2018 Patrick R. Michaud (pmichaud@pobox.com)
003
2021-12-17
jrmu
This file is part of PmWiki; you can redistribute it and/or modify
004
2021-12-17
jrmu
it under the terms of the GNU General Public License as published
005
2021-12-17
jrmu
by the Free Software Foundation; either version 2 of the License, or
006
2021-12-17
jrmu
(at your option) any later version. See pmwiki.php for full details.
007
2021-12-17
jrmu
008
2021-12-17
jrmu
This file does simple reference counting on pages in a PmWiki site.
009
2021-12-17
jrmu
Simply activate this script using
010
2021-12-17
jrmu
include_once('scripts/refcount.php');
011
2021-12-17
jrmu
in the config.php file and then use ?action=refcount to bring up
012
2021-12-17
jrmu
the reference count form. The output is a table where each row
013
2021-12-17
jrmu
of the table contains a page name or link reference, the number
014
2021-12-17
jrmu
of (non-RecentChanges) pages that contain links to the page,
015
2021-12-17
jrmu
the number of RecentChanges pages with links to the page, and the
016
2021-12-17
jrmu
total number of references in all pages.
017
2021-12-17
jrmu
018
2021-12-17
jrmu
Script maintained by Petko YOTOV www.pmwiki.org/petko
019
2021-12-17
jrmu
*/
020
2021-12-17
jrmu
021
2021-12-17
jrmu
SDV($PageRefCountFmt,"<h2 class='wikiaction'>Reference Count Results</h2>");
022
2021-12-17
jrmu
SDV($RefCountTimeFmt," <small>%Y-%b-%d %H:%M</small>");
023
2021-12-17
jrmu
SDV($HandleActions['refcount'], 'HandleRefCount');
024
2021-12-17
jrmu
025
2021-12-17
jrmu
function PrintRefCount($pagename) {
026
2021-12-17
jrmu
global $GroupPattern,$NamePattern,$PageRefCountFmt,$RefCountTimeFmt, $ScriptUrl;
027
2021-12-17
jrmu
$pagelist = ListPages();
028
2021-12-17
jrmu
$grouplist = array();
029
2021-12-17
jrmu
foreach($pagelist as $pname) {
030
2021-12-17
jrmu
if (!preg_match("/^($GroupPattern)[\\/.]($NamePattern)$/",$pname,$m))
031
2021-12-17
jrmu
continue;
032
2021-12-17
jrmu
$grouplist[$m[1]]=$m[1];
033
2021-12-17
jrmu
}
034
2021-12-17
jrmu
asort($grouplist);
035
2021-12-17
jrmu
$grouplist = array_merge(array('all' => 'all groups'),$grouplist);
036
2021-12-17
jrmu
037
2021-12-17
jrmu
$wlist = array('all','missing','existing','orphaned');
038
2021-12-17
jrmu
$tlist = isset($_REQUEST['tlist']) ? $_REQUEST['tlist'] : array('all');
039
2021-12-17
jrmu
$flist = isset($_REQUEST['flist']) ? $_REQUEST['flist'] : array('all');
040
2021-12-17
jrmu
$whichrefs = @$_REQUEST['whichrefs'];
041
2021-12-17
jrmu
$showrefs = (@$_REQUEST['showrefs']=='checked')? "checked='checked'" : '';
042
2021-12-17
jrmu
$submit = @$_REQUEST['submit'];
043
2021-12-17
jrmu
044
2021-12-17
jrmu
echo FmtPageName($PageRefCountFmt,$pagename);
045
2021-12-17
jrmu
echo FmtPageName("<form method='post' action='{\$PageUrl}'><input type='hidden' name='action' value='refcount'/>
046
2021-12-17
jrmu
<table cellspacing='10'><tr><td valign='top'>Show
047
2021-12-17
jrmu
<br/><select name='whichrefs'>",$pagename);
048
2021-12-17
jrmu
foreach($wlist as $w)
049
2021-12-17
jrmu
echo "<option ",($whichrefs==$w) ? 'selected="selected"' : ''," value='$w'>$w</option>\n";
050
2021-12-17
jrmu
echo "</select></td><td valign='top'> page names in group<br/>
051
2021-12-17
jrmu
<select name='tlist[]' multiple='multiple' size='4'>";
052
2021-12-17
jrmu
foreach($grouplist as $g=>$t)
053
2021-12-17
jrmu
echo "<option ",in_array($g,$tlist) ? 'selected="selected"' : ''," value='$g'>$t</option>\n";
054
2021-12-17
jrmu
echo "</select></td><td valign='top'> referenced from pages in<br/>
055
2021-12-17
jrmu
<select name='flist[]' multiple='multiple' size='4'>";
056
2021-12-17
jrmu
foreach($grouplist as $g=>$t)
057
2021-12-17
jrmu
echo "<option ",in_array($g,$flist) ? 'selected="selected"' : ''," value='$g'>$t</option>\n";
058
2021-12-17
jrmu
echo "</select></td></tr></table>
059
2021-12-17
jrmu
<p><input type='checkbox' name='showrefs' id='chk_showrefs' value='checked' $showrefs/>
060
2021-12-17
jrmu
<label for='chk_showrefs'>Display referencing pages</label>
061
2021-12-17
jrmu
</p><p><input type='submit' name='submit' value='Search'/></p></form><hr/>";
062
2021-12-17
jrmu
063
2021-12-17
jrmu
if ($submit) {
064
2021-12-17
jrmu
foreach($pagelist as $pname) {
065
2021-12-17
jrmu
$ref = array();
066
2021-12-17
jrmu
$page = ReadPage($pname, READPAGE_CURRENT);
067
2021-12-17
jrmu
if (!$page) continue;
068
2021-12-17
jrmu
$tref[$pname]['time'] = $page['time'];
069
2021-12-17
jrmu
if (!in_array('all',$flist) &&
070
2021-12-17
jrmu
!in_array(FmtPageName('$Group',$pname),$flist)) continue;
071
2021-12-17
jrmu
$rc = preg_match('/RecentChanges$/',$pname);
072
2021-12-17
jrmu
foreach(explode(',',@$page['targets']) as $r) {
073
2021-12-17
jrmu
if ($r=='') continue;
074
2021-12-17
jrmu
if ($rc) @$tref[$r]['rc']++;
075
2021-12-17
jrmu
else { @$tref[$r]['page']++; @$pref[$r][$pname]++; }
076
2021-12-17
jrmu
}
077
2021-12-17
jrmu
}
078
2021-12-17
jrmu
uasort($tref,'RefCountCmp');
079
2021-12-17
jrmu
echo "<table class='refcount'>
080
2021-12-17
jrmu
<tr><th></th><th colspan='2'>Referring pages</th></tr>
081
2021-12-17
jrmu
<tr><th>Name / Time</th><th>All</th><th>R.C.</th></tr>";
082
2021-12-17
jrmu
reset($tref);
083
2021-12-17
jrmu
foreach($tref as $p=>$c) {
084
2021-12-17
jrmu
if (!in_array('all',$tlist) &&
085
2021-12-17
jrmu
!in_array(FmtPageName('$Group',$p),$tlist)) continue;
086
2021-12-17
jrmu
if ($whichrefs=='missing' && PageExists($p)) continue;
087
2021-12-17
jrmu
elseif ($whichrefs=='existing' && !PageExists($p)) continue;
088
2021-12-17
jrmu
elseif ($whichrefs=='orphaned' &&
089
2021-12-17
jrmu
(@$tref[$p]['page']>0 || !PageExists($p))) continue;
090
2021-12-17
jrmu
echo "<tr><td valign='top'>",LinkPage($pagename, '', $p, '', $p);
091
2021-12-17
jrmu
if (@$tref[$p]['time']) echo strftime($RefCountTimeFmt,$tref[$p]['time']);
092
2021-12-17
jrmu
if ($showrefs && is_array(@$pref[$p])) {
093
2021-12-17
jrmu
foreach($pref[$p] as $pr=>$pc)
094
2021-12-17
jrmu
echo "<dd>", LinkPage($pagename, '', $pr, '', $pr);
095
2021-12-17
jrmu
}
096
2021-12-17
jrmu
echo "</td>";
097
2021-12-17
jrmu
echo "<td align='center' valign='top'>",@$tref[$p]['page']+0,"</td>";
098
2021-12-17
jrmu
echo "<td align='center' valign='top'>",@$tref[$p]['rc']+0,"</td>";
099
2021-12-17
jrmu
echo "</tr>";
100
2021-12-17
jrmu
}
101
2021-12-17
jrmu
echo "</table>";
102
2021-12-17
jrmu
}
103
2021-12-17
jrmu
}
104
2021-12-17
jrmu
105
2021-12-17
jrmu
106
2021-12-17
jrmu
function RefCountCmp($ua,$ub) {
107
2021-12-17
jrmu
if (@($ua['page']!=$ub['page'])) return @($ub['page']-$ua['page']);
108
2021-12-17
jrmu
if (@($ua['rc']!=$ub['rc'])) return @($ub['rc']-$ua['rc']);
109
2021-12-17
jrmu
return @($ub['time']-$ua['time']);
110
2021-12-17
jrmu
}
111
2021-12-17
jrmu
112
2021-12-17
jrmu
113
2021-12-17
jrmu
114
2021-12-17
jrmu
function HandleRefCount($pagename, $auth='read') {
115
2021-12-17
jrmu
global $HandleRefCountFmt,$PageStartFmt,$PageEndFmt;
116
2021-12-17
jrmu
$page = RetrieveAuthPage($pagename, $auth, true, READPAGE_CURRENT);
117
2021-12-17
jrmu
if (!$page) Abort('?unauthorized');
118
2021-12-17
jrmu
PCache($pagename, $page);
119
2021-12-17
jrmu
SDV($HandleRefCountFmt,array(&$PageStartFmt,
120
2021-12-17
jrmu
'function:PrintRefCount',&$PageEndFmt));
121
2021-12-17
jrmu
PrintFmt($pagename,$HandleRefCountFmt);
122
2021-12-17
jrmu
}
123
2021-12-17
jrmu
IRCNow