[pmwiki-devel] modifying $pagename upon first Save - FREQ
J. Meijer
commentgg at hotmail.com
Thu Nov 30 18:34:58 CST 2006
> From: pmichaud at pobox.com
> Your description misstates the purpose and function of $EditFunctions.
> $EditFunctions doesn't contain HandleEdit, $HandleActions does.
> $EditFunctions is a list of functions to be called whenever the
> page is being edited or updated.
>
> And this thus answers your question -- what you really want
> to do is to modify pagename just before the page gets saved.
> For that you just need to insert a special function in
> $EditFunctions that will correct the pagename just before
> the page gets saved. Something like:
>
> function TransformPageName(&$pagename, &$page, &$new) {
> global $EnablePost;
> ## adjust $pagename if page is about to be saved
> if ($EnablePost) {
> $pagename = preg_replace('/___.*$/', '_01', $pagename);
> }
> }
>
> ## Insert 'TransformPageName' immediately before 'PostPage'
> array_splice($EditFunctions,
> array_search('PostPage', $EditFunctions),
> 0, 'TransformPageName');
>
Great! This promises to work and resolves my problem.
The approach reveals my problem with the edit functions: I simply adhered to "their API", limiting access to $pagename:
MyEditFunction($pagename, &$page,&$new)
While I wanted to have (and even suggested) is:
MyEditFunction(&$pagename, &$page,&$new) # note added the & in front of $pagename
Just as you state. I mistakenly assumed this would change the API, but heck no, this is PHP :-))
:-)))
/jm
>
> Note that as described here, HandleEdit will still use the
> permissions of the original $pagename to decide if the
> author has permissions to edit the page. If you want to
> verify that the author has write permissions under the
> new pagename, make an additional call to CondAuth()
> after changing the pagename, and set $EnablePost to zero
> if the page should not be saved.
>
Good reminder.
_________________________________________________________________
Search from any Web page with powerful protection. Get the FREE Windows Live Toolbar Today!
http://get.live.com/toolbar/overview
More information about the pmwiki-devel
mailing list