Smalyshev has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/399546 )

Change subject: Add support for namespaces
......................................................................

Add support for namespaces

TODO: not supported in embed, as of yet, and not in query string.

Bug: T176190
Change-Id: I8044f69c04782c4b11988cdf800a5c2948a59689
---
M embed.html
M i18n/en.json
M i18n/qqq.json
M index.html
M wikibase/config.js
M wikibase/init.js
M wikibase/queryService/RdfNamespaces.js
M wikibase/queryService/api/Sparql.js
M wikibase/queryService/ui/App.js
9 files changed, 65 insertions(+), 12 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/wikidata/query/gui 
refs/changes/46/399546/1

diff --git a/embed.html b/embed.html
index 72cbf8a..874a33a 100644
--- a/embed.html
+++ b/embed.html
@@ -266,7 +266,7 @@
                $( document ).ready( function() {
                        var config = CONFIG,
                                lang = Cookies.get( 'lang' ) ? Cookies.get( 
'lang' ) : config.language,
-                               sparqlApi = new 
wikibase.queryService.api.Sparql( config.api.sparql.uri, lang ),
+                               sparqlApi = new 
wikibase.queryService.api.Sparql( config.api.sparql.uri, lang, 
config.api.sparql.base ),
                                resultView = new 
wikibase.queryService.ui.ResultView( sparqlApi ),
                                query = decodeURIComponent( 
window.location.hash.substr( 1 ) );
 
diff --git a/i18n/en.json b/i18n/en.json
index bc27b7a..0c31331 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -83,5 +83,6 @@
     "wdqs-result-map-layers-all": "All layers",
     "wdqs-result-map-progress": "Loading map data: $1%",
     "wdqs-embed-button-edit-query": "Edit this query",
-    "wdqs-embed-button-edit-query-title": "Edit this query with the SPARQL 
editor"
+    "wdqs-embed-button-edit-query-title": "Edit this query with the SPARQL 
editor",
+    "wdqs-namespace-label": "Namespace:"
 }
diff --git a/i18n/qqq.json b/i18n/qqq.json
index 2921354..217733c 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -85,5 +85,6 @@
        "wdqs-result-map-layers-all": "Label for all layers in layer control on 
map view",
        "wdqs-result-map-progress": "Message while loading data for the map 
view. $1 is a percentage from 0 to 100.",
        "wdqs-embed-button-edit-query": "Label for button in embed",
-       "wdqs-embed-button-edit-query-title": "Title for button in embed"
+       "wdqs-embed-button-edit-query-title": "Title for button in embed",
+       "wdqs-namespace-label": "Label for namespace selector"
 }
diff --git a/index.html b/index.html
index e2170ab..abee5c4 100644
--- a/index.html
+++ b/index.html
@@ -101,6 +101,12 @@
                                                </li>
                                        </ul>
                                        <ul class="nav navbar-nav navbar-right">
+                                               <li style="display: none" 
id="namespaces-selector">
+                                                       <form 
class="navbar-form pull-right form-inline">
+                                                               <label 
for="namespace" class="control-label"><span 
data-i18n="wdqs-namespace-label"></span></label>
+                                                               <select 
id="namespace" class="form-control"></select>
+                                                       </form>
+                                               </li>
                                                <li>
                                                        <a href="#" 
class="uls-trigger" data-toggle="tooltip"></a>
                                                </li>
diff --git a/wikibase/config.js b/wikibase/config.js
index 68a4a4c..4067c8c 100644
--- a/wikibase/config.js
+++ b/wikibase/config.js
@@ -20,7 +20,9 @@
                language: getUserLanguage() || 'en',
                api: {
                        sparql: {
-                               uri: '/sparql'
+                               uri: '/sparql',
+                               base: '/bigdata/',
+                               namespaces: [ 'wdq', 'categories' ]
                        },
                        wikibase: {
                                uri: 'https://www.wikidata.org/w/api.php'
@@ -56,8 +58,8 @@
                return $.extend( true, {}, configDeploy, {
                        api: {
                                sparql: {
-                                       uri: 'https://query.wikidata.org/sparql'
-
+                                       uri: 
'https://query.wikidata.org/sparql',
+                                       base: 
'https://query.wikidata.org/bigdata/'
                                }
                        },
                        i18nLoad: function( lang ) {
diff --git a/wikibase/init.js b/wikibase/init.js
index bc4bddc..aa87faf 100644
--- a/wikibase/init.js
+++ b/wikibase/init.js
@@ -34,7 +34,7 @@
                        setLanguage( lang, false );
 
                        var api = new wb.api.Wikibase( config.api.wikibase.uri, 
lang ),
-                               sparqlApi = new wb.api.Sparql( 
config.api.sparql.uri, lang ),
+                               sparqlApi = new wb.api.Sparql( 
config.api.sparql.uri, lang, config.api.sparql.base ),
                                querySamplesApi = new wb.api.QuerySamples( lang 
),
                                codeSamplesApi = new wb.api.CodeSamples(
                                        config.api.sparql.uri,
@@ -43,6 +43,19 @@
                                ),
                                languageSelector = new 
wb.ui.i18n.LanguageSelector( $( '.uls-trigger' ), api, lang );
 
+                       if ( config.api.sparql.namespaces ) {
+                               if( config.api.sparql.namespaces.length > 1 ) {
+                                       $( '#namespaces-selector' ).show();
+                                       var list = $( '#namespace' )[0];
+                                       $.each( config.api.sparql.namespaces, 
function ( index, text)  {
+                                               
list.options[list.options.length] = new Option( text );
+                                       } );
+                               } else {
+                                       // Single NS - just set it
+                    sparqlApi.setNamespace( config.api.sparql.namespaces[0] );
+                               }
+            }
+
                        languageSelector.setChangeListener( function( lang ) {
                                api.setLanguage( lang );
                                sparqlApi.setLanguage( lang );
diff --git a/wikibase/queryService/RdfNamespaces.js 
b/wikibase/queryService/RdfNamespaces.js
index 02ad3b2..01e6a04 100644
--- a/wikibase/queryService/RdfNamespaces.js
+++ b/wikibase/queryService/RdfNamespaces.js
@@ -24,7 +24,8 @@
                        prv: 'http://www.wikidata.org/prop/reference/value/',
                        prn: 
'http://www.wikidata.org/prop/reference/value-normalized/',
                        wdno: 'http://www.wikidata.org/prop/novalue/',
-                       wdata: 
'http://www.wikidata.org/wiki/Special:EntityData/'
+                       wdata: 
'http://www.wikidata.org/wiki/Special:EntityData/',
+                       mediawiki: 'https://www.mediawiki.org/ontology#'
                },
                W3C: {
                        rdfs: 'http://www.w3.org/2000/01/rdf-schema#',
diff --git a/wikibase/queryService/api/Sparql.js 
b/wikibase/queryService/api/Sparql.js
index bd55824..e61a517 100644
--- a/wikibase/queryService/api/Sparql.js
+++ b/wikibase/queryService/api/Sparql.js
@@ -5,7 +5,8 @@
 wikibase.queryService.api.Sparql = ( function( $ ) {
        'use strict';
 
-       var SPARQL_SERVICE_URI = 
'https://query.wikidata.org/bigdata/namespace/wdq/sparql',
+       var SPARQL_SERVICE_URI = 'https://query.wikidata.org/bigdata/',
+               SPARQL_DEFAULT_NAMESPACE = 'wdq',
                ERROR_CODES = {
                        TIMEOUT: 10,
                        MALFORMED: 20,
@@ -31,9 +32,11 @@
         *
         * @param {string} [serviceUri] Optional URI to the SPARQL service 
endpoint
         * @param {string} [language]
+        * @param {string} {baseServiceUri}
         */
-       function SELF( serviceUri, language ) {
-               this._serviceUri = serviceUri || SPARQL_SERVICE_URI;
+       function SELF( serviceUri, language, baseServiceUri ) {
+               this._baseServiceUri = baseServiceUri || SPARQL_SERVICE_URI;
+               this._serviceUri = serviceUri || this.getNamespaceUrl( 
SPARQL_DEFAULT_NAMESPACE );
                this._language = language || DEFAULT_LANGUAGE;
        }
 
@@ -47,6 +50,12 @@
         * @private
         */
        SELF.prototype._serviceUri = null;
+
+       /**
+        * @property {string}
+        * @private
+        */
+       SELF.prototype._baseServiceUri = null;
 
        /**
         * @property {number}
@@ -483,6 +492,22 @@
                this._language = language;
        };
 
-       return SELF;
+       /**
+        * Get URL from namespace name
+        * @private
+        */
+       SELF.prototype.getNamespaceUrl = function( namespace ) {
+               return this._baseServiceUri + 'namespace/' + namespace + 
'/sparql';
+       };
 
+       /**
+        * Set API namespace
+        * @param namespace
+        */
+       SELF.prototype.setNamespace = function( namespace ) {
+               namespace = namespace || SPARQL_DEFAULT_NAMESPACE;
+               this._serviceUri = this.getNamespaceUrl( namespace );
+       };
+
+       return SELF;
 }( jQuery ) );
diff --git a/wikibase/queryService/ui/App.js b/wikibase/queryService/ui/App.js
index d571ea1..697831c 100644
--- a/wikibase/queryService/ui/App.js
+++ b/wikibase/queryService/ui/App.js
@@ -463,6 +463,10 @@
                        self._toggleFullscreen();
                } );
 
+               $( '#namespace' ).change( function (e) {
+                       self._sparqlApi.setNamespace( $( this ).val() );
+               } );
+
                $( window ).on( 'popstate', $.proxy( this._initQuery, this ) );
 
                this._initPopovers();

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I8044f69c04782c4b11988cdf800a5c2948a59689
Gerrit-PatchSet: 1
Gerrit-Project: wikidata/query/gui
Gerrit-Branch: master
Gerrit-Owner: Smalyshev <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to