[pmwiki-users] How to test permissions for target of link?

Lars Eighner surname at larseighner.com
Mon Oct 10 19:46:20 CDT 2011


On Tue, 11 Oct 2011, Petko Yotov wrote:

> You'll need to override the LinkPage() function.
>
> 1. Copy the LinkPage() function from pmwiki.php to your local/config.php. You
> will only make changes to config.php, not to pmwiki.php.
>
> 2. Rename the one in config.php, from "function LinkPage(...)" to "function
> MyLinkPage(...)", that's an added "My" glued before LinkPage.
>
> 3. Add to config.php such a line, before or after the function:
>
>  $LinkFunctions['<:page>'] = 'MyLinkPage';
>
> 4. Near the middle of the function block in config.php, after the line:
>
>  if (!$tgtname) return '';  # (this line exists)
>
>  insert this line:
>
>  if(!CondAuth($tgtname, 'read')) return '[hidden link]'; # new line
>
>
> It is probably better to return the plain text "[hidden link]" instead of
> nothing, otherwise a	reader may not quite understand your sentences. Writers
> may also be annoyed if they add to the wiki source some links which disappear
> from the rendered page.
>
> Petko
>
> P.S. Reminder. It is not recommended to edit pmwiki.php or other files from
> the core distribution because if you change them, when you upgrade you'll need
> to re-apply your customizations. PmWiki is designed to allow the replacement
> via programming hooks of many functions with ones you write, without the need
> to modify the core files.
>


Bingo!

I made the following small changes to the above:

In MyLinkPage


1) Immediately after the globals declaration I added

$ppath = $path;

2) I changed the conditional as follows:

if (!CondAuth($tgtname,'read')){
if ($txt !== $ppath ){
return "<span class='hide'>[Private Link]</span><span " .
        "class='privatelink'>$txt</span>";
}else{
return "<span class='privatelink'>[Privacy Link]</span>";
}
}


-- 
Lars Eighner
http://www.larseighner.com/index.html
8800 N IH35 APT 1191 AUSTIN TX 78753-5266




More information about the pmwiki-users mailing list