getPage() public method

Returns a WikiPage object populated with the page data.
public getPage ( string $title ) : WikiPage
$title string The name of the wiki article
return WikiPage The page object
コード例 #1
0
ファイル: examples.php プロジェクト: iurnah/Wikimate
$username = trim(fread(STDIN, 100));
echo "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
    echo "Title: " . $page->getTitle() . "\n";
    // get the number of sections on the page
    echo "Number of sections: " . $page->getNumSections() . "\n";
    // get an array of where each section starts and its length
    echo "Section offsets:" . print_r($page->getSectionOffsets(), true) . "\n";
}
コード例 #2
0
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();
    }
}