Hi all,
I've just started on a MediaWiki extension that uses the MW API for bulk-editing articles. Unfortunately for some reason after making the call to edit the pages, instead of the browser seeing whatever I have written with $wgOut->addHTML(), the browser gets redirected to the last page that was edited.
This is the code I am using to perform the edit, where $p is a result returned from a previous Query API call (to get the list of pages that need editing.)
$req = new FauxRequest(array( 'action' => 'edit', 'bot' => true, 'token' => $p['edittoken'], 'title' => $p['title'], 'summary' => $this->strSummary, 'text' => $newContent, 'basetimestamp' => $p['starttimestamp'] ), true); $processor = new ApiMain($req, true); $processor->execute();
If I comment out the execute() line then I see my summary Special page, but with execute() present I get pushed onto the last article edited instead (although every edit does go through successfully.) The other API call (for querying the page content) works fine, it's only the Edit call that seems to exhibit this behaviour.
Does anyone have any idea what's going on here? I'm running MW 1.14.0.
Many thanks, Adam.
2009/5/2 Adam Nielsen a.nielsen@shikadi.net:
Hi all,
I've just started on a MediaWiki extension that uses the MW API for bulk-editing articles. Unfortunately for some reason after making the call to edit the pages, instead of the browser seeing whatever I have written with $wgOut->addHTML(), the browser gets redirected to the last page that was edited.
This is the code I am using to perform the edit, where $p is a result returned from a previous Query API call (to get the list of pages that need editing.)
$req = new FauxRequest(array( 'action' => 'edit', 'bot' => true, 'token' => $p['edittoken'], 'title' => $p['title'], 'summary' => $this->strSummary, 'text' => $newContent, 'basetimestamp' => $p['starttimestamp'] ), true); $processor = new ApiMain($req, true); $processor->execute();
If I comment out the execute() line then I see my summary Special page, but with execute() present I get pushed onto the last article edited instead (although every edit does go through successfully.) The other API call (for querying the page content) works fine, it's only the Edit call that seems to exhibit this behaviour.
Does anyone have any idea what's going on here? I'm running MW 1.14.0.
This is a consequence of the lack of separation between DB and UI logic in EditPage.php . Until EditPage.php is drastically rewritten, I'm afraid calling action=edit internally is just not going to work :(
Roan Kattouw (Catrope)
Unfortunately for some reason after making the call to edit the pages, instead of the browser seeing whatever I have written with $wgOut->addHTML(), the browser gets redirected to the last page that was edited.
This is a consequence of the lack of separation between DB and UI logic in EditPage.php . Until EditPage.php is drastically rewritten, I'm afraid calling action=edit internally is just not going to work :(
Thanks for the quick response! Is there any way I can somehow save the state before the Edit call, and restore it afterwards? I tried it with $wgRequest and it didn't work, but I'm not sure exactly what I'd need to save.
Thanks, Adam.
2009/5/2 Adam Nielsen a.nielsen@shikadi.net:
Unfortunately for some reason after making the call to edit the pages, instead of the browser seeing whatever I have written with $wgOut->addHTML(), the browser gets redirected to the last page that was edited.
This is a consequence of the lack of separation between DB and UI logic in EditPage.php . Until EditPage.php is drastically rewritten, I'm afraid calling action=edit internally is just not going to work :(
Thanks for the quick response! Is there any way I can somehow save the state before the Edit call, and restore it afterwards? I tried it with $wgRequest and it didn't work, but I'm not sure exactly what I'd need to save.
Off the top of my head, you need to save and restore at least $wgRequest, $wgTitle and $wgOut.
Roan Kattouw (Catrope)
Adam Nielsen wrote:
Thanks for the quick response! Is there any way I can somehow save the state before the Edit call, and restore it afterwards? I tried it with $wgRequest and it didn't work, but I'm not sure exactly what I'd need to save.
Thanks, Adam.
Try with $wgOut. Doing $wgOut->redirect('', '200'); may be enough to disable that.
2009/5/2 Platonides platonides@gmail.com:
Adam Nielsen wrote:
Thanks for the quick response! Is there any way I can somehow save the state before the Edit call, and restore it afterwards? I tried it with $wgRequest and it didn't work, but I'm not sure exactly what I'd need to save.
Thanks, Adam.
Try with $wgOut. Doing $wgOut->redirect('', '200'); may be enough to disable that.
It'll probably disable the redirect thing, but the rest of $wgOut would still be messed up, so you'd still need to clone and restore $wgOut.
Roan Kattouw (Catrope)
Thanks for the suggestions!
Try with $wgOut. Doing $wgOut->redirect('', '200'); may be enough to disable that.
This only seems to give me an error:
Fatal error: Call to a member function getNamespace() on a non-object in includes/Skin.php on line 218
It'll probably disable the redirect thing, but the rest of $wgOut would still be messed up, so you'd still need to clone and restore $wgOut.
Well I saved/restored $wgOut, $wgRequest and $wgTitle but it had no effect. Looking through the API, it looks like it already does this to some extent:
# Fake $wgRequest for some hooks inside EditPage # FIXME: This interface SUCKS $oldRequest = $wgRequest; $wgRequest = $req;
So it looks like more hunting will be required to find out exactly what needs to be saved.
Cheers, Adam.
2009/5/3 Adam Nielsen a.nielsen@shikadi.net:
Thanks for the suggestions!
Try with $wgOut. Doing $wgOut->redirect('', '200'); may be enough to disable that.
This only seems to give me an error:
Fatal error: Call to a member function getNamespace() on a non-object in includes/Skin.php on line 218
It'll probably disable the redirect thing, but the rest of $wgOut would still be messed up, so you'd still need to clone and restore $wgOut.
Well I saved/restored $wgOut, $wgRequest and $wgTitle but it had no effect. Looking through the API, it looks like it already does this to some extent:
# Fake $wgRequest for some hooks inside EditPage # FIXME: This interface SUCKS $oldRequest = $wgRequest; $wgRequest = $req;
So it looks like more hunting will be required to find out exactly what needs to be saved.
Yeah, I noticed the API already saves $wgRequest. Could you try doing $wgOut->disable(); after saving $wgOut?
Roan Kattouw (Catrope)
Well I saved/restored $wgOut, $wgRequest and $wgTitle but it had no effect. Looking through the API, it looks like it already does this to some extent:
# Fake $wgRequest for some hooks inside EditPage # FIXME: This interface SUCKS $oldRequest = $wgRequest; $wgRequest = $req;
So it looks like more hunting will be required to find out exactly what needs to be saved.
Yeah, I noticed the API already saves $wgRequest. Could you try doing $wgOut->disable(); after saving $wgOut?
Hmm, well that stops the output and leaves me with a blank page (no HTML or anything.) The URL contains the correct address though (of my Special page, it hasn't changed to the URL of the last page edited.)
I wonder why the output doesn't seem to get enabled again after restoring $wgOut? No errors about headers or anything being set already...
Cheers, Adam.
2009/5/3 Adam Nielsen a.nielsen@shikadi.net:
Well I saved/restored $wgOut, $wgRequest and $wgTitle but it had no effect. Looking through the API, it looks like it already does this to some extent:
# Fake $wgRequest for some hooks inside EditPage # FIXME: This interface SUCKS $oldRequest = $wgRequest; $wgRequest = $req;
So it looks like more hunting will be required to find out exactly what needs to be saved.
Yeah, I noticed the API already saves $wgRequest. Could you try doing $wgOut->disable(); after saving $wgOut?
Hmm, well that stops the output and leaves me with a blank page (no HTML or anything.) The URL contains the correct address though (of my Special page, it hasn't changed to the URL of the last page edited.)
I wonder why the output doesn't seem to get enabled again after restoring $wgOut? No errors about headers or anything being set already...
You're probably doing something like
global $wgOut; $oldOut = $wgOut; $wgOut->disable(); // do API call $wgOut = $oldOut;
If that doesn't work, try to replace the second line with $oldOut = clone $wgOut;
Roan Kattouw (Catrope)
You're probably doing something like
global $wgOut; $oldOut = $wgOut; $wgOut->disable(); // do API call $wgOut = $oldOut;
If that doesn't work, try to replace the second line with $oldOut = clone $wgOut;
Aha! That did the trick. I take it 'clone' does a deep copy?
I did some experimenting and you don't need to save $wgRequest, but you do need to save $wgTitle. $wgTitle doesn't need to be cloned, but $wgOut does. Once you clone $wgOut, you don't need to disable it. (But it probably can't hurt, maybe it might make things more efficient?)
Perhaps this could be added to the Edit API as a temporary workaround until the 'FIXME' part gets fixed?
At any rate it's working now, so thanks very much for your help! Again, here is the working code in full:
$o = clone $wgOut; //$wgOut->disable(); // not necessary with clone $t = $wgTitle; $req = new FauxRequest(array( 'action' => 'edit', 'bot' => true, 'token' => $p['edittoken'], 'title' => $p['title'], 'summary' => $this->strSummary, 'text' => $newContent, 'basetimestamp' => $p['starttimestamp'] ), true); $processor = new ApiMain($req, true); $processor->execute(); $wgTitle = $t; $wgOut = $o;
Cheers, Adam.
Hello,
I am new in using Api.
Several APi actions have this Note :
Note: In this example, all parameters are passed in a GET request just for the sake of simplicity. However, action=move requires POST requests; GET requests will cause an error.
( http://www.mediawiki.org/wiki/API:Edit_-_Move ) for instance.
I have no idea of how I can make a POST request with a MediaWiki. Would it be possible to make POST point on a page like : "How to do a POST request" in the documentation ?
I am sure I am missing something obvious, but I did not find any solution.
Thanks for helping.
Francois Colonna
Colonna Francois wrote:
Hello,
I am new in using Api.
Several APi actions have this Note :
Note: In this example, all parameters are passed in a GET request just for the sake of simplicity. However, action=move requires POST requests; GET requests will cause an error.
( http://www.mediawiki.org/wiki/API:Edit_-_Move ) for instance.
I have no idea of how I can make a POST request with a MediaWiki. Would it be possible to make POST point on a page like : "How to do a POST request" in the documentation ?
I am sure I am missing something obvious, but I did not find any solution.
Thanks for helping.
Francois Colonna
It depends on your framework. How are you calling the API?
Le dimanche 31 mai 2009 à 00:05 +0200, Platonides a écrit :
Colonna Francois wrote:
Hello,
I am new in using Api.
Several APi actions have this Note :
Note: In this example, all parameters are passed in a GET request just for the sake of simplicity. However, action=move requires POST requests; GET requests will cause an error.
( http://www.mediawiki.org/wiki/API:Edit_-_Move ) for instance.
I have no idea of how I can make a POST request with a MediaWiki. Would it be possible to make POST point on a page like : "How to do a POST request" in the documentation ?
I am sure I am missing something obvious, but I did not find any solution.
Thanks for helping.
Francois Colonna
It depends on your framework. How are you calling the API?
with wget :
wget -O - 'http://localhost/~wiki/mediawiki/api.php?action=query&generator=allpages...' > T.xml
that is the a typical GET request. Best regards F.C.
you can just add --post-data= to the command to make a POST with wget, but parameters will stil be passed as a GET request (i.e. in the URL). If you want to pass the as post data, then pass them in --post-data with same format as a query string, e.g. --post- data='param1=value1¶m2=value2'
Cheers, Alexandre Emsenhuber
Le 31 mai 09 à 14:03, Colonna Francois a écrit :
Le dimanche 31 mai 2009 à 00:05 +0200, Platonides a écrit :
Colonna Francois wrote:
Hello,
I am new in using Api.
Several APi actions have this Note :
Note: In this example, all parameters are passed in a GET request just for the sake of simplicity. However, action=move requires POST requests; GET requests will cause an error.
( http://www.mediawiki.org/wiki/API:Edit_-_Move ) for instance.
I have no idea of how I can make a POST request with a MediaWiki. Would it be possible to make POST point on a page like : "How to do a POST request" in the documentation ?
I am sure I am missing something obvious, but I did not find any solution.
Thanks for helping.
Francois Colonna
It depends on your framework. How are you calling the API?
with wget :
wget -O - 'http://localhost/~wiki/mediawiki/api.php?action=query&generator=allpages...'
T.xml
that is the a typical GET request. Best regards F.C.
Mediawiki-api mailing list Mediawiki-api@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-api
Le dimanche 31 mai 2009 à 14:59 +0200, Alexandre Emsenhuber a écrit :
you can just add --post-data= to the command to make a POST with wget, but parameters will stil be passed as a GET request (i.e. in the URL). If you want to pass the as post data, then pass them in --post-data with same format as a query string, e.g. --post- data='param1=value1¶m2=value2'
Cheers, Alexandre Emsenhuber
Hello Alexandre,
I dit what you said : wget --post-data='action=query&prop=info&intoken=move&titles=A%20B&format=xml' -O - 'http://localhost/~wiki/mediawiki/api.php' > T.xml
I works, except that I got a warning which in fact is an error :
<?xml version="1.0"?><api><query><pages><page pageid="221" ns="0" title="A B" touched="2009-05-31T16:34:48Z" lastrevid="448" counter="1" length="9" new="" starttimestamp="2009-05-31T17:22:43Z" /></pages></query> <warnings><info> Action 'move' is not allowed for the current user</info> </warnings></api>
What can I do to tell wget which user is sending a request. I tried
wget --post-data='user=colonna&password=...&action...&format=xml' -O - 'http://localhost/~wiki/mediawiki/api.php' > T.xml
I still have :
Action 'move' is not allowed for the current user
Thanks for helping. Francois Colonna
2009/5/31 Colonna Francois colonna@lct.jussieu.fr:
What can I do to tell wget which user is sending a request. I tried
wget --post-data='user=colonna&password=...&action...&format=xml' -O - 'http://localhost/~wiki/mediawiki/api.php' > T.xml
I still have :
Action 'move' is not allowed for the current user
Thanks for helping. Francois Colonna
You have to login first and pass the cookies you received; I'm not sure this is something wget can do, so you might wanna look for a more advanced client library that supports this. There are even dedicated client libraries for the MediaWiki API, see http://www.mediawiki.org/wiki/API:Client_Code .
Roan Kattouw (Catrope)
wget does indeed support this, using the --save-cookies and --load-cookies options. (See the man-page, e.g. http://www.gnu.org/software/wget/manual/wget.html, for details.)
-Ran (User:Ruakh on WMF projects)
On Sun, May 31, 2009 at 3:07 PM, Roan Kattouw roan.kattouw@gmail.comwrote:
2009/5/31 Colonna Francois colonna@lct.jussieu.fr:
What can I do to tell wget which user is sending a request. I tried
wget --post-data='user=colonna&password=...&action...&format=xml' -O - '
http://localhost/~wiki/mediawiki/api.phphttp://localhost/%7Ewiki/mediawiki/api.php'
T.xml
I still have :
Action 'move' is not allowed for the current user
Thanks for helping. Francois Colonna
You have to login first and pass the cookies you received; I'm not sure this is something wget can do, so you might wanna look for a more advanced client library that supports this. There are even dedicated client libraries for the MediaWiki API, see http://www.mediawiki.org/wiki/API:Client_Code .
Roan Kattouw (Catrope)
Mediawiki-api mailing list Mediawiki-api@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-api
I would install tcpflow and see how these things are actually passed. lynx, w3m, lwp-request all have POST options... Actually nowadays all I use is $ dlocate MediaWiki::API libmediawiki-api-perl: /usr/share/man/man3/MediaWiki::API.3pm.gz here on Debian. So I don't have to mess with the POST details.
mediawiki-api@lists.wikimedia.org