Niedzielski has uploaded a new change for review. https://gerrit.wikimedia.org/r/274045
Change subject: Add support for no language wikis ...................................................................... Add support for no language wikis • Don't assume nonempty language code. • Add empty language for development to the end of the language list. • Fix comparison of a null and an empty string in StringUtil.equals. Change-Id: I1ba833d8ae5b049233683c3bf3e10ebae9304d74 --- M app/src/main/java/org/wikipedia/Site.java M app/src/main/java/org/wikipedia/util/StringUtil.java M app/src/main/res/values/languages_list.xml M scripts/generate_wiki_languages.py 4 files changed, 17 insertions(+), 15 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/apps/android/wikipedia refs/changes/45/274045/1 diff --git a/app/src/main/java/org/wikipedia/Site.java b/app/src/main/java/org/wikipedia/Site.java index 70b7e3e..89f068e 100644 --- a/app/src/main/java/org/wikipedia/Site.java +++ b/app/src/main/java/org/wikipedia/Site.java @@ -18,7 +18,6 @@ * The base URL and Wikipedia language code for a wiki site. Examples: * * <ul> - * <lh>Name: host / language code</lh> * <lh>Name: scheme / host / language code</lh> * <li>English Wikipedia: HTTPS / en.wikipedia.org / en</li> * <li>Chinese Wikipedia: HTTPS / zh.wikipedia.org / zh-hans or zh-hant</li> @@ -27,6 +26,7 @@ * <li>Võro Wikipedia: HTTPS / fiu-vro.wikipedia.org / fiu-vro</li> * <li>Simple English Wikipedia: HTTPS / simple.wikipedia.org / simple</li> * <li>Simple English Wikipedia (beta cluster mirror): HTTP / simple.wikipedia.beta.wmflabs.org / simple</li> + * <li>Development: HTTP / 192.168.1.11:8080 / (none)</li> * </ul> */ public class Site implements Parcelable { @@ -42,26 +42,26 @@ @SerializedName("domain") @NonNull private final Uri uri; - @NonNull private final String languageCode; + @NonNull private final String languageCode; // possibly empty /** * @return True if the host is supported by the app. */ public static boolean supportedHost(@NonNull String host) { - // TODO: this host assumption won't work for custom domains like meta, the Wikipedia beta - // cluster, and Vagrant instances. + // endswith? return host.matches("[a-z\\-]+\\.(m\\.)?" + Prefs.getMediaWikiBaseUri().getHost()); } public static Site forLanguageCode(@NonNull String languageCode) { - // TODO: this host assumption won't work for custom domains like meta, the Wikipedia beta - // cluster, and Vagrant instances. Uri uri = Prefs.getMediaWikiBaseUri(); boolean secureSchema = uri.getScheme().equals("https"); - return new Site(secureSchema, languageCodeToSubdomain(languageCode) + "." + uri.getHost(), + return new Site(secureSchema, (languageCode.isEmpty() ? "" : (languageCodeToSubdomain(languageCode) + ".")) + uri.getHost(), languageCode); } + // TODO: remove method. + // Not recommended. This method cannot resolve multi-dialect wikis like Simplified and + // Traditional Chinese. public Site(@NonNull String host) { this(host, hostToLanguageCode(host)); } @@ -73,6 +73,7 @@ public Site(boolean secureScheme, @NonNull String host, @NonNull String languageCode) { this(new Uri.Builder() .scheme(secureScheme ? "https" : "http") + // TODO: verify no one is passing in mobile hosts and remove hostToDesktop(). .encodedAuthority(hostToDesktop(host)) .build(), languageCode); } @@ -122,11 +123,13 @@ * <li>Võro Wikipedia: fiu-vro.m.wikipedia.org</li> * <li>Simple English Wikipedia: simple.m.wikipedia.org</li> * <li>Simple English Wikipedia (beta cluster mirror): simple.m.wikipedia.beta.wmflabs.org</li> + * <li>Development: m.192.168.1.11:8080</li> * </ul> */ @NonNull public String mobileHost() { - return hostToMobile(host()); + String subdomain = languageCodeToSubdomain(languageCode); + return host().replaceFirst("^" + subdomain + "\\.?", "$0m."); } /** @@ -248,11 +251,6 @@ @NonNull private static String hostToDesktop(@NonNull String host) { return host.replaceFirst("\\.m\\.", "."); - } - - @NonNull - private String hostToMobile(@NonNull String host) { - return host.replaceFirst("\\.", ".m."); } private Site(@NonNull Uri uri, @NonNull String languageCode) { diff --git a/app/src/main/java/org/wikipedia/util/StringUtil.java b/app/src/main/java/org/wikipedia/util/StringUtil.java index 53ef0e9..bdcaf87 100644 --- a/app/src/main/java/org/wikipedia/util/StringUtil.java +++ b/app/src/main/java/org/wikipedia/util/StringUtil.java @@ -46,8 +46,8 @@ return value == null ? defaultValue : value; } - public static boolean equals(CharSequence lhs, CharSequence rhs) { - return emptyIfNull(lhs).equals(emptyIfNull(rhs)); + public static boolean equals(@Nullable CharSequence lhs, @Nullable CharSequence rhs) { + return lhs == rhs || lhs != null && lhs.equals(rhs); } @NonNull diff --git a/app/src/main/res/values/languages_list.xml b/app/src/main/res/values/languages_list.xml index d0b1897..90c339c 100644 --- a/app/src/main/res/values/languages_list.xml +++ b/app/src/main/res/values/languages_list.xml @@ -293,6 +293,7 @@ <item>hz</item> <item>kr</item> <item>test</item> + <item></item> </string-array> <string-array name="preference_language_local_names"> <item>English</item> @@ -587,6 +588,7 @@ <item>Otsiherero</item> <item>Kanuri</item> <item>Test</item> + <item>None (development)</item> </string-array> <string-array name="preference_language_canonical_names"> <item>English</item> @@ -881,5 +883,6 @@ <item>Herero</item> <item>Kanuri</item> <item>Test</item> + <item>None (development)</item> </string-array> </resources> diff --git a/scripts/generate_wiki_languages.py b/scripts/generate_wiki_languages.py index 8a6c044..425fd38 100755 --- a/scripts/generate_wiki_languages.py +++ b/scripts/generate_wiki_languages.py @@ -39,6 +39,7 @@ eng_name=row[1].replace("'", "\\'")) add_lang(key='test', local_name='Test', eng_name='Test') +add_lang(key='', local_name='None', eng_name='None (development)') # Generate the XML, for Android NAMESPACE = 'http://schemas.android.com/tools' -- To view, visit https://gerrit.wikimedia.org/r/274045 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I1ba833d8ae5b049233683c3bf3e10ebae9304d74 Gerrit-PatchSet: 1 Gerrit-Project: apps/android/wikipedia Gerrit-Branch: master Gerrit-Owner: Niedzielski <sniedziel...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits