[pmwiki-users] Changing the Page Action on Page Load

Bruce & Ann Reidenbach bereiden at gmail.com
Thu Sep 2 10:15:11 CDT 2010

Again, thanks to all for helping out here.  And thanks to Peter for the
"fancy" suggestion.  Here is the code.

Markup ('PageAction', '<include', '/\\(:pageaction\\s+(.+?):\\)/ei',
>         "PageAction ('$pagename', '$action', '$1')");
> # Change the page action when the page is opened
> #   If no incoming action is specified, i.e., (:pageaction myaction:),
> redirect with the requested
> #   action if the current page action is 'browse'.  Otherwise, redirect
> with the requested action
> #   if the current page action matches the specified incoming page action
> from the option list.
> function PageAction ($pagename, $action, $opt) {
>   $args = ParseArgs ($opt);
>   foreach ($args as $key => $req) {
>     if (strlen ($key) == 0) {  #  No incoming action specified?
>       $key = 'browse';         #  Default to 'browse'
>       $req = $args[''][0];
>     }
>     if ($action == $key && $action != $req) {
>       Redirect ("{$pagename}?action=$req");
>     }
>   }
> }

It doesn't appear to work with some of the special actions like diff or
upload, but other than that, it works pretty well.

On Wed, Sep 1, 2010 at 4:04 PM, Peter Bowers <pbowers at pobox.com> wrote:

> By the time your Markup() rule is called it is too late to change $action
> and make it have any effect.
> PmWiki (in the big picture) does a bunch of configuration tasks and then it
> checks the value of $action and calls an action handler function based on
> the value of $action.  It is that action handler which then does everything
> else, including processing all the rules, including the one you have put in
> place.
> Changing $action after the action handler is called is like shutting the
> barn door after the horse is gone...
> The way I would solve it would be to redirect to the same page but with a
> different action=X parameter in the URL.  Make sure you check your $action
> first to avoid an infinite redirect and also to still allow yourself to edit
> the page, use diagnostics, etc.  If you want to get fancy you might want to
> look into (:pageaction browse=mynewaction print=myprint edit=myedit:) type
> of syntax which would allow mapping of various actions to other actions
> (take a look at the ParseArgs() function if you decide to try to implement
> this more generalized functionality).
> I'm not personally seeing the utility of the rule, but the beauty of pmwiki
> is its flexibility in allowing everyone to use it in their own way...
> -Peter
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.pmichaud.com/pipermail/pmwiki-users/attachments/20100902/743f394c/attachment.html>

More information about the pmwiki-users mailing list