Karima Rafes has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/404093 )

Change subject: - Fix errors messages - Upgrade sgvizler2 - prepare release
......................................................................

- Fix errors messages
- Upgrade sgvizler2
- prepare release

Change-Id: Id9211e26cdffddd80c219aa7b9cafe76313efb79
---
M README
M extension.json
M i18n/linkedwiki/en.json
M i18n/linkedwiki/fr.json
M i18n/sparqlquery/en.json
M i18n/sparqlquery/fr.json
M keys.js
M package.json
M parser/SparqlParser.php
9 files changed, 90 insertions(+), 57 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/LinkedWiki 
refs/changes/93/404093/1

diff --git a/README b/README
index 480c89e..6af8adc 100644
--- a/README
+++ b/README
@@ -33,7 +33,6 @@
 
 Optional extensions :
 * "Scribunto" in order to use the Lua class of Linkedwiki
-* "Widgets"  in order to use the parser WSparql with a Mediawiki widget
 
 == Tutorial and download ==
 
@@ -43,6 +42,7 @@
 
 * v3.1.1 Update Sgvizler2 and bootstrap by Karima Rafes 
<karima.ra...@bordercloud.com>
          - Fix bugs in special page and parser
+         - Fix errors messages
 
 * v3.1.0 Use Sgvizler2, javascript wrapper for easy visualisation of SPARQL 
result sets. ( T143364 )
         - Update lib bordercloud/sparql
diff --git a/extension.json b/extension.json
index e0df00d..17f7f9f 100644
--- a/extension.json
+++ b/extension.json
@@ -1,6 +1,6 @@
 {
        "name": "LinkedWiki",
-       "version": "3.1.0 Beta",
+       "version": "3.1.1",
        "author": [
                "[https://www.mediawiki.org/wiki/User:Karima_Rafes Karima 
Rafes]"
        ],
diff --git a/i18n/linkedwiki/en.json b/i18n/linkedwiki/en.json
index 0ef82d7..990fd49 100644
--- a/i18n/linkedwiki/en.json
+++ b/i18n/linkedwiki/en.json
@@ -8,5 +8,9 @@
        "linkedwiki-refresh": "Refresh",
        "linkedwiki-duration": "Duration of query",
 
-       "specialpages-group-linkedwiki_group": "SPARQL and RDF tools"
+       "specialpages-group-linkedwiki_group": "SPARQL and RDF tools",
+
+       "linkedwiki-error-server": "Sorry, the sparql server sent an error. 
(see details with parameter log=2)",
+       "linkedwiki-error-endpoint-init": "Sorry, there is an error with your 
endpoint. (see details with parameter log=2)",
+       "linkedwiki-error-endpoint-empty": "Where is the Endpoint or the 
configuration ?"
 }
diff --git a/i18n/linkedwiki/fr.json b/i18n/linkedwiki/fr.json
index 827cb42..114ef7d 100644
--- a/i18n/linkedwiki/fr.json
+++ b/i18n/linkedwiki/fr.json
@@ -7,5 +7,9 @@
        "linkedwiki-refresh": "Rafraîchir",
        "linkedwiki-duration": "Durée du calcul",
 
-       "specialpages-group-linkedwiki_group": "Outils pour SPARQL et RDF"
+       "specialpages-group-linkedwiki_group": "Outils pour SPARQL et RDF",
+
+       "linkedwiki-error-server": "Désolé, le serveur SPARQL a envoyé une 
erreur. (voir les détails avec le paramètre log=2)",
+       "linkedwiki-error-endpoint-init": "Désolé, il y a un erreur à 
l'initialisation du endpoint SPARQL. (voir les détails avec le paramètre 
log=2)",
+       "linkedwiki-error-endpoint-empty": "Où est le paramètre endpoint ou 
configuration ?"
 }
diff --git a/i18n/sparqlquery/en.json b/i18n/sparqlquery/en.json
index c814563..6bf3bfd 100644
--- a/i18n/sparqlquery/en.json
+++ b/i18n/sparqlquery/en.json
@@ -5,7 +5,7 @@
        "linkedwiki-specialsparqlquery": "SPARQL editor",
        "linkedwiki-specialsparqlquery_categorysparqlquery": "SPARQL query",
        "linkedwiki-specialsparqlquery_mainpage": "This page will be used to 
test, optimize and share your queries if you wish.\n\nPost your questions to: 
[https://www.mediawiki.org/wiki/Extension_talk:LinkedWiki Talk:linkedwiki]",
-       "linkedwiki-specialsparqlquery_sendquery": "Search",
+       "linkedwiki-specialsparqlquery_sendquery": "Execute query",
        "linkedwiki-specialsparqlquery_usethisquery": "Howto use this query in 
this wiki",
        "linkedwiki-specialsparqlquery_usethisquery_tutorial": "Copy and paste 
this line in a page of this wiki.\n\nSee more: 
[https://www.mediawiki.org/wiki/Extension:LinkedWiki Extension:LinkedWiki]",
        "linkedwiki-specialsparqlquery_endpointsparql": "Endpoint SPARQL",
diff --git a/i18n/sparqlquery/fr.json b/i18n/sparqlquery/fr.json
index 2478d56..21196c1 100644
--- a/i18n/sparqlquery/fr.json
+++ b/i18n/sparqlquery/fr.json
@@ -5,7 +5,7 @@
        "linkedwiki-specialsparqlquery": "Editeur SPARQL",
        "linkedwiki-specialsparqlquery_categorysparqlquery": "Requête SPARQL",
        "linkedwiki-specialsparqlquery_mainpage": "Cette page va vous servir à 
tester, optimiser et partager vos requêtes si vous le souhaitez.\n\nPostez vos 
questions à : [https://www.mediawiki.org/wiki/Extension_talk:LinkedWiki 
Discussion linkedwiki]",
-       "linkedwiki-specialsparqlquery_sendquery": "Envoyer",
+       "linkedwiki-specialsparqlquery_sendquery": "Exécuter la requête",
        "linkedwiki-specialsparqlquery_usethisquery": "Utiliser cette requête 
au sein de ce Wiki",
        "linkedwiki-specialsparqlquery_usethisquery_tutorial": "Pour cela, il 
vous suffit de copier le text suivant dans une page du wiki. Pour formater 
l'affichage, voir : [http://www.mediawiki.org/wiki/Extension:LinkedWiki 
Extension:LinkedWiki]",
        "linkedwiki-specialsparqlquery_endpointsparql": "Point d'accès SPARQL",
diff --git a/keys.js b/keys.js
index d167ec5..bf99759 100644
--- a/keys.js
+++ b/keys.js
@@ -5,11 +5,3 @@
 // OpenStreetMap Access Token
 // Todo put the link of tutorial to create a new token
 //var osmAccessToken = "OPENSTREETMAP_ACCESS_TOKEN";
-
-// Google Api key
-// Todo put the link of tutorial to create a new key
-var googleApiKey = "AIzaSyBro_IlWgOb5o4C80IWZhq0YHhemlRta3Q";
-
-// OpenStreetMap Access Token
-// Todo put the link of tutorial to create a new token
-var osmAccessToken = 
"pk.eyJ1Ijoia3JhZmVzIiwiYSI6ImNqNm02eDduaDF2aG0ycW5oZzhxbzUwZmEifQ.SE1YXz0mqTkafrwd_YXn1A";
diff --git a/package.json b/package.json
index 65a3394..9ad8bc0 100644
--- a/package.json
+++ b/package.json
@@ -12,6 +12,6 @@
                "bootstrap": "^4.0.0-beta.3",
                "font-awesome": "^4.7.0",
                "popper.js": "^1.12.9",
-               "sgvizler2": "^1.0.8"
+               "sgvizler2": "^1.0.9"
        }
 }
diff --git a/parser/SparqlParser.php b/parser/SparqlParser.php
index 285825f..70db600 100644
--- a/parser/SparqlParser.php
+++ b/parser/SparqlParser.php
@@ -58,7 +58,7 @@
 
             $chart = isset($vars["chart"]) ? $vars["chart"] : '';
             $options = isset($vars["options"]) ? $vars["options"] : '';
-            $log = isset($vars["log"]) ? $vars["log"] : '';
+            $log = isset($vars["log"]) ? $vars["log"] : 1;
 
 
             if(!EMPTY($chart)){
@@ -77,14 +77,34 @@
                     $parser->disableCache();
                 }
                 if ($templateBare == "tableCell") {
-                   return SparqlParser::tableCell($query, $config, $endpoint, 
$debug);
+                   return SparqlParser::tableCell(
+                       $query,
+                       $config,
+                       $endpoint,
+                       $debug,
+                       $log);
                 } else {
                     if ($templates != "") {
-                        return SparqlParser::simpleHTMLWithTemplate($query, 
$config, $endpoint,
-                            $classHeaders, $headers, $templates, $footer, 
$debug);
+                        return SparqlParser::simpleHTMLWithTemplate(
+                            $query,
+                            $config,
+                            $endpoint,
+                            $classHeaders,
+                            $headers,
+                            $templates,
+                            $footer,
+                            $debug,
+                            $log);
                     } else {
-                        return SparqlParser::simpleHTML($query, $config, 
$endpoint,
-                            $classHeaders, $headers, $footer, $debug);
+                        return SparqlParser::simpleHTML(
+                            $query,
+                            $config,
+                            $endpoint,
+                            $classHeaders,
+                            $headers,
+                            $footer,
+                            $debug,
+                            $log);
                     }
                 }
             }
@@ -105,22 +125,13 @@
         $log = '',
         $debug = null)
     {
-        global $wgOut ;
-        $str = "";
-
         $methodSg = "";
         $parameterSg = "";
         $endpointSg = "";
         $logSg = $log;
 
-//        $specialC = array("&#39;","&nbsp;");
-//        $replaceC = array("'", " ");
-//        $querySparql = str_replace($specialC, $replaceC, $querySparqlWiki);
-
         if(EMPTY($config) && EMPTY($endpoint)){
-            return array("<pre>Where is the Endpoint or the configuration 
?</pre>", 'noparse' => true, 'isHTML' =>
-                false);
-
+            return 
SparqlParser::printMessageErrorDebug(1,wfMessage('linkedwiki-error-endpoint-empty')->text());
         }else if (!EMPTY($endpoint)){
             $endpointSg = $endpoint;
         }else if (!EMPTY($config)){
@@ -134,15 +145,12 @@
             }
         }
 
-        if($debug){
+        if(SparqlParser::isDebug($debug)){
             $logSg = 2;
         }
 
-        //echo $querySparql;
         $uniqId = "ID". uniqid();
         $str = "<div id='".$uniqId."' " ;
-
-// Affiche : Un 'apostrophe' en &lt;strong&gt;gras&lt;/strong&gt;
 
         $str .="data-sgvizler-query='" .  htmlentities($querySparqlWiki, 
ENT_QUOTES, "UTF-8") . "' \n" .
 
@@ -162,7 +170,6 @@
             $str .= "data-sgvizler-endpoint-query-parameter=\"" . $parameterSg 
. "\" \n";
         }
         $str .=  "></div>";
-        //echo $str;
 
         return array($str, 'isChildObj' => true);
     }
@@ -175,15 +182,17 @@
         $headers = '',
         $templates = '',
         $footer = '',
-        $debug = null)
+        $debug = null,
+        $log = '')
     {
+        $isDebug = SparqlParser::isDebug($debug);
         $specialC = array("&#39;");
         $replaceC = array("'");
         $querySparql = str_replace($specialC, $replaceC, $querySparqlWiki);
 
         $arrEndpoint = ToolsParser::newEndpoint($config, $endpoint);
         if ($arrEndpoint["endpoint"] == null) {
-            return array("<pre>" . $arrEndpoint["errorMessage"] . "</pre>", 
'noparse' => true, 'isHTML' => false);
+            return 
SparqlParser::printMessageErrorDebug($log,wfMessage('linkedwiki-error-endpoint-init')->text(),$arrEndpoint["errorMessage"]);
         }
         $sp = $arrEndpoint["endpoint"];
 
@@ -192,9 +201,9 @@
         if ($errs) {
             $strerr = "";
             foreach ($errs as $err) {
-                $strerr .= "'''Error #sparql :" . $err . "'''<br/>";
+                $strerr .= "'''Error #sparql :" . $err . "'''";
             }
-            return $strerr;
+            return 
SparqlParser::printMessageErrorDebug($log,wfMessage('linkedwiki-error-server')->text(),$strerr);
         }
         $variables = $rs['result']['variables'];
         $TableFormatTemplates = explode(",", $templates);
@@ -253,17 +262,18 @@
 
         if ($footer != "NO"  && $footer != "no") {
             $str .= "|- style=\"font-size:80%\" align=\"right\"\n";
-            $str .= "| colspan=\"" . count($TableFormatTemplates) . "\"|" . 
SparqlParser::footer($rs['query_time'], $querySparqlWiki, $config, $endpoint, 
$classHeaders, $headers) . "\n";
+            $str .= "| colspan=\"" . count($TableFormatTemplates) . "\"|" .
+                SparqlParser::footer($rs['query_time'], $querySparqlWiki, 
$config, $endpoint, $classHeaders, $headers)
+                . "\n";
         }
-
         $str .= "|}\n";
 
-        if ($debug != null && ($debug == "YES" || $debug == "yes")) {
+        if($isDebug){
             $str .= "INPUT WIKI : " . $querySparqlWiki . "\n";
             $str .= "Query : " . $querySparql . "\n";
             $str .= print_r($arrayParameters, true);
             $str .= print_r($rs, true);
-            return array("<pre>" . $str . "</pre>", 'noparse' => true, 
'isHTML' => true);
+            return SparqlParser::printMessageErrorDebug(2,"Debug 
messages",$str);
         }
         return array($str, 'noparse' => false, 'isHTML' => false);
     }
@@ -274,15 +284,17 @@
         $classHeaders = '',
         $headers = '',
         $footer = '',
-        $debug = null)
+        $debug = null,
+        $log = '')
     {
+        $isDebug = SparqlParser::isDebug($debug);
         $specialC = array("&#39;");
         $replaceC = array("'");
         $querySparql = str_replace($specialC, $replaceC, $querySparqlWiki);
 
         $arrEndpoint = ToolsParser::newEndpoint($config, $endpoint);
         if ($arrEndpoint["endpoint"] == null) {
-            return array("<pre>" . $arrEndpoint["errorMessage"] . "</pre>", 
'noparse' => true, 'isHTML' => false);
+            return 
SparqlParser::printMessageErrorDebug($log,wfMessage('linkedwiki-error-endpoint-init')->text(),$arrEndpoint["errorMessage"]);
         }
         $sp = $arrEndpoint["endpoint"];
 
@@ -291,9 +303,9 @@
         if ($errs) {
             $strerr = "";
             foreach ($errs as $err) {
-                $strerr .= "'''Error #sparql :" . $err . "'''<br/>";
+                $strerr .= "'''Error #sparql :" . $err . "'''";
             }
-            return $strerr;
+            return 
SparqlParser::printMessageErrorDebug($log,wfMessage('linkedwiki-error-server')->text(),$strerr);
         }
 
         $lignegrise = false;
@@ -358,25 +370,30 @@
 
         $str .= "</table>\n";
 
-        if ($debug != null && ($debug == "YES" || $debug == "yes" || $debug == 
"1")) {
+        if ($isDebug) {
             $str .= "INPUT WIKI: \n" . $querySparqlWiki . "\n";
             $str .= "QUERY : " . $querySparql . "\n";
             $str .= print_r($rs, true);
-            return array("<pre>" . htmlspecialchars($str) . "</pre>", 
'noparse' => true, 'isHTML' => false);
+            return SparqlParser::printMessageErrorDebug(2,"Debug 
messages",$str);
         }
-
         return array($str, 'noparse' => false, 'isHTML' => true);
     }
 
-    public static function tableCell($querySparqlWiki, $config, $endpoint, 
$debug = null)
+    public static function tableCell(
+        $querySparqlWiki,
+        $config,
+        $endpoint,
+        $debug = null,
+        $log = '')
     {
+        $isDebug = SparqlParser::isDebug($debug);
         $specialC = array("&#39;");
         $replaceC = array("'");
         $querySparql = str_replace($specialC, $replaceC, $querySparqlWiki);
 
         $arrEndpoint = ToolsParser::newEndpoint($config, $endpoint);
         if ($arrEndpoint["endpoint"] == null) {
-            return array("<pre>" . $arrEndpoint["errorMessage"] . "</pre>", 
'noparse' => true, 'isHTML' => false);
+            return 
SparqlParser::printMessageErrorDebug($log,wfMessage('linkedwiki-error-endpoint-init')->text(),$arrEndpoint["errorMessage"]);
         }
         $sp = $arrEndpoint["endpoint"];
         $rs = $sp->query($querySparqlWiki);
@@ -384,9 +401,9 @@
         if ($errs) {
             $strerr = "";
             foreach ($errs as $err) {
-                $strerr .= "'''Error #sparql :" . $err . "'''<br/>";
+                $strerr .= "'''Error #sparql :" . $err . "'''";
             }
-            return $strerr;
+            return 
SparqlParser::printMessageErrorDebug($log,wfMessage('linkedwiki-error-server')->text(),$strerr);
         }
 
         $variables = $rs['result']['variables'];
@@ -410,11 +427,11 @@
             $str .= "\n|- \n";
         }
 
-        if ($debug != null && ($debug == "YES" || $debug == "yes" || $debug == 
"1")) {
+        if ($isDebug) {
             $str .= "INPUT WIKI: \n" . $querySparqlWiki . "\n";
             $str .= "QUERY : " . $querySparql . "\n";
             $str .= print_r($rs, true);
-            return array("<pre>" . htmlspecialchars($str) . "</pre>", 
'noparse' => true, 'isHTML' => false);
+            return SparqlParser::printMessageErrorDebug(2,"Debug 
messages",$str);
         }
 
         return array($str, 'noparse' => false, 'isHTML' => false);
@@ -467,4 +484,20 @@
         return $result;
     }
 
+    private static function isDebug($debugParam)
+    {
+        return $debugParam != null && ($debugParam == "YES" || $debugParam == 
"yes" || $debugParam == "1");
+    }
+
+    private static function printMessageErrorDebug($logLevel = 0, $messageName 
= "",$details = "")
+    {
+        $html = "";
+        if ($logLevel == 2) { //debug
+            $html .= "<p style='color:red'>" . htmlspecialchars($messageName) 
. "</p>";
+            $html .= "<pre>" . htmlspecialchars($details) . "</pre>";
+        } elseif ($logLevel == 1) {
+            $html .= "<p style='color:red'>" . htmlspecialchars($messageName) 
. "</p>";
+        } // $logLevel == 0 // Print nothing
+        return array($html, 'noparse' => true, 'isHTML' => false);
+    }
 }

-- 
To view, visit https://gerrit.wikimedia.org/r/404093
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Id9211e26cdffddd80c219aa7b9cafe76313efb79
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/LinkedWiki
Gerrit-Branch: master
Gerrit-Owner: Karima Rafes <karima.ra...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to