Mholloway has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/330819 )
Change subject: Get wikibase item ID in MW API page lead requests
......................................................................
Get wikibase item ID in MW API page lead requests
RESTBase page lead responses already return the wikibase ID, if present.
This adds logic to do the same for MW API requests so that we can have
feature parity for the two loading methods.
This should complement (and not conflict with, at least in the current
iteration) Ie1b18879dfe634241ce09913959b5b53056f840e.
Depends on a change in MobileFrontend to do for empty pageprops result
sets what I20bc5a43c2f348925584b8473f95abb87c623974 did for empty
protection result sets, so we don't have to add complex and fragile logic
to conditionally handle empty arrays.
Bug: T154032
Change-Id: I11b37fa6f27adf64fd1f41e10d4127bdc0ad422d
Depends-On: I5dacdaf356bfb4d85a62a7e8972b5e6e14f22458
---
M app/src/main/java/org/wikipedia/page/PageProperties.java
M app/src/main/java/org/wikipedia/server/PageLeadProperties.java
M app/src/main/java/org/wikipedia/server/mwapi/MwPageLead.java
M app/src/main/java/org/wikipedia/server/mwapi/MwPageService.java
4 files changed, 39 insertions(+), 5 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/apps/android/wikipedia
refs/changes/19/330819/1
diff --git a/app/src/main/java/org/wikipedia/page/PageProperties.java
b/app/src/main/java/org/wikipedia/page/PageProperties.java
index 52e22fe..8130c44 100644
--- a/app/src/main/java/org/wikipedia/page/PageProperties.java
+++ b/app/src/main/java/org/wikipedia/page/PageProperties.java
@@ -42,6 +42,7 @@
private final String leadImageName;
@Nullable private final String titlePronunciationUrl;
@Nullable private final Location geo;
+ @Nullable private final String wikiBaseItem;
/**
* True if the user who first requested this page can edit this page
@@ -78,6 +79,7 @@
isMainPage = core.isMainPage();
isDisambiguationPage = core.isDisambiguation();
+ wikiBaseItem = core.getWikiBaseItem();
}
/**
@@ -123,6 +125,7 @@
isMainPage = json.has("mainpage");
isDisambiguationPage = json.has("disambiguation");
+ wikiBaseItem = json.optString("wikibase_item");
}
public int getPageId() {
@@ -188,6 +191,11 @@
return leadImageName;
}
+ @Nullable
+ public String getWikiBaseItem() {
+ return wikiBaseItem;
+ }
+
@Override
public int describeContents() {
return 0;
@@ -209,6 +217,7 @@
parcel.writeInt(isDisambiguationPage ? 1 : 0);
parcel.writeString(leadImageUrl);
parcel.writeString(leadImageName);
+ parcel.writeString(wikiBaseItem);
}
private PageProperties(Parcel in) {
@@ -226,6 +235,7 @@
isDisambiguationPage = in.readInt() == 1;
leadImageUrl = in.readString();
leadImageName = in.readString();
+ wikiBaseItem = in.readString();
}
public static final Parcelable.Creator<PageProperties> CREATOR
@@ -265,7 +275,8 @@
&& isDisambiguationPage == that.isDisambiguationPage
&& TextUtils.equals(editProtectionStatus,
that.editProtectionStatus)
&& TextUtils.equals(leadImageUrl, that.leadImageUrl)
- && TextUtils.equals(leadImageName, that.leadImageName);
+ && TextUtils.equals(leadImageName, that.leadImageName)
+ && TextUtils.equals(wikiBaseItem, that.wikiBaseItem);
}
@Override
@@ -280,6 +291,7 @@
result = 31 * result + (isDisambiguationPage ? 1 : 0);
result = 31 * result + (leadImageUrl != null ? leadImageUrl.hashCode()
: 0);
result = 31 * result + (leadImageName != null ?
leadImageName.hashCode() : 0);
+ result = 31 * result + (wikiBaseItem != null ? wikiBaseItem.hashCode()
: 0);
result = 31 * result + (canEdit ? 1 : 0);
result = 31 * result + pageId;
result = 31 * result + namespace.code();
@@ -302,6 +314,7 @@
json.put("displaytitle", displayTitleText);
json.put(JSON_NAME_TITLE_PRONUNCIATION_URL, titlePronunciationUrl);
json.put(JSON_NAME_GEO, GeoMarshaller.marshal(geo));
+ json.put("wikibase_item", wikiBaseItem);
if (editProtectionStatus == null) {
json.put("protection", new JSONArray());
} else {
diff --git a/app/src/main/java/org/wikipedia/server/PageLeadProperties.java
b/app/src/main/java/org/wikipedia/server/PageLeadProperties.java
index 2d4e119..c24ef5f 100644
--- a/app/src/main/java/org/wikipedia/server/PageLeadProperties.java
+++ b/app/src/main/java/org/wikipedia/server/PageLeadProperties.java
@@ -43,6 +43,9 @@
String getNormalizedTitle();
@Nullable
+ String getWikiBaseItem();
+
+ @Nullable
String getDescription();
/**
diff --git a/app/src/main/java/org/wikipedia/server/mwapi/MwPageLead.java
b/app/src/main/java/org/wikipedia/server/mwapi/MwPageLead.java
index b16e2cd..4c3c615 100644
--- a/app/src/main/java/org/wikipedia/server/mwapi/MwPageLead.java
+++ b/app/src/main/java/org/wikipedia/server/mwapi/MwPageLead.java
@@ -5,6 +5,8 @@
import android.support.annotation.Nullable;
import android.support.annotation.VisibleForTesting;
+import com.google.gson.annotations.SerializedName;
+
import org.wikipedia.dataclient.WikiSite;
import org.wikipedia.page.Namespace;
import org.wikipedia.page.Page;
@@ -114,6 +116,7 @@
@SuppressWarnings("unused") @Nullable private Thumb thumb;
@SuppressWarnings("unused") @Nullable private Protection protection;
@SuppressWarnings("unused") @Nullable private List<Section> sections;
+ @SuppressWarnings("unused") @Nullable private PageProps pageprops;
/** Converter */
public PageProperties toPageProperties(@NonNull WikiSite wiki) {
@@ -195,6 +198,12 @@
@Override
@Nullable
+ public String getWikiBaseItem() {
+ return pageprops != null && pageprops.getWikiBaseItem() != null ?
pageprops.getWikiBaseItem() : null;
+ }
+
+ @Override
+ @Nullable
public String getFirstAllowedEditorRole() {
return protection != null ? protection.getFirstAllowedEditorRole()
: null;
}
@@ -243,4 +252,13 @@
return url;
}
}
+
+ static class PageProps {
+ @SuppressWarnings("unused") @SerializedName("wikibase_item") @Nullable
+ private String wikiBaseItem;
+
+ @Nullable String getWikiBaseItem() {
+ return wikiBaseItem;
+ }
+ }
}
diff --git a/app/src/main/java/org/wikipedia/server/mwapi/MwPageService.java
b/app/src/main/java/org/wikipedia/server/mwapi/MwPageService.java
index 33248f1..605eeb8 100644
--- a/app/src/main/java/org/wikipedia/server/mwapi/MwPageService.java
+++ b/app/src/main/java/org/wikipedia/server/mwapi/MwPageService.java
@@ -175,8 +175,8 @@
@GET("w/api.php?action=mobileview&format=json&formatversion=2&prop="
+
"text%7Csections%7Clanguagecount%7Cthumb%7Cimage%7Cid%7Cnamespace%7Crevision"
+
"%7Cdescription%7Clastmodified%7Cnormalizedtitle%7Cdisplaytitle%7Cprotection"
- +
"%7Ceditable&onlyrequestedsections=1§ions=0§ionprop=toclevel%7Cline"
- + "%7Canchor&noheadings=true")
+ +
"%7Ceditable%7Cpageprops&pageprops=wikibase_item&onlyrequestedsections=1"
+ +
"§ions=0§ionprop=toclevel%7Cline%7Canchor&noheadings=true")
Call<MwPageLead> pageLead(@Query("page") String title,
@Query("thumbsize") int leadImageThumbWidth,
@Query("noimages") Boolean noImages);
@@ -203,8 +203,8 @@
@GET("w/api.php?action=mobileview&format=json&formatversion=2&prop="
+
"text%7Csections%7Clanguagecount%7Cthumb%7Cimage%7Cid%7Crevision%7Cdescription"
+
"%7Clastmodified%7Cnormalizedtitle%7Cdisplaytitle%7Cprotection%7Ceditable"
- +
"&onlyrequestedsections=1§ions=all§ionprop=toclevel%7Cline%7Canchor"
- + "&noheadings=true")
+ +
"%7Cpageprops&pageprops=wikibase_item&onlyrequestedsections=1§ions=all"
+ + "§ionprop=toclevel%7Cline%7Canchor&noheadings=true")
Call<MwPageCombo> pageCombo(@Query("page") String title,
@Query("noimages") Boolean noImages);
}
--
To view, visit https://gerrit.wikimedia.org/r/330819
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I11b37fa6f27adf64fd1f41e10d4127bdc0ad422d
Gerrit-PatchSet: 1
Gerrit-Project: apps/android/wikipedia
Gerrit-Branch: master
Gerrit-Owner: Mholloway <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits