Skip Menu |

This queue is for tickets about the MediaWiki-API CPAN distribution.

Report information
The Basics
Id: 39279
Status: resolved
Priority: 0/
Queue: MediaWiki-API

People
Owner: Nobody in particular
Requestors: BrightD [...] acm.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: Cannot get edit to work with MW 1.13
Date: Sun, 14 Sep 2008 22:13:09 -0500
To: bug-MediaWiki-API [...] rt.cpan.org
From: "David A. Bright" <BrightD [...] acm.org>
I've got an installation of MW 1.13 (actually, 1.13.1) and I have tried to use the MediaWiki API module to edit pages with no luck. I can login and get pages without a problem, but if I try to use the edit method, I get this: malformed JSON string, neither array, object, number, string or atom, at character offset 0 ["<br />\n<b>Fatal err..."] at /Library/Perl/ 5.8.8/MediaWiki/API.pm line 225. If I try with the api method, I get this: 3: badtoken: Invalid token at /Users/david/bin/MW-UpdatePage.pl line 76. My code to get the edit token is: # Get edit token my $token = $mw->api( { action => 'query', prop => 'info|revisions', intoken => 'edit', titles => $pageTitle } ) || die $mw->{error}->{code} . ': ' . $mw->{error}- Show quoted text
>{details};
$token = $page->{'query'}->{'pages'}->{'1'}->{'edittoken'}; My edit() call looks like: $mw->edit( { action => 'edit', bot => 1, basetimestamp => $page->{'timestamp'}, token => $page->{'query'}->{'pages'}->{'1'}- Show quoted text
>{'edittoken'},
title => $pageTitle, text => $newPageContents } ) || die $mw->{error}->{code} . ': ' . $mw->{error}- Show quoted text
>{details};
And my api() call looks like: $mw->api( { action => 'edit', bot => 1, basetimestamp => $page->{'timestamp'}, token => $page->{'query'}->{'pages'}->{'1'}- Show quoted text
>{'edittoken'},
title => $pageTitle, summary => "Automated update", text => $newPageContents } ) || die $mw->{error}->{code} . ': ' . $mw->{error}- Show quoted text
>{details};
I don't know if this is a bug in MW, MediaWiki::API, or if I am just failing to understand how to use the API. I'm running on Mac OS X 10.5.4, perl 5.8.8 Thanks.
On Sun Sep 14 23:13:40 2008, BrightD@acm.org wrote: Show quoted text
> malformed JSON string, neither array, object, number, string or atom, > at character offset 0 ["<br />\n<b>Fatal err..."] at /Library/Perl/ > 5.8.8/MediaWiki/API.pm line 225.
this generally means the MediaWiki API has returned something other than JSON. I will be releasing a new version with better error handling shortly. Until then you could try accessing the api.php directly from the URL in a web browser and see what it gives you. Is your wiki accessibible publically so I can test it to see what the problem might be ? Show quoted text
> If I try with the api method, I get this: > > 3: badtoken: Invalid token at /Users/david/bin/MW-UpdatePage.pl line 76.
this error was returned from the Show quoted text
> > My code to get the edit token is: > > # Get edit token > my $token = $mw->api( { > action => 'query', > prop => 'info|revisions', > intoken => 'edit', > titles => $pageTitle } ) > || die $mw->{error}->{code} . ': ' . $mw->{error}-
> >{details};
> $token = $page->{'query'}->{'pages'}->{'1'}->{'edittoken'}; > > My edit() call looks like: > > $mw->edit( { > action => 'edit', > bot => 1, > basetimestamp => $page->{'timestamp'}, > token => $page->{'query'}->{'pages'}->{'1'}-
> >{'edittoken'},
> title => $pageTitle, > text => $newPageContents } ) > || die $mw->{error}->{code} . ': ' . $mw->{error}-
> >{details};
the edit call handles tokens itself, so you don't need to use the token here anyway. Just to check have you enabled the writeapi in your mediawiki8 LocalSettings.php ? $wgEnableWriteAPI = true; Best Regards Jools
Subject: Re: [rt.cpan.org #39279] Cannot get edit to work with MW 1.13
Date: Thu, 18 Sep 2008 11:01:31 -0500
To: bug-MediaWiki-API [...] rt.cpan.org
From: "David Bright" <BrightD [...] acm.org>
On Thu, Sep 18, 2008 at 10:29 AM, Jools Smyth via RT < bug-MediaWiki-API@rt.cpan.org> wrote: Show quoted text
> <URL: http://rt.cpan.org/Ticket/Display.html?id=39279 > > > On Sun Sep 14 23:13:40 2008, BrightD@acm.org wrote:
> > malformed JSON string, neither array, object, number, string or atom, > > at character offset 0 ["<br />\n<b>Fatal err..."] at /Library/Perl/ > > 5.8.8/MediaWiki/API.pm line 225.
> > this generally means the MediaWiki API has returned something other than > JSON. I will be releasing a new version with better error handling > shortly. Until then you could try accessing the api.php directly from > the URL in a web browser and see what it gives you. > > Is your wiki accessibible publically so I can test it to see what the > problem might be ?
Unfortunately, no; but I'd be happy to run something against my wiki and send the output to you. If we really get stuck I may be able to set up a test wiki that is publically visible. Show quoted text
> > If I try with the api method, I get this: > > > > 3: badtoken: Invalid token at /Users/david/bin/MW-UpdatePage.pl line 76.
> > this error was returned from the >
> > >{details};
> > the edit call handles tokens itself, so you don't need to use the token > here anyway.
That's good. Initially I thought it would, but got a JSON error. I mucked around with finding the token in an attempt to get around the edit() error I got before I added in the token. Just to check have you enabled the writeapi in your mediawiki8 Show quoted text
> LocalSettings.php ?
Yes.
On Thu Sep 18 12:01:47 2008, BrightD@acm.org wrote: Show quoted text
> Unfortunately, no; but I'd be happy to run something against my wiki and > send the output to you. If we really get stuck I may be able to set up a > test wiki that is publically visible.
I have uploaded a new version of the module (0.14) which should appear shortly. It includes some additional error handling in the decode part of the module which should give you more information on why the edit call was failing. Please try this new version and run the code which previously produced malformed JSON string, neither array, object, number, string or atom, at character offset 0 ["<br />\n<b>Fatal err..."] at /Library/Perl/ 5.8.8/MediaWiki/API.pm line 225. and see what it returns now. Cheers!
Subject: Re: [rt.cpan.org #39279] Cannot get edit to work with MW 1.13
Date: Mon, 22 Sep 2008 12:02:17 -0500
To: bug-MediaWiki-API [...] rt.cpan.org
From: "David Bright" <BrightD [...] acm.org>
On Sun, Sep 21, 2008 at 7:04 AM, Jools Smyth via RT <bug-MediaWiki-API@rt.cpan.org> wrote: Show quoted text
> I have uploaded a new version of the module (0.14) which should appear > shortly. It includes some additional error handling in the decode part > of the module which should give you more information on why the edit > call was failing. Please try this new version and run the code which > previously produced
Thanks. This version allowed me to track down the problem quickly to the PasswordReset extension, which apparently doesn't work when accessing the wiki through the API. Disabling the extension allowed me to edit through the API. Thanks again.