[pmwiki-users] please help me with conceptualize a recipe
Crisses
crisses at kinhost.org
Sun Oct 8 07:58:03 CDT 2006
On Oct 8, 2006, at 12:06 AM, JB wrote:
> I want to create a recipe to convert a simple table to
> table directives.
>
> I envision someone would add a recipe file to the config.php
> which would enable someone to type in a url with
> "?action=converttable". This would take the page source,
> convert the code, then put it into the edit form. They would
> then click "save" to save the changes. This is similar to
> how a restore works and I think it makes sense here too.
>
> I think I need help with 3 things here:
>
> 1) how to add the action "?action=converttable"
It should be a "hidden" input field on the form.
Then in the actual cookbook program:
$HandleAction['converttable'] = "functionname";
function converttable() {
//your function here
}
Doing it this way, cookbook recipes are loaded into memory during the
reading of config.php but do not actually run until the main
pmwiki.php has loaded standard modules such as the formulas for the
standard markup.
> 2) how to get the page source code
>
> I could then figure out how to manipulate the
> code myself, then,
$oldpage = ReadPage($pagename);
now $oldpage is an array. $oldpage['text'] is the body of the pmwiki
page.
do
$newpage = $oldpage;
and work on the value of $newpage['text']
> 3) put the new code into the edit form.
This one I'm not sure. I know there's a HandleEdit function in PmWiki
Are there other recipes that alter things before they go to the
browser? I would look at how they do it.
It could also be that you actually change the page using
UpdatePage ($pagename,$oldpage,$newpage);
then redirect the browser to edit the page, which I think is
HandleEdit($pagename, $auth = 'edit')
Because you have to be sure that they're authorized to edit the page :)
So in other words, you'd be actually changing the table first, then
allowing the person to immediately change the page.
Note, with this method, there's no backing out from the change
without using the page history/diff file. There's probably a way to
just throw the changed text into the edit box and give the person the
chance to say "ewwww -- that's too ugly." and back out. :)
Also note that you'd want to check edit permissions before committing
to editing that page. Again, I'm not sure how to do it.
Crisses
More information about the pmwiki-users
mailing list