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

Change subject: Bumped graph-shared lib - null support
......................................................................

Bumped graph-shared lib - null support

Change-Id: If173c1fdceea7c44b1cb441ca809e83a24c695cb
---
M lib/graph2.compiled.js
1 file changed, 173 insertions(+), 171 deletions(-)


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

diff --git a/lib/graph2.compiled.js b/lib/graph2.compiled.js
index 933bf1c..10c0c54 100644
--- a/lib/graph2.compiled.js
+++ b/lib/graph2.compiled.js
@@ -1,4 +1,110 @@
 (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof 
require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var 
f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var 
l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return 
s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof 
require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return 
s})({1:[function(require,module,exports){
+( function ( $, mw, vg ) {
+
+       'use strict';
+       /* global require */
+
+       var VegaWrapper = require( 'graph-shared' );
+
+       // eslint-disable-next-line no-new
+       new VegaWrapper( {
+               datalib: vg.util,
+               useXhr: true,
+               isTrusted: mw.config.get( 'wgGraphIsTrusted' ),
+               domains: mw.config.get( 'wgGraphAllowedDomains' ),
+               domainMap: false,
+               logger: function ( warning ) {
+                       mw.log.warn( warning );
+               },
+               parseUrl: function ( opt ) {
+                       // Parse URL
+                       var uri = new mw.Uri( opt.url );
+                       // reduce confusion, only keep expected values
+                       if ( uri.port ) {
+                               uri.host += ':' + uri.port;
+                               delete uri.port;
+                       }
+                       // If url begins with   protocol:///...  mark it as 
having relative host
+                       if ( /^[a-z]+:\/\/\//.test( opt.url ) ) {
+                               uri.isRelativeHost = true;
+                       }
+                       if ( uri.protocol ) {
+                               // All other libs use trailing colon in the 
protocol field
+                               uri.protocol += ':';
+                       }
+                       // Node's path includes the query, whereas pathname is 
without the query
+                       // Standardizing on pathname
+                       uri.pathname = uri.path;
+                       delete uri.path;
+                       return uri;
+               },
+               formatUrl: function ( uri, opt ) {
+                       // Format URL back into a string
+                       // Revert path into pathname
+                       uri.path = uri.pathname;
+                       delete uri.pathname;
+
+                       if ( location.host.toLowerCase() === 
uri.host.toLowerCase() ) {
+                               if ( !mw.config.get( 'wgGraphIsTrusted' ) ) {
+                                       // Only send this header when hostname 
is the same.
+                                       // This is broader than the same-origin 
policy,
+                                       // but playing on the safer side.
+                                       opt.headers = { 'Treat-as-Untrusted': 1 
};
+                               }
+                       } else if ( opt.addCorsOrigin ) {
+                               // All CORS api calls require origin parameter.
+                               // It would be better to use location.origin,
+                               // but apparently it's not universal yet.
+                               uri.query.origin = location.protocol + '//' + 
location.host;
+                       }
+
+                       uri.protocol = VegaWrapper.removeColon( uri.protocol );
+
+                       return uri.toString();
+               },
+               languageCode: mw.config.get( 'wgUserLanguage' )
+       } );
+
+       /**
+        * Set up drawing canvas inside the given element and draw graph data
+        *
+        * @param {HTMLElement} element
+        * @param {Object|string} data graph spec
+        * @param {Function} [callback] function(error) called when drawing is 
done
+        */
+       mw.drawVegaGraph = function ( element, data, callback ) {
+               vg.parse.spec( data, function ( error, chart ) {
+                       if ( !error ) {
+                               chart( { el: element } ).update();
+                       }
+                       if ( callback ) {
+                               callback( error );
+                       }
+               } );
+       };
+
+       mw.hook( 'wikipage.content' ).add( function ( $content ) {
+               var specs = mw.config.get( 'wgGraphSpecs' );
+               if ( !specs ) {
+                       return;
+               }
+               $content.find( '.mw-graph.mw-graph-always' ).each( function () {
+                       var graphId = $( this ).data( 'graph-id' );
+                       if ( !specs.hasOwnProperty( graphId ) ) {
+                               mw.log.warn( graphId );
+                       } else {
+                               mw.drawVegaGraph( this, specs[ graphId ], 
function ( error ) {
+                                       if ( error ) {
+                                               mw.log.warn( error );
+                                       }
+                               } );
+                       }
+               } );
+       } );
+
+}( jQuery, mediaWiki, vg ) );
+
+},{"graph-shared":3}],2:[function(require,module,exports){
 'use strict';
 
 /**
@@ -24,73 +130,6 @@
             })
             .join('|') + ')$', 'i');
 };
-
-},{}],2:[function(require,module,exports){
-'use strict';
-/* global module */
-
-module.exports = parseWikidataValue;
-
-/**
- * Given a value object as returned from Wikidata Query Service, returns a 
simplified value
- * @param {object} value Original object as sent by the Wikidata query service
- * @param {string} value.type SPARQL data type (literal, uri)
- * @param {string} value.datatype XMLSchema data type
- * @param {*} value.value The actual value sent by the Wikidata query service
- * @param {boolean=} ignoreUnknown if false, will return value.value even if 
it cannot be recognized
- * @return {*}
- */
-function parseWikidataValue(value, ignoreUnknown) {
-    var temp;
-
-    if (!value || !value.type || value.value === undefined) {
-        return undefined;
-    }
-
-    switch (value.type) {
-        case 'literal':
-            switch (value.datatype) {
-                case 'http://www.w3.org/2001/XMLSchema#double':
-                case 'http://www.w3.org/2001/XMLSchema#float':
-                case 'http://www.w3.org/2001/XMLSchema#decimal':
-                case 'http://www.w3.org/2001/XMLSchema#integer':
-                case 'http://www.w3.org/2001/XMLSchema#long':
-                case 'http://www.w3.org/2001/XMLSchema#int':
-                case 'http://www.w3.org/2001/XMLSchema#short':
-                case 'http://www.w3.org/2001/XMLSchema#nonNegativeInteger':
-                case 'http://www.w3.org/2001/XMLSchema#positiveInteger':
-                case 'http://www.w3.org/2001/XMLSchema#unsignedLong':
-                case 'http://www.w3.org/2001/XMLSchema#unsignedInt':
-                case 'http://www.w3.org/2001/XMLSchema#unsignedShort':
-                case 'http://www.w3.org/2001/XMLSchema#nonPositiveInteger':
-                case 'http://www.w3.org/2001/XMLSchema#negativeInteger':
-                    temp = parseFloat(value.value);
-                    if (temp.toString() === value.value) {
-                        // use number only if it is fully round-tripable back 
to string
-                        // TBD: this might be overcautios, and would cause 
more problems than solve
-                        return temp;
-                    }
-                    break;
-                case 'http://www.opengis.net/ont/geosparql#wktLiteral':
-                    // Point(-64.2 -36.62)  -- (longitude latitude)
-                    temp = /^Point\(([-0-9.]+) 
([-0-9.]+)\)$/.exec(value.value);
-                    if (temp) {
-                        return [parseFloat(temp[1]), parseFloat(temp[2])];
-                    }
-                    break;
-            }
-            break;
-        case 'uri':
-            // "http://www.wikidata.org/entity/Q12345";  ->  "Q12345"
-            temp = 
/^http:\/\/www\.wikidata\.org\/entity\/(Q[1-9][0-9]*)$/.exec(value.value);
-            if (temp) {
-                return temp[1];
-            }
-            break;
-    }
-    return ignoreUnknown ? undefined : value.value;
-}
-
 
 },{}],3:[function(require,module,exports){
 'use strict';
@@ -342,8 +381,8 @@
                         action: 'jsondata',
                         title: decodedPathname.substring(1)
                     };
-                    if (this.languageCode) {
-                        urlParts.query.uselang = this.languageCode;
+                    if (urlParts.siteLanguage || this.languageCode) {
+                        urlParts.query.uselang = urlParts.siteLanguage || 
this.languageCode;
                     }
                 }
 
@@ -514,7 +553,9 @@
             data.data = data.data.map(function(v) {
                 var row = {}, i;
                 for (i = 0; i < fields.length; i++) {
-                    row[fields[i]] = v[i];
+                    if (v[i] !== null) {
+                        row[fields[i]] = v[i];
+                    }
                 }
                 return row;
             });
@@ -546,110 +587,71 @@
     throw new Error('Disabled');
 }
 
-},{"domain-validator":1,"wd-type-parser":2}],4:[function(require,module,exports){
-( function ( $, mw, vg ) {
+},{"domain-validator":2,"wd-type-parser":4}],4:[function(require,module,exports){
+'use strict';
+/* global module */
 
-       'use strict';
-       /* global require */
+module.exports = parseWikidataValue;
 
-       var VegaWrapper = require( 'graph-shared' );
+/**
+ * Given a value object as returned from Wikidata Query Service, returns a 
simplified value
+ * @param {object} value Original object as sent by the Wikidata query service
+ * @param {string} value.type SPARQL data type (literal, uri)
+ * @param {string} value.datatype XMLSchema data type
+ * @param {*} value.value The actual value sent by the Wikidata query service
+ * @param {boolean=} ignoreUnknown if false, will return value.value even if 
it cannot be recognized
+ * @return {*}
+ */
+function parseWikidataValue(value, ignoreUnknown) {
+    var temp;
 
-       // eslint-disable-next-line no-new
-       new VegaWrapper( {
-               datalib: vg.util,
-               useXhr: true,
-               isTrusted: mw.config.get( 'wgGraphIsTrusted' ),
-               domains: mw.config.get( 'wgGraphAllowedDomains' ),
-               domainMap: false,
-               logger: function ( warning ) {
-                       mw.log.warn( warning );
-               },
-               parseUrl: function ( opt ) {
-                       // Parse URL
-                       var uri = new mw.Uri( opt.url );
-                       // reduce confusion, only keep expected values
-                       if ( uri.port ) {
-                               uri.host += ':' + uri.port;
-                               delete uri.port;
-                       }
-                       // If url begins with   protocol:///...  mark it as 
having relative host
-                       if ( /^[a-z]+:\/\/\//.test( opt.url ) ) {
-                               uri.isRelativeHost = true;
-                       }
-                       if ( uri.protocol ) {
-                               // All other libs use trailing colon in the 
protocol field
-                               uri.protocol += ':';
-                       }
-                       // Node's path includes the query, whereas pathname is 
without the query
-                       // Standardizing on pathname
-                       uri.pathname = uri.path;
-                       delete uri.path;
-                       return uri;
-               },
-               formatUrl: function ( uri, opt ) {
-                       // Format URL back into a string
-                       // Revert path into pathname
-                       uri.path = uri.pathname;
-                       delete uri.pathname;
+    if (!value || !value.type || value.value === undefined) {
+        return undefined;
+    }
 
-                       if ( location.host.toLowerCase() === 
uri.host.toLowerCase() ) {
-                               if ( !mw.config.get( 'wgGraphIsTrusted' ) ) {
-                                       // Only send this header when hostname 
is the same.
-                                       // This is broader than the same-origin 
policy,
-                                       // but playing on the safer side.
-                                       opt.headers = { 'Treat-as-Untrusted': 1 
};
-                               }
-                       } else if ( opt.addCorsOrigin ) {
-                               // All CORS api calls require origin parameter.
-                               // It would be better to use location.origin,
-                               // but apparently it's not universal yet.
-                               uri.query.origin = location.protocol + '//' + 
location.host;
-                       }
+    switch (value.type) {
+        case 'literal':
+            switch (value.datatype) {
+                case 'http://www.w3.org/2001/XMLSchema#double':
+                case 'http://www.w3.org/2001/XMLSchema#float':
+                case 'http://www.w3.org/2001/XMLSchema#decimal':
+                case 'http://www.w3.org/2001/XMLSchema#integer':
+                case 'http://www.w3.org/2001/XMLSchema#long':
+                case 'http://www.w3.org/2001/XMLSchema#int':
+                case 'http://www.w3.org/2001/XMLSchema#short':
+                case 'http://www.w3.org/2001/XMLSchema#nonNegativeInteger':
+                case 'http://www.w3.org/2001/XMLSchema#positiveInteger':
+                case 'http://www.w3.org/2001/XMLSchema#unsignedLong':
+                case 'http://www.w3.org/2001/XMLSchema#unsignedInt':
+                case 'http://www.w3.org/2001/XMLSchema#unsignedShort':
+                case 'http://www.w3.org/2001/XMLSchema#nonPositiveInteger':
+                case 'http://www.w3.org/2001/XMLSchema#negativeInteger':
+                    temp = parseFloat(value.value);
+                    if (temp.toString() === value.value) {
+                        // use number only if it is fully round-tripable back 
to string
+                        // TBD: this might be overcautios, and would cause 
more problems than solve
+                        return temp;
+                    }
+                    break;
+                case 'http://www.opengis.net/ont/geosparql#wktLiteral':
+                    // Point(-64.2 -36.62)  -- (longitude latitude)
+                    temp = /^Point\(([-0-9.]+) 
([-0-9.]+)\)$/.exec(value.value);
+                    if (temp) {
+                        return [parseFloat(temp[1]), parseFloat(temp[2])];
+                    }
+                    break;
+            }
+            break;
+        case 'uri':
+            // "http://www.wikidata.org/entity/Q12345";  ->  "Q12345"
+            temp = 
/^http:\/\/www\.wikidata\.org\/entity\/(Q[1-9][0-9]*)$/.exec(value.value);
+            if (temp) {
+                return temp[1];
+            }
+            break;
+    }
+    return ignoreUnknown ? undefined : value.value;
+}
 
-                       uri.protocol = VegaWrapper.removeColon( uri.protocol );
 
-                       return uri.toString();
-               },
-               languageCode: mw.config.get( 'wgUserLanguage' )
-       } );
-
-       /**
-        * Set up drawing canvas inside the given element and draw graph data
-        *
-        * @param {HTMLElement} element
-        * @param {Object|string} data graph spec
-        * @param {Function} [callback] function(error) called when drawing is 
done
-        */
-       mw.drawVegaGraph = function ( element, data, callback ) {
-               vg.parse.spec( data, function ( error, chart ) {
-                       if ( !error ) {
-                               chart( { el: element } ).update();
-                       }
-                       if ( callback ) {
-                               callback( error );
-                       }
-               } );
-       };
-
-       mw.hook( 'wikipage.content' ).add( function ( $content ) {
-               var specs = mw.config.get( 'wgGraphSpecs' );
-               if ( !specs ) {
-                       return;
-               }
-               $content.find( '.mw-graph.mw-graph-always' ).each( function () {
-                       var graphId = $( this ).data( 'graph-id' );
-                       if ( !specs.hasOwnProperty( graphId ) ) {
-                               mw.log.warn( graphId );
-                       } else {
-                               mw.drawVegaGraph( this, specs[ graphId ], 
function ( error ) {
-                                       if ( error ) {
-                                               mw.log.warn( error );
-                                       }
-                               } );
-                       }
-               } );
-       } );
-
-}( jQuery, mediaWiki, vg ) );
-
-},{"graph-shared":3}]},{},[4]);
+},{}]},{},[1]);

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: If173c1fdceea7c44b1cb441ca809e83a24c695cb
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Graph
Gerrit-Branch: master
Gerrit-Owner: Yurik <yu...@wikimedia.org>

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

Reply via email to