protected function setup() { global $wgOut, $wgRequest; $httpaccept = isset($_SERVER['HTTP_ACCEPT']) ? $_SERVER['HTTP_ACCEPT'] : null; $rdftype = wfNegotiateType(wfAcceptToPrefs($httpaccept), wfAcceptToPrefs(self::RDF_TYPE_PREFS)); if (!$rdftype) { throw new HttpError(406, wfMessage('notacceptable')); } $wgOut->disable(); $wgRequest->response()->header("Content-type: {$rdftype}; charset=utf-8"); $wgOut->sendCacheControl(); return true; }
/** * @private */ function rdfSetup() { global $wgOut, $_SERVER; $rdftype = wfNegotiateType(wfAcceptToPrefs(@$_SERVER['HTTP_ACCEPT']), wfAcceptToPrefs(RDF_TYPE_PREFS)); if (!$rdftype) { wfHttpError(406, "Not Acceptable", wfMsg("notacceptable")); return false; } else { $wgOut->disable(); header("Content-type: {$rdftype}"); $wgOut->sendCacheControl(); return true; } }
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; } }
function MwRdfOutputTurtle($model) { global $wgOut, $_SERVER, $wgRdfNamespaces; $rdftype = wfNegotiateType(wfAcceptToPrefs($_SERVER['HTTP_ACCEPT']), wfAcceptToPrefs(MWRDF_TYPE_PREFS)); if (!$rdftype) { wfHttpError(406, "Not Acceptable", wfMsg("notacceptable")); return false; } else { $wgOut->disable(); header("Content-type: {$rdftype}; charset=utf-8"); $wgOut->sendCacheControl(); # Make sure serializer is loaded require_once RDFAPI_INCLUDE_DIR . PACKAGE_SYNTAX_N3; $ser = new N3Serializer(); foreach ($wgRdfNamespaces as $key => $value) { $ser->addNSPrefix($key, $value); } print $ser->serialize($model); return true; } }