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

Petko Yotov 5ko at 5ko.fr
Mon Oct 10 18:01:45 CDT 2011


On Tuesday 11 October 2011 00:02:35, Lars Eighner wrote :
> I want to suppess links (both for create and existing pages) when the
> reader does not have read permission for the target of the link.
...
> I want to do this in PHP at the config level because I do not want to
> introduce more markup complications for naive authors.

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.

> Motivation:
> I want to use PmWiki for genealogy. I want pages pertaining to persons to
> be named according to the person's name.  I want pages pertaining to
> historic (i.e. deceased and presumed deceased) persons and consenting
> adults to be publically readable.  But I want to conceal the identities of
> living adults who have not given me permission and living children so they
> appear only to family members who have read permissions.



More information about the pmwiki-users mailing list