Use composer to install the library and all its dependencies:
composer require "addwiki/mediawiki-api-base:~0.3.0"
// Load all the stuff
require_once( __DIR__ . '/vendor/autoload.php' );
// Log in to a wiki
$api = new MediawikiApi( 'http://localhost/w/api.php' );
$api->login( new ApiUser( 'username', 'password' ) );
// Make a POST request
$api->postRequest( new SimpleRequest( 'purge', array( 'titles' => 'FooBar' ) ) );
// Make a GET request
$queryResponse = $api->getRequest( new SimpleRequest( 'query', array( 'meta' => 'siteinfo' ) ) );
// Make a bad request and catch the error
try{
$api->postRequest( new SimpleRequest( 'FooBarBaz' ) );
}
catch ( UsageException $e ) {
echo "Oh no the api returned an error!";
}
//Logout
$api->logout();