SPARQL_EXTENSION_NAME,
"author" => SPARQL_EXTENSION_AUTHOR,
"url" => SPARQL_EXTENSION_URL,
"description" => SPARQL_EXTENSION_DESCRIPTION,
);
/*
* extension setup function
*/
function Sparql_Setup() {
global $wgDebugLogGroups, $IP;
// log - make sure this is writeable by php/apache
$wgDebugLogGroups = array("SPARQL_LOG" => "$IP/logs/sparql.log");
// add scripts present in every page (try to keep to minimum)
addUtilityScripts();
return true;
}
/*
* parser function setup
*/
function Sparql_ParserFunctionSetup($parser) {
// Set a function hook associating the "example" magic word with our function
$parser->setFunctionHook("twinkle", "Sparql_ParserFunctionRender" );
// no hash needed
$parser->setFunctionHook("sparqlencode", "Sparql_SparqlEncode", SFH_NO_HASH);
return true;
}
/*
* register magic words
*/
function Sparql_ParserFunctionMagic(&$magicWords, $langCode) {
$magicWords["twinkle"] = array( 0, "twinkle","sparql");
$magicWords["sparqlencode"] = array( 0, "sparqlencode");
return true;
}
/*
* similar to anchorencode but leaves the slashes intact
*/
function Sparql_SparqlEncode($parser, $text) {
$a = urlencode( $text );
$a = strtr( $a, array( '%' => '.', '+' => '_' ) );
# leave colons alone, however
$a = str_replace( '.3A', ':', $a );
# leave forward slashes alone, however
$a = str_replace( '.2F', '/', $a );
# leave parentheses, however
$a = str_replace( '.28', '(', $a );
$a = str_replace( '.29', ')', $a );
# TODO this is a bit of a hack to work with the current (patched)
# state of the RDF export
# $a = str_replace( '-', '-2D', $a );
return $a;
}
/*
* main function that outputs wiki text or HTML from the query
*/
function Sparql_ParserFunctionRender(&$parser) {
// get the function arguments
$argv = func_get_args();
// parser is first - remove it
array_shift($argv);
// pass the arguments to the output factory that decides how to get the data,
// in what format and how to display it
$output = SparqlOutputFactory::getOutputForFormat($argv);
if ($output) {
// if array - output it in the "parser" format (ie with flags)
// if not an array output it w/o processing - raw (used in drawing charts)
if (is_array($output)) {
return $output;
} else {
return $parser->insertStripItem( $output, $parser->mStripState );
}
} else {
return wfMsg('no_data');
}
}
/*
* 1) google visualization ap
* 2) script needed for converting the & -> left over from parser output
*/
function addUtilityScripts() {
global $wgOut, $wgHeader;
$wgOut->addHeadItem("loadScriptForGoogleVisualization", "\n");
$wgOut->addScript("\n");
//This breaks things - jquery is likely already loaded via Semantic Forms
//$wgOut->addScript("\n");
$wgOut->addScript("\n");
$wgOut->addScript("\n");
}