Yurik has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/383049 )
Change subject: Use global config everywhere
......................................................................
Use global config everywhere
* Ensure config is loaded before all other code
* Do not use any hardcoded URL values outside of config
* Minor optimization for localhost debugging
Change-Id: I933162c48aaddb121062a1e39e484ed2f4c9ece8
---
M embed.html
M examples/dialog.html
M examples/editor.html
M examples/result.html
M examples/sparql.html
M index.html
M wikibase/config.js
M wikibase/init.js
M wikibase/queryService/api/Sparql.js
M wikibase/tests/QueryHelper.html
M wikibase/tests/index.html
11 files changed, 58 insertions(+), 47 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/wikidata/query/gui
refs/changes/49/383049/1
diff --git a/embed.html b/embed.html
index 553a14b..840738d 100644
--- a/embed.html
+++ b/embed.html
@@ -192,6 +192,7 @@
<!-- endbuild -->
<!-- build:js js/embed.wdqs.min.js -->
+ <script src="wikibase/config.js"></script>
<script src="wikibase/queryService/ui/ResultView.js"></script>
<script
src="wikibase/queryService/ui/resultBrowser/helper/FormatterHelper.js"></script>
<script
src="wikibase/queryService/ui/resultBrowser/AbstractResultBrowser.js"></script>
@@ -221,7 +222,6 @@
<script
src="wikibase/queryService/ui/queryHelper/SelectorBox.js"></script>
<script
src="wikibase/queryService/ui/queryHelper/QueryTemplate.js"></script>
<script src="wikibase/queryService/ui/toolbar/ActionBar.js"></script>
- <script src="wikibase/config.js"></script>
<!-- endbuild -->
<script type="text/javascript">
diff --git a/examples/dialog.html b/examples/dialog.html
index 577a34a..155f192 100644
--- a/examples/dialog.html
+++ b/examples/dialog.html
@@ -20,6 +20,7 @@
<script
src="../vendor/bootstrapx-clickover/bootstrapx-clickover.js"></script>
<!-- JS files -->
+ <script src="../wikibase/config.js"></script>
<script src="../wikibase/queryService/api/QuerySamples.js"></script>
<script src="../wikibase/queryService/api/Wikibase.js"></script>
<script src="../wikibase/queryService/api/Tracking.js"></script>
@@ -59,7 +60,7 @@
function( query, title ) {
alert( title + '\n\n' + query );
},
- 'https://query.wikidata.org/embed.html');
+ CONFIG.location.index + 'embed.html');
} );
</script>
</body>
diff --git a/examples/editor.html b/examples/editor.html
index 0dfd902..ee44547 100644
--- a/examples/editor.html
+++ b/examples/editor.html
@@ -22,6 +22,7 @@
<script
src="../node_modules/codemirror/addon/display/fullscreen.js"></script>
<!-- JS files -->
+ <script src="../wikibase/config.js"></script>
<script
src="../wikibase/queryService/ui/editor/hint/Sparql.js"></script>
<script src="../wikibase/queryService/ui/editor/hint/Rdf.js"></script>
<script
src="../wikibase/queryService/ui/editor/tooltip/Rdf.js"></script>
diff --git a/examples/result.html b/examples/result.html
index a921d10..410384e 100644
--- a/examples/result.html
+++ b/examples/result.html
@@ -35,7 +35,8 @@
<script src="../node_modules/wellknown/wellknown.js"></script>
<script src="../node_modules/d3/d3.js"></script>
- <!-- JS files -->
+ <!-- JS files -->
+ <script src="../wikibase/config.js"></script>
<script src="../wikibase/queryService/api/Sparql.js"></script>
<script src="../wikibase/queryService/RdfNamespaces.js"></script>
<script
src="../wikibase/queryService/ui/resultBrowser/helper/FormatterHelper.js"></script>
@@ -45,28 +46,28 @@
<div id="result"></div>
<script type="text/javascript">
/* SPARQL Query */
- var query = '#Lighthouses in Norway\n' +
- 'SELECT DISTINCT ?item ?itemLabel ?coor ?image\n' +
- 'WHERE\n' +
- '{\n' +
- ' ?item wdt:P31 wd:Q39715 . \n' +
- ' ?item wdt:P17 wd:Q20 .' +
- ' OPTIONAL { ?item wdt:P625 ?coor }\n' +
- ' OPTIONAL { ?item wdt:P18 ?image }\n' +
- ' SERVICE wikibase:label { bd:serviceParam
wikibase:language "nb,nn,en,fi" }\n' +
- '}\n' +
+ var query = '#Lighthouses in Norway\n' +
+ 'SELECT DISTINCT ?item ?itemLabel ?coor ?image\n' +
+ 'WHERE\n' +
+ '{\n' +
+ ' ?item wdt:P31 wd:Q39715 . \n' +
+ ' ?item wdt:P17 wd:Q20 .' +
+ ' OPTIONAL { ?item wdt:P625 ?coor }\n' +
+ ' OPTIONAL { ?item wdt:P18 ?image }\n' +
+ ' SERVICE wikibase:label { bd:serviceParam
wikibase:language "nb,nn,en,fi" }\n' +
+ '}\n' +
'ORDER BY ?itemLabel\n';
/* JS Code */
$(document).ready(function() {
var api = new wikibase.queryService.api.Sparql();
-
+
//modify formatter
var formatter = new
wikibase.queryService.ui.resultBrowser.helper.FormatterHelper();
formatter.formatValue = function( data ){
return 'This is my formatter:' + JSON.stringify( data );
};
-
+
api.query( query ).done(function() {
var result = new
wikibase.queryService.ui.resultBrowser.CoordinateResultBrowser()
result.setFormatter( formatter );
diff --git a/examples/sparql.html b/examples/sparql.html
index bf2d822..0176117 100644
--- a/examples/sparql.html
+++ b/examples/sparql.html
@@ -10,7 +10,8 @@
<!-- JS vendor files -->
<script src="../node_modules/jquery/dist/jquery.js"></script>
- <!-- JS files -->
+ <!-- JS files -->
+ <script src="../wikibase/config.js"></script>
<script src="../wikibase/queryService/api/Sparql.js"></script>
<select class="countries">
@@ -22,14 +23,14 @@
var api = new wikibase.queryService.api.Sparql();
var query = 'SELECT ?countryLabel WHERE { ?country wdt:P31
wd:Q6256 . SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
} ORDER BY ?countryLabel';
-
+
api.query( query ).done( function(){
var json = JSON.parse( api.getResultAsJson() );
$.each(json, function( key, value ){
$( '.countries' ).append( $( '<option/>'
).text( value.countryLabel ) );
} );
-
+
} );
});
</script>
diff --git a/index.html b/index.html
index 946a003..3ba7ab9 100644
--- a/index.html
+++ b/index.html
@@ -101,7 +101,7 @@
</nav>
<div id="query-box">
- <form id="query-form"
action="https://query.wikidata.org/bigdata/namespace/wdq/sparql">
+ <form id="query-form">
<div class="query-main">
<div class="toolbar">
<div
class="toolbar-top">
@@ -322,6 +322,7 @@
<!-- endbuild -->
<!-- build:js js/wdqs.min.js -->
+ <script src="wikibase/config.js"></script>
<script src="wikibase/queryService/ui/App.js"></script>
<script src="wikibase/queryService/ui/toolbar/ActionBar.js"></script>
<script
src="wikibase/queryService/ui/i18n/LanguageSelector.js"></script>
@@ -359,7 +360,6 @@
<script src="wikibase/queryService/api/Wikibase.js"></script>
<script src="wikibase/queryService/api/Tracking.js"></script>
<script src="wikibase/queryService/RdfNamespaces.js"></script>
- <script src="wikibase/config.js"></script>
<script src="wikibase/init.js"></script>
<!-- endbuild -->
</body>
diff --git a/wikibase/config.js b/wikibase/config.js
index 1911906..83551cd 100644
--- a/wikibase/config.js
+++ b/wikibase/config.js
@@ -44,30 +44,30 @@
}
};
- var configLocal = $.extend( true, {}, configDeploy, {
- api: {
- sparql: {
- uri:
'https://query.wikidata.org/bigdata/namespace/wdq/sparql'
- }
- },
- i18nLoad: function( lang ) {
- return $.when(
- $.i18n().load( 'i18n/' + lang +
'.json', lang ),
- $.i18n().load(
'node_modules/jquery.uls/i18n/' + lang + '.json', lang )
- );
- },
- brand: {
- title: 'Localhost'
- },
- location: {
- index: './index.html'
- }
- } );
-
var hostname = window.location.hostname.toLowerCase();
if ( hostname === '' || hostname === 'localhost' || hostname ===
'127.0.0.1' ) {
- return configLocal;
+ // Override for local debugging
+ return $.extend( true, {}, configDeploy, {
+ api: {
+ sparql: {
+ uri:
'https://query.wikidata.org/bigdata/namespace/wdq/sparql'
+
+ }
+ },
+ i18nLoad: function( lang ) {
+ return $.when(
+ $.i18n().load( 'i18n/' + lang +
'.json', lang ),
+ $.i18n().load(
'node_modules/jquery.uls/i18n/' + lang + '.json', lang )
+ );
+ },
+ brand: {
+ title: 'Localhost'
+ },
+ location: {
+ index: './index.html'
+ }
+ } );
}
return configDeploy;
diff --git a/wikibase/init.js b/wikibase/init.js
index f6a9650..0fbae93 100644
--- a/wikibase/init.js
+++ b/wikibase/init.js
@@ -29,6 +29,8 @@
function() {
setBrand();
+ $( '#query-form' ).attr( 'action',
config.api.sparql.uri );
+
var lang = Cookies.get( 'lang' ) ? Cookies.get( 'lang'
) : config.language;
setLanguage( lang, false );
diff --git a/wikibase/queryService/api/Sparql.js
b/wikibase/queryService/api/Sparql.js
index bd55824..2089c3d 100644
--- a/wikibase/queryService/api/Sparql.js
+++ b/wikibase/queryService/api/Sparql.js
@@ -2,10 +2,10 @@
wikibase.queryService = wikibase.queryService || {};
wikibase.queryService.api = wikibase.queryService.api || {};
-wikibase.queryService.api.Sparql = ( function( $ ) {
+wikibase.queryService.api.Sparql = ( function( $, config ) {
'use strict';
- var SPARQL_SERVICE_URI =
'https://query.wikidata.org/bigdata/namespace/wdq/sparql',
+ var SPARQL_SERVICE_URI = config.api.sparql.uri,
ERROR_CODES = {
TIMEOUT: 10,
MALFORMED: 20,
@@ -485,4 +485,4 @@
return SELF;
-}( jQuery ) );
+}( jQuery, CONFIG ) );
diff --git a/wikibase/tests/QueryHelper.html b/wikibase/tests/QueryHelper.html
index f0879e4..9c54464 100644
--- a/wikibase/tests/QueryHelper.html
+++ b/wikibase/tests/QueryHelper.html
@@ -22,7 +22,9 @@
<script src="../../node_modules/select2/dist/js/select2.js"></script>
<script
src="../../vendor/sparqljs/dist/sparqljs-browser-min.js"></script>
<script
src="../../vendor/bootstrapx-clickover/bootstrapx-clickover.js"></script>
- <!-- wikibase -->
+
+ <!-- wikibase -->
+ <script src="../../wikibase/config.js"></script>
<script src="../queryService/RdfNamespaces.js"></script>
<script src="../queryService/api/Wikibase.js"></script>
<script src="../queryService/api/Sparql.js"></script>
@@ -30,10 +32,11 @@
<script src="../queryService/ui/queryHelper/SelectorBox.js"></script>
<script src="../queryService/ui/queryHelper/SparqlQuery.js"></script>
<script src="../queryService/ui/queryHelper/QueryTemplate.js"></script>
-<!-- Tests -->
+
+ <!-- Tests -->
<script src="queryService/ui/queryHelper/QueryHelper.test.js"></script>
<script src="queryService/ui/queryHelper/SparqlQuery.test.js"></script>
<script
src="queryService/ui/queryHelper/QueryTemplate.test.js"></script>
-
+
</body>
</html>
diff --git a/wikibase/tests/index.html b/wikibase/tests/index.html
index aa224c0..9390dd5 100644
--- a/wikibase/tests/index.html
+++ b/wikibase/tests/index.html
@@ -36,7 +36,9 @@
<script src="../../node_modules/wellknown/wellknown.js"></script>
<script
src="../../vendor/bootstrap-tags/js/bootstrap-tags.min.js"></script>
+
<!-- wikibase -->
+ <script src="../../wikibase/config.js"></script>
<script src="../queryService/api/Wikibase.js"></script>
<script src="../queryService/api/Sparql.js"></script>
<script src="../queryService/ui/editor/hint/Rdf.js"></script>
--
To view, visit https://gerrit.wikimedia.org/r/383049
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I933162c48aaddb121062a1e39e484ed2f4c9ece8
Gerrit-PatchSet: 1
Gerrit-Project: wikidata/query/gui
Gerrit-Branch: master
Gerrit-Owner: Yurik <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits