chnm / Scripto

Scripto is an open source documentary transcription tool library written in PHP.
34 stars 6 forks source link

MediaWiki's login action is deprecated #26

Open jimsafley opened 7 years ago

jimsafley commented 7 years ago

See https://www.mediawiki.org/wiki/API:Login

Since MediaWiki 1.27.0 the login action has been deprecated in favor of the new clientlogin action. We've already seen an inconsistency in the API result (see #25) but we need to prepare for login's eventual removal.

In Scripto_Service_MediaWiki::login() we'll need to replace the existing login requests with the clientlogin interactive flow:

$params = array('meta' => 'tokens', 'type' => 'login');
$response = $this->_request('query', $params);
$logintoken = $response['query']['tokens']['logintoken'];

$params = array(
    'username' => $username,
    'password' => $password,
    'logintoken' => $logintoken,
    'loginreturnurl' => 'http://example.com',
    'rememberMe' => '1',
);
$response = $this->_request('clientlogin', $params);

On top of this we'll need a way to determine when to use the login action for older installations.

jimsafley commented 7 years ago

The only way I've found to get the MediaWiki version from the API:

$params = array('meta' => 'siteinfo');
$response = $this->query($params);
preg_match('/MediaWiki ([\d\.]+)/i', $response['query']['general']['generator'], $matches);
// $matches[1] should be the version

We could use version_compare() to test for compatibility.