function execute( $par ) { global $wgRequest, $wgOut, $smwgARC2StoreConfig, $wgServer, $wgScriptPath, $wgUser; $this->setHeaders(); $output = ""; # Get request data from, e.g. $rdfio_action = $wgRequest->getText( 'rdfio_action' ); # instantiation $store = ARC2::getStore( $smwgARC2StoreConfig ); $output .= "\n===RDF Store Setup===\n'''Status:'''\n\n"; if ( !$store->isSetUp() ) { $output .= "* Store is '''not''' set up\n"; if ( $rdfio_action == "setup" ) { if ( !$wgUser->matchEditToken( $wgRequest->getText( 'token' ) ) ) { die( 'Cross-site request forgery detected!' ); } else { if ( $this->m_issysop ) { $output .= "* Setting up now ...\n"; $store->setUp(); $output .= "* Done!\n"; } else { $errormessage = "Only sysops can perform this operation!"; $wgOut->addHTML( RDFIOUtils::formatErrorHTML( "Permission Error", $errormessage ) ); } } } } else { $output .= "* Store is already set up.\n"; } $wgOut->addWikiText( $output ); $htmlOutput = '<form method="get" action="' . $wgServer . $wgScriptPath . '/index.php/Special:ARC2Admin" name="createEditQuery"> <input type="submit" name="rdfio_action" value="setup">' . Html::Hidden( 'token', $wgUser->editToken() ) . ' </form>'; $wgOut->addHTML( $htmlOutput ); }
function execute( $par ) { global $wgOut, $wgUser; $this->setHeaders(); $this->handleRequestData(); $showscreensonly = false; if ( $this->m_action == 'Import' ) { if ( !$wgUser->matchEditToken( $this->m_edittoken ) ) { die( 'Cross-site request forgery detected!' ); } elseif ( !$this->m_haswriteaccess ) { $errortitle = "Permission error"; $errormessage = "The current user lacks access either to edit or create pages (or both) in this wiki."; $wgOut->addHTML( RDFIOUtils::formatErrorHTML( $errortitle, $errormessage ) ); $this->outputHTMLForm(); } else { $this->initSMWBatchWriter(); $existunabbrpropertyuris = $this->m_smwbatchwriter->checkForNamespacesWithoutPrefix(); $abbreviateuriscreen = ''; $unabbrentityurilist = ''; if ( $existunabbrpropertyuris && $this->m_show_abbrscreen_properties ) { $suggestedbaseuris = $this->m_smwbatchwriter->getNamespacesWithoutPrefix(); $abbreviateuriscreen = $this->generateURIAbbreviationScreen( $suggestedbaseuris ); $showscreensonly = true; } if ( $this->m_show_abbrscreen_entities ) { $unabbrentityuris = $this->m_smwbatchwriter->getUnabbrEntityURIs(); $unabbrentityurilist = $this->generateUnabbrEntityList( $unabbrentityuris ); $showscreensonly = true; } if ( $showscreensonly ) { $contentbeforehtmlform = $abbreviateuriscreen . "\n" . $unabbrentityurilist; $wgOut->addHTML( $this->getHTMLFormContent( $contentbeforehtmlform ) ); } else { $this->executeSMWBatchWriter(); } } } elseif ( $this->m_action == 'AddNsPrefixes' ) { $this->addNewNsPrefixes(); $this->executeSMWBatchWriter(); } else { $this->outputHTMLForm(); } }
/** * Delete the facts stored in page handlers, from the wiki */ private function deletePageDataFromWiki() { global $wgOut; $pages = $this->m_pages; foreach ( $pages as $page ) { $page->deleteDataFromWiki(); if ( $page->hasErrors() ) { $errortitle = "Error for wikipage \"" . $page->getWikiTitleFull() . "\"</h3>"; $wgOut->addHTML( RDFIOUtils::formatErrorHTML( $errortitle, $page->getErrorText() ) ); } } }
function failMsg($message) { global $wgOut; $errorHtml = RDFIOUtils::formatErrorHTML("Error!", $message); $wgOut->addHTML($errorHtml); }
/** * Check if deleting from wiki is allowed, and handle a number * of exceptions to that, by showing error messages etc */ function checkAllowDelete() { global $wgRequest, $wgUser, $wgOut, $rdfiogAllowRemoteEdit; if ( !$wgUser->matchEditToken( $wgRequest->getText( 'token' ) ) && !$rdfiogAllowRemoteEdit ) { die( 'Cross-site request forgery detected!' ); } else { if ( $this->m_hasdeleteaccess || $rdfiogAllowRemoteEdit ) { return true; } else { $errortitle = "Permission error"; $errormessage = "The current user lacks access either to edit or delete pages (or both) in this wiki."; $wgOut->addHTML( RDFIOUtils::formatErrorHTML( $errortitle, $errormessage ) ); return false; } } }
static function showErrorMessage( $title, $message ) { global $wgOut; $errorhtml = RDFIOUtils::formatErrorHTML( $title, $message ); $wgOut->addHTML( $errorhtml ); }
protected function import($limit = 10, $offset = 0) { global $wgOut, $wgRequest; //$rdfioUtils = new RDFIOUtils(); $externalSparqlUrl = $wgRequest->getText('extsparqlurl'); if ($externalSparqlUrl === '') { throw new RDFIOException('Empty SPARQL Url provided!'); } else { if (!RDFIOUtils::isURI($externalSparqlUrl)) { throw new RDFIOException('Invalid SPARQL Url provided! (Must start with \'http://\' or \'https://\')'); } } $sparqlQuery = urlencode("SELECT DISTINCT * WHERE { ?s ?p ?o } OFFSET {$offset} LIMIT {$limit}"); $sparqlQueryUrl = $externalSparqlUrl . '/' . '?query=' . $sparqlQuery; $sparqlResultXml = file_get_contents($sparqlQueryUrl); $sparqlResultXmlObj = simplexml_load_string($sparqlResultXml); $importTriples = array(); if (is_object($sparqlResultXmlObj)) { foreach ($sparqlResultXmlObj->results->children() as $result) { $triple = array(); // $wgOut->addHTML( print_r($result, true) ); foreach ($result as $binding) { if ($binding['name'] == 's') { $s = (string) $binding->uri[0]; if ($s == '') { throw new Exception('Could not extract subject from empty string (' . print_r($binding->uri, true) . '), in SPARQLImport'); } $triple['s'] = $s; $triple['s_type'] = $this->resourceType($triple['s']); } else { if ($binding['name'] == 'p') { $p = (string) $binding->uri[0]; if ($p == '') { throw new Exception('Could not extract predicate from empty string (' . print_r($binding->uri, true) . '), in SPARQLImport'); } $triple['p'] = $p; $triple['p_type'] = $this->resourceType($triple['p']); } else { if ($binding['name'] == 'o') { $o = (string) $binding->uri[0]; if ($o == '') { throw new Exception('Could not extract object from empty string (' . print_r($binding->uri, true) . '), in SPARQLImport'); } $triple['o'] = $o; $triple['o_type'] = $this->resourceType($triple['o']); $triple['o_datatype'] = ''; } } } } $importTriples[] = $triple; } $rdfImporter = new RDFIORDFImporter(); $rdfImporter->importTriples($importTriples); $wgOut->addHTML($rdfImporter->showImportedTriples($importTriples)); } else { RDFIOUtils::formatErrorHTML("Error", "There was a problem importing from the endpoint. Are you sure that the given URL is a valid SPARQL endpoint?"); } return $output = array('externalSparqlUrl' => $externalSparqlUrl); }