Commit 39ad4b00 authored by Krzysztof Kutt's avatar Krzysztof Kutt
Browse files

SPARQL UPDATE form by Michal Dobija

parent 7438eeaf
if(isset($_GET['query']) && !empty($_GET['query'])){
$result = parse_command($_GET['query']);
echo "Query successfull";
echo "Query failed";
}else {
require_once './update_form.php';
function insert_clause($name, $value, $filename){
$fileContents = file_get_contents($filename);
$fileContents = $fileContents.'[['.$name.':'.$value.'|]]'.PHP_EOL;
file_put_contents($filename, $fileContents);
function remove_clause($name, $value, $filename){
$fileContents = file_get_contents($filename);
$fileContents = preg_replace("/\[\[".$name.":".$value."\|\]\]\n?/",'',$fileContents);
file_put_contents($filename, $fileContents);
//WARNING: This assumes this file is in /dokuwiki/sparql
function convert_to_path($pagename){
$output = dirname(__DIR__).'/data/pages'.'/'.preg_replace('/:/','/',$pagename).'.txt';
return $output;
function parse_command($command){
$result = preg_match("/delete data.*{[\n\s]*([^\s]*)\s*([^\s]*)\s*([^\s]*)\s*\.\n}/is",$command,$matches);
if($result == 1 && check_can_edit($matches[1])){
return TRUE;
$result = preg_match("/insert data.*{[\n\s]*([^\s]*)\s*([^\s]*)\s*([^\s]*)\s*\.\n}/is",$command,$matches);
if($result == 1 && check_can_edit($matches[1])){
return TRUE;
return FALSE;
//WARNING: This assumes this file is in /dokuwiki/sparql. Takes page in the "category:page" form
function check_can_edit($pagename){
$address = 'http://'.preg_replace("#sparql/test.php#",'doku.php?id='.$pagename.'&do=edit',$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
$contents = file_get_contents($address);
if(preg_match("/.*this page is read only.*/i",$contents) || preg_match("/.*This page is currently locked.*/i",$contents)){
return FALSE;
return TRUE;
<!DOCTYPE html>
<html xmlns="">
<head><title>Loki SPARQL Endpoint</title>
<link rel="stylesheet" type="text/css" href="fuseki.css" />
<h1>Loki SPARQL SELECT Endpoint</h1>
<div class="moreindent">
<form method="get">
<p> Currently the only accepted format is "INSERT DATA"/"DELETE DATA" (case insensitive), followed by "{". then the triple, separated with any whitespace and ending with a dot (there has to be whitespace between the triple and the dot), then "}". Newlines are ignored.
<textarea style="background-color: #F0F0F0;" name="query" id="query" cols="80" rows="20"></textarea>
<input type="submit" value="Modify Data"/>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment