Yurik has uploaded a new change for review.
https://gerrit.wikimedia.org/r/281975
Change subject: Support wikitabular graph protocol
......................................................................
Support wikitabular graph protocol
Change-Id: I6eb35ea739f5827a14f85758748c313701734880
---
M lib/graph2.compiled.js
1 file changed, 31 insertions(+), 3 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Graph
refs/changes/75/281975/1
diff --git a/lib/graph2.compiled.js b/lib/graph2.compiled.js
index ae1292c..9044848 100644
--- a/lib/graph2.compiled.js
+++ b/lib/graph2.compiled.js
@@ -256,6 +256,8 @@
break;
case 'wikiraw':
+ case 'wikitabular':
+ case 'wikijson':
// 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.
@@ -263,7 +265,13 @@
// Query value must be a valid MediaWiki title string, but we only
ensure
// there is no pipe symbol, the rest is handlered by the api.
if (!/^\/[^|]+$/.test(urlParts.pathname)) {
- throw new Error('wikiraw: invalid title');
+ throw new Error(urlParts.protocol + ': invalid title');
+ }
+ opt.isApiCall = true;
+ opt.extractApiContent = true;
+ if (urlParts.protocol !== 'wikiraw') {
+ opt.parseJson = true;
+ opt.parseTabular = urlParts.protocol === 'wikitabular';
}
urlParts.query = {
format: 'json',
@@ -275,8 +283,6 @@
};
urlParts.pathname = '/w/api.php';
urlParts.protocol = sanitizedHost.protocol;
- opt.isApiCall = true;
- opt.extractApiContent = true;
break;
case 'wikirawupload':
@@ -347,6 +353,28 @@
if (opt.extractApiContent) {
try {
data = json.query.pages[0].revisions[0].content;
+ if (opt.parseJson) {
+ data = JSON.parse(data);
+ if (json.error) {
+ error = new Error('Page does not contain valid
json: ' + JSON.stringify(json.error));
+ data = undefined;
+ } else if (opt.parseTabular) {
+ if (Array.isArray(data.rows)) {
+ var result = [];
+ data.rows.forEach(function(v){
+ var row = {};
+ for(var i=0; i<data.headers.length; i++) {
+ row[data.headers[i]] = v[i];
+ }
+ result.push(row);
+ });
+ data = result;
+ } else {
+ error = new Error('page is not a valid dsv
data');
+ data = undefined;
+ }
+ }
+ }
} catch (e) {
data = undefined;
error = new Error('Page content not available ' + opt.url);
--
To view, visit https://gerrit.wikimedia.org/r/281975
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I6eb35ea739f5827a14f85758748c313701734880
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