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

Change subject: Avoid IP edits when user is logged in
......................................................................


Avoid IP edits when user is logged in

Specify assert=user when submitting an edit.
This will ensure that the edit is saved under the user's account, instead
of an IP address, as has been reported by several users.

Bug: T75086
Change-Id: Ica13fa1af4865c325d4566e0c7936374e8e4e61f
---
M wikipedia/res/values-qq/strings.xml
M wikipedia/res/values/strings.xml
M wikipedia/src/main/java/org/wikipedia/editing/DoEditTask.java
M wikipedia/src/main/java/org/wikipedia/editing/EditSectionActivity.java
4 files changed, 22 insertions(+), 4 deletions(-)

Approvals:
  BearND: Looks good to me, approved
  Deskana: Looks good to me, but someone else must approve
  jenkins-bot: Verified



diff --git a/wikipedia/res/values-qq/strings.xml 
b/wikipedia/res/values-qq/strings.xml
index 2d47183..eec2e9f 100644
--- a/wikipedia/res/values-qq/strings.xml
+++ b/wikipedia/res/values-qq/strings.xml
@@ -366,4 +366,5 @@
   <string name="gallery_fair_use_license">Short name of the Fair Use license 
when applied to media that do not have attribution information.
 {{Identical|Fair use}}</string>
   <string name="gallery_uploader_unknown">Text displayed when the uploader of 
a media item is not known.</string>
+  <string name="edit_save_unknown_error">Error message shown when there was an 
unknown error while saving the edit made by the user. The \"%s\" symbol is 
replaced with the error code returned by the server.</string>
 </resources>
diff --git a/wikipedia/res/values/strings.xml b/wikipedia/res/values/strings.xml
index f9b7278..1fd3e79 100644
--- a/wikipedia/res/values/strings.xml
+++ b/wikipedia/res/values/strings.xml
@@ -277,4 +277,5 @@
     <string name="captcha_image">Captcha image</string>
     <string name="gallery_fair_use_license">Fair use</string>
     <string name="gallery_uploader_unknown">Uploader unknown</string>
+    <string name="edit_save_unknown_error">Could not save your edit: 
%s</string>
 </resources>
diff --git a/wikipedia/src/main/java/org/wikipedia/editing/DoEditTask.java 
b/wikipedia/src/main/java/org/wikipedia/editing/DoEditTask.java
index a96a9f1..df6e841 100644
--- a/wikipedia/src/main/java/org/wikipedia/editing/DoEditTask.java
+++ b/wikipedia/src/main/java/org/wikipedia/editing/DoEditTask.java
@@ -16,8 +16,10 @@
     private final int sectionID;
     private final String summary;
     private final String editToken;
+    private final boolean loggedIn;
 
-    public DoEditTask(Context context, PageTitle title, String 
sectionWikitext, int sectionID, String editToken, String summary) {
+    public DoEditTask(Context context, PageTitle title, String 
sectionWikitext, int sectionID,
+                      String editToken, String summary, boolean loggedIn) {
         super(
                 SINGLE_THREAD,
                 
((WikipediaApp)context.getApplicationContext()).getAPIForSite(title.getSite())
@@ -27,16 +29,24 @@
         this.sectionID = sectionID;
         this.editToken = editToken;
         this.summary = summary;
+        this.loggedIn = loggedIn;
     }
 
     @Override
     public RequestBuilder buildRequest(Api api) {
-        return api.action("edit")
+        RequestBuilder req = api.action("edit")
                 .param("title", title.getPrefixedText())
                 .param("section", String.valueOf(sectionID))
                 .param("text", sectionWikitext)
                 .param("token", editToken)
                 .param("summary", summary);
+        if (loggedIn) {
+            // if the app believes that the user is logged in, then make sure 
to send an "assert"
+            // parameter to the API, so that it will notify us if the user was 
actually logged
+            // out on another device, and we'll need to log back in behind the 
scenes.
+            req = req.param("assert", "user");
+        }
+        return req;
     }
 
     @Override
diff --git 
a/wikipedia/src/main/java/org/wikipedia/editing/EditSectionActivity.java 
b/wikipedia/src/main/java/org/wikipedia/editing/EditSectionActivity.java
index ddd9e07..544f08b 100644
--- a/wikipedia/src/main/java/org/wikipedia/editing/EditSectionActivity.java
+++ b/wikipedia/src/main/java/org/wikipedia/editing/EditSectionActivity.java
@@ -249,7 +249,8 @@
                 String summaryText = TextUtils.isEmpty(sectionHeading) ? "" : 
("/* " + sectionHeading + " */ ");
                 summaryText += editPreviewFragment.getSummary();
 
-                new DoEditTask(EditSectionActivity.this, title, 
sectionText.getText().toString(), sectionID, token, summaryText) {
+                new DoEditTask(EditSectionActivity.this, title, 
sectionText.getText().toString(),
+                        sectionID, token, summaryText, 
app.getUserInfoStorage().isLoggedIn()) {
                     @Override
                     public void onBeforeExecute() {
                         if (!isFinishing()) {
@@ -362,7 +363,8 @@
     }
 
     private void handleEditingException(EditingException ee) {
-        if (app.getUserInfoStorage().isLoggedIn() && 
ee.getCode().equals("badtoken")) {
+        if (app.getUserInfoStorage().isLoggedIn() && 
(ee.getCode().equals("badtoken")
+                || ee.getCode().equals("assertuserfailed"))) {
             // looks like our session expired.
             app.getEditTokenStorage().clearAllTokens();
             app.getCookieManager().clearAllCookies();
@@ -415,6 +417,10 @@
                 });
             }
             builder.show();
+        } else {
+            // an unknown error occurred, so just dismiss the progress dialog 
and show a message.
+            progressDialog.dismiss();
+            Crouton.makeText(this, 
String.format(getString(R.string.edit_save_unknown_error), ee.getCode()), 
Style.ALERT).show();
         }
     }
 

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Ica13fa1af4865c325d4566e0c7936374e8e4e61f
Gerrit-PatchSet: 5
Gerrit-Project: apps/android/wikipedia
Gerrit-Branch: master
Gerrit-Owner: Dbrant <[email protected]>
Gerrit-Reviewer: BearND <[email protected]>
Gerrit-Reviewer: Brion VIBBER <[email protected]>
Gerrit-Reviewer: Deskana <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to