[pmwiki-users] summarize function (pagelisting with includes)

Martin Fick fick at fgm.com
Fri Mar 4 13:47:54 CST 2005


  I have hacked the include fucniton to create a new markup
and function called summarize.  Think of this as a
multi-file include. The syntax is similar to the include
syntax (:summarize pages#start#end:) where pages is a
regular expression wildcard.  This includes the text from
all the matching pages if they contain the start anchor. 
It preceedes each page's include text with the name of the
page linked to itself.

            --------
Example:
 
  (:summarixe  Machine.*#Net#NetEnd)
  
  Suppose there are many wiki pages starting with the name
Machine i.e. Machine_bilbo, Machine_frodo, ..., and that
the each have a  section with their network info describes
as such:

[[#Net]]
   IP: xxx.xxx.xxx.xxx
   Mask: xxx.xxx.xxx.xxx
   Gateway: xxx.xxx.xxx.xxx
[[#Netend]]



Than you would see this included:


Machine_bilbo (link)

   IP: xxx.xxx.xxx.xxx
   Mask: xxx.xxx.xxx.xxx
   Gateway: xxx.xxx.xxx.xxx

Machine_frodo (link)

   IP: xxx.xxx.xxx.xxx
   Mask: xxx.xxx.xxx.xxx
   Gateway: xxx.xxx.xxx.xxx

Machine_.... (link)

   IP: xxx.xxx.xxx.xxx
   Mask: xxx.xxx.xxx.xxx
   Gateway: xxx.xxx.xxx.xxx

            --------

  I hope this might be usefull to someone else or if it can
be improved (I think globbing might be better than
regexp), included as an addition to pmwiki.

  It seems like there might be other similar ideas that
could be added too/instead.  Maybe (:include:) should be
enhanced to do globbing (similar without titles), and/or
(:pagelist:) could be enhanced to perform this?

-Martin


-----------------------------------------------------------------------
Code:


Markup('summarize','>if',"/\\(:(summarize\\s+.+?):\\)/e",
  "PRR().SummarizeText(\$pagename,'$1')");

function SummarizeText($pagename,$inclspec) {
  global $MaxIncludes,$IncludeBadAnchorFmt;
  SDV($IncludeBadAnchorFmt,"summarize: #\$BadAnchor \$[not found]\n");
  $npat = '[[:alpha:]][-\\w]*';
  if (preg_match("/^summarize\\s+([^#\\s]+)(.*)$/",$inclspec,$match)) {
    @list($inclstr,$inclname,$opts) = $match;
    $inclnames = ListPages("|$inclname|");
    $stext = '';
    foreach($inclnames as $inclname) {
      $itext = "";
      if ($inclname==$pagename) continue;
      $inclpage=RetrieveAuthPage($inclname,'read',false);
      $itext=@$inclpage['text'];
      foreach(preg_split('/\\s+/',$opts) as $o) {
        if (preg_match("/^#($npat)?(\\.\\.)?(#($npat)?)?$/",$o,$match)) {
          @list($x,$aa,$dots,$b,$bb)=$match;
          if (!$dots && !$b) $bb=$npat;
          if ($b=='#') $bb=$npat;
          if ($aa) {
            $anchor=preg_match("/^.*?([^\n]*\\[\\[#$aa\\]\\])/s", $itext);
            if ($anchor)
              $itext=preg_replace("/^.*?([^\n]*\\[\\[#$aa\\]\\])/s",'$1',$itext,1);
            else $itext = "";
          }
          if ($bb)
          	$itext=preg_replace("/(.)[^\n]*\\[\\[#$bb\\]\\].*$/s",'$1',$itext,1);
          continue;
        }
      }
      if ($itext)  $itext = "\n!!!![[$inclname]]\n\n" . $itext;
      $stext .= htmlspecialchars($itext,ENT_NOQUOTES);
    }
    return $stext;
  }
  return Keep($inclspec);
}



More information about the pmwiki-users mailing list