|
PITS /
00985Summary: Same group link formatting
Created: 2007-10-03 11:48
Status: Open
Category: Feature
From: pjv
Assigned:
Priority: 31
Version: 2.2.0-beta63
OS: N/A
Description: For my website I wanted the sidebar to have links for each group and to further have specific CSS styling if the current page is of that group. Unfortunately, the current PmWiki only seems to offer 'selflink' and 'wikilink' classes. I wanted an additional class 'grouplink' to be added to any link that targets the same group as the current page. I made the following changes to pmwiki.php, LinkPage function:
$tgtgroup = PageVar($tgtname, '$Group');
$pagegroup = PageVar($pagename, '$Group');
$fmt = ($tgtname == $pagename && $qf == '')
? $LinkPageSelfFmt
: ($tgtgroup == $pagegroup)
? $LinkGroupFmt : $LinkPageExistsFmt;
$LinkPageSelfFmt = '<a class=\'selflink grouplink\' href=\'$LinkUrl\'>$LinkText</a>'; $LinkGroupFmt = '<a class=\'wikilink grouplink\' href=\'$LinkUrl\'>$LinkText</a>'; I have no idea if this is a good way of achieving my desired result, but it works for me. I'm adding it to PITS because I'd prefer not to have to patch every time I upgrade, and would like to know if there's a better way of achieving the same result. You could achieve the same result without having to patch the core (see below):
You may then use it directly from Related source code:
<?php if (!defined('PmWiki')) exit();
function LinkPageGroup($pagename,$imap,$path,$title,$txt,$fmt=NULL) {
global $QueryFragPattern, $LinkPageExistsFmt, $LinkPageSelfFmt,
$LinkPageCreateSpaceFmt, $LinkPageCreateFmt, $LinkTargets,
$EnableLinkPageRelative, $LinkGroupFmt;
if (!$fmt && $path{0} == '#') {
$path = preg_replace("/[^-.:\\w]/", '', $path);
return ($path) ? "<a href='#$path'>$txt</a>" : '';
}
if (!preg_match("/^\\s*([^#?]+)($QueryFragPattern)?$/",$path,$match))
return '';
$tgtname = MakePageName($pagename, $match[1]);
if (!$tgtname) return '';
$qf = @$match[2];
@$LinkTargets[$tgtname]++;
if (!$fmt) {
if (!PageExists($tgtname) && !preg_match('/[&?]action=/', $qf))
$fmt = preg_match('/\\s/', $txt)
? $LinkPageCreateSpaceFmt : $LinkPageCreateFmt;
else {
$tgtgroup = PageVar($tgtname, '$Group');
$pagegroup = PageVar($pagename, '$Group');
$fmt = ($tgtname == $pagename && $qf == '')
? $LinkPageSelfFmt
: ($tgtgroup == $pagegroup)
? $LinkGroupFmt : $LinkPageExistsFmt;
}
}
$url = PageVar($tgtname, '$PageUrl');
if (@$EnableLinkPageRelative)
$url = preg_replace('!^[a-z]+://[^/]*!i', '', $url);
$fmt = str_replace(array('$LinkUrl', '$LinkText'),
array($url.PUE($qf), $txt), $fmt);
return FmtPageName($fmt,$tgtname);
}
$LinkPageSelfFmt = '<a class=\'selflink grouplink\' href=\'$LinkUrl\'>$LinkText</a>';
$LinkGroupFmt = '<a class=\'wikilink grouplink\' href=\'$LinkUrl\'>$LinkText</a>';
$LinkFunctions['<:page>'] = 'LinkPageGroup';
BTW, you just come to write your own cookbook recipe. I'll let you release it as a real one ;) Dfaure October 04, 2007, at 07:59 AM Thanks! Of course, maintaining a whole function in a cookbook entry is actually more work than updating two lines in pmwiki.php when upgrading. Still, it's a bit cleaner I suppose. Do you happen to know if the solution is correct? I couldn't work out what $qf is used for in the original code. - pjv Improved Solution: Active Page Group ParentsI updated your suggestions and came up with the following solution which also adds extra information about the link. Here is an illustration, imagine a list of links possibly put in a Group header.
If we are currently viewing the Group 1 parent 2 then the following class names are applied to the links:
Notice that only the group members of the currently selected page have
The best way to achieve this is to overwrite the default There is a working solution from some time -- you can have a different CSS class to links to other WikiGroups. Check it at Cookbook.ExternalLinks. --Petko November 15, 2007, at 06:18 PM |