Author: Robert McLeod
Example #1
0
<?php

include 'globals.php';
$wiki = new Wikimate();
$data = array('list' => 'recentchanges');
// Send data as a query
$array_result = $wiki->query($data);
foreach ($array_result as $value) {
    echo $value . "</br>";
}
Example #2
0
<?php

include 'globals.php';
$api_url = 'http://localhost/mediawiki/api.php';
echo "Connecting to: {$api_url}\n";
echo "Enter your username: "******"Enter your password: "******"Attempting to log in . . . ";
    if ($wiki->login($username, $password)) {
        echo "Success.\n";
    } else {
        $error = $wiki->getError();
        echo "\nWikimate error: " . $error['login'] . "\n";
        exit(1);
    }
} catch (Exception $e) {
    echo "\nWikimate exception: " . $e->getMessage() . "\n";
    exit(1);
}
echo "Fetching 'Sausages'...\n";
$page = $wiki->getPage('Sausages');
// check if the page exists or not
if (!$page->exists()) {
    echo "'Sausages' doesn't exist.\n";
} else {
    // get the page title
function writeOnWiki($output, $CONFIG)
{
    try {
        // Write outpput on wiki page
        $wiki = new Wikimate($CONFIG['WIKI_API_URL']);
        if (!$wiki->login($CONFIG['WIKI_USERNAME'], $CONFIG['WIKI_PASSWORD'])) {
            $error = $wiki->getError();
            return "Wikimate error: " . $error['login'];
        }
    } catch (Exception $e) {
        // Some wiki error
        return "Wikimate error: " . $e->getMessage();
    }
    // Connect to required page
    $page = $wiki->getPage($CONFIG['WIKI_PAGE']);
    if (!$page->exists()) {
        // No page found error
        return "No such page: " . $CONFIG['WIKI_PAGE'];
    }
    try {
        // Try to write on the page
        if (!$page->setText($output)) {
            return "Page was not updated. " . print_r($page->getError());
        }
    } catch (Exception $e) {
        // Some wiki error
        return "Error updating page: " . $e->getMessage();
    }
}