|
Cookbook /
ClusterSummary:Group-clustering recipe.
Version:2007-06-26
Prerequisites:PmWiki 2.2beta, may work with 2.1.27 but not tested
Status:beta
Maintainer:Kathryn Andersen
File:cluster.phpΔ
Discussion: Cluster-Talk
Questions answered by this recipeHow can I cluster my wiki-groups so they behave like a hierarchy of groups? DescriptionGroup-clustering recipe. This recipe enables wiki-pages to be clustered, so that they can share and inherit common information:
This also provides useful page-variables, and link short-cuts. ActivationTo activate this recipe, download cluster.phpΔ and put it into your cookbook directory. Add the following line to your local/config.php:
include_once("$FarmD/cookbook/cluster.php");
Configuration variablesThese can be set in local/config.php
How The Clustering WorksLet's use the common Kingdom-Animal-Canine example. Suppose you have a group called Kingdom, another group called Kingdom-Animal, another called Kingdom-Animal-Canine, and another called Kingdom-Plant. PagesGroup headers, group footers and group attributes pages will be searched for from the specific to the general. The first page found will be the one that is used. For example, if Kingdom-Animal-Canine.GroupHeader and Kingdom.GroupHeader exist, then if one is in the Kingdom-Animal-Canine group, then Kingdom-Animal-Canine.GroupHeader will be used, but if one is in the Kingdom-Plant group then Kingdom.GroupHeader will be used. Likewise for GroupFooter and GroupAttributes. Configuration filesConfiguration files are also searched for from the specific to the general, and, again, the first one found will be the one used. Suppose local/Kingdom.php and local/Kingdom-Animal-Canine.Dog.php exist. When on the Kingdom-Animal.HomePage page, the Kingdom.php config will be used. When on the Kingdom-Animal-Canine.Dog page, the Kingdom-Animal-Canine.Dog.php config file will be used -- and the Kingdom.php config file will NOT be used. If you want to "inherit" the settings from Kingdom.php, then you would add include_once("to the Kingdom-Animal-Canine.Dog.php file. CSS style sheetsCSS style sheets follow the same pattern, but all stylesheets are included, since Cascading Style Sheets have inheritance built-in. Suppose pub/css/local.css, pub/css/Kingdom.css and pub/css/Kingdom-Animal-Canine.css exist. On the Kingdom-Animal.HomePage page, the CSS sheets will be local.css and Kingdom.css. On the Kingdom-Animal-Canine.HomePage page, the CSS sheets will be local.css, Kingdom.css and Kingdom-Animal-Canine.css. Name-based clusteringIf $ClusterEnableNameClustering is true, then clustering is done on page names as well as group names. This uses the same separator ('-' by default) as for group-based clustering. For example, if you have these pages:
When name-based clustering is enabled, you could, for example, have a special "GroupHeader" for Terriers; it would be called Kingdom-Animal-Canine.Dog-Terrier-GroupHeader and would affect the pages Kingdom-Animal-Canine.Dog-Terrier and Kingdom-Animal-Canine.Dog-Terrier-WestHighland More examplesSee http://www.katspace.org/kriki/Kingdom/ for some live examples. Link ShortcutsThree kinds of link-shortcuts are provided, when making [[links]]:
Page Variables
DirectivesTo enable more fine-grained control of both links and titles, the (:clusterslice:) directive is provided. Cluster-slice provides a "slice" of the "clustered" page-name, with options to return links, names or titles of the segments of the cluster.
Options:
Note: The start and length options are based on that of the substr PHP function.
Using the BreadCrumbThe $BreadCrumb page-variable creates a breadcrumb-trail. To use it, put in your Group.GroupHeader page:
This will display the breadcrumb trail at the top of pages in that group. So what is a breadcrumb-trail? Here's an example. If you are on the Kingdom-Animal-Feline.Cat page, the breadcrumb trail that is put into the $BreadCrumb variable would be:
The ' - ' used as a separator can be changed by setting $ClusterBreadCrumbSeparator to the desired separator. For example:
This would give
If $ClusterEnableBreadCrumbName is false, then the name of the page is not included in the breadcrumb.
The $BreadCrumbTitle page-variable creates a breadcrumb-trail where instead of using the name of the group, it uses the title in the link label. To use it, put in your Group.GroupHeader page:
The $BreadCrumbNoTitle page-variable creates a breadcrumb-trail where it always uses the name in the link label. To use it, put in your Group.GroupHeader page:
Using the SideBarIn order to take advantage of the SideBar and RightBar clustering, you need to edit your skin template. A normal skin template would have something like this:
What Cluster does is give you an additional page-variable, so you can go
instead. The $ClusterSideBar page-variable will be set to the appropriate side-bar for the current group, doing the search in the same kind of way that GroupHeader or GroupFooter etc are searched for. That is, you create a Side Bar for the Top Level Group of the cluster, it will be applied to all "Child" groups through the Custer. So, for example, if you create Kingdom.SideBar, it will be used not only for all pages in the "Kingdom" group, but all pages in the "Kingdom-Animal" and "Kingdom-Plant" groups. Likewise the $ClusterRightBar page-variable should be used in skins that have a RightBar; for example:
FunctionsFor skin writers, there is a function ClusterPageName which can be used to make general page variables to find suitable "clustered" pages in the same way that $ClusterSideBar does. The page-variable declaration for $ClusterSideBar is: $FmtPV['$ClusterSideBar'] = 'ClusterPageName($group, "SideBar", $name)'; Arguments:
So, if, for example, you want to make a $ClusterMenuBar variable, which looks for MenuBar pages, you would use the following: $FmtPV['$ClusterMenuBar'] = 'ClusterPageName($group, "MenuBar", $name)'; To make sure that this still works even if Cluster isn't installed, you would do something like this:
if (function_exists('ClusterPageName')) {
$FmtPV['$ClusterMenuBar'] = 'ClusterPageName($group, "MenuBar", $name)';
}
LimitationsThis does not give Kingdom/Animal/Canine style links; it is only limited to clustering configuration and pages. It does not provide a full "hierarchical groups" facility. TipsPage ListsThe $gN page variables are very useful in making hierarchical menus to use in your sidebar. The following is an example of one. (Note that this pagelist template is usable in PmWiki version 2.2beta36 or greater.) fmt=#hgtitle2 Two-level list of groups (showing title), giving nested hierarchical groups of top two levels.
[[#hgtitle2]]
(:template defaults order=group list=group:)
(:template first {=$g1}:)
(:if equal "{=$g0}" "1" ):)
*[[{=$Group}.|{=$GroupTitle}]]
(:ifend:)
(:template first {=$g2}:)
(:if ( equal "{=$g1}" "{*$g1}" and equal "{=$g0}" "2" ) :)
**[[{=$Group}.|{=$GroupTitle}]]
(:ifend:)
[[#hgtitle2end]]
Note that the "group" list used by this is a custom #make a group-only Group.Group/Group.HomePage search pattern $SearchPatterns['group'][] = '/([-\w]+)\.\1$|\.' . "$DefaultName" . '$/'; fmt=#currentclusterdesc This uses the $g01 variable. Devised by Kathryn Andersen and Feral.
[[#currentclusterdesc]]
(:template defaults order=group list=group:)
(:template first {=$Group}:)
(:if equal "{=$g0}" "{*$g01}" :)
*[[{=$Group}|{=$GroupTitlespaced}]]
(:if ( equal "{=$g0}" "{*$g01}" and !equal "{{=$Group}$Description}" "" ) :)
->'-%smaller italic small-caps%Description:%% {{=$Group}$Description}-'
(:ifend:)
[[#currentclusterdesc]]
fmt=#clustertrail1 Dynamic group trail of form <<prev.Title | $n1 | next.Title>>; useful for name-based clustering.
[[#clustertrail1]]
(:if equal {*$FullName} {=$FullName}:)<<[[{<$FullName}|{<$Title}]] | [[{=$Group}.{=$n1}|{=$n1}]] | [[{>$FullName}|{>$Title}]]>>(:ifend:)
[[#clustertrail1end]]
NotesThis is very similar to Cookbook.Hg because we have used each others' code. See Hierarchical Groups for differences. Release Notes
See AlsoContributorsCommentsSee discussion at Cluster-Talk User notes? : If you use, used or reviewed this recipe, you can add your name. These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki. |