コード例 #1
0
ファイル: index.php プロジェクト: vanatomy/wikislurp
// Check that required parameters are given
if (!$error && (!isset($_GET['secret']) || !$_GET['secret'])) {
    $error = array("error" => "Bad request - Secret not given", "status" => 400);
}
if (!$error && (!isset($_GET['query']) || !$_GET['query'])) {
    $error = array("error" => "Bad request - Query not given", "status" => 400);
}
// check that secret matches config secret
if (!$error && $WIKI_SLURP_CONFIG['SECRET'] != $_GET['secret']) {
    $error = array("error" => "Unauthorised - Secret is not valid", "status" => 401);
}
if ($error) {
    $obj = $error;
} else {
    $wiki = new MediaWiki($WIKI_SLURP_CONFIG);
    $obj = $wiki->getArticle($_GET);
}
if (isset($obj['status']) && 200 != $obj['status']) {
    header("HTTP/1.0 {$obj['status']} {$obj['error']}");
}
$output = isset($_GET['output']) ? $_GET['output'] : '';
switch ($output) {
    case 'json':
        header("Content-type: application/json");
        echo json_encode($obj);
        break;
    default:
        // is this a suitable mimetype?
        header("Content-type: text/x-php");
        echo serialize($obj);
}