[pmwiki-users] create pages externally through bash- / php-script?

Patrick R. Michaud pmichaud at pobox.com
Thu Aug 24 16:33:59 CDT 2006


On Thu, Aug 24, 2006 at 11:15:04PM +0200, Thomas -Balu- Walter wrote:
> > Of course, it's possible to get PmWiki to update the pages as well--
> > write a recipe that adds a new ?action= that queries the routers
> > for configuration and rewrites the appropriate pages (via calls
> > to WritePage).  Then arrange for cron(1) to call PmWiki once per day
> > with the special ?action= value to do the updates.  
> 
> This is IMHO the most elegant solution - and the easiest too I guess :) 
> 
> > PmWiki used to save changes only if content differed, but sometimes
> > we want to force a page save because of attributes being updated or
> > other changes in the configuration.
> > 
> > Still, it's not at all hard to configure PmWiki to save pages only
> > when the content changes -- let me know if you need the code for
> > this and I'll post it as a recipe.
> 
> Hm, now while seeing the reason for this, I'm not yet sure if I still
> want that. But on the other hand it would perhaps be nice to have the
> option. 
> 
> In my case it would be stupid to change the page history if the
> router config did not change, because the main idea was to have all the
> changes in the history. A new daily saved page with no changes would
> make that difficult.

Ah, you're wanting to keep the history as well.  Then it's a little
different (but still, not too difficult).

The easiest thing to do here may be something along the lines of:

    ##  Get current report into $text.  Writing 
    ##  GetRouterConfig(...) is up to you.  :-)
    $text = GetRouterConfig(...);

    ##  Read the current version of the page
    $page = ReadPage($routerpagename, READPAGE_CURRENT);

    ## if the current report matches what is in the page now,
    ## we don't need to update
    if ($page['text'] == $text) return;

    ## We have an update.  Make it look as though an author submitted
    ## a "save page" request, and let HandleEdit perform the update 
    ## for us.
    $_POST['text'] = $text;
    $_POST['post'] = 1;
    HandleEdit($routerpage, '');

This will cause the page to be updated with its history, as well
as updating RecentChanges pages, page indexes, etc.  Essentially,
we're just making it look as though someone submitted a new page
to PmWiki (and only if the contents actually change).

(The '' argument to HandleEdit is an extension I'm thinking of adding
to the authorization routines, it *always* authorizes the action
regardless of the visitor's current authorization status.  Thus
the script wouldn't have to worry about any password protection
on the pages its writing.)

> What about changing the history only if some attribute, or the content
> was changed (or if it is forced with a parameter somehow)?

We might be able to do this.  Maybe there can be a separate
'postchange' button that does the same as 'post' but saves
the page only if the content has actually changed somehow.
Then the above would become:

    $_POST['text'] = GetRouterConfig(...);
    $_POST['postchange'] = 1;
    HandleEdit($routerpage, '');

Pretty nice, except you still have to write the GetRouterConfig()
function.  :-)

Pm




More information about the pmwiki-users mailing list