Cscott has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/150438

Change subject: Handle protocol-relative URLs in attribution information.
......................................................................

Handle protocol-relative URLs in attribution information.

Change-Id: I8a1c678bd40f2d8d2403ed843f1f81f74249736b
---
M lib/attribution.js
1 file changed, 14 insertions(+), 2 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Collection/OfflineContentGenerator/bundler
 refs/changes/38/150438/1

diff --git a/lib/attribution.js b/lib/attribution.js
index 4108d46..ec76071 100644
--- a/lib/attribution.js
+++ b/lib/attribution.js
@@ -64,6 +64,17 @@
 };
 
 /**
+ * Convert a protocol-relative URL to an http:// URL.
+ */
+var protofy = function(url) {
+       if (url.indexOf('//') === 0) {
+               // protocol-relative URL; assume http
+               return 'http:' + url;
+       }
+       return url;
+}
+
+/**
  * Turn a string array into a wikitext string that can be run through
  * a parser to create a localized string that looks like "<a>, <b> and <c>"
  *
@@ -107,7 +118,7 @@
 
        var canonicalUrl = function(item) {
                // create a ?oldid= format URL.
-               return item.isVersionOf + '?oldid=' + item.revision;
+               return protofy(item.isVersionOf + '?oldid=' + item.revision);
        };
 
        // articles; then image attribution; then calling out to parsoid
@@ -184,7 +195,8 @@
                        var rights = siteinfos.map(function(siteinfo) {
                                var r = siteinfo.rightsinfo || {};
                                if (r.url) {
-                                       return '[' + encodeURI(r.url) + ' ' + 
mangle(r.text || '') + ']';
+                                       return '[' + encodeURI(protofy(r.url)) 
+ ' ' +
+                                               mangle(r.text || '') + ']';
                                } else {
                                        return mangle(r.text || '');
                                }

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I8a1c678bd40f2d8d2403ed843f1f81f74249736b
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Collection/OfflineContentGenerator/bundler
Gerrit-Branch: master
Gerrit-Owner: Cscott <[email protected]>

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

Reply via email to