El 10/12/13 00:33, Liangent ha escrit:

On Tue, Dec 10, 2013 at 7:13 AM, Toni Hermoso Pulido <[email protected]
<mailto:[email protected]>> 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
    <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();.


Hello Liangent,

it does not seem to work. In the end, call seems to be performed as anonymous.

In any case, I would continue sticked to doEdit, as Max pointed out.

Thanks!

--
Toni Hermoso Pulido
http://www.cau.cat

_______________________________________________
Wikitech-l mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/wikitech-l

Reply via email to