jenkins-bot has submitted this change and it was merged.

Change subject: Resolve protocol-relative license URLs before passing for 
external handling
......................................................................


Resolve protocol-relative license URLs before passing for external handling

A file's license URL field will sometimes contain a protocol-relative
URL pointing to an on-wiki File: page describing the terms of our use,
particularly in the case of copyrighted media presented under terms of
fair use.

This adds a call to NetworkUtils.resolveProtocolRelativeUrl before
passing them to the system so that it knows how to handle them.

Also refactored the external link handler in GalleryActivity to use
NetworkUtils.resolveProtocolRelativeUrl rather than repeating ourselves.

Bug: T110946
Change-Id: Icfe96b39ddd7e80a37d31626e03949e064fe1f0c
---
M app/src/main/java/org/wikipedia/page/gallery/GalleryActivity.java
M app/src/main/java/org/wikipedia/util/NetworkUtils.java
2 files changed, 6 insertions(+), 14 deletions(-)

Approvals:
  Sniedzielski: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/app/src/main/java/org/wikipedia/page/gallery/GalleryActivity.java 
b/app/src/main/java/org/wikipedia/page/gallery/GalleryActivity.java
index a4da2bd..5cba842 100644
--- a/app/src/main/java/org/wikipedia/page/gallery/GalleryActivity.java
+++ b/app/src/main/java/org/wikipedia/page/gallery/GalleryActivity.java
@@ -44,6 +44,8 @@
 import java.util.HashMap;
 import java.util.Map;
 
+import static org.wikipedia.util.NetworkUtils.resolveProtocolRelativeUrl;
+
 public class GalleryActivity extends ThemedActionBarActivity {
     private static final String TAG = "GalleryActivity";
     public static final int ACTIVITY_RESULT_FILEPAGE_SELECT = 1;
@@ -130,7 +132,7 @@
             public void onClick(View v) {
                 String licenseUrl = (String) v.getTag();
                 if (!TextUtils.isEmpty(licenseUrl)) {
-                    Utils.handleExternalLink(GalleryActivity.this, 
Uri.parse(licenseUrl));
+                    Utils.handleExternalLink(GalleryActivity.this, 
Uri.parse(resolveProtocolRelativeUrl(licenseUrl)));
                 }
             }
         });
@@ -321,11 +323,8 @@
             new LinkMovementMethodExt(new LinkMovementMethodExt.UrlHandler() {
         @Override
         public void onUrlClick(String url) {
-            if (url.startsWith("//")) {
-                // That's a protocol specific link! Make it https!
-                url = "https:" + url;
-            }
-            Log.d(TAG, "Link clicked was " + url);
+            Log.v(TAG, "Link clicked was " + url);
+            url = resolveProtocolRelativeUrl(url);
             Site site = app.getPrimarySite();
             if (url.startsWith("/wiki/")) {
                 PageTitle title = site.titleForInternalLink(url);
diff --git a/app/src/main/java/org/wikipedia/util/NetworkUtils.java 
b/app/src/main/java/org/wikipedia/util/NetworkUtils.java
index f363f96..cde2543 100644
--- a/app/src/main/java/org/wikipedia/util/NetworkUtils.java
+++ b/app/src/main/java/org/wikipedia/util/NetworkUtils.java
@@ -67,14 +67,7 @@
      * @return A fully qualified, protocol specified URL
      */
     public static String resolveProtocolRelativeUrl(String url) {
-        String fullUrl;
-        if (url.startsWith("//")) {
-            // That's a protocol specific link! Make it https!
-            fullUrl = WikipediaApp.getInstance().getNetworkProtocol() + ":" + 
url;
-        } else {
-            fullUrl = url;
-        }
-        return fullUrl;
+        return (url.startsWith("//") ? 
WikipediaApp.getInstance().getNetworkProtocol() + ":" + url : url);
     }
 
     /**

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Icfe96b39ddd7e80a37d31626e03949e064fe1f0c
Gerrit-PatchSet: 1
Gerrit-Project: apps/android/wikipedia
Gerrit-Branch: master
Gerrit-Owner: Mholloway <[email protected]>
Gerrit-Reviewer: BearND <[email protected]>
Gerrit-Reviewer: Brion VIBBER <[email protected]>
Gerrit-Reviewer: Dbrant <[email protected]>
Gerrit-Reviewer: Niedzielski <[email protected]>
Gerrit-Reviewer: Sniedzielski <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to