Yurik has uploaded a new change for review.
https://gerrit.wikimedia.org/r/267016
Change subject: (WIP) migrating to shared protocol lib
......................................................................
(WIP) migrating to shared protocol lib
Change-Id: If17019f119a97eb45ab0acfd3a19819da34fe496
---
M extension.json
M includes/DataModule.php
M modules/graph1.js
M modules/graph2.js
M package.json
5 files changed, 31 insertions(+), 125 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Graph
refs/changes/16/267016/1
diff --git a/extension.json b/extension.json
index 52ef7fc..e8880c4 100644
--- a/extension.json
+++ b/extension.json
@@ -75,7 +75,7 @@
"lib/d3.js",
"lib/topojson.js",
"lib/vega2/vega.js",
- "modules/graph2.js"
+ "modules/graph2.compiled.js"
],
"dependencies": [
"ext.graph.data",
@@ -128,7 +128,8 @@
"ext.graph.visualEditor"
],
"config": {
- "GraphDataDomains": [],
+ "GraphHttpDomains": [],
+ "GraphHttpsDomains": [],
"GraphDefaultVegaVer": 1,
"GraphEnableGZip": false,
"GraphIsTrusted": false,
diff --git a/includes/DataModule.php b/includes/DataModule.php
index a36f913..f48e38b 100644
--- a/includes/DataModule.php
+++ b/includes/DataModule.php
@@ -19,7 +19,8 @@
public function getScript( ResourceLoaderContext $context ) {
$config = $context->getResourceLoader()->getConfig();
return ResourceLoader::makeConfigSetScript( array(
- 'wgGraphDataDomains' => $config->get(
'GraphDataDomains' ),
+ 'wgGraphHttpDomains' => $config->get(
'GraphHttpDomains' ),
+ 'wgGraphHttpsDomains' => $config->get(
'GraphHttpsDomains' ),
'wgGraphIsTrusted' => $config->get( 'GraphIsTrusted' ),
) );
}
diff --git a/modules/graph1.js b/modules/graph1.js
index 3a9f425..6728449 100644
--- a/modules/graph1.js
+++ b/modules/graph1.js
@@ -7,7 +7,7 @@
}
if ( originalSanitize === false ) {
// Make sure we only initialize graphs once
- vg.config.domainWhiteList = mw.config.get(
'wgGraphDataDomains' );
+ vg.config.domainWhiteList = [];
if ( !mw.config.get( 'wgGraphIsTrusted' ) ) {
vg.config.dataHeaders = { 'Treat-as-Untrusted':
1 };
}
diff --git a/modules/graph2.js b/modules/graph2.js
index cc89824..36b089c 100644
--- a/modules/graph2.js
+++ b/modules/graph2.js
@@ -1,130 +1,30 @@
( function ( $, mw ) {
- var originalSanitize, originalLoader;
- vg.config.load.domainWhiteList = mw.config.get( 'wgGraphDataDomains' );
+ 'use strict';
- vg.util.load.file = vg.util.load.http = function ( url, opt, callback )
{
- callback( new Error( 'Loading of ' + url + ' is not allowed' )
);
- };
+ var VegaWrapper = require('graph-shared');
- // Override loader so that we can do post-loader data processing
- originalLoader = vg.util.load.loader.bind( vg.util.load );
- vg.util.load.loader = function ( opt, callback ) {
- return originalLoader.call( vg.util.load, opt, function (
error, data ) {
- var json;
-
- if ( error ) {
- callback( error );
- return;
- }
- if ( opt.isApiCall ) {
- // This was an API call - check for errors
- json = JSON.parse( data ) ;
- if ( json.error ) {
- error = new Error( 'API error: ' +
JSON.stringify( json.error ) );
- data = undefined;
- } else {
- if ( json.warnings ) {
- mw.log( 'API warnings: ' +
JSON.stringify( json.warnings ) );
- }
- if ( opt.extractApiContent ) {
- try {
- data =
json.query.pages[ 0 ].revisions[ 0 ].content;
- } catch ( e ) {
- data = undefined;
- error = new Error(
'Page content not available ' + opt.url );
- }
- }
- }
- }
- callback( error, data );
- } );
- };
-
- // Override sanitizer to implement custom protocols and extra validation
- originalSanitize = vg.util.load.sanitizeUrl.bind( vg.util.load );
- vg.util.load.sanitizeUrl = function ( opt ) {
- var path, query,
- location = window.location,
- url = new mw.Uri( opt.url );
-
- switch ( url.protocol ) {
- case 'http':
- case 'https':
- // Will disable this as soon as all graphs have
been switched to custom protocols
- // unless mw.config.get( 'wgGraphIsTrusted' )
is true
- path = decodeURIComponent( url.path );
- query = url.query;
- break;
-
- case 'wikiapi':
- // wikiapi:///?action=query&list=allpages
- // Call to api.php - ignores the path
parameter, and only uses the query
- path = '/w/api.php';
- query = $.extend( url.query, { format: 'json',
formatversion: 'latest' } );
- opt.isApiCall = true;
- break;
-
- case 'wikirest':
- // wikirest:///api/rest_v1/page/...
- // Call to RESTbase api - requires the path to
start with "/api/"
- if ( !/^\/api\//.test( url.path ) ) {
- return false;
- }
- path = url.path;
- query = url.query;
- break;
-
- case 'wikiraw':
- // wikiraw:///MyPage/data
- // Get raw content of a wiki page, where the
path is the title
- // of the page with an additional leading '/'
which gets removed.
- // Uses mediawiki api, and extract the content
after the request
- path = '/w/api.php';
- query = {
- format: 'json',
- formatversion: 'latest',
- action: 'query',
- prop: 'revisions',
- rvprop: 'content',
- titles: url.path.substring( 1 )
- };
- opt.isApiCall = true;
- opt.extractApiContent = true;
- break;
-
- case 'wikirawupload':
- //
wikirawupload://upload.wikimedia.org/wikipedia/commons/3/3e/Einstein_1921_by_F_Schmutzer_-_restoration.jpg
- // Get an image for the graph, e.g. from commons
- // This tag specifies any content from the
uploads.* domain, without query params
- if ( !/^upload\./.test( url.host ) ) {
- return false;
- }
- path = url.path;
- break;
+ var parseUri = function ( opt ) {
+ var uri = new mw.Uri( opt.url );
+ // reduce confusion, only keep expected values
+ if (uri.port) {
+ uri.host += ':' + uri.port;
+ delete uri.port;
}
-
- if ( location.hostname.toLowerCase() === url.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.isApiCall ) {
- // All CORS api calls require origin parameter
- // It would be better to use location.origin, but
apparently it's not universal yet
- query.origin = location.protocol + '//' + location.host;
- }
-
- opt.url = new mw.Uri( {
- host: url.host,
- port: url.port,
- path: path,
- query: query
- } ).toString();
-
- return originalSanitize.call( vg.util.load, opt );
+ return uri;
};
+
+ new VegaWrapper(
+ vg.util.load, true,
+ true, // mw.config.get( 'wgGraphIsTrusted' ), TODO: switch to
config-controlled value
+ mw.config.get( 'wgGraphHttpDomains' ),
+ mw.config.get( 'wgGraphHttpsDomains' ),
+ false,
+ function( tmp ) {
+ console.log( tmp );
+ }, $.extend, parseUri, function( uri ) {
+ return uri.toString();
+ });
/**
* Set up drawing canvas inside the given element and draw graph data
@@ -162,4 +62,5 @@
}
} );
} );
+
}( jQuery, mediaWiki ) );
diff --git a/package.json b/package.json
index 5b786ef..3a7dfab 100644
--- a/package.json
+++ b/package.json
@@ -4,10 +4,13 @@
"private": true,
"description": "Build tools for the Graph-MediaWiki extension.",
"scripts": {
+ "build-lib": "node_modules/.bin/browserify lib/mapbox-main.js -o
lib/mapbox-lib.js && cp -rv node_modules/mapbox.js/theme/* lib/ && rm
lib/images/render.sh",
"test": "grunt test"
},
"devDependencies": {
+ "graph-shared": "git+http://[email protected]/nyurik/graph-shared",
"vega": "^2.4.0",
+ "browserify": "^13.0.0",
"grunt": "0.4.5",
"grunt-cli": "0.1.13",
"grunt-contrib-csslint": "0.5.0",
--
To view, visit https://gerrit.wikimedia.org/r/267016
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: If17019f119a97eb45ab0acfd3a19819da34fe496
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Graph
Gerrit-Branch: master
Gerrit-Owner: Yurik <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits