[pmwiki-users] Compute $EditRedirectFmt?
Stirling Westrup
sti at pooq.com
Thu Nov 9 15:26:47 CST 2006
Lucian Wischik wrote:
> I'm trying to use $EditRedirectFmt. The documentation
> http://www.pmwiki.org/wiki/PmWiki/EditVariables#EditRedirectFmt
> suggests examples like
> $EditRedirectFmt = '{$Group}.HomePage';
>
> But I want $EditRedirectFmt to be computed through a regexp on
> the $FullName. For example, if the user was editing a page
> "Main/TopicComments" then I want to redirect to "Main/Topic".
> (i.e. stripping "Comments" off the end).
>
> It looks like $EditRedirectFmt can't be used in this way. That's
> because it merely gets substituted by the FmtPageName function.
> I guess I could alter pmwiki.php myself to get the desired effect,
> but I want to confine myself to local changes.
>
> Am I wrong? Is it possible somehow to use $EditRedirectFmt as I wish?
There are a couple of ways to do it. First of all, if all you need to do is
strip off a simple ending, then you can do this:
$BaseNamePatterns['/Comments$/'] = '';
$EditRedirectFmt = '{$BaseName}';
$BaseNamePatterns is an array of regular expression replacements that get
performed on $FullName to yield $BaseName. If that's not sufficient, you can
always define your own computed variable:
$EditRedirectFmt = '{$RedirectName}';
$FmtPV['$RedirectName'] = 'RedirectFunc($pagename)';
function RedirectFunc($pagename)
{ return Some_Arbitrary_Calculation($pagename);
}
More information about the pmwiki-users
mailing list