Pergunta

I'm trying to make a simple extension that moves a page on my mediawiki site, but whether using curl or FauxRequest, I always get bad token response. Tried urlencoding, not encoding, escaping, without +/, etc, doesn't matter.

Code looks like this currently using FauxRequest, with param1/2/3 coming from the parser function I'm creating.

global $wgRequest;
$token = $token = $wgUser->editToken();

$params = new FauxRequest( 
    array(
        'action'    => 'move',
        'from'      => $param1,
        'to'        => $param2,
        'format'    => 'php',
        'reason'    => $param3,
        'token'     => $token)
);
$api = new ApiMain( $params, true);
$api->execute();
$data = & $api->getResultData();


$output = "moved $param1 to $param2 - $token";

also tried the below code using curl instead, which results in bad token as well

global $wgUser;
$token = $wgUser->editToken();
$url = 'http://www.website.com/api.php?';
    $myvars = 'action=move&format=xml&from=' . "$param1" . '&to=' . "$param2" . '&reason=' . "$param3" . '&token=' . urlencode($token);

    $ch = curl_init( $url );
    curl_setopt( $ch, CURLOPT_POST, 1);
    curl_setopt( $ch, CURLOPT_POSTFIELDS, $myvars);
    curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt( $ch, CURLOPT_HEADER, 0);
    curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1);

    $response = curl_exec( $ch );


$output = "moved $param1 to $param2 - $myvars - $response";

Am I missing something in the code, or could I have a setting wrong somewhere?

Any help would be hugely appreciated!

Foi útil?

Solução 2

I was recommended to not use either method for moving a page in an extension, and was instructed to use the following code instead, which works great. Hope this helps someone.

$oldTitle = Title::newFromText( $param1 );
$newTitle = Title::newFromText( $param2 );
// Error checking here
$oldTitle->moveTo( $newTitle, true, $param3, true );

Outras dicas

The actual error might be something else. Did you try doing it as specified in https://www.mediawiki.org/wiki/API:Calling_internally

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top