addwiki/mediawiki-api-base

A basic Mediawiki api base lib

Installs: 3 328

Dependents: 4

Stars: 4

Watchers: 4

Forks: 5

Language: PHP

0.3 2015-06-01 09:08 UTC

README

Build Status Code Coverage Scrutinizer Code Quality Dependency Status

On Packagist: Latest Stable Version Download count

Installation

Use composer to install the library and all its dependencies:

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

Example Usage

// 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();