Пример #1
0
function wfRdfSpecialPage($par)
{
    global $wgRequest, $wgOut, $_SERVER, $_REQUEST;
    MwRdf::setup();
    $target = $wgRequest->getVal('target');
    if (!isset($target) || $target == null) {
        # no target parameter
        MwRdf::ShowForm();
        return;
    }
    if (strlen($target) == 0) {
        # no target contents
        MwRdf::ShowForm(wfMsg('badtitle'));
        return;
    }
    $nt = Title::newFromText($target);
    if ($nt->getArticleID() == 0) {
        # not an article
        MwRdf::ShowForm(wfMsg('badtitle'));
        return;
    }
    $format = $wgRequest->getVal('format', 'rdfxml');
    $accept = isset($_SERVER['HTTP_ACCEPT']) ? $_SERVER['HTTP_ACCEPT'] : null;
    $rdftype = wfNegotiateType(wfAcceptToPrefs($accept), wfAcceptToPrefs(MwRdf::getTypePrefs($format)));
    if (!$rdftype) {
        wfHttpError(406, "Not Acceptable", wfMsg("notacceptable"));
        return false;
    }
    $wgOut->disable();
    if (!headers_sent()) {
        header("Content-type: {$rdftype}");
    }
    $wgOut->sendCacheControl();
    $mf = MwRdf::ModelingAgent($nt);
    # Note: WebRequest chokes on arrays here
    $modelnames = null;
    if (isset($_REQUEST['modelnames'])) {
        $modelnames = $_REQUEST['modelnames'];
    }
    if (is_null($modelnames)) {
        $modelnames = $mf->listDefaultModels();
    }
    if (is_string($modelnames)) {
        $modelnames = explode(',', $modelnames);
    }
    if (!$modelnames) {
        MwRdf::ShowForm(wfMsg('nomodelsselected'));
        return;
    }
    $model = $mf->retrieveModel($modelnames);
    if (!$model->current()) {
        $mf->storeAllModels();
        $model = $mf->retrieveModel($modelnames);
    }
    $ser = MwRdf::Serializer($format);
    $text = $model->serializeStatements($ser);
    # XXX: Test Hook: it would be better if we could capture the
    # print statement below with an output buffer, but that is
    # disabled for the CLI in PHP 5
    if (isset($_SERVER['CONTEXT']) && $_SERVER['CONTEXT'] == 'phpunit test') {
        return $text;
    } else {
        print $text;
        return true;
    }
}