addwiki/mediawiki-api-base

A basic Mediawiki api base lib

Installs: 4 180

Dependents: 4

Stars: 5

Watchers: 5

Forks: 6

Language: PHP

1.0.0 2015-08-23 13:23 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:~1.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( FluentRequest::factory->setAction( 'purge' )->setParam( 'titles', 'FooBar' ) );

// Make a GET request
$queryResponse = $api->getRequest( FluentRequest::factory->setAction( 'query' )->setParam( '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();