BearND has submitted this change and it was merged.

Change subject: Display message about protection status when editing
......................................................................


Display message about protection status when editing

Change-Id: I7b361ae5536a205e45256d488b547e7b96930559
---
M wikipedia-it/src/main/java/org/wikipedia/test/PageTests.java
M wikipedia-it/src/main/java/org/wikipedia/test/ParcelableTest.java
M wikipedia/res/values-qq/strings.xml
M wikipedia/res/values/strings.xml
M wikipedia/src/main/java/org/wikipedia/Utils.java
M wikipedia/src/main/java/org/wikipedia/editing/EditHandler.java
M wikipedia/src/main/java/org/wikipedia/editing/EditSectionActivity.java
M wikipedia/src/main/java/org/wikipedia/page/Page.java
M wikipedia/src/main/java/org/wikipedia/page/PageProperties.java
M wikipedia/src/main/java/org/wikipedia/page/PageViewFragment.java
10 files changed, 96 insertions(+), 14 deletions(-)

Approvals:
  BearND: Verified; Looks good to me, approved



diff --git a/wikipedia-it/src/main/java/org/wikipedia/test/PageTests.java 
b/wikipedia-it/src/main/java/org/wikipedia/test/PageTests.java
index 8c1931e..a90e033 100644
--- a/wikipedia-it/src/main/java/org/wikipedia/test/PageTests.java
+++ b/wikipedia-it/src/main/java/org/wikipedia/test/PageTests.java
@@ -16,7 +16,7 @@
             sections.add(new Section(i, 1, "Something " + i, "Something_" + i, 
"Content Something" + i));
         }
         PageTitle title = new PageTitle(null, "Test", new 
Site("en.wikipedia.org"));
-        PageProperties props = new PageProperties("2001-02-03T04:00:00Z", 
"null");
+        PageProperties props = new PageProperties("2001-02-03T04:00:00Z", 
"null", null);
         Page page = new Page(title, sections, props);
         assertEquals(page, new Page(page.toJSON()));
     }
diff --git a/wikipedia-it/src/main/java/org/wikipedia/test/ParcelableTest.java 
b/wikipedia-it/src/main/java/org/wikipedia/test/ParcelableTest.java
index 099a4ea..8b95292 100644
--- a/wikipedia-it/src/main/java/org/wikipedia/test/ParcelableTest.java
+++ b/wikipedia-it/src/main/java/org/wikipedia/test/ParcelableTest.java
@@ -44,7 +44,7 @@
             sections.add(new Section(i, 1, "Something " + i, "Something_" + i, 
"Content Something" + i));
         }
         PageTitle title = new PageTitle(null, "Test", new 
Site("en.wikipedia.org"));
-        PageProperties props = new PageProperties("", "Something");
+        PageProperties props = new PageProperties("", "Something", 
"autoconfirmed");
         Page page = new Page(title, sections, props);
         parcelAndTestObjects(page);
     }
diff --git a/wikipedia/res/values-qq/strings.xml 
b/wikipedia/res/values-qq/strings.xml
index ef958b1..829e718 100644
--- a/wikipedia/res/values-qq/strings.xml
+++ b/wikipedia/res/values-qq/strings.xml
@@ -130,4 +130,7 @@
   <string name="history_search_list_hint">Hint for textbox that searches list 
of items in browsing history as user typesj</string>
   <string name="history_search_empty_message">Message shown when no history 
itmes were found that match the user\'s query. %s is replaced with the query 
string.</string>
   <string name="error_can_not_process_link">Message shown in a toast when the 
app encounters a link it can not process.</string>
+  <string name="page_protected_autoconfirmed">Message shown to users when 
editing a semi-protected page</string>
+  <string name="page_protected_sysop">Message shown to users when editing a 
fully protected page</string>
+  <string name="page_protected_other">Message shown to users when editing a 
page that is protected with a custom level of protection. %s refers to the name 
of the protection level. Examples include \'templateeditor\' on enwiki.</string>
 </resources>
diff --git a/wikipedia/res/values/strings.xml b/wikipedia/res/values/strings.xml
index 3961236..da34fa5 100644
--- a/wikipedia/res/values/strings.xml
+++ b/wikipedia/res/values/strings.xml
@@ -137,4 +137,7 @@
     <string name="history_search_list_hint">Search</string>
     <string name="history_search_empty_message">No pages found matching 
\'%s\'</string>
     <string name="error_can_not_process_link">Could not display this 
link</string>
+    <string name="page_protected_autoconfirmed">This page has been 
semi-protected.</string>
+    <string name="page_protected_sysop">This page has been fully 
protected.</string>
+    <string name="page_protected_other">This page has been protected to the 
following levels: %s</string>
 </resources>
diff --git a/wikipedia/src/main/java/org/wikipedia/Utils.java 
b/wikipedia/src/main/java/org/wikipedia/Utils.java
index a5a72a3..c223310 100644
--- a/wikipedia/src/main/java/org/wikipedia/Utils.java
+++ b/wikipedia/src/main/java/org/wikipedia/Utils.java
@@ -421,4 +421,21 @@
 
         return sdf.format(date);
     }
+
+    /**
+     * Convert a JSONArray object to a String Array.
+     *
+     * @param array A JSONArray containing only Strings
+     * @return A String[] with all the items in the JSONArray
+     */
+    public static String[] JSONArrayToStringArray(JSONArray array) {
+        if (array == null) {
+            return null;
+        }
+        String[] stringArray = new String[array.length()];
+        for (int i = 0; i < array.length(); i++) {
+            stringArray[i] = array.optString(i);
+        }
+        return stringArray;
+    }
 }
diff --git a/wikipedia/src/main/java/org/wikipedia/editing/EditHandler.java 
b/wikipedia/src/main/java/org/wikipedia/editing/EditHandler.java
index 7069054..a63df4a 100644
--- a/wikipedia/src/main/java/org/wikipedia/editing/EditHandler.java
+++ b/wikipedia/src/main/java/org/wikipedia/editing/EditHandler.java
@@ -34,6 +34,7 @@
             intent.setAction(EditSectionActivity.ACTION_EDIT_SECTION);
             intent.putExtra(EditSectionActivity.EXTRA_SECTION, section);
             intent.putExtra(EditSectionActivity.EXTRA_TITLE, 
currentPage.getTitle());
+            intent.putExtra(EditSectionActivity.EXTRA_PAGE_PROPS, 
currentPage.getPageProperties());
             fragment.startActivityForResult(intent, REQUEST_EDIT_SECTION);
         }
     }
diff --git 
a/wikipedia/src/main/java/org/wikipedia/editing/EditSectionActivity.java 
b/wikipedia/src/main/java/org/wikipedia/editing/EditSectionActivity.java
index 959bd4e..518bdd8 100644
--- a/wikipedia/src/main/java/org/wikipedia/editing/EditSectionActivity.java
+++ b/wikipedia/src/main/java/org/wikipedia/editing/EditSectionActivity.java
@@ -4,6 +4,7 @@
 import android.content.*;
 import android.os.*;
 import android.support.v7.app.*;
+import android.text.TextUtils;
 import android.util.*;
 import android.view.*;
 import android.webkit.*;
@@ -26,11 +27,13 @@
     public static final String ACTION_EDIT_SECTION = 
"org.wikipedia.edit_section";
     public static final String EXTRA_TITLE = 
"org.wikipedia.edit_section.title";
     public static final String EXTRA_SECTION = 
"org.wikipedia.edit_section.section";
+    public static final String EXTRA_PAGE_PROPS = 
"org.wikipedia.edit_section.pageprops";
 
     private WikipediaApp app;
 
     private PageTitle title;
     private Section section;
+    private PageProperties pageProps;
 
     private String sectionWikitext;
 
@@ -72,6 +75,7 @@
 
         title = getIntent().getParcelableExtra(EXTRA_TITLE);
         section = getIntent().getParcelableExtra(EXTRA_SECTION);
+        pageProps = getIntent().getParcelableExtra(EXTRA_PAGE_PROPS);
 
         progressDialog = new ProgressDialog(this);
 
@@ -391,6 +395,20 @@
         sectionText.setText(sectionWikitext);
         ViewAnimations.crossFade(sectionProgress, sectionContainer);
         supportInvalidateOptionsMenu();
+
+        if (pageProps != null && pageProps.getEditProtectionStatus() != null) {
+            String message;
+            if (pageProps.getEditProtectionStatus().equals("sysop")) {
+                message = getString(R.string.page_protected_sysop);
+            } else if 
(pageProps.getEditProtectionStatus().equals("autoconfirmed")) {
+                message = getString(R.string.page_protected_autoconfirmed);
+            } else {
+                message = getString(R.string.page_protected_other, 
pageProps.getEditProtectionStatus());
+            }
+            Crouton.makeText(this,
+                    message,
+                    Style.INFO).show();
+        }
     }
 
     @Override
diff --git a/wikipedia/src/main/java/org/wikipedia/page/Page.java 
b/wikipedia/src/main/java/org/wikipedia/page/Page.java
index 7192176..a9a216e 100644
--- a/wikipedia/src/main/java/org/wikipedia/page/Page.java
+++ b/wikipedia/src/main/java/org/wikipedia/page/Page.java
@@ -118,6 +118,6 @@
         for (int i = 0; i < sectionsJSON.length(); i++) {
             sections.add(new Section(sectionsJSON.optJSONObject(i)));
         }
-        pageProperties = new PageProperties(json.optJSONObject("properties"));
+        pageProperties = 
PageProperties.parseJSON(json.optJSONObject("properties"));
     }
 }
diff --git a/wikipedia/src/main/java/org/wikipedia/page/PageProperties.java 
b/wikipedia/src/main/java/org/wikipedia/page/PageProperties.java
index 76625f2..2e655d7 100644
--- a/wikipedia/src/main/java/org/wikipedia/page/PageProperties.java
+++ b/wikipedia/src/main/java/org/wikipedia/page/PageProperties.java
@@ -1,8 +1,10 @@
 package org.wikipedia.page;
 
 import android.os.*;
+import android.text.TextUtils;
 import android.util.*;
 import org.json.*;
+import org.wikipedia.Utils;
 
 import java.text.*;
 import java.util.*;
@@ -13,9 +15,17 @@
 public class PageProperties implements Parcelable {
     private final Date lastModified;
     private final String displayTitleText;
+    private final String editProtectionStatus;
     private SimpleDateFormat sdf;
 
-    public PageProperties(String lastModifiedText, String displayTitleText) {
+    /**
+     * Create a new PageProperties object.
+     *
+     * @param lastModifiedText Last modified date in ISO8601 format
+     * @param displayTitleText The title to be displayed for this page
+     * @param editProtectionStatus The edit protection status applied to this 
page
+     */
+    public PageProperties(String lastModifiedText, String displayTitleText, 
String editProtectionStatus) {
         lastModified = new Date();
         sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
         sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
@@ -25,6 +35,7 @@
             Log.d("PageProperties", "Failed to parse date: " + 
lastModifiedText);
         }
         this.displayTitleText = displayTitleText;
+        this.editProtectionStatus = editProtectionStatus;
     }
 
     public Date getLastModified() {
@@ -33,6 +44,10 @@
 
     public String getDisplayTitle() {
         return displayTitleText;
+    }
+
+    public String getEditProtectionStatus() {
+        return editProtectionStatus;
     }
 
     @Override
@@ -44,11 +59,13 @@
     public void writeToParcel(Parcel parcel, int flags) {
         parcel.writeLong(lastModified.getTime());
         parcel.writeString(displayTitleText);
+        parcel.writeString(editProtectionStatus);
     }
 
     private PageProperties(Parcel in) {
         lastModified = new Date(in.readLong());
         displayTitleText = in.readString();
+        editProtectionStatus = in.readString();
     }
 
     public static final Parcelable.Creator<PageProperties> CREATOR
@@ -74,22 +91,23 @@
         PageProperties that = (PageProperties) o;
 
         return lastModified.equals(that.lastModified)
-                && displayTitleText.equals(that.displayTitleText);
+                && displayTitleText.equals(that.displayTitleText)
+                && TextUtils.equals(editProtectionStatus, 
that.editProtectionStatus);
     }
 
     @Override
     public int hashCode() {
         int result = lastModified.hashCode();
         result = 31 * result + displayTitleText.hashCode();
+        if (editProtectionStatus != null) {
+            result = 63 * result + editProtectionStatus.hashCode();
+        }
         return result;
     }
 
     @Override
     public String toString() {
-        return "PageProperties{"
-                + "displayTitleText='" + displayTitleText + '\''
-                + ", lastModified=" + lastModified.getTime()
-                + '}';
+        return toJSON().toString();
     }
 
     public JSONObject toJSON() {
@@ -97,6 +115,15 @@
         try {
             json.put("lastmodified", sdf.format(getLastModified()));
             json.put("displaytitle", displayTitleText);
+            if (editProtectionStatus == null) {
+                json.put("protection", new JSONArray());
+            } else {
+                JSONObject protectionStatusObject = new JSONObject();
+                JSONArray editProtectionStatusArray = new JSONArray();
+                editProtectionStatusArray.put(editProtectionStatus);
+                protectionStatusObject.put("edit", editProtectionStatusArray);
+                json.put("protection", protectionStatusObject);
+            }
         } catch (JSONException e) {
             // Goddamn it Java
             throw new RuntimeException(e);
@@ -105,10 +132,23 @@
         return json;
     }
 
-    public PageProperties(JSONObject json) {
-        this(
+    /**
+     * Construct a PageProperties object from JSON returned either from 
mobileview or toJSON
+     *
+     * @param json JSON generated either by action=mobileview or by toJSON()
+     */
+    public static PageProperties parseJSON(JSONObject json) {
+        String editProtection = null;
+        // Mediawiki API is stupid!
+        if (!(json.opt("protection") instanceof JSONArray)
+                && json.optJSONObject("protection").has("edit")
+                ) {
+            editProtection = 
json.optJSONObject("protection").optJSONArray("edit").optString(0);
+        }
+        return new PageProperties(
                 json.optString("lastmodified"),
-                json.optString("displaytitle")
+                json.optString("displaytitle"),
+                editProtection
         );
     }
 }
diff --git a/wikipedia/src/main/java/org/wikipedia/page/PageViewFragment.java 
b/wikipedia/src/main/java/org/wikipedia/page/PageViewFragment.java
index 6a4cad7..b680f35 100644
--- a/wikipedia/src/main/java/org/wikipedia/page/PageViewFragment.java
+++ b/wikipedia/src/main/java/org/wikipedia/page/PageViewFragment.java
@@ -358,7 +358,7 @@
         @Override
         public RequestBuilder buildRequest(Api api) {
             RequestBuilder builder =  super.buildRequest(api);
-            builder.param("prop", builder.getParams().get("prop") + 
"|lastmodified|normalizedtitle|displaytitle");
+            builder.param("prop", builder.getParams().get("prop") + 
"|lastmodified|normalizedtitle|displaytitle|protection");
             return builder;
         }
 
@@ -368,7 +368,7 @@
         public List<Section> processResult(ApiResult result) throws Throwable {
             JSONObject mobileView = 
result.asObject().optJSONObject("mobileview");
             if (mobileView != null) {
-                pageProperties = new PageProperties(mobileView);
+                pageProperties = PageProperties.parseJSON(mobileView);
                 if (mobileView.has("redirected")) {
                     // Handle redirects properly.
                     title = new PageTitle(mobileView.optString("redirected"), 
title.getSite());

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I7b361ae5536a205e45256d488b547e7b96930559
Gerrit-PatchSet: 8
Gerrit-Project: apps/android/wikipedia
Gerrit-Branch: master
Gerrit-Owner: Yuvipanda <yuvipa...@gmail.com>
Gerrit-Reviewer: BearND <bsitzm...@wikimedia.org>
Gerrit-Reviewer: Brion VIBBER <br...@wikimedia.org>
Gerrit-Reviewer: Dbrant <dbr...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to