[Pmwiki-users] code for trees (update)

J. Meijer commentgg
Fri Jul 30 17:54:10 CDT 2004


There are some problems with the code I sent earlier which may confuse, so here is an update. Most corrections do not affect the basic demonstration the code represents, because the leading '.', '/' and '//' are not recognized by pmwiki. 

Note also that when you specify a bare pagename, such as [[\\Page]], the link will get $DefaultTitle appended, because I used FmtWikiLink(). 

The revised code has been update within the context of the original message, below. 

Better luck this time. 

-jm



ps I'm now in need of an "all-pages renaming mechanism" and persistent links through a page-id. 


----- Original Message ----- 
Subject: code for trees



Below you'll find code for working with trees, using the tree-syntax I published in another mail. The thing was put together today in a few spare hours. But apparently it is working, at least it is *already* useful demonstration. 

Limitations: the [[.ParentPage]], [[/SubPage]] and [[//Global.Group.Page]] constructs don't work, because this requires reworking of some more regular expressions inside of pmwiki.php (for these to accept the leading '.', '/' and '//'). PM does this best anyway. 

Also, because the '/' is used to denote root or groundlevels, this breaks the PmWiki/Documentation style of links: you'll need to use the [[PmWiki.Documentation docs]] style. I'm using [PmWiki.{Documentation}] instead. 

I will *not* be pursuing further integration of trees in pmwiki because I am using an entirely different proprietary syntax. So the code below is just a useful proof of concept for others to integrate. 

The code is very small. Which is a credit to the pmwiki group. 

To make the code work you'll need to make a small patch to pmwiki right after the assignments of $LinkPatterns, see the code below. As said, to enable all functionality, more patches to regular expressions in pmwiki.php are needed. 

Goodluck,

Jan



-----------------------------------------
Lloydd Budd, still here?
-----------------------------------------


# put in the local/config.php at the end 
# because $GroupnamePattern is replaced.

function resolveLink($lnk,$pg) {
  if(false!==$i=strpos($lnk,'/')) { 
    # PeerPage/SubPage OR //PmWiki.Documentation
    if(($i==0) and (@$lnk[1]=='/')) return substr($lnk,2);
    $lnk=explode('/',$lnk,2);
    if(!$i) return "$pg.$lnk[1]";
    return resolveLink($lnk[0],$pg).'.'.$lnk[1];
  } else { 
    #normal relative or anchored link (.Middle.Page)
    $lnks=explode('.',$lnk);
    $pg=explode('.',$pg);
    if($lnk[0]!='.') { 
      # peer page
      $pg=array_splice($pg,0,count($pg)-count($lnks));
      if($pg=implode($pg,'.'))$pg.='.';
      return $pg.$lnk;
    } else { 
      # anchored .Middle.Page
      while(count($pg) and (array_pop($pg)!=$lnks[1]));
      if(!$pg=implode('.',$pg)) return substr($lnk,1);
      return $pg.$lnk;
} } }

$treeowl=$FmtWikiLink;
$FmtWikiLink='treeWikiLink';

function treeWikiLink($pat,$ref,$btext,$out=NULL,$rname=NULL) {
  global $treeowl,$pagename;
  $ref=resolveLink($ref,$pagename);
  return $treeowl($pat,$ref,$btext,$out,$rname);
}

$OLDGNP=$GroupNamePattern;
$GroupNamePattern="{$OLDGNP}(?:[\\/.]$OLDGNP)*";

### You need to PATCH pmwiki.php, at least: ###
#--- if (preg_match("/^($GroupnamePattern)[\\/.]?\$/",$pagename,$match)) { 
#+++ if (preg_match("/^($OLDGNP)[\\/.]?\$/",$pagename,$match)) {





----- From Original Message ----- 
Subject: Wikilink tree syntax

I'll be going with a group.page scheme where the group can have structure, f.e. "A.B.C". That structure I'll still treat as a group even though it now has internal structure. Wikilinks are resolved in the following manner.

Simple wikilinks. From within "Group.Page" the following wikilinks become:
 [PeerPage] ___________Group*PeerPage
 [PeerGroup.Page] ______PeerGroup.Page
 [Higher.Group.Page] ____Higher.Group.Page

Using this form of wikilinks, the current pmwiki pagenames can be created, but now also at any desired depth. The asterisks '*' is used to visualize the point where defaulting from the current path ends.

>From within "Top.Middle.Group.Page" the same wikilinks become:
 [PeerPage] ___________Top.Middle.Group*PeerPage
 [PeerGroup.Page] ______Top.Middle*PeerGroup.Page
 [Higher.Group.Page] ____Top*Higher.Group.Page

All the above simple wikilinks are relative to the current group.

Going up in a tree. Begin the wikilink with the separator. In the example it is used to anchor the starting level to 'Middle', wherever it is located
within the path:
 [.Middle] _____________Top*Middle
 [.Middle.Page] _________Top*Middle.Page

Going deeper. Use an anchor, here '/' is chosen, to denote the current groundlevel:
 [/Sub] _______________Top.Middle.Group.Page*Sub
 [/Sub.Note] ___________Top.Middle.Group.Page*Sub.Note

Going to a subpage in any peer (=page at same depth but in another group). Use the groundlevel anchor:
 [Peer/Sub] ____________Top.Middle.Group*Peer.Sub
 [Group.Peer/Sub.Note] __Top.Middle*Group.Peer.Sub.Note

Making a global reference. Only required from within a complex tree. Include the wikilink after two anchors (my choice for simplicity):
 [//Top.Middle] _________*Top.Middle
 [//Top.Middle.Group] ____*Top.Middle.Group


-------------- next part --------------
An HTML attachment was scrubbed...
URL: /pipermail/pmwiki-users_pmichaud.com/attachments/20040730/8f94abc5/attachment.htm


More information about the pmwiki-users mailing list