[pmwiki-users] action=autoedit

Patrick R. Michaud pmichaud at pobox.com
Sat Jun 24 21:28:15 CDT 2006


On Sat, Jun 24, 2006 at 11:31:32PM +0200, Knut Alboldt wrote:
> Hi !
> 
> I'm looking for a function to change page-contents by a link-click (e.g. 
>   Icon in a page-list): e.g. todo-list with a link / icon to change the 
> status from "todo" to "done".
> 
> I thought about a page-link like 
> ...pagename?action=autoedit?editmac=macroname
> 
> so before I start to implement something on my own I rather ask: does 
> anybody has already implemented something like this ?

I haven't implemented anything like this, but I would warn
about spiders, which like to come along and activate
any links you happen to provide on the page.  :-)  

In short, if you don't pass the link through a form submittal or
authorization of some sort, you may quickly find that all of 
your "todo" links mysteriously got "done".  :-)

> all "editmacs" are just php-includefiles containing regex-pattern like 
> ROSPatterns.
> 
> action=autoedit will be processed like:
> 
> 1) check edit auth of requested page
> 2) read page
> 3) do regex change on $page[text]
> 4) save page
> 5) redir to browse changed page
> 
> Do I have to serve any other functions e.g. like last-changes etc ?
> which std-function could I use ?
> 
> Can I use the HandleEdit-function with some args to pass so that the 
> Edit-mode will be left automatically and the ROSPatterns will be processed ?

Yes.  I think something like the following would work:

   if ($action == 'autoedit') {
      ##   switch to 'edit' action, and indicate that the text is to be updated
      $action = 'edit';
      $_POST['post'] = 1;
      ##   change this pattern 
      $ROSPatterns['/todo/'] = 'done';
    }
    
The first line invokes the special ?action=autoedit function,
which switches the action to 'edit', thus invoking HandleEdit() later,
and sets $_POST['post'] to indicate that the page is to be saved
(as if an author had hit the "Save" button).

Since $_POST['text'] isn't set, HandleEdit() will use the existing
page text as the text to be saved.  However, the $ROSPatterns entry
will be applied to the page before it's actually saved.

Again, a problem with this is that any spider that happens
to invoke ?action=autoedit in a link (and has edit authorization 
to the page) will cause the page to be updated.  Better might be
to actually have the icon be a form button that sets the
value.  The link (in HTML) would need to look something like:

    <form action='$PageUrl' method='POST'>
      <input type='hidden' name='n' value='$FullName' />
      <input type='hidden' name='action' value='edit' />
      <input type='submit' name='postdone' value='Done' />
    </form>

If something like that is in place for the link, then all that 
is needed in local/config.php is something to add the 
$ROSPattern in response to a 'postdone' submit:

    if (@$_POST['postdone']) { $ROSPatterns['/todo/'] = 'done'; }

(PmWiki's HandleEdit() function already knows that any control
beginning with the letters 'post' are an indication that the
page is to be saved.)

Pm




More information about the pmwiki-users mailing list