[Pmwiki-users] finding orphaned pages

Christian Ridderström chr
Sun Jan 18 09:14:17 CST 2004


On Sat, 17 Jan 2004, Christian Ridderstr?m wrote:

> On Fri, 16 Jan 2004, Patrick R. Michaud wrote:
> 
> > Take a look at the refcount.php script; it can be activated via
> > 
> >     include_once("scripts/refcount.php");
> > 
> > in local.php.  You can see it in action at
> > 
> >     http://www.pmichaud.com/wiki?action=refcount
> > 
> > Do a search for "existing" pages and then scroll to the bottom of the
> > list--all of the pages that have a reference count of zero are "orphaned"
> > pages.
> 
> This reminds me... 'refcount.php' could use an update so that it works 
> with the automatic links to groups (can't remember what cookbook this is 
> right now, but bascially, if you have a group called PmWiki and you write
> 	PmWiki
> this will automatically be interpreted as PmWiki/PmWiki (very nice btw)).
> 
> Now, IIRC, 'refcount.php' incorrectly (well, sort of) reports 'PmWiki' as 
> an orphaned link, rather than recognizing that it's the name of a group 
> etc.

This patch fixes the problem:
[chr]$ diff -u refcount.php refcount-mod.php 
--- refcount.php	2004-01-18 17:07:20.000000000 +0100
+++ refcount-mod.php	2004-01-18 17:07:09.000000000 +0100
@@ -26,7 +26,7 @@
   global $WikiLibDirs,$WikiDir,$GroupNamePattern,$PageTitlePattern,
     $PageRefCountFmt,$WikiWordPattern,$FreeLinkPattern,$UrlPathPattern,
     $WikiPageExistsFmt, $WikiPageCreateFmt, $WikiPageCreateSpaceFmt,
-    $RefCountTimeFmt;
+    $RefCountTimeFmt, $FmtWikiLink;
   if (!isset($WikiLibDirs)) $WikiLibDirs = array($WikiDir,"wikilib.d");
   $grouplist = array('all' => ' all groups');
   foreach($WikiLibDirs as $d) {
@@ -86,7 +86,7 @@
       $text = preg_replace("/\\[\\[#[A-Za-z][-.:\\w]*?\\]\\]/",' ',$text);
       if (!preg_match_all("/(($GroupNamePattern)[\\/.])?(($WikiWordPattern)|($FreeLinkPattern))/",$text,$match)) continue;
       for($i=0;$i<count($match[0]);$i++) {
-        @$ref[FmtWikiLink('',$match[0][$i],NULL,'PageName',$pagename)]++;
+        @$ref[$FmtWikiLink('',$match[0][$i],NULL,'PageName',$pagename)]++;
       }
       $rc = preg_match('/RecentChanges$/',$pagename);
       foreach($ref as $r=>$c) {

I think these changes are safe... at least they worked for me in a vanilla
configuration.

Patrick, if it's safe, maybe you could modify scripts/refcount.php?

And finally, just to be complete, this is what you use in your local 
configuration file:

// 
//      Automatic creation of group links 
// 
// The hook below changes a wiki-link pointing to a non-existing page, 
// so that it points to the homepage of a group with the same name as the 
// link (if that group and it's homepage exists). 
// 
// Caveat: If $DefaultTitle is different for different groups, this code 
// might not work properly. 
// 
// Note: If 'scripts/refcount.php' is used, it must be included below 
//       this piece of code. 
//
$oldFmtFcn_AutoCreateGroupLink = $FmtWikiLink; 
$FmtWikiLink = 'AutoCreateGroupLink'; 
function AutoCreateGroupLink($pat,$ref,$btext,$out=NULL,$pname=NULL) { 
  global $DefaultTitle, $SpaceWikiWords, $oldFmtFcn_AutoCreateGroupLink; 
  $pg = FmtWikiLink($pat,$ref,$btext,'PageName',$pname); 
  if (!PageExists($pg)) { 
    $t = preg_replace("/^.*\\./",'',$pg); 
    if (PageExists("$t.$t")) { 
      $tref = ($SpaceWikiWords) ? AsSpaced($t) : $t; 
      $ref = "$t/\{\{$tref}}"; 
    } elseif (PageExists("$t.$DefaultTitle"))  // try HomePage
      $ref = "$t.\{\{$DefaultTitle}}"; 
  } 
  return $oldFmtFcn_AutoCreateGroupLink($pat,$ref,$btext,$out,$pname); 
} 
 
include_once("scripts/refcount.php");

Should I make a cookbook page out of this?

/Christian 

-- 
Dr. Christian Ridderstr?m, +46-8-768 39 44       http://www.md.kth.se/~chr




More information about the pmwiki-users mailing list