A basic Mediawiki api base lib

Installs: 5 156

Dependents: 4

Stars: 6

Watchers: 6

Forks: 7

Open Issues: 2

1.1.0 2015-09-05 12:12 UTC


Build Status Code Coverage Scrutinizer Code Quality Latest Stable Version Download count

Issue tracker:

addwiki/mediawiki-api-base is a PHP HTTP client wrapped around guzzle that makes it easy to interest with a mediawiki installation.

  • Uses PSR-3 interfaces for logging
  • Handles Mediawiki login, sessions, cookies and tokens
  • Handles response errors by throwing catchable UsageExceptions
  • Retries failed requests where possible


Use composer to install the library and all its dependencies:

composer require "addwiki/mediawiki-api-base:~1.0"

Example Usage

You can either construct an api object by simply passing the api enbpoint:

$api = new MediawikiApi( 'http://localhost/w/api.php' );

Or you can pass a guzzle ClientInterface, allowing more flexability:

$api = new MediawikiApi( new Client( array( 'base_url' => 'http://localhost/w/api.php' ) ) );

You can easily log in and out:

$api->login( new ApiUser( 'username', 'password' ) );

And make various requests:

$api->postRequest( FluentRequest::factory()->setAction( 'purge' )->setParam( 'titles', 'FooBar' ) );

$queryResponse = $api->getRequest( FluentRequest::factory()->setAction( 'query' )->setParam( 'meta', 'siteinfo' ) );

    $api->postRequest( new SimpleRequest( 'FooBarBaz' ) );
catch ( UsageException $e ) {
    echo "Oh no the api returned an error!";