[pmwiki-users] Update pmwiki using perl scripts

Ginil Gharat Ginil.Gharat at ascindia.com
Sun Feb 26 23:28:37 CST 2006


Thanks to Joachim and Ian for their suggestions.

Especially the "action=source" is very cool. I was earlier trying to
override the previous text instead of updating.

The problem I am trying to solve is a minor one. The will *not* be any
simultaneous updates to the page I am updating. There are going to be some
*defined* pages which will be updated by crontab/autosys scripts which wud
publish some automated reports ( nightly builds errors/ regression test
results etal )to these pages.

I am able to "get" the page contents using the "action=source" action. Only
problem is when I try to update the existing html it fails and throws the
authentication page. I have tried using a existint cookie to benefit, *but*
no success here ... Also I have tried using the URL like
http://${arg_twiki_server}/index.php?n=RiskHedge.TestPage?action=edit?authid
=userid?authpw=password but again without success and which makes sense to
me as this page is using POST method and *not* get method. The surprising
part is even when I am sending `hidden` values to this form (html) it fails
to get the values and authenticate the user.

Sorry to bother u Ian but if can point me to the url where u have the email
updating the pmwiki pages that wud be a life-saver ...

Thanks and regards,
_Nik


-----Original Message-----
From: pmwiki-users-bounces at pmichaud.com
[mailto:pmwiki-users-bounces at pmichaud.com] On Behalf Of 


------------------------------

Message: 3
Date: Fri, 24 Feb 2006 10:52:42 +0100
From: Joachim Durchholz <jo at durchholz.org>
Subject: Re: [pmwiki-users] Update pmwiki using perl scripts ...
To: pmwiki-users at pmichaud.com
Message-ID: <43FED76A.90207 at durchholz.org>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

Ginil Gharat schrieb:
>  
> Pmwiki, I suppose is written in php, so is it possible to update using 
> perl scripts ?

Sure. PHP or shell script would do as well.

 > I was trying to use WWW-Mechanize-1.18 but was *not* very
> successful with my attempts.

I'm not sure what WWW-Mechanize does. It would help to hear what exactly 
the problems were.

Anyway, here's how I'd approach that:

1) Get the previous contents of the page via wget or curl, with an URL 
of http://server/path/pmwiki.php?n=Group.Page&action=source. The 
relevant part here is the action=source bit, it will return the page's 
wikitext as text/plain.
2) Modify the page (presumably by appending or prepending the new log 
entries).
3) Write the result back using a POST request. (This might involve going 
through a login dialog, or whatever authentication is installed on your 
wiki.)

There's a danger here: You can't lock PmWiki pages against concurrent 
access. To be really complete, the script would have to react to an 
error message in a useful way (possibly by regetting the updated page 
contents and trying again; or by saving the page including the conflict 
markers and sending a mail to the administrator to clean up the mess 
manually).


An alternative approach would be a recipe that implements a new action, 
say ?action=update. Take a look at the Cookbook recipes, several of them 
implement new actions. The advantage is that you can work "from the 
inside" and don't have to worry about authorizing the access (but you'd 
have to worry about adding authorization to the new action).

Or you could call PmWiki from the command line. Write a shell script 
that unsets any of the usual CGI variables (say, REQUEST_URI), write a 
code snippet in config.php that checks whether $_ENV ['REQUEST_URI'] is 
set, and if it isn't, assume it's called from the command line and do 
your updates.

Whichever of the two methods you chose, after that your code is inside 
PmWiki and can access all the methods to update the page store.

Regards,
Jo



------------------------------
------------------------------

Message: 5
Date: Fri, 24 Feb 2006 10:02:31 +0000
From: Ian Barton <lists at manor-farm.org>
Subject: Re: [pmwiki-users] Update pmwiki using perl scripts ...
To: pmwiki-users at pmichaud.com
Message-ID: <43FED9B7.4080606 at manor-farm.org>
Content-Type: text/plain; charset=ISO-8859-1


>  Is it possible to write to pmwiki pages using some `api` ? We have 
> some jobs ( cron/autosys) which wud like to write the output of 
> nightly  builds and regression tests to be written directly to the 
> pmwiki pages instead of manually writing to pmwiki pages.
>  
> Pmwiki, I suppose is written in php, so is it possible to update using 
> perl scripts ? I was trying to use WWW-Mechanize-1.18 but was *not* 
> very successful with my attempts. But I still think its not a big deal 
> and even using basic HTTP authentication, I shud be able to update 
> pmwiki thru' scripts.

You should be able to adapt my email text to a page script, which I keep
forgetting to put in the Cookbook:) Search the list for "Appending Text to a
wiki Page Via Email". If you can't find it, I can email it to you.

Ian.







More information about the pmwiki-users mailing list