[Pmwiki-users] Orphaned pages search?

Patrick R. Michaud pmichaud at pobox.com
Sat May 24 11:22:41 CDT 2003


--PEIAKu/WMn1b1Hv9
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

Found the problem with Galleon/Mozilla not being able to produce the
output results--it was a bug in the refcount.php script that wasn't
correctly specifying a value for the submit button.  A corrected
refcount.php is attached (and will appear in the next PmWiki release).

Pm



On Sat, May 24, 2003 at 07:49:11AM -0500, Tom Hoover wrote:
> On Fri, May 23, 2003 at 11:33:15PM -0600, Patrick R. Michaud wrote:
> > Yeah, refcount is supposed to be able to find orphaned pages for you.
> > You're getting the form but not results?  That's a bit odd--I'm not
> > exactly sure why that would be happening.  After pressing the submit
> > button, are you at least getting the headers that appear below the 
> > refcount form, or are those missing also?
> 
> I'm not even getting the table headers...the resulting page looks
> _exactly_ like the original page (only the form and submit
> button...nothing below the horizontal line).
> 
> > I've enabled ?action=refcount on the pmichaud.com site so that you can
> > try it out there.  
> 
> I went to your site, and experienced the exact same thing.  Since I'm
> sure that it's definitely working on your site, I did a little more
> investigative work.  I normally run Galeon (based on Mozilla).  I tried
> the following browsers, with the following results:
> 
> Linux:
> 	Galeon				doesn't work
> 	Mozilla				doesn't work
> 	Opera				works
> 
> Win98 (Please don't tell anyone...I don't really have a Windows machine, 
> 		but rather an emulated one under Win4Lin):   :-)
> 	Mozilla				doesn't work
> 	Internet Explorer	works
> 
> So, it appears that it's something related to Mozilla.  I looked at the
> HTML source of the resulting page...the results table is completely
> missing.
> 
> I'm curious...what browser do you use?
> 
> 
> _______________________________________________
> Pmwiki-users mailing list
> Pmwiki-users at pmichaud.com
> http://pmichaud.com/mailman/listinfo/pmwiki-users_pmichaud.com
> 

--PEIAKu/WMn1b1Hv9
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="refcount.php"

<?php
/*  Copyright 2002-2003 Patrick R. Michaud (pmichaud at pobox.com)
    This file is part of PmWiki; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published
    by the Free Software Foundation; either version 2 of the License
    (at your option) any later version.  See pmwiki.php for full details.

    This file adds the capability to perform reference counts on
    pages in the PmWiki database.  Simply use "?action=refcount" to
    bring up the reference count form.  The output is a table
    where each row of the table contains a page name or link reference,
    the number of (non-RecentChanges) pages that contain links to the
    page, the number of RecentChanges pages with links to the page, and
    the total number of references in all pages.

    Adding "&expand=y" to the URL causes each entry to be followed by
    a list of the pages containing references to the link or page.

    This script can be activated by placing 
	include_once("scripts/refcount.php");
    in the local.php file.
*/

SDV($PageRefCountFmt,"<h1>Reference Count Results</h1><p>");
SDV($RefCountTimeFmt," <small>%Y-%b-%d %H:%M</small>");
if ($action=='refcount') { HandleRefCount(); EndHTML(); exit(); }

function HandleRefCount() {
  global $WikiLibDirs,$WikiDir,$GroupNamePattern,$PageTitlePattern,
    $PageRefCountFmt,$WikiWordPattern,$FreeLinkPattern,$UrlPathPattern,
    $WikiPageExistsFmt, $WikiPageCreateFmt, $WikiPageCreateSpaceFmt,
    $RefCountTimeFmt;
  $expand = $HTTP_GET_VARS['expand'];
  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');
  $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 = "<a target='_blank' href='\$PageUrl'>\$LinkText</a>";
  $WikiPageCreateFmt = 
    "\$LinkText<a target='_blank' href='\$PageUrl?action=edit'>?</a>";
  $WikiPageCreateSpaceFmt = $WikiPageCreateFmt;
  
  StartHTML("Reference count results");
  echo FmtPageName($PageRefCountFmt,NULL);
  echo "<form method='post'><input type='hidden' action='refcount'>
    <table cellspacing='10'><tr><td valign='top'>Show 
    <br><select name='whichrefs'>";
  foreach($wlist as $w)  
    echo "<option ",($whichrefs==$w) ? 'selected' : ''," value='$w'>$w\n";
  echo "</select></td><td valign='top'> page names in group<br>
    <select name='tlist[]' multiple size='4'>";
  foreach($grouplist as $g=>$t) 
    echo "<option ",in_array($g,$tlist) ? 'selected' : ''," value='$g'>$t\n";
  echo "</select></td><td valign='top'> referenced from pages in<br>
    <select name='flist[]' multiple size='4'>";
  foreach($grouplist as $g=>$t) 
    echo "<option ",in_array($g,$flist) ? 'selected' : ''," value='$g'>$t\n";
  echo "</select></td></tr></table>
    <p><input type='checkbox' name='showrefs' value='checked' $showrefs> 
      Display referencing pages
    <p><input type='submit' name='submit' value='Search'></form><p><hr>";
  if ($submit) {
    foreach($pagelist as $pagename) {
      $ref=array();
      if (!in_array('all',$flist) && 
          !in_array(FmtPageName('$Group',$pagename),$flist)) continue;
      $page = ReadPage($pagename);  if (!$page) continue;
      $text = preg_replace("/\\[\\=.*?\\=\\]/",' ',$page['text']);
      $text = preg_replace("/\\w+:($UrlPathPattern)/",' ',$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)]++;
      }
      $rc = preg_match('/RecentChanges$/',$pagename);
      $tref[$pagename]['time'] = $page['time'];
      foreach($ref as $r=>$c) {
        $tref[$r]['tot'] += $c;
        if ($rc) $tref[$r]['rc']++;
        else { $tref[$r]['page']++; $pref[$r][$pagename]++; }
      }
    }
    uasort($tref,'RefCountCmp');
    echo "<table >
      <tr><th></th><th colspan='2'>Referring pages</th><th>Total</th></tr>
      <tr><th>Name / Time</th><th>All</th><th>R.C.</th><th>Refs</th></tr>";
    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;
      echo "<tr><td valign='top'>",FmtWikiLink('',$p,NULL),
        strftime($RefCountTimeFmt,$tref[$p]['time']);
      if ($showrefs && is_array($pref[$p])) {
        foreach($pref[$p] as $pr=>$pc) echo "<dd>",FmtWikiLink('',$pr,NULL);
      }
      echo "</td>";
      echo "<td align='center' valign='top'>",
        FmtPageName("<a href='\$ScriptUrl?action=search&amp;text=\$Title_'
          target='_blank'>",$p),$tref[$p]['page']+0,"</a></td>";
      echo "<td align='center' valign='top'>",$tref[$p]['rc'],"</td>";
      echo "<td align='center' valign='top'>",$tref[$p]['tot'],"</td>";
      echo "</tr>";
    }
    echo "</table>";
  }
  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'];
}
  
?>

--PEIAKu/WMn1b1Hv9--




More information about the pmwiki-users mailing list