[pmwiki-users] Recent page and external link flagging features

Hans B PUFAL hans at pufal.net
Tue Aug 2 03:27:27 CDT 2005


Hello I have just started using pmwiki for a private project.

For my subscribers I thought it would be nice to flag links to pages 
which have changed recently. My home page contains a topic index and 
just by glancing there any recent changes instantly seen.

At the same time I added a second feature to flag links to external pages.

The feature involves changes to index.php as follows :

The set of link page variables needed to be moved to after the loading 
of config.php so as to allow config modifications. Also note that 
addition of $LinkPageRecentFmt :

  SDV($LinkRecentFlag,'');           # flag for recently changed pages
  SDV($LinkExternalFlag,'');	   # flag for external links	
  SDV($RecentPeriod,0);		   # Time for which pages are 'recent'

  $LinkPageSelfFmt = "<a class='selflink'  href='\$LinkUrl'>\$LinkText</a>";
  $LinkPageExistsFmt = "<a class='wikilink' 
href='\$LinkUrl'>\$LinkText</a>";
  $LinkPageRecentFmt = "<a class='wikilink' 
href='\$LinkUrl'>\$LinkText</a>.$LinkRecentFlag";
  $LinkPageCreateFmt =
   "<a class='createlinktext' 
href='\$PageUrl?action=edit'>\$LinkText</a><a
     class='createlink' href='\$PageUrl?action=edit'>?</a>";
  $UrlLinkFmt =
   "<a class='urllink' href='\$LinkUrl' 
rel='nofollow'>\$LinkText</a>.$LinkExternalFlag";

My config.php includes the following to enable recent page flagging :
I use a .png img but any HTML can be used

$LinkRecentFlag='<img src="recent.png">';
$RecentPeriod=72*60*60;

back to index.php , add the following two procedures, I put them between
readPage and writePage :

  function PageTime($pagename) {
   # return the page time
   global $WikiLibDirs,$Now;
   foreach ($WikiLibDirs as $dir)
     if ($page = $dir->read($pagename)) break;
   return (@$page['time']) ? $page['time'] : $Now;
  }

  function PageRecent($pagename) {
   global $Now,$RecentPeriod,$LinkRecentFlag;
   return $RecentPeriod && $LinkRecentFlag && (($Now - 
PageTime($pagename)) < $RecentPeriod);
  }

These can be combined but I suspect that the PageTime procedure may come 
in handy later ;-)

Finally in function LinkPage, add $LinkPageRecentFmt to the global list
and add the call to PageRecent as shown in thais fragment :

     if (PageExists($tgtname))
       $fmt = ($tgtname==$pagename && $qf=='') ?  $LinkPageSelfFmt
         : (PageRecent($tgtname) ? $LinkPageRecentFmt : 
$LinkPageExistsFmt);
     elseif (preg_match('/\\s/',$txt)) $fmt=$LinkPageCreateSpaceFmt;
     else $fmt=$LinkPageCreateFmt;


By default the entire feature is off, it must be enabled from the config 
file. A point to note is the fact that link pages are now read in order 
to get their timestamp, this may slow down page proceesing a little. I 
did think of using the filesystem timestamp but that is not what the 
rest of the code uses.

This seems to work fine but it is my first foray into pmwiki changes. If 
I have made some blunder I hope someone will (gently) point it out to me.

Hope this little hack is useful to someone, perhaps even as an update to 
a future version.

Best regards,


    Hans B PUFAL
  Paleoinformaticien
   Grenoble, FRANCE





More information about the pmwiki-users mailing list