[pmwiki-devel] modifying $pagename upon first Save - FREQ

J. Meijer commentgg at hotmail.com
Wed Dec 13 17:38:19 CST 2006

Pm, looking at the new release, beta 17, I noticed the following fix of UpdatePage() somehow wasn't included:

  function UpdatePage($pagename, &$page, &$new, $fnlist = NULL) {


  function UpdatePage(  *** & *** $pagename, &$page, &$new, $fnlist = NULL) {

The *** just mark the addition. 

Without this pagenames can't be cleanly updated within EditFunctions. Any change won't be propagated back to HandleEdit() and it'll do bad things. 

Not worth it, still deciding or a slip? 



On 12/2/06,  J. Meijer <commentgg at hotmail.com> wrote:

Tested it now and my script is working. BUT I needed to patch pmwiki.php. Read on.

> Date: Thu, 30 Nov 2006 18:22:09 -0600
> From: pmichaud at pobox.com
> On Thu, Nov 30, 2006 at 10:34:24PM +0000, J. Meijer wrote:
> >
> > What I want is to start of with a pagename like this:
> >
> >   Event.2006-11-30___xx
> >
> > and have it transformed into
> >
> >   Event.2006-11-30_01
> >
> > when it is saved. I can't fix the pagename before a Save because
> > multiple users would end up competing for the same pagename.
> >
> > I found I can't do it decently. I have to resolve to hacks. These
> > hacks don't guarantee that that all page actions that result in
> > page creation have the pagename fixed.
> >
> > What I really want is a hook to HandleEdit(), so actions that do
> > some preprocessing and then revert to standard HandleEdit()
> > processing have a single point where $pagename can be set/changed,
> > just before the page is created first time. This hook may go into
> > UpdatePage() instead. The point is I can't get things done properly.
> > Replacing HandleEdit in $EditFunctions with my own version just
> > makes sure that any recipy that reverts to HandleEdit won't call mine.
> 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');
> So, the TransformPageName function will be called *immediately*
> before PostPage, and set value of $pagename (which PostPage and
> subsequent functions will use to actually save the page).

This works after adding '&' to the declaration of UpdatePage():

  UpdatePage(  &  $pagename, etc

Because otherwise any changes to pagename don't revert back to the caller (HandleEdit) and it'll do things the wrong way.

Furthermore, after modifying the pagename, I needed to migrate $PCache[$pagename] data to its new name.

Maybe there is additional cached information that need to be migrated?

I also thought it would be a good idea to change the $pagename global to the new name.

That's it.


Express yourself with gadgets on Windows Live Spaces

More information about the pmwiki-devel mailing list