public function execute() { global $wgRequest, $wgOut, $smwgMessageBroker, $smwgWebserviceEndpoint, $wgUser, $smwgEnableObjectLogicRules; $wgOut->setPageTitle(wfMsg('tsa')); $html = ""; if ($wgRequest->getVal('init') != NULL) { // after init smwfGetStore()->initialize(false); $html .= $wgUser->getSkin()->makeKnownLinkObj(Title::newFromText("TSA", NS_SPECIAL), wfMsg('smw_tsa_waitsoemtime')); $wgOut->addHTML($html); return; } $html .= "<div style=\"margin-bottom:10px;\">" . wfMsg('smw_tsa_welcome') . "</div>"; global $smwgTripleStoreGraph; TSConnection::getConnector()->connect(); try { $status = TSConnection::getConnector()->getStatus($smwgTripleStoreGraph); } catch (Exception $e) { // if no connection could be created $html .= "<div style=\"color:red;font-weight:bold;\">" . wfMsg('smw_tsa_couldnotconnect') . "</div>" . wfMsg('smw_tsa_addtoconfig') . "<pre>\$smwgMessageBroker = <IP of messagebroker>\n" . "\$smwgWebserviceEndpoint = <IP and port of SPARQL endpoint>\n\nExample:\n\n\$smwgMessageBroker = \"localhost\";\n" . "\$smwgWebserviceEndpoint = \"localhost:8080\";</pre>" . wfMsg('smw_tsa_addtoconfig2') . " <pre>enableSMWHalo('SMWHaloStore2', 'SMWTripleStore', 'http://mywiki');</pre>" . wfMsg('smw_tsa_addtoconfig3'); $smwForumLink = '<a href="http://smwforum.ontoprise.com/smwforum/index.php/Help:Installing_the_Basic_Triplestore_manually">SMW-Forum</a>'; $html .= "<br><b>" . wfMsg('smw_tsa_addtoconfig4', $smwForumLink) . "</b>"; $wgOut->addHTML($html); return; } // normal $html .= "<h2>" . wfMsg('smw_tsa_driverinfo') . "</h2>" . $status['driverInfo'] . ""; $html .= "<h2>" . wfMsg('smw_tsa_tscinfo') . "</h2>"; $html .= wfMsg('smw_tsa_tscversion') . ": " . $status['tscversion']; // show warning when rule support is missing or defined although it is not available. if (in_array('RULES', $status['features']) && (!isset($smwgEnableObjectLogicRules) || $smwgEnableObjectLogicRules === false)) { $html .= "<div style=\"color:red;font-weight:bold;\">" . wfMsg('smw_tsa_rulesupport') . "</div>"; } if (!in_array('RULES', $status['features']) && $smwgEnableObjectLogicRules === true) { $html .= "<div style=\"color:red;font-weight:bold;\">" . wfMsg('smw_tsa_norulesupport') . "</div>"; } $html .= "<h2>" . wfMsg('smw_tsa_status') . "</h2>"; if ($status['isInitialized'] == true) { $html .= "<div style=\"color:green;font-weight:bold;\">" . wfMsg('smw_tsa_wikiconfigured', is_array($smwgWebserviceEndpoint) ? implode(", ", $smwgWebserviceEndpoint) : $smwgWebserviceEndpoint) . "</div>"; $tsaPage = Title::newFromText("TSA", NS_SPECIAL); $html .= "<br><form><input name=\"init\" type=\"submit\" value=\"" . wfMsg('smw_tsa_reinitialize') . "\"/><input name=\"title\" type=\"hidden\" value=\"" . $tsaPage->getPrefixedDBkey() . "\"/></form>"; } else { $html .= "<div style=\"color:red;font-weight:bold;\">" . wfMsg('smw_tsa_notinitalized') . "</div>" . wfMsg('smw_tsa_pressthebutton'); $tsaPage = Title::newFromText("TSA", NS_SPECIAL); $html .= "<br><form><input name=\"init\" type=\"submit\" value=\"" . wfMsg('smw_tsa_initialize') . "\"/><input name=\"title\" type=\"hidden\" value=\"" . $tsaPage->getPrefixedDBkey() . "\"/></form>"; } $wgOut->addHTML($html); }
public static function getConnector() { if (is_null(self::$_instance)) { global $smwgMessageBroker, $smwgWebserviceProtocol; if (isset($smwgMessageBroker)) { if (isset($smwgWebserviceProtocol) && strtolower($smwgWebserviceProtocol) === 'rest') { self::$_instance = new TSConnectorMessageBrokerAndRESTWebservice(); } else { trigger_error("SOAP requests to TSC are not supported anymore."); } } else { if (isset($smwgWebserviceProtocol) && strtolower($smwgWebserviceProtocol) === 'rest') { self::$_instance = new TSConnectorRESTWebservice(); } else { trigger_error("SOAP requests to TSC are not supported anymore."); } } } return self::$_instance; }
public function filterBrowse($p_array) { $browserFilter = new SMWOntologyBrowserFilter(); $type = $p_array[0]; $hint = explode(" ", $p_array[1]); $hint = smwfEliminateStopWords($hint); if ($type != 'instance') { return parent::filterBrowse($p_array); } global $wgServer, $wgScript, $smwgWebserviceUser, $smwgWebservicePassword, $smwgDeployVersion; $client = TSConnection::getConnector(); $client->connect(); try { global $smwgTripleStoreGraph; $dataSpace = $this->getDataSourceParameters(); //query for ($i = 0; $i < count($hint); $i++) { $hint[$i] = preg_quote($hint[$i]); $hint[$i] = str_replace("\\", "\\\\", $hint[$i]); } $filter = ""; if (count($hint) > 0) { $filter = "FILTER ("; for ($i = 0; $i < count($hint); $i++) { if ($i > 0) { $filter .= " && "; } $filter .= "regex(str(?s), \"{$hint[$i]}\", \"i\")"; } $filter .= ")"; } $response = $client->query(TSNamespaces::getW3CPrefixes() . " SELECT ?s ?cat WHERE { ?s ?p ?o. OPTIONAL { ?s rdf:type ?cat. } {$filter} }", "limit=1000{$dataSpace}"); $titles = array(); $this->parseInstances($response, $titles); } catch (Exception $e) { return "Internal error: " . $e->getMessage(); } // do not show partitions. 1000 instances is maximum here. return SMWOntologyBrowserXMLGenerator::encapsulateAsInstancePartition($titles, 1001, 0); }
function initialize($verbose = true) { global $smwgMessageBroker, $smwgTripleStoreGraph, $wgDBtype, $wgDBport, $wgDBserver, $wgDBname, $wgDBuser, $wgDBpassword, $wgDBprefix, $wgLanguageCode, $smwgBaseStore, $smwgIgnoreSchema, $smwgNamespaceIndex; $ignoreSchema = isset($smwgIgnoreSchema) && $smwgIgnoreSchema === true ? "true" : "false"; try { $con = TSConnection::getConnector(); $sparulCommands = array(); $sparulCommands[] = "DROP SILENT GRAPH <{$smwgTripleStoreGraph}>"; // drop may fail. don't worry $sparulCommands[] = "CREATE SILENT GRAPH <{$smwgTripleStoreGraph}>"; $sparulCommands[] = "LOAD smw://" . urlencode($wgDBuser) . ":" . urlencode($wgDBpassword) . "@{$wgDBserver}:{$wgDBport}/{$wgDBname}?lang={$wgLanguageCode}&smwstore={$smwgBaseStore}&ignoreSchema={$ignoreSchema}&smwnsindex={$smwgNamespaceIndex}#" . urlencode($wgDBprefix) . " INTO <{$smwgTripleStoreGraph}>"; $con->connect(); $con->update("/topic/WIKI.TS.UPDATE", $sparulCommands); $con->disconnect(); } catch (Exception $e) { } }
function smwf_tb_getTripleStoreStatus() { global $smwgTripleStoreGraph; $con = TSConnection::getConnector(); try { $con->connect(); $statusInfo = $con->getStatus($smwgTripleStoreGraph); $response = new AjaxResponse(json_encode($statusInfo)); $response->setContentType("application/json"); $response->setResponseCode(200); $con->disconnect(); } catch (Exception $e) { $response = new AjaxResponse($e->getMessage()); $response->setContentType("application/text"); $response->setResponseCode(500); } return $response; }
/** * @see superclass */ function getPropertySubjects(SMWPropertyValue $property, $value, $requestoptions = NULL) { if (!$property->isUserDefined()) { return parent::getPropertySubjects($property, $value, $requestoptions); } if (smwfCheckIfPredefinedSMWHaloProperty($property)) { return parent::getPropertyValues($subject, $property, $requestoptions, $outputformat); } global $smwgTripleStoreGraph; $client = TSConnection::getConnector(); $client->connect(); $values = array(); $propertyName = $property->getWikiPageValue()->getTitle()->getDBkey(); $limit = isset($requestoptions->limit) ? " LIMIT " . $requestoptions->limit : ""; $offset = isset($requestoptions->offset) ? " OFFSET " . $requestoptions->offset : ""; $nsPrefixProp = $this->tsNamespace->getNSPrefix($property->getWikiPageValue()->getTitle()->getNamespace()); try { if (is_null($value)) { $response = $client->query("SELECT ?s WHERE { GRAPH ?g { ?s <{$smwgTripleStoreGraph}/{$nsPrefixProp}#{$propertyName}> ?o. } } {$limit} {$offset}", "merge=false|graph={$smwgTripleStoreGraph}"); } else { if ($value instanceof SMWWikiPageValue) { $objectName = $value->getTitle()->getDBkey(); $nsPrefixObj = $this->tsNamespace->getNSPrefix($value->getTitle()->getNamespace()); $response = $client->query("SELECT ?s WHERE { GRAPH ?g { ?s <{$smwgTripleStoreGraph}/{$nsPrefixProp}#{$propertyName}> <{$smwgTripleStoreGraph}/{$nsPrefixObj}#{$objectName}>. } } {$limit} {$offset}", "merge=false"); } else { $objectvalue = str_replace('"', '\\"', array_shift($value->getDBkeys())); $objecttype = WikiTypeToXSD::getXSDType($value->getTypeID()); $response = $client->query("SELECT ?s WHERE { GRAPH ?g { ?s <{$smwgTripleStoreGraph}/{$nsPrefixProp}#{$propertyName}> \"{$objectvalue}\"^^{$objecttype}. } } {$limit} {$offset}", "merge=false"); } } } catch (Exception $e) { wfDebug("Triplestore does probably not run.\n"); $response = TSNamespaces::$EMPTY_SPARQL_XML; } // query global $smwgSPARQLResultEncoding; // PHP strings are always interpreted in ISO-8859-1 but may be actually encoded in // another charset. if (isset($smwgSPARQLResultEncoding) && $smwgSPARQLResultEncoding == 'UTF-8') { $response = utf8_decode($response); } $dom = simplexml_load_string($response); $annotations = array(); $results = $dom->xpath('//result'); foreach ($results as $r) { $children = $r->children(); // binding nodes $b = $children->binding[0]; // predicate $sv = $b->children()->uri[0]; $title = $this->getTitleFromURI((string) $sv); $value = SMWWikiPageValue::makePage($title->getDBkey(), $title->getNamespace()); $metadata = $sv->attributes(); foreach ($metadata as $mdProperty => $mdValue) { if (strpos($mdProperty, "_meta_") === 0) { $value->setMetadata(substr($mdProperty, 6), explode("|||", $mdValue)); } } $values[] = $value; } return $values; }