Karima Rafes has submitted this change and it was merged. Change subject: Add the lua function in order to load turtle code in a page between the tag : source ......................................................................
Add the lua function in order to load turtle code in a page between the tag : source Change-Id: I2dcff5a5dbd1d8ebaef0a4fc66571c32e604ef8d --- M LinkedWiki.php M LinkedWikiConfig.php M extension.json M lua/LinkedWiki.lua M lua/LinkedWiki.lua.php M storageMethod/DatabaseExampleMethod.php M storageMethod/SimpleStorageMethod.php M storageMethod/StorageInGraphMethod.php M storageMethod/StorageMethodAbstract.php M storageMethod/WikidataStorageMethod.php 10 files changed, 95 insertions(+), 15 deletions(-) Approvals: Karima Rafes: Verified; Looks good to me, approved diff --git a/LinkedWiki.php b/LinkedWiki.php index bf9bf3a..52014e0 100644 --- a/LinkedWiki.php +++ b/LinkedWiki.php @@ -60,4 +60,29 @@ $extraLibraries['linkedwiki'] = 'Scribunto_LuaLinkedWikiLibrary'; return true; } + + public static function RawPageSource( &$rawAction, &$text) { + if($rawAction != '' && isset($_REQUEST["includeOnlyTag"])){ + $tag = $_REQUEST["includeOnlyTag"]; + preg_match_all( + '#<'.$tag.'.*?>(.*?)</'.$tag.'>#is', + $text, + $matches + ); + $text = ""; + $textTemp = ""; + foreach($matches[1] as $source){ + $textTemp.= $source; + } + $parameters = array("?subject","?type","?property"); + $url = "<".$rawAction->getTitle()->getFullURL().">"; + $values = array($url,$url,$url); + $text = str_replace($parameters, + $values, + $textTemp); + /* + $text.= print_r($rawAction,true);*/ + } + return true; + } } diff --git a/LinkedWikiConfig.php b/LinkedWikiConfig.php index 43ad013..8652815 100644 --- a/LinkedWikiConfig.php +++ b/LinkedWikiConfig.php @@ -403,6 +403,10 @@ return $this->storageMethod->getQueryDeleteSubject(); } + public function getQueryLoadData($url) + { + return $this->storageMethod->getQueryLoadData($url); + } public function setSubject($iriSubject) { diff --git a/extension.json b/extension.json index 33ce0e1..7d01d05 100644 --- a/extension.json +++ b/extension.json @@ -39,6 +39,9 @@ ], "ScribuntoExternalLibraries": [ "LinkedWiki::scribuntoExternalLibraries" + ], + "RawPageViewBeforeOutput": [ + "LinkedWiki::RawPageSource" ] }, "MessagesDirs": { @@ -147,7 +150,7 @@ "lang": "en" }, "http://database-test": { - "debug": true, + "debug": false, "isReadOnly": false, "typeRDFDatabase": "virtuoso", "endpoint": "", diff --git a/lua/LinkedWiki.lua b/lua/LinkedWiki.lua index 4371b24..8278c1b 100644 --- a/lua/LinkedWiki.lua +++ b/lua/LinkedWiki.lua @@ -100,6 +100,10 @@ return php.removeSubject(iriSubject) end +function linkedwiki.loadData(titles) + return php.loadData(titles) +end + local currentFullPageName function linkedwiki.getCurrentTitle() local currentFullPageName @@ -286,6 +290,11 @@ return linkedwiki.removeSubject() end + function Linkedwiki:loadData(titles) + self:initConfig() + return linkedwiki.loadData(titles) + end + function Linkedwiki:printItemInWiki(valueInWiki, valueInDB, tagLang) --mw.log("linkedwiki.printTitleInWiki("..valueInWiki..",".. valueInDB..")") diff --git a/lua/LinkedWiki.lua.php b/lua/LinkedWiki.lua.php index 1bcb322..bff20ce 100644 --- a/lua/LinkedWiki.lua.php +++ b/lua/LinkedWiki.lua.php @@ -58,6 +58,7 @@ 'addPropertyWithIri' => array($this, 'addPropertyWithIri'), 'addPropertyWithLitteral' => array($this, 'addPropertyWithLitteral'), 'removeSubject' => array($this, 'removeSubject'), + 'loadData' => array($this, 'loadData'), ); return $this->getEngine()->registerInterface( __DIR__ . '/LinkedWiki.lua', $lib, array() @@ -361,7 +362,6 @@ return array($response); } - public function removeSubject($iriSubject = null) { if ($iriSubject === null && $this->subject ===null) { @@ -391,4 +391,27 @@ return array($response); } + + public function loadData($titles) + { + $listTitle = explode (",",$titles); + $q = ""; + foreach ($listTitle as $title){ + $titleObject = Title::newFromText( trim($title) ); + if ( $titleObject->exists() ) { + $q .= + $this->getInstanceConfig()->getQueryLoadData($titleObject->getFullURL()."?action=raw&includeOnlyTag=source") .' ; '; + } + } + + $this->setLastQuery($q);//for debug + $endpoint = $this->getInstanceEndpoint(); + $response = $endpoint->query($q, 'raw'); + $err = $endpoint->getErrors(); + if ($err) { + $message = $this->getInstanceConfig()->isDebug() ? $response . print_r($err, true) :"ERROR SPARQL (see details in mode debug)"; + return array("ERROR : " . $message); + } + return array($response); + } } diff --git a/storageMethod/DatabaseExampleMethod.php b/storageMethod/DatabaseExampleMethod.php index 116fb88..2a5b17e 100644 --- a/storageMethod/DatabaseExampleMethod.php +++ b/storageMethod/DatabaseExampleMethod.php @@ -98,4 +98,11 @@ } EOT; } + + public function getQueryLoadData($url) + { + return <<<EOT +LOAD <$url> INTO GRAPH <$this->graphNamed> +EOT; + } } \ No newline at end of file diff --git a/storageMethod/SimpleStorageMethod.php b/storageMethod/SimpleStorageMethod.php index d090e76..8484b04 100644 --- a/storageMethod/SimpleStorageMethod.php +++ b/storageMethod/SimpleStorageMethod.php @@ -75,4 +75,11 @@ EOT; } + public function getQueryLoadData($url) + { + return <<<EOT +LOAD <$url> +EOT; + } + } \ No newline at end of file diff --git a/storageMethod/StorageInGraphMethod.php b/storageMethod/StorageInGraphMethod.php index 7e2fc99..747b1b9 100644 --- a/storageMethod/StorageInGraphMethod.php +++ b/storageMethod/StorageInGraphMethod.php @@ -98,4 +98,11 @@ } EOT; } + + public function getQueryLoadData($url) + { + return <<<EOT +LOAD <$url> INTO GRAPH <$this->graphNamed> +EOT; + } } \ No newline at end of file diff --git a/storageMethod/StorageMethodAbstract.php b/storageMethod/StorageMethodAbstract.php index 9751f0a..2280401 100644 --- a/storageMethod/StorageMethodAbstract.php +++ b/storageMethod/StorageMethodAbstract.php @@ -25,5 +25,5 @@ abstract public function getQueryReadValue(); abstract public function getQueryInsertValue(); abstract public function getQueryDeleteSubject(); - + abstract public function getQueryLoadData($url); } \ No newline at end of file diff --git a/storageMethod/WikidataStorageMethod.php b/storageMethod/WikidataStorageMethod.php index a94bdb2..97f5277 100644 --- a/storageMethod/WikidataStorageMethod.php +++ b/storageMethod/WikidataStorageMethod.php @@ -57,22 +57,17 @@ public function getQueryInsertValue() { - return <<<EOT -INSERT DATA - { - ?subject ?property ?value . - } -EOT; + return ""; } public function getQueryDeleteSubject() { - return <<<EOT -DELETE - { ?subject ?property ?value . } -WHERE - { ?subject ?property ?value . } -EOT; + return ""; + } + + public function getQueryLoadData($url) + { + return ""; } } \ No newline at end of file -- To view, visit https://gerrit.wikimedia.org/r/310582 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I2dcff5a5dbd1d8ebaef0a4fc66571c32e604ef8d Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/LinkedWiki Gerrit-Branch: master Gerrit-Owner: Karima Rafes <karima.ra...@gmail.com> Gerrit-Reviewer: Jackmcbarn <jackmcb...@gmail.com> Gerrit-Reviewer: Karima Rafes <karima.ra...@gmail.com> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits