PHP code example of quranacademy / mediawiki-sdk

1. Go to this page and download the library: Download quranacademy/mediawiki-sdk library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

quranacademy / mediawiki-sdk example snippets


use MediaWiki\Api\Api;
use MediaWiki\Api\Exceptions\ApiException;
use MediaWiki\Storage\FileStore;
use MediaWiki\HttpClient\CurlHttpClient;

$url = 'http://ru.example.com/api.php';

$httpClient = new CurlHttpClient();
$storage = new FileStore(__DIR__.'/storage/cache');

$api = new Api($url, $httpClient, $storage);

$username = 'John@FooBot';
$password = 'pri9l1fl1j315hmp3okbnqspqcgaue1t';

try {
    $api->login($username, $password);
} catch (ApiException $exception) {
    echo sprintf('MediaWiki API Error: ', $exception->getMessage());

    exit;
}

// bool(true)
var_dump($api->isLoggedIn());

// выход
$api->logout();

$parameters = [
    'action' => 'query',
    'list' => 'allpages',
];

$response = $api->request('POST', $parameters);

// или

$parameters = [
    'list' => 'allpages',
];

$response = $api->query($parameters);

var_dump($response);