On Tue, Dec 10, 2013 at 7:13 AM, Toni Hermoso Pulido <toni...@cau.cat>wrote:
> Hello, > > I'm trying to perform an API edit call in a maintenance script using this > example in MW 1.19.9 > http://www.mediawiki.org/wiki/API:Calling_internally > > > $user = User::newFromId( 1 ); // Using WikiSysiop > $page = WikiPage::newFromID( $id ); > $titleText = $page->getTitle()->getPrefixedText(); > > $text = "..."; > > global $wgRequest; > > $req = new DerivativeRequest( > $wgRequest, > array( > 'action' => 'edit', > 'title' => $titleText, > 'text' => $text, > 'token' => $user->editToken(), > ), true); > > $api = new ApiMain( $req, true ); > > $api->execute(); > > However, I get this problem: > Unexpected non-MediaWiki exception encountered, of type "UsageException" > badtoken: Invalid token > > Any idea what can be wrong? > Token is not used to do user lookup. You need to call $api->getContext()->setUser( $user ); before $api->execute();. -Liangent > > P.D.: I already use WikiPage::doEdit() successfully. > > -- > Toni Hermoso Pulido > http://www.cau.cat > > _______________________________________________ > Wikitech-l mailing list > Wikitech-l@lists.wikimedia.org > https://lists.wikimedia.org/mailman/listinfo/wikitech-l _______________________________________________ Wikitech-l mailing list Wikitech-l@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/wikitech-l