mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +01:00
Data client simplification / removal (#5507)
* Removed unused code from the data client module * Move remaining code out of the data-client and remove it
This commit is contained in:
parent
72a6fd2c90
commit
0c3085257d
337 changed files with 964 additions and 31321 deletions
|
|
@ -16,7 +16,6 @@ if (isRunningOnTravisAndIsNotPRBuild) {
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
|
||||||
implementation project(':wikimedia-data-client')
|
|
||||||
// Utils
|
// Utils
|
||||||
implementation 'in.yuvi:http.fluent:1.3'
|
implementation 'in.yuvi:http.fluent:1.3'
|
||||||
implementation 'com.google.code.gson:gson:2.8.5'
|
implementation 'com.google.code.gson:gson:2.8.5'
|
||||||
|
|
|
||||||
|
|
@ -59,7 +59,7 @@ import org.acra.annotation.AcraCore;
|
||||||
import org.acra.annotation.AcraDialog;
|
import org.acra.annotation.AcraDialog;
|
||||||
import org.acra.annotation.AcraMailSender;
|
import org.acra.annotation.AcraMailSender;
|
||||||
import org.acra.data.StringFormat;
|
import org.acra.data.StringFormat;
|
||||||
import org.wikipedia.language.AppLanguageLookUpTable;
|
import fr.free.nrw.commons.language.AppLanguageLookUpTable;
|
||||||
import timber.log.Timber;
|
import timber.log.Timber;
|
||||||
|
|
||||||
@AcraCore(
|
@AcraCore(
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,7 @@ package fr.free.nrw.commons
|
||||||
import android.os.Parcelable
|
import android.os.Parcelable
|
||||||
import fr.free.nrw.commons.location.LatLng
|
import fr.free.nrw.commons.location.LatLng
|
||||||
import kotlinx.android.parcel.Parcelize
|
import kotlinx.android.parcel.Parcelize
|
||||||
import org.wikipedia.dataclient.mwapi.MwQueryPage
|
import fr.free.nrw.commons.wikidata.model.page.PageTitle
|
||||||
import org.wikipedia.page.PageTitle
|
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
@Parcelize
|
@Parcelize
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,6 @@ import okhttp3.Response;
|
||||||
import okhttp3.ResponseBody;
|
import okhttp3.ResponseBody;
|
||||||
import okhttp3.logging.HttpLoggingInterceptor;
|
import okhttp3.logging.HttpLoggingInterceptor;
|
||||||
import okhttp3.logging.HttpLoggingInterceptor.Level;
|
import okhttp3.logging.HttpLoggingInterceptor.Level;
|
||||||
import org.wikipedia.dataclient.okhttp.HttpStatusException;
|
|
||||||
import timber.log.Timber;
|
import timber.log.Timber;
|
||||||
|
|
||||||
public final class OkHttpConnectionFactory {
|
public final class OkHttpConnectionFactory {
|
||||||
|
|
@ -110,4 +109,30 @@ public final class OkHttpConnectionFactory {
|
||||||
|
|
||||||
private OkHttpConnectionFactory() {
|
private OkHttpConnectionFactory() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class HttpStatusException extends IOException {
|
||||||
|
private final int code;
|
||||||
|
private final String url;
|
||||||
|
public HttpStatusException(@NonNull Response rsp) {
|
||||||
|
this.code = rsp.code();
|
||||||
|
this.url = rsp.request().url().uri().toString();
|
||||||
|
try {
|
||||||
|
if (rsp.body() != null && rsp.body().contentType() != null
|
||||||
|
&& rsp.body().contentType().toString().contains("json")) {
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
// Log?
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int code() {
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getMessage() {
|
||||||
|
String str = "Code: " + code + ", URL: " + url;
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,8 +20,8 @@ import androidx.core.content.ContextCompat;
|
||||||
import fr.free.nrw.commons.kvstore.JsonKvStore;
|
import fr.free.nrw.commons.kvstore.JsonKvStore;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import org.wikipedia.dataclient.WikiSite;
|
import fr.free.nrw.commons.wikidata.model.WikiSite;
|
||||||
import org.wikipedia.page.PageTitle;
|
import fr.free.nrw.commons.wikidata.model.page.PageTitle;
|
||||||
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
package fr.free.nrw.commons.actions
|
package fr.free.nrw.commons.actions
|
||||||
|
|
||||||
import org.wikipedia.dataclient.mwapi.MwResponse
|
import fr.free.nrw.commons.wikidata.mwapi.MwResponse
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Response of the Thanks API.
|
* Response of the Thanks API.
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,11 @@
|
||||||
package fr.free.nrw.commons.actions
|
package fr.free.nrw.commons.actions
|
||||||
|
|
||||||
import fr.free.nrw.commons.wikidata.WikidataConstants.MW_API_PREFIX
|
import fr.free.nrw.commons.wikidata.WikidataConstants.MW_API_PREFIX
|
||||||
|
import fr.free.nrw.commons.wikidata.model.Entities
|
||||||
|
import fr.free.nrw.commons.wikidata.model.edit.Edit
|
||||||
import io.reactivex.Observable
|
import io.reactivex.Observable
|
||||||
import io.reactivex.Single
|
import io.reactivex.Single
|
||||||
import org.wikipedia.dataclient.mwapi.MwQueryResponse
|
import fr.free.nrw.commons.wikidata.mwapi.MwQueryResponse
|
||||||
import org.wikipedia.edit.Edit
|
|
||||||
import org.wikipedia.wikidata.Entities
|
|
||||||
import retrofit2.http.*
|
import retrofit2.http.*
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ import fr.free.nrw.commons.auth.login.LoginResult;
|
||||||
import fr.free.nrw.commons.databinding.ActivityLoginBinding;
|
import fr.free.nrw.commons.databinding.ActivityLoginBinding;
|
||||||
import fr.free.nrw.commons.utils.ActivityUtils;
|
import fr.free.nrw.commons.utils.ActivityUtils;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import org.wikipedia.dataclient.mwapi.MwQueryResponse;
|
import fr.free.nrw.commons.wikidata.mwapi.MwQueryResponse;
|
||||||
import fr.free.nrw.commons.auth.login.LoginCallback;
|
import fr.free.nrw.commons.auth.login.LoginCallback;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ package fr.free.nrw.commons.auth.csrf
|
||||||
|
|
||||||
import androidx.annotation.VisibleForTesting
|
import androidx.annotation.VisibleForTesting
|
||||||
import fr.free.nrw.commons.auth.SessionManager
|
import fr.free.nrw.commons.auth.SessionManager
|
||||||
import org.wikipedia.dataclient.mwapi.MwQueryResponse
|
import fr.free.nrw.commons.wikidata.mwapi.MwQueryResponse
|
||||||
import fr.free.nrw.commons.auth.login.LoginClient
|
import fr.free.nrw.commons.auth.login.LoginClient
|
||||||
import fr.free.nrw.commons.auth.login.LoginCallback
|
import fr.free.nrw.commons.auth.login.LoginCallback
|
||||||
import fr.free.nrw.commons.auth.login.LoginFailedException
|
import fr.free.nrw.commons.auth.login.LoginFailedException
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
package fr.free.nrw.commons.auth.csrf
|
package fr.free.nrw.commons.auth.csrf
|
||||||
|
|
||||||
import fr.free.nrw.commons.wikidata.WikidataConstants.MW_API_PREFIX
|
import fr.free.nrw.commons.wikidata.WikidataConstants.MW_API_PREFIX
|
||||||
import org.wikipedia.dataclient.mwapi.MwQueryResponse
|
import fr.free.nrw.commons.wikidata.mwapi.MwQueryResponse
|
||||||
import retrofit2.Call
|
import retrofit2.Call
|
||||||
import retrofit2.http.GET
|
import retrofit2.http.GET
|
||||||
import retrofit2.http.Headers
|
import retrofit2.http.Headers
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ import fr.free.nrw.commons.auth.login.LoginResult.ResetPasswordResult
|
||||||
import fr.free.nrw.commons.wikidata.WikidataConstants.WIKIPEDIA_URL
|
import fr.free.nrw.commons.wikidata.WikidataConstants.WIKIPEDIA_URL
|
||||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||||
import io.reactivex.schedulers.Schedulers
|
import io.reactivex.schedulers.Schedulers
|
||||||
import org.wikipedia.dataclient.mwapi.MwQueryResponse
|
import fr.free.nrw.commons.wikidata.mwapi.MwQueryResponse
|
||||||
import retrofit2.Call
|
import retrofit2.Call
|
||||||
import retrofit2.Callback
|
import retrofit2.Callback
|
||||||
import retrofit2.Response
|
import retrofit2.Response
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ package fr.free.nrw.commons.auth.login
|
||||||
|
|
||||||
import fr.free.nrw.commons.wikidata.WikidataConstants.MW_API_PREFIX
|
import fr.free.nrw.commons.wikidata.WikidataConstants.MW_API_PREFIX
|
||||||
import io.reactivex.Observable
|
import io.reactivex.Observable
|
||||||
import org.wikipedia.dataclient.mwapi.MwQueryResponse
|
import fr.free.nrw.commons.wikidata.mwapi.MwQueryResponse
|
||||||
import retrofit2.Call
|
import retrofit2.Call
|
||||||
import retrofit2.http.Field
|
import retrofit2.http.Field
|
||||||
import retrofit2.http.FormUrlEncoded
|
import retrofit2.http.FormUrlEncoded
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ import com.google.gson.annotations.SerializedName
|
||||||
import fr.free.nrw.commons.auth.login.LoginResult.OAuthResult
|
import fr.free.nrw.commons.auth.login.LoginResult.OAuthResult
|
||||||
import fr.free.nrw.commons.auth.login.LoginResult.ResetPasswordResult
|
import fr.free.nrw.commons.auth.login.LoginResult.ResetPasswordResult
|
||||||
import fr.free.nrw.commons.auth.login.LoginResult.Result
|
import fr.free.nrw.commons.auth.login.LoginResult.Result
|
||||||
import org.wikipedia.dataclient.mwapi.MwServiceError
|
import fr.free.nrw.commons.wikidata.mwapi.MwServiceError
|
||||||
|
|
||||||
class LoginResponse {
|
class LoginResponse {
|
||||||
@SerializedName("error")
|
@SerializedName("error")
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ import androidx.annotation.Nullable;
|
||||||
|
|
||||||
import fr.free.nrw.commons.campaigns.models.Campaign;
|
import fr.free.nrw.commons.campaigns.models.Campaign;
|
||||||
import fr.free.nrw.commons.theme.BaseActivity;
|
import fr.free.nrw.commons.theme.BaseActivity;
|
||||||
import org.wikipedia.util.DateUtil;
|
import fr.free.nrw.commons.utils.DateUtil;
|
||||||
|
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
package fr.free.nrw.commons.category
|
package fr.free.nrw.commons.category
|
||||||
|
|
||||||
import io.reactivex.Single
|
import io.reactivex.Single
|
||||||
import org.wikipedia.dataclient.mwapi.MwQueryResponse
|
import fr.free.nrw.commons.wikidata.mwapi.MwQueryResponse
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import javax.inject.Singleton
|
import javax.inject.Singleton
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ import fr.free.nrw.commons.media.MediaDetailPagerFragment;
|
||||||
import fr.free.nrw.commons.theme.BaseActivity;
|
import fr.free.nrw.commons.theme.BaseActivity;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import org.wikipedia.page.PageTitle;
|
import fr.free.nrw.commons.wikidata.model.page.PageTitle;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This activity displays details of a particular category
|
* This activity displays details of a particular category
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ package fr.free.nrw.commons.category;
|
||||||
|
|
||||||
import io.reactivex.Single;
|
import io.reactivex.Single;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import org.wikipedia.dataclient.mwapi.MwQueryResponse;
|
import fr.free.nrw.commons.wikidata.mwapi.MwQueryResponse;
|
||||||
import retrofit2.http.GET;
|
import retrofit2.http.GET;
|
||||||
import retrofit2.http.Query;
|
import retrofit2.http.Query;
|
||||||
import retrofit2.http.QueryMap;
|
import retrofit2.http.QueryMap;
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,7 @@ import java.util.Objects;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.wikipedia.dataclient.WikiSite;
|
import fr.free.nrw.commons.wikidata.model.WikiSite;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ package fr.free.nrw.commons.delete;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
import org.wikipedia.util.DateUtil;
|
import fr.free.nrw.commons.utils.DateUtil;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,6 @@ import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
import org.wikipedia.AppAdapter;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Dependency Provider class for Commons Android.
|
* The Dependency Provider class for Commons Android.
|
||||||
|
|
|
||||||
|
|
@ -45,8 +45,8 @@ import okhttp3.HttpUrl;
|
||||||
import okhttp3.OkHttpClient;
|
import okhttp3.OkHttpClient;
|
||||||
import okhttp3.logging.HttpLoggingInterceptor;
|
import okhttp3.logging.HttpLoggingInterceptor;
|
||||||
import okhttp3.logging.HttpLoggingInterceptor.Level;
|
import okhttp3.logging.HttpLoggingInterceptor.Level;
|
||||||
import org.wikipedia.dataclient.WikiSite;
|
import fr.free.nrw.commons.wikidata.model.WikiSite;
|
||||||
import org.wikipedia.json.GsonUtil;
|
import fr.free.nrw.commons.wikidata.GsonUtil;
|
||||||
import timber.log.Timber;
|
import timber.log.Timber;
|
||||||
|
|
||||||
@Module
|
@Module
|
||||||
|
|
|
||||||
|
|
@ -7,11 +7,11 @@ import fr.free.nrw.commons.upload.depicts.DepictsInterface
|
||||||
import fr.free.nrw.commons.upload.structure.depictions.DepictedItem
|
import fr.free.nrw.commons.upload.structure.depictions.DepictedItem
|
||||||
import fr.free.nrw.commons.upload.structure.depictions.get
|
import fr.free.nrw.commons.upload.structure.depictions.get
|
||||||
import fr.free.nrw.commons.wikidata.WikidataProperties
|
import fr.free.nrw.commons.wikidata.WikidataProperties
|
||||||
|
import fr.free.nrw.commons.wikidata.model.DataValue
|
||||||
import fr.free.nrw.commons.wikidata.model.DepictSearchItem
|
import fr.free.nrw.commons.wikidata.model.DepictSearchItem
|
||||||
|
import fr.free.nrw.commons.wikidata.model.Entities
|
||||||
|
import fr.free.nrw.commons.wikidata.model.Statement_partial
|
||||||
import io.reactivex.Single
|
import io.reactivex.Single
|
||||||
import org.wikipedia.wikidata.DataValue
|
|
||||||
import org.wikipedia.wikidata.Entities
|
|
||||||
import org.wikipedia.wikidata.Statement_partial
|
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import javax.inject.Singleton
|
import javax.inject.Singleton
|
||||||
|
|
|
||||||
|
|
@ -6,12 +6,12 @@ import fr.free.nrw.commons.upload.structure.depictions.get
|
||||||
import fr.free.nrw.commons.utils.CommonsDateUtil
|
import fr.free.nrw.commons.utils.CommonsDateUtil
|
||||||
import fr.free.nrw.commons.utils.MediaDataExtractorUtil
|
import fr.free.nrw.commons.utils.MediaDataExtractorUtil
|
||||||
import fr.free.nrw.commons.wikidata.WikidataProperties
|
import fr.free.nrw.commons.wikidata.WikidataProperties
|
||||||
|
import fr.free.nrw.commons.wikidata.model.DataValue
|
||||||
|
import fr.free.nrw.commons.wikidata.model.Entities
|
||||||
import org.apache.commons.lang3.StringUtils
|
import org.apache.commons.lang3.StringUtils
|
||||||
import org.wikipedia.dataclient.mwapi.MwQueryPage
|
import fr.free.nrw.commons.wikidata.mwapi.MwQueryPage
|
||||||
import org.wikipedia.gallery.ExtMetadata
|
import fr.free.nrw.commons.wikidata.model.gallery.ExtMetadata
|
||||||
import org.wikipedia.gallery.ImageInfo
|
import fr.free.nrw.commons.wikidata.model.gallery.ImageInfo
|
||||||
import org.wikipedia.wikidata.DataValue
|
|
||||||
import org.wikipedia.wikidata.Entities
|
|
||||||
import java.text.ParseException
|
import java.text.ParseException
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package org.wikipedia.language;
|
package fr.free.nrw.commons.language;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
|
|
@ -8,8 +8,7 @@ import androidx.annotation.ArrayRes;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
import org.wikipedia.dataclient.R;
|
import fr.free.nrw.commons.R;
|
||||||
|
|
||||||
import java.lang.ref.SoftReference;
|
import java.lang.ref.SoftReference;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
@ -5,10 +5,10 @@ import fr.free.nrw.commons.Media
|
||||||
import fr.free.nrw.commons.category.ContinuationClient
|
import fr.free.nrw.commons.category.ContinuationClient
|
||||||
import fr.free.nrw.commons.explore.media.MediaConverter
|
import fr.free.nrw.commons.explore.media.MediaConverter
|
||||||
import fr.free.nrw.commons.utils.CommonsDateUtil
|
import fr.free.nrw.commons.utils.CommonsDateUtil
|
||||||
|
import fr.free.nrw.commons.wikidata.model.Entities
|
||||||
import io.reactivex.Single
|
import io.reactivex.Single
|
||||||
import org.wikipedia.dataclient.mwapi.MwQueryPage
|
import fr.free.nrw.commons.wikidata.mwapi.MwQueryPage
|
||||||
import org.wikipedia.dataclient.mwapi.MwQueryResponse
|
import fr.free.nrw.commons.wikidata.mwapi.MwQueryResponse
|
||||||
import org.wikipedia.wikidata.Entities
|
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import javax.inject.Singleton
|
import javax.inject.Singleton
|
||||||
|
|
|
||||||
|
|
@ -115,9 +115,9 @@ import java.util.regex.Pattern;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.wikipedia.dataclient.mwapi.MwQueryPage;
|
import fr.free.nrw.commons.wikidata.mwapi.MwQueryPage;
|
||||||
import org.wikipedia.language.AppLanguageLookUpTable;
|
import fr.free.nrw.commons.language.AppLanguageLookUpTable;
|
||||||
import org.wikipedia.util.DateUtil;
|
import fr.free.nrw.commons.utils.DateUtil;
|
||||||
import timber.log.Timber;
|
import timber.log.Timber;
|
||||||
|
|
||||||
public class MediaDetailFragment extends CommonsDaggerSupportFragment implements
|
public class MediaDetailFragment extends CommonsDaggerSupportFragment implements
|
||||||
|
|
|
||||||
|
|
@ -2,10 +2,10 @@ package fr.free.nrw.commons.media;
|
||||||
|
|
||||||
import static fr.free.nrw.commons.wikidata.WikidataConstants.MW_API_PREFIX;
|
import static fr.free.nrw.commons.wikidata.WikidataConstants.MW_API_PREFIX;
|
||||||
|
|
||||||
|
import fr.free.nrw.commons.wikidata.model.Entities;
|
||||||
import io.reactivex.Observable;
|
import io.reactivex.Observable;
|
||||||
import io.reactivex.Single;
|
import io.reactivex.Single;
|
||||||
import org.wikipedia.dataclient.mwapi.MwQueryResponse;
|
import fr.free.nrw.commons.wikidata.mwapi.MwQueryResponse;
|
||||||
import org.wikipedia.wikidata.Entities;
|
|
||||||
import retrofit2.http.GET;
|
import retrofit2.http.GET;
|
||||||
import retrofit2.http.Query;
|
import retrofit2.http.Query;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ package fr.free.nrw.commons.media;
|
||||||
|
|
||||||
import io.reactivex.Single;
|
import io.reactivex.Single;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import org.wikipedia.dataclient.mwapi.MwQueryResponse;
|
import fr.free.nrw.commons.wikidata.mwapi.MwQueryResponse;
|
||||||
import retrofit2.http.GET;
|
import retrofit2.http.GET;
|
||||||
import retrofit2.http.Query;
|
import retrofit2.http.Query;
|
||||||
import retrofit2.http.QueryMap;
|
import retrofit2.http.QueryMap;
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ package fr.free.nrw.commons.media;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.annotation.VisibleForTesting;
|
import androidx.annotation.VisibleForTesting;
|
||||||
|
|
||||||
import org.wikipedia.dataclient.mwapi.MwResponse;
|
import fr.free.nrw.commons.wikidata.mwapi.MwResponse;
|
||||||
|
|
||||||
public class MwParseResponse extends MwResponse {
|
public class MwParseResponse extends MwResponse {
|
||||||
@Nullable
|
@Nullable
|
||||||
|
|
|
||||||
|
|
@ -4,10 +4,10 @@ import fr.free.nrw.commons.BetaConstants
|
||||||
import fr.free.nrw.commons.Media
|
import fr.free.nrw.commons.Media
|
||||||
import fr.free.nrw.commons.category.ContinuationClient
|
import fr.free.nrw.commons.category.ContinuationClient
|
||||||
import fr.free.nrw.commons.explore.media.MediaConverter
|
import fr.free.nrw.commons.explore.media.MediaConverter
|
||||||
|
import fr.free.nrw.commons.wikidata.model.Entities
|
||||||
import io.reactivex.Single
|
import io.reactivex.Single
|
||||||
import org.wikipedia.dataclient.mwapi.MwQueryPage
|
import fr.free.nrw.commons.wikidata.mwapi.MwQueryPage
|
||||||
import org.wikipedia.dataclient.mwapi.MwQueryResponse
|
import fr.free.nrw.commons.wikidata.mwapi.MwQueryResponse
|
||||||
import org.wikipedia.wikidata.Entities
|
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import javax.inject.Singleton
|
import javax.inject.Singleton
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ package fr.free.nrw.commons.media;
|
||||||
import static fr.free.nrw.commons.media.MediaInterface.MEDIA_PARAMS;
|
import static fr.free.nrw.commons.media.MediaInterface.MEDIA_PARAMS;
|
||||||
|
|
||||||
import io.reactivex.Single;
|
import io.reactivex.Single;
|
||||||
import org.wikipedia.dataclient.mwapi.MwQueryResponse;
|
import fr.free.nrw.commons.wikidata.mwapi.MwQueryResponse;
|
||||||
import retrofit2.http.GET;
|
import retrofit2.http.GET;
|
||||||
import retrofit2.http.Query;
|
import retrofit2.http.Query;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,8 +17,8 @@ import okhttp3.OkHttpClient;
|
||||||
import okhttp3.Request;
|
import okhttp3.Request;
|
||||||
import okhttp3.Response;
|
import okhttp3.Response;
|
||||||
import okhttp3.ResponseBody;
|
import okhttp3.ResponseBody;
|
||||||
import org.wikipedia.dataclient.mwapi.MwQueryPage;
|
import fr.free.nrw.commons.wikidata.mwapi.MwQueryPage;
|
||||||
import org.wikipedia.dataclient.mwapi.MwQueryResponse;
|
import fr.free.nrw.commons.wikidata.mwapi.MwQueryResponse;
|
||||||
import timber.log.Timber;
|
import timber.log.Timber;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,9 @@
|
||||||
package fr.free.nrw.commons.mwapi;
|
package fr.free.nrw.commons.mwapi;
|
||||||
|
|
||||||
import org.wikipedia.dataclient.mwapi.MwQueryLogEvent;
|
import fr.free.nrw.commons.wikidata.mwapi.MwQueryResponse;
|
||||||
import org.wikipedia.dataclient.mwapi.MwQueryResponse;
|
import fr.free.nrw.commons.wikidata.mwapi.MwQueryResult;
|
||||||
import org.wikipedia.dataclient.mwapi.MwQueryResult;
|
import fr.free.nrw.commons.wikidata.mwapi.UserInfo;
|
||||||
import org.wikipedia.dataclient.mwapi.UserInfo;
|
import fr.free.nrw.commons.utils.DateUtil;
|
||||||
import org.wikipedia.util.DateUtil;
|
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
@ -44,16 +43,4 @@ public class UserClient {
|
||||||
}
|
}
|
||||||
}).single(false);
|
}).single(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Observable<MwQueryLogEvent> logEvents(String user) {
|
|
||||||
try {
|
|
||||||
return userInterface.getUserLogEvents(user, Collections.emptyMap())
|
|
||||||
.map(MwQueryResponse::query)
|
|
||||||
.map(MwQueryResult::logevents)
|
|
||||||
.flatMap(Observable::fromIterable);
|
|
||||||
} catch (Throwable throwable) {
|
|
||||||
return Observable.empty();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
package fr.free.nrw.commons.mwapi;
|
package fr.free.nrw.commons.mwapi;
|
||||||
|
|
||||||
import org.wikipedia.dataclient.mwapi.MwQueryResponse;
|
import fr.free.nrw.commons.wikidata.mwapi.MwQueryResponse;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,8 +9,8 @@ import fr.free.nrw.commons.bookmarks.BookmarkFragment;
|
||||||
import fr.free.nrw.commons.contributions.ContributionsFragment;
|
import fr.free.nrw.commons.contributions.ContributionsFragment;
|
||||||
import fr.free.nrw.commons.explore.ExploreFragment;
|
import fr.free.nrw.commons.explore.ExploreFragment;
|
||||||
import fr.free.nrw.commons.nearby.fragments.NearbyParentFragment;
|
import fr.free.nrw.commons.nearby.fragments.NearbyParentFragment;
|
||||||
import org.wikipedia.model.EnumCode;
|
import fr.free.nrw.commons.wikidata.model.EnumCode;
|
||||||
import org.wikipedia.model.EnumCodeMap;
|
import fr.free.nrw.commons.wikidata.model.EnumCodeMap;
|
||||||
|
|
||||||
import fr.free.nrw.commons.R;
|
import fr.free.nrw.commons.R;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,8 +7,8 @@ import androidx.fragment.app.Fragment;
|
||||||
import fr.free.nrw.commons.R;
|
import fr.free.nrw.commons.R;
|
||||||
import fr.free.nrw.commons.bookmarks.BookmarkFragment;
|
import fr.free.nrw.commons.bookmarks.BookmarkFragment;
|
||||||
import fr.free.nrw.commons.explore.ExploreFragment;
|
import fr.free.nrw.commons.explore.ExploreFragment;
|
||||||
import org.wikipedia.model.EnumCode;
|
import fr.free.nrw.commons.wikidata.model.EnumCode;
|
||||||
import org.wikipedia.model.EnumCodeMap;
|
import fr.free.nrw.commons.wikidata.model.EnumCodeMap;
|
||||||
|
|
||||||
|
|
||||||
public enum NavTabLoggedOut implements EnumCode {
|
public enum NavTabLoggedOut implements EnumCode {
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ package fr.free.nrw.commons.notification
|
||||||
import com.hannesdorfmann.adapterdelegates4.dsl.adapterDelegateViewBinding
|
import com.hannesdorfmann.adapterdelegates4.dsl.adapterDelegateViewBinding
|
||||||
import fr.free.nrw.commons.notification.models.Notification
|
import fr.free.nrw.commons.notification.models.Notification
|
||||||
import fr.free.nrw.commons.databinding.ItemNotificationBinding
|
import fr.free.nrw.commons.databinding.ItemNotificationBinding
|
||||||
import org.wikipedia.util.StringUtil
|
import fr.free.nrw.commons.utils.StringUtil
|
||||||
|
|
||||||
|
|
||||||
fun notificationDelegate(onNotificationClicked: (Notification) -> Unit) =
|
fun notificationDelegate(onNotificationClicked: (Notification) -> Unit) =
|
||||||
|
|
|
||||||
|
|
@ -6,12 +6,12 @@ import fr.free.nrw.commons.notification.models.NotificationType
|
||||||
import io.reactivex.Observable
|
import io.reactivex.Observable
|
||||||
import io.reactivex.Single
|
import io.reactivex.Single
|
||||||
import fr.free.nrw.commons.auth.csrf.CsrfTokenClient
|
import fr.free.nrw.commons.auth.csrf.CsrfTokenClient
|
||||||
import org.wikipedia.dataclient.mwapi.MwQueryResponse
|
import fr.free.nrw.commons.wikidata.mwapi.MwQueryResponse
|
||||||
import org.wikipedia.util.DateUtil
|
import fr.free.nrw.commons.utils.DateUtil
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import javax.inject.Named
|
import javax.inject.Named
|
||||||
import javax.inject.Singleton
|
import javax.inject.Singleton
|
||||||
import org.wikipedia.notifications.Notification as WikimediaNotification
|
import fr.free.nrw.commons.wikidata.model.notifications.Notification as WikimediaNotification
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
class NotificationClient @Inject constructor(
|
class NotificationClient @Inject constructor(
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ package fr.free.nrw.commons.notification
|
||||||
|
|
||||||
import fr.free.nrw.commons.wikidata.WikidataConstants.MW_API_PREFIX
|
import fr.free.nrw.commons.wikidata.WikidataConstants.MW_API_PREFIX
|
||||||
import io.reactivex.Observable
|
import io.reactivex.Observable
|
||||||
import org.wikipedia.dataclient.mwapi.MwQueryResponse
|
import fr.free.nrw.commons.wikidata.mwapi.MwQueryResponse
|
||||||
import retrofit2.http.Field
|
import retrofit2.http.Field
|
||||||
import retrofit2.http.FormUrlEncoded
|
import retrofit2.http.FormUrlEncoded
|
||||||
import retrofit2.http.GET
|
import retrofit2.http.GET
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.core.app.NotificationCompat;
|
import androidx.core.app.NotificationCompat;
|
||||||
|
|
||||||
import org.wikipedia.dataclient.mwapi.MwQueryPage;
|
import fr.free.nrw.commons.wikidata.mwapi.MwQueryPage;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ import java.util.Collections;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.wikipedia.dataclient.mwapi.MwQueryPage;
|
import fr.free.nrw.commons.wikidata.mwapi.MwQueryPage;
|
||||||
import timber.log.Timber;
|
import timber.log.Timber;
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
package fr.free.nrw.commons.review;
|
package fr.free.nrw.commons.review;
|
||||||
|
|
||||||
import org.wikipedia.dataclient.mwapi.MwQueryResponse;
|
import fr.free.nrw.commons.wikidata.mwapi.MwQueryResponse;
|
||||||
|
|
||||||
import io.reactivex.Observable;
|
import io.reactivex.Observable;
|
||||||
import retrofit2.http.GET;
|
import retrofit2.http.GET;
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ import android.util.AttributeSet;
|
||||||
|
|
||||||
import androidx.appcompat.widget.AppCompatTextView;
|
import androidx.appcompat.widget.AppCompatTextView;
|
||||||
|
|
||||||
import org.wikipedia.util.StringUtil;
|
import fr.free.nrw.commons.utils.StringUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An {@link AppCompatTextView} which formats the text to HTML displayable text and makes any
|
* An {@link AppCompatTextView} which formats the text to HTML displayable text and makes any
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ import fr.free.nrw.commons.R
|
||||||
import fr.free.nrw.commons.databinding.RowItemLanguagesSpinnerBinding
|
import fr.free.nrw.commons.databinding.RowItemLanguagesSpinnerBinding
|
||||||
import fr.free.nrw.commons.utils.LangCodeUtils
|
import fr.free.nrw.commons.utils.LangCodeUtils
|
||||||
import org.apache.commons.lang3.StringUtils
|
import org.apache.commons.lang3.StringUtils
|
||||||
import org.wikipedia.language.AppLanguageLookUpTable
|
import fr.free.nrw.commons.language.AppLanguageLookUpTable
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -39,7 +39,8 @@ class LanguagesAdapter constructor(
|
||||||
private var languageNamesList: List<String>
|
private var languageNamesList: List<String>
|
||||||
private var languageCodesList: List<String>
|
private var languageCodesList: List<String>
|
||||||
|
|
||||||
var language: AppLanguageLookUpTable = AppLanguageLookUpTable(context)
|
var language: AppLanguageLookUpTable =
|
||||||
|
AppLanguageLookUpTable(context)
|
||||||
init {
|
init {
|
||||||
languageNamesList = language.localizedNames
|
languageNamesList = language.localizedNames
|
||||||
languageCodesList = language.codes
|
languageCodesList = language.codes
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ import okhttp3.MediaType;
|
||||||
import okhttp3.MultipartBody;
|
import okhttp3.MultipartBody;
|
||||||
import okhttp3.RequestBody;
|
import okhttp3.RequestBody;
|
||||||
import fr.free.nrw.commons.auth.csrf.CsrfTokenClient;
|
import fr.free.nrw.commons.auth.csrf.CsrfTokenClient;
|
||||||
import org.wikipedia.dataclient.mwapi.MwException;
|
import fr.free.nrw.commons.wikidata.mwapi.MwException;
|
||||||
import timber.log.Timber;
|
import timber.log.Timber;
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@ package fr.free.nrw.commons.upload
|
||||||
|
|
||||||
import android.os.Parcel
|
import android.os.Parcel
|
||||||
import android.os.Parcelable
|
import android.os.Parcelable
|
||||||
import org.wikipedia.gallery.ImageInfo
|
|
||||||
|
|
||||||
private const val RESULT_SUCCESS = "Success"
|
private const val RESULT_SUCCESS = "Success"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,8 @@ import static fr.free.nrw.commons.wikidata.WikidataConstants.MW_API_PREFIX;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import io.reactivex.Observable;
|
import io.reactivex.Observable;
|
||||||
import org.wikipedia.dataclient.mwapi.MwPostResponse;
|
import fr.free.nrw.commons.wikidata.mwapi.MwPostResponse;
|
||||||
import org.wikipedia.dataclient.mwapi.MwQueryResponse;
|
import fr.free.nrw.commons.wikidata.mwapi.MwQueryResponse;
|
||||||
import retrofit2.http.Field;
|
import retrofit2.http.Field;
|
||||||
import retrofit2.http.FormUrlEncoded;
|
import retrofit2.http.FormUrlEncoded;
|
||||||
import retrofit2.http.GET;
|
import retrofit2.http.GET;
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
package fr.free.nrw.commons.upload.depicts;
|
package fr.free.nrw.commons.upload.depicts;
|
||||||
|
|
||||||
import fr.free.nrw.commons.wikidata.model.DepictSearchResponse;
|
import fr.free.nrw.commons.wikidata.model.DepictSearchResponse;
|
||||||
|
import fr.free.nrw.commons.wikidata.model.Entities;
|
||||||
import io.reactivex.Single;
|
import io.reactivex.Single;
|
||||||
import org.wikipedia.wikidata.Entities;
|
|
||||||
import retrofit2.http.GET;
|
import retrofit2.http.GET;
|
||||||
import retrofit2.http.Query;
|
import retrofit2.http.Query;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,10 +8,10 @@ import fr.free.nrw.commons.nearby.Place
|
||||||
import fr.free.nrw.commons.upload.WikidataItem
|
import fr.free.nrw.commons.upload.WikidataItem
|
||||||
import fr.free.nrw.commons.wikidata.WikidataProperties
|
import fr.free.nrw.commons.wikidata.WikidataProperties
|
||||||
import fr.free.nrw.commons.wikidata.WikidataProperties.*
|
import fr.free.nrw.commons.wikidata.WikidataProperties.*
|
||||||
|
import fr.free.nrw.commons.wikidata.model.DataValue
|
||||||
|
import fr.free.nrw.commons.wikidata.model.Entities
|
||||||
|
import fr.free.nrw.commons.wikidata.model.Statement_partial
|
||||||
import kotlinx.android.parcel.Parcelize
|
import kotlinx.android.parcel.Parcelize
|
||||||
import org.wikipedia.wikidata.DataValue
|
|
||||||
import org.wikipedia.wikidata.Entities
|
|
||||||
import org.wikipedia.wikidata.Statement_partial
|
|
||||||
import java.math.BigInteger
|
import java.math.BigInteger
|
||||||
import java.security.MessageDigest
|
import java.security.MessageDigest
|
||||||
import java.security.NoSuchAlgorithmException
|
import java.security.NoSuchAlgorithmException
|
||||||
|
|
|
||||||
53
app/src/main/java/fr/free/nrw/commons/utils/DateUtil.java
Normal file
53
app/src/main/java/fr/free/nrw/commons/utils/DateUtil.java
Normal file
|
|
@ -0,0 +1,53 @@
|
||||||
|
package fr.free.nrw.commons.utils;
|
||||||
|
|
||||||
|
import static android.text.format.DateFormat.getBestDateTimePattern;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
|
import java.text.ParseException;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Locale;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.TimeZone;
|
||||||
|
|
||||||
|
public final class DateUtil {
|
||||||
|
private static Map<String, SimpleDateFormat> DATE_FORMATS = new HashMap<>();
|
||||||
|
|
||||||
|
// TODO: Switch to DateTimeFormatter when minSdk = 26.
|
||||||
|
|
||||||
|
public static synchronized String iso8601DateFormat(Date date) {
|
||||||
|
return getCachedDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.ROOT, true).format(date);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static synchronized Date iso8601DateParse(String date) throws ParseException {
|
||||||
|
return getCachedDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.ROOT, true).parse(date);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getMonthOnlyDateString(@NonNull Date date) {
|
||||||
|
return getDateStringWithSkeletonPattern(date, "MMMM d");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getExtraShortDateString(@NonNull Date date) {
|
||||||
|
return getDateStringWithSkeletonPattern(date, "MMM d");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static synchronized String getDateStringWithSkeletonPattern(@NonNull Date date, @NonNull String pattern) {
|
||||||
|
return getCachedDateFormat(getBestDateTimePattern(Locale.getDefault(), pattern), Locale.getDefault(), false).format(date);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static SimpleDateFormat getCachedDateFormat(String pattern, Locale locale, boolean utc) {
|
||||||
|
if (!DATE_FORMATS.containsKey(pattern)) {
|
||||||
|
SimpleDateFormat df = new SimpleDateFormat(pattern, locale);
|
||||||
|
if (utc) {
|
||||||
|
df.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||||
|
}
|
||||||
|
DATE_FORMATS.put(pattern, df);
|
||||||
|
}
|
||||||
|
return DATE_FORMATS.get(pattern);
|
||||||
|
}
|
||||||
|
|
||||||
|
private DateUtil() {
|
||||||
|
}
|
||||||
|
}
|
||||||
38
app/src/main/java/fr/free/nrw/commons/utils/StringUtil.java
Normal file
38
app/src/main/java/fr/free/nrw/commons/utils/StringUtil.java
Normal file
|
|
@ -0,0 +1,38 @@
|
||||||
|
package fr.free.nrw.commons.utils;
|
||||||
|
|
||||||
|
import android.os.Build;
|
||||||
|
import android.text.Html;
|
||||||
|
import android.text.Spanned;
|
||||||
|
import android.text.SpannedString;
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
|
public final class StringUtil {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param source String that may contain HTML tags.
|
||||||
|
* @return returned Spanned string that may contain spans parsed from the HTML source.
|
||||||
|
*/
|
||||||
|
@NonNull public static Spanned fromHtml(@Nullable String source) {
|
||||||
|
if (source == null) {
|
||||||
|
return new SpannedString("");
|
||||||
|
}
|
||||||
|
if (!source.contains("<") && !source.contains("&")) {
|
||||||
|
// If the string doesn't contain any hints of HTML entities, then skip the expensive
|
||||||
|
// processing that fromHtml() performs.
|
||||||
|
return new SpannedString(source);
|
||||||
|
}
|
||||||
|
source = source.replaceAll("‎", "\u200E")
|
||||||
|
.replaceAll("‏", "\u200F")
|
||||||
|
.replaceAll("&", "&");
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||||
|
return Html.fromHtml(source, Html.FROM_HTML_MODE_LEGACY);
|
||||||
|
} else {
|
||||||
|
//noinspection deprecation
|
||||||
|
return Html.fromHtml(source);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private StringUtil() {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
package fr.free.nrw.commons.wikidata
|
package fr.free.nrw.commons.wikidata
|
||||||
|
|
||||||
import okhttp3.OkHttpClient
|
import okhttp3.OkHttpClient
|
||||||
import org.wikipedia.json.GsonUtil
|
|
||||||
import retrofit2.Retrofit
|
import retrofit2.Retrofit
|
||||||
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory
|
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory
|
||||||
import retrofit2.converter.gson.GsonConverterFactory
|
import retrofit2.converter.gson.GsonConverterFactory
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,16 @@
|
||||||
package org.wikipedia.json;
|
package fr.free.nrw.commons.wikidata;
|
||||||
|
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import androidx.annotation.VisibleForTesting;
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.GsonBuilder;
|
import com.google.gson.GsonBuilder;
|
||||||
import org.wikipedia.dataclient.SharedPreferenceCookieManager;
|
import fr.free.nrw.commons.wikidata.json.RequiredFieldsCheckOnReadTypeAdapterFactory;
|
||||||
import org.wikipedia.dataclient.WikiSite;
|
import fr.free.nrw.commons.wikidata.model.DataValue;
|
||||||
import org.wikipedia.page.Namespace;
|
import fr.free.nrw.commons.wikidata.model.WikiSite;
|
||||||
import org.wikipedia.wikidata.DataValue;
|
import fr.free.nrw.commons.wikidata.json.NamespaceTypeAdapter;
|
||||||
|
import fr.free.nrw.commons.wikidata.json.PostProcessingTypeAdapter;
|
||||||
|
import fr.free.nrw.commons.wikidata.json.UriTypeAdapter;
|
||||||
|
import fr.free.nrw.commons.wikidata.json.WikiSiteTypeAdapter;
|
||||||
|
import fr.free.nrw.commons.wikidata.model.page.Namespace;
|
||||||
|
|
||||||
public final class GsonUtil {
|
public final class GsonUtil {
|
||||||
private static final String DATE_FORMAT = "MMM dd, yyyy HH:mm:ss";
|
private static final String DATE_FORMAT = "MMM dd, yyyy HH:mm:ss";
|
||||||
|
|
@ -18,7 +21,6 @@ public final class GsonUtil {
|
||||||
.registerTypeHierarchyAdapter(Uri.class, new UriTypeAdapter().nullSafe())
|
.registerTypeHierarchyAdapter(Uri.class, new UriTypeAdapter().nullSafe())
|
||||||
.registerTypeHierarchyAdapter(Namespace.class, new NamespaceTypeAdapter().nullSafe())
|
.registerTypeHierarchyAdapter(Namespace.class, new NamespaceTypeAdapter().nullSafe())
|
||||||
.registerTypeAdapter(WikiSite.class, new WikiSiteTypeAdapter().nullSafe())
|
.registerTypeAdapter(WikiSite.class, new WikiSiteTypeAdapter().nullSafe())
|
||||||
.registerTypeAdapter(SharedPreferenceCookieManager.class, new CookieManagerTypeAdapter().nullSafe())
|
|
||||||
.registerTypeAdapterFactory(new RequiredFieldsCheckOnReadTypeAdapterFactory())
|
.registerTypeAdapterFactory(new RequiredFieldsCheckOnReadTypeAdapterFactory())
|
||||||
.registerTypeAdapterFactory(new PostProcessingTypeAdapter());
|
.registerTypeAdapterFactory(new PostProcessingTypeAdapter());
|
||||||
|
|
||||||
|
|
@ -28,10 +30,5 @@ public final class GsonUtil {
|
||||||
return DEFAULT_GSON;
|
return DEFAULT_GSON;
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
|
||||||
public static GsonBuilder getDefaultGsonBuilder() {
|
|
||||||
return DEFAULT_GSON_BUILDER;
|
|
||||||
}
|
|
||||||
|
|
||||||
private GsonUtil() { }
|
private GsonUtil() { }
|
||||||
}
|
}
|
||||||
|
|
@ -10,7 +10,7 @@ import javax.inject.Inject;
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
import fr.free.nrw.commons.auth.csrf.CsrfTokenClient;
|
import fr.free.nrw.commons.auth.csrf.CsrfTokenClient;
|
||||||
import org.wikipedia.dataclient.mwapi.MwPostResponse;
|
import fr.free.nrw.commons.wikidata.mwapi.MwPostResponse;
|
||||||
import timber.log.Timber;
|
import timber.log.Timber;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ import javax.inject.Singleton;
|
||||||
import fr.free.nrw.commons.wikidata.model.AddEditTagResponse;
|
import fr.free.nrw.commons.wikidata.model.AddEditTagResponse;
|
||||||
import io.reactivex.Observable;
|
import io.reactivex.Observable;
|
||||||
import io.reactivex.ObservableSource;
|
import io.reactivex.ObservableSource;
|
||||||
import org.wikipedia.wikidata.Statement_partial;
|
import fr.free.nrw.commons.wikidata.model.Statement_partial;
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
public class WikidataClient {
|
public class WikidataClient {
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,12 @@ import fr.free.nrw.commons.upload.WikidataItem;
|
||||||
import fr.free.nrw.commons.upload.WikidataPlace;
|
import fr.free.nrw.commons.upload.WikidataPlace;
|
||||||
import fr.free.nrw.commons.utils.ConfigUtils;
|
import fr.free.nrw.commons.utils.ConfigUtils;
|
||||||
import fr.free.nrw.commons.utils.ViewUtil;
|
import fr.free.nrw.commons.utils.ViewUtil;
|
||||||
|
import fr.free.nrw.commons.wikidata.model.DataValue;
|
||||||
|
import fr.free.nrw.commons.wikidata.model.DataValue.ValueString;
|
||||||
|
import fr.free.nrw.commons.wikidata.model.EditClaim;
|
||||||
|
import fr.free.nrw.commons.wikidata.model.Snak_partial;
|
||||||
|
import fr.free.nrw.commons.wikidata.model.Statement_partial;
|
||||||
|
import fr.free.nrw.commons.wikidata.model.WikiBaseMonolingualTextValue;
|
||||||
import io.reactivex.Observable;
|
import io.reactivex.Observable;
|
||||||
import io.reactivex.schedulers.Schedulers;
|
import io.reactivex.schedulers.Schedulers;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
@ -27,13 +33,7 @@ import java.util.UUID;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
import org.wikipedia.dataclient.mwapi.MwPostResponse;
|
import fr.free.nrw.commons.wikidata.mwapi.MwPostResponse;
|
||||||
import org.wikipedia.wikidata.DataValue;
|
|
||||||
import org.wikipedia.wikidata.DataValue.ValueString;
|
|
||||||
import org.wikipedia.wikidata.EditClaim;
|
|
||||||
import org.wikipedia.wikidata.Snak_partial;
|
|
||||||
import org.wikipedia.wikidata.Statement_partial;
|
|
||||||
import org.wikipedia.wikidata.WikiBaseMonolingualTextValue;
|
|
||||||
import timber.log.Timber;
|
import timber.log.Timber;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ package fr.free.nrw.commons.wikidata;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
import org.wikipedia.dataclient.mwapi.MwQueryResponse;
|
import fr.free.nrw.commons.wikidata.mwapi.MwQueryResponse;
|
||||||
|
|
||||||
import fr.free.nrw.commons.wikidata.model.WbCreateClaimResponse;
|
import fr.free.nrw.commons.wikidata.model.WbCreateClaimResponse;
|
||||||
import io.reactivex.Observable;
|
import io.reactivex.Observable;
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ import fr.free.nrw.commons.kvstore.JsonKvStore
|
||||||
import okhttp3.Cookie
|
import okhttp3.Cookie
|
||||||
import okhttp3.HttpUrl
|
import okhttp3.HttpUrl
|
||||||
import okhttp3.HttpUrl.Companion.toHttpUrlOrNull
|
import okhttp3.HttpUrl.Companion.toHttpUrlOrNull
|
||||||
import org.wikipedia.dataclient.WikiSite
|
import fr.free.nrw.commons.wikidata.model.WikiSite
|
||||||
|
|
||||||
private const val COOKIE_STORE = "cookie_store"
|
private const val COOKIE_STORE = "cookie_store"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,11 @@
|
||||||
package org.wikipedia.json;
|
package fr.free.nrw.commons.wikidata.json;
|
||||||
|
|
||||||
import com.google.gson.TypeAdapter;
|
import com.google.gson.TypeAdapter;
|
||||||
import com.google.gson.stream.JsonReader;
|
import com.google.gson.stream.JsonReader;
|
||||||
import com.google.gson.stream.JsonToken;
|
import com.google.gson.stream.JsonToken;
|
||||||
import com.google.gson.stream.JsonWriter;
|
import com.google.gson.stream.JsonWriter;
|
||||||
|
|
||||||
import org.wikipedia.page.Namespace;
|
import fr.free.nrw.commons.wikidata.model.page.Namespace;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package org.wikipedia.json;
|
package fr.free.nrw.commons.wikidata.json;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.TypeAdapter;
|
import com.google.gson.TypeAdapter;
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package org.wikipedia.json;
|
package fr.free.nrw.commons.wikidata.json;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
|
@ -12,7 +12,7 @@ import com.google.gson.reflect.TypeToken;
|
||||||
import com.google.gson.stream.JsonReader;
|
import com.google.gson.stream.JsonReader;
|
||||||
import com.google.gson.stream.JsonWriter;
|
import com.google.gson.stream.JsonWriter;
|
||||||
|
|
||||||
import org.wikipedia.json.annotations.Required;
|
import fr.free.nrw.commons.wikidata.json.annotations.Required;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
|
|
@ -29,7 +29,7 @@ import java.util.Set;
|
||||||
* TODO: Handle null values in lists during deserialization, perhaps with a new @RequiredElements
|
* TODO: Handle null values in lists during deserialization, perhaps with a new @RequiredElements
|
||||||
* annotation and another corresponding TypeAdapter(Factory).
|
* annotation and another corresponding TypeAdapter(Factory).
|
||||||
*/
|
*/
|
||||||
class RequiredFieldsCheckOnReadTypeAdapterFactory implements TypeAdapterFactory {
|
public class RequiredFieldsCheckOnReadTypeAdapterFactory implements TypeAdapterFactory {
|
||||||
@Nullable @Override public final <T> TypeAdapter<T> create(@NonNull Gson gson, @NonNull TypeToken<T> typeToken) {
|
@Nullable @Override public final <T> TypeAdapter<T> create(@NonNull Gson gson, @NonNull TypeToken<T> typeToken) {
|
||||||
Class<?> rawType = typeToken.getRawType();
|
Class<?> rawType = typeToken.getRawType();
|
||||||
Set<Field> requiredFields = collectRequiredFields(rawType);
|
Set<Field> requiredFields = collectRequiredFields(rawType);
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package org.wikipedia.json;
|
package fr.free.nrw.commons.wikidata.json;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (C) 2011 Google Inc.
|
* Copyright (C) 2011 Google Inc.
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package org.wikipedia.json;
|
package fr.free.nrw.commons.wikidata.json;
|
||||||
|
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package org.wikipedia.json;
|
package fr.free.nrw.commons.wikidata.json;
|
||||||
|
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
|
||||||
|
|
@ -8,7 +8,7 @@ import com.google.gson.stream.JsonReader;
|
||||||
import com.google.gson.stream.JsonToken;
|
import com.google.gson.stream.JsonToken;
|
||||||
import com.google.gson.stream.JsonWriter;
|
import com.google.gson.stream.JsonWriter;
|
||||||
|
|
||||||
import org.wikipedia.dataclient.WikiSite;
|
import fr.free.nrw.commons.wikidata.model.WikiSite;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package org.wikipedia.json.annotations;
|
package fr.free.nrw.commons.wikidata.json.annotations;
|
||||||
|
|
||||||
|
|
||||||
import java.lang.annotation.Documented;
|
import java.lang.annotation.Documented;
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package org.wikipedia.model
|
package fr.free.nrw.commons.wikidata.model
|
||||||
|
|
||||||
import org.apache.commons.lang3.builder.EqualsBuilder
|
import org.apache.commons.lang3.builder.EqualsBuilder
|
||||||
import org.apache.commons.lang3.builder.HashCodeBuilder
|
import org.apache.commons.lang3.builder.HashCodeBuilder
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
package org.wikipedia.wikidata
|
package fr.free.nrw.commons.wikidata.model
|
||||||
|
|
||||||
import org.wikipedia.json.RuntimeTypeAdapterFactory
|
import fr.free.nrw.commons.wikidata.json.RuntimeTypeAdapterFactory
|
||||||
|
|
||||||
sealed class DataValue(val type: String) {
|
sealed class DataValue(val type: String) {
|
||||||
companion object {
|
companion object {
|
||||||
|
|
@ -1,6 +1,4 @@
|
||||||
package org.wikipedia.wikidata
|
package fr.free.nrw.commons.wikidata.model
|
||||||
|
|
||||||
import org.wikipedia.wikidata.DataValue.EntityId
|
|
||||||
|
|
||||||
|
|
||||||
data class EditClaim(val claims: List<Statement_partial>) {
|
data class EditClaim(val claims: List<Statement_partial>) {
|
||||||
|
|
@ -16,7 +14,7 @@ data class EditClaim(val claims: List<Statement_partial>) {
|
||||||
Snak_partial(
|
Snak_partial(
|
||||||
"value",
|
"value",
|
||||||
propertyName,
|
propertyName,
|
||||||
EntityId(
|
DataValue.EntityId(
|
||||||
WikiBaseEntityValue(
|
WikiBaseEntityValue(
|
||||||
"item",
|
"item",
|
||||||
it,
|
it,
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package org.wikipedia.wikidata;
|
package fr.free.nrw.commons.wikidata.model;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
|
@ -8,11 +8,10 @@ import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.wikipedia.dataclient.mwapi.MwResponse;
|
import fr.free.nrw.commons.wikidata.mwapi.MwResponse;
|
||||||
import org.wikipedia.json.PostProcessingTypeAdapter;
|
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
public class Entities extends MwResponse implements PostProcessingTypeAdapter.PostProcessable {
|
public class Entities extends MwResponse {
|
||||||
@Nullable private Map<String, Entity> entities;
|
@Nullable private Map<String, Entity> entities;
|
||||||
private int success;
|
private int success;
|
||||||
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package org.wikipedia.model
|
package fr.free.nrw.commons.wikidata.model
|
||||||
|
|
||||||
interface EnumCode {
|
interface EnumCode {
|
||||||
fun code(): Int
|
fun code(): Int
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package org.wikipedia.model
|
package fr.free.nrw.commons.wikidata.model
|
||||||
|
|
||||||
import android.util.SparseArray
|
import android.util.SparseArray
|
||||||
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package org.wikipedia.wikidata
|
package fr.free.nrw.commons.wikidata.model
|
||||||
|
|
||||||
import com.google.gson.annotations.SerializedName
|
import com.google.gson.annotations.SerializedName
|
||||||
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package org.wikipedia.wikidata
|
package fr.free.nrw.commons.wikidata.model
|
||||||
|
|
||||||
import com.google.gson.annotations.SerializedName
|
import com.google.gson.annotations.SerializedName
|
||||||
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package org.wikipedia.wikidata
|
package fr.free.nrw.commons.wikidata.model
|
||||||
|
|
||||||
import com.google.gson.annotations.SerializedName
|
import com.google.gson.annotations.SerializedName
|
||||||
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package org.wikipedia.wikidata
|
package fr.free.nrw.commons.wikidata.model
|
||||||
|
|
||||||
import com.google.gson.annotations.SerializedName
|
import com.google.gson.annotations.SerializedName
|
||||||
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package org.wikipedia.dataclient;
|
package fr.free.nrw.commons.wikidata.model;
|
||||||
|
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Parcel;
|
import android.os.Parcel;
|
||||||
|
|
@ -9,9 +9,8 @@ import androidx.annotation.NonNull;
|
||||||
|
|
||||||
import com.google.gson.annotations.SerializedName;
|
import com.google.gson.annotations.SerializedName;
|
||||||
|
|
||||||
import org.wikipedia.language.AppLanguageLookUpTable;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.wikipedia.page.PageTitle;
|
import fr.free.nrw.commons.language.AppLanguageLookUpTable;
|
||||||
import org.wikipedia.util.UriUtil;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The base URL and Wikipedia language code for a MediaWiki site. Examples:
|
* The base URL and Wikipedia language code for a MediaWiki site. Examples:
|
||||||
|
|
@ -38,8 +37,10 @@ import org.wikipedia.util.UriUtil;
|
||||||
* </ul>
|
* </ul>
|
||||||
*/
|
*/
|
||||||
public class WikiSite implements Parcelable {
|
public class WikiSite implements Parcelable {
|
||||||
|
private static String WIKIPEDIA_URL = "https://wikipedia.org/";
|
||||||
|
|
||||||
public static final String DEFAULT_SCHEME = "https";
|
public static final String DEFAULT_SCHEME = "https";
|
||||||
private static String DEFAULT_BASE_URL = Service.WIKIPEDIA_URL;
|
private static String DEFAULT_BASE_URL = WIKIPEDIA_URL;
|
||||||
|
|
||||||
public static final Parcelable.Creator<WikiSite> CREATOR = new Parcelable.Creator<WikiSite>() {
|
public static final Parcelable.Creator<WikiSite> CREATOR = new Parcelable.Creator<WikiSite>() {
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -57,14 +58,6 @@ public class WikiSite implements Parcelable {
|
||||||
@SerializedName("domain") @NonNull private final Uri uri;
|
@SerializedName("domain") @NonNull private final Uri uri;
|
||||||
@NonNull private String languageCode;
|
@NonNull private String languageCode;
|
||||||
|
|
||||||
public static boolean supportedAuthority(@NonNull String authority) {
|
|
||||||
return authority.endsWith(Uri.parse(DEFAULT_BASE_URL).getAuthority());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void setDefaultBaseUrl(@NonNull String url) {
|
|
||||||
DEFAULT_BASE_URL = TextUtils.isEmpty(url) ? Service.WIKIPEDIA_URL : url;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static WikiSite forLanguageCode(@NonNull String languageCode) {
|
public static WikiSite forLanguageCode(@NonNull String languageCode) {
|
||||||
Uri uri = ensureScheme(Uri.parse(DEFAULT_BASE_URL));
|
Uri uri = ensureScheme(Uri.parse(DEFAULT_BASE_URL));
|
||||||
return new WikiSite((languageCode.isEmpty()
|
return new WikiSite((languageCode.isEmpty()
|
||||||
|
|
@ -80,7 +73,7 @@ public class WikiSite implements Parcelable {
|
||||||
// Special case for Wikipedia only: assume English subdomain when none given.
|
// Special case for Wikipedia only: assume English subdomain when none given.
|
||||||
authority = "en.wikipedia.org";
|
authority = "en.wikipedia.org";
|
||||||
}
|
}
|
||||||
String langVariant = UriUtil.getLanguageVariantFromUri(tempUri);
|
String langVariant = getLanguageVariantFromUri(tempUri);
|
||||||
if (!TextUtils.isEmpty(langVariant)) {
|
if (!TextUtils.isEmpty(langVariant)) {
|
||||||
languageCode = langVariant;
|
languageCode = langVariant;
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -92,6 +85,16 @@ public class WikiSite implements Parcelable {
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Get language variant code from a Uri, e.g. "zh-*", otherwise returns empty string. */
|
||||||
|
@NonNull
|
||||||
|
private String getLanguageVariantFromUri(@NonNull Uri uri) {
|
||||||
|
if (TextUtils.isEmpty(uri.getPath())) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
String[] parts = StringUtils.split(StringUtils.defaultString(uri.getPath()), '/');
|
||||||
|
return parts.length > 1 && !parts[0].equals("wiki") ? parts[0] : "";
|
||||||
|
}
|
||||||
|
|
||||||
public WikiSite(@NonNull String url) {
|
public WikiSite(@NonNull String url) {
|
||||||
this(url.startsWith("http") ? Uri.parse(url) : url.startsWith("//")
|
this(url.startsWith("http") ? Uri.parse(url) : url.startsWith("//")
|
||||||
? Uri.parse(DEFAULT_SCHEME + ":" + url) : Uri.parse(DEFAULT_SCHEME + "://" + url));
|
? Uri.parse(DEFAULT_SCHEME + ":" + url) : Uri.parse(DEFAULT_SCHEME + "://" + url));
|
||||||
|
|
@ -147,15 +150,6 @@ public class WikiSite implements Parcelable {
|
||||||
return String.format("%1$s://%2$s", scheme(), mobileAuthority());
|
return String.format("%1$s://%2$s", scheme(), mobileAuthority());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return The canonical "desktop" form of the authority. For example, if the authority
|
|
||||||
* is in a "mobile" form, e.g. en.m.wikipedia.org, this will become en.wikipedia.org.
|
|
||||||
*/
|
|
||||||
@NonNull
|
|
||||||
public String desktopAuthority() {
|
|
||||||
return authority().replace(".m.", ".");
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
public String subdomain() {
|
public String subdomain() {
|
||||||
return languageCodeToSubdomain(languageCode);
|
return languageCodeToSubdomain(languageCode);
|
||||||
|
|
@ -199,37 +193,6 @@ public class WikiSite implements Parcelable {
|
||||||
return languageCode;
|
return languageCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: this method doesn't have much to do with WikiSite. Move to PageTitle?
|
|
||||||
/**
|
|
||||||
* Create a PageTitle object from an internal link string.
|
|
||||||
*
|
|
||||||
* @param internalLink Internal link target text (eg. /wiki/Target).
|
|
||||||
* Should be URL decoded before passing in
|
|
||||||
* @return A {@link PageTitle} object representing the internalLink passed in.
|
|
||||||
*/
|
|
||||||
public PageTitle titleForInternalLink(String internalLink) {
|
|
||||||
// Strip the /wiki/ from the href
|
|
||||||
return new PageTitle(UriUtil.removeInternalLinkPrefix(internalLink), this);
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: this method doesn't have much to do with WikiSite. Move to PageTitle?
|
|
||||||
/**
|
|
||||||
* Create a PageTitle object from a Uri, taking into account any fragment (section title) in the link.
|
|
||||||
* @param uri Uri object to be turned into a PageTitle.
|
|
||||||
* @return {@link PageTitle} object that corresponds to the given Uri.
|
|
||||||
*/
|
|
||||||
public PageTitle titleForUri(Uri uri) {
|
|
||||||
String path = uri.getPath();
|
|
||||||
if (!TextUtils.isEmpty(uri.getFragment())) {
|
|
||||||
path += "#" + uri.getFragment();
|
|
||||||
}
|
|
||||||
return titleForInternalLink(path);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull public String dbName() {
|
|
||||||
return subdomain().replaceAll("-", "_") + "wiki";
|
|
||||||
}
|
|
||||||
|
|
||||||
// Auto-generated
|
// Auto-generated
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
|
|
@ -0,0 +1,36 @@
|
||||||
|
package fr.free.nrw.commons.wikidata.model.edit;
|
||||||
|
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
import fr.free.nrw.commons.wikidata.mwapi.MwPostResponse;
|
||||||
|
|
||||||
|
public class Edit extends MwPostResponse {
|
||||||
|
@Nullable private Result edit;
|
||||||
|
|
||||||
|
@Nullable public Result edit() {
|
||||||
|
return edit;
|
||||||
|
}
|
||||||
|
|
||||||
|
public class Result {
|
||||||
|
@Nullable private String result;
|
||||||
|
@Nullable private String code;
|
||||||
|
@Nullable private String info;
|
||||||
|
@Nullable private String warning;
|
||||||
|
|
||||||
|
public boolean editSucceeded() {
|
||||||
|
return "Success".equals(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable public String code() {
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable public String info() {
|
||||||
|
return info;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable public String warning() {
|
||||||
|
return warning;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,9 +1,8 @@
|
||||||
package org.wikipedia.edit;
|
package fr.free.nrw.commons.wikidata.model.edit;
|
||||||
|
|
||||||
import android.os.Parcel;
|
import android.os.Parcel;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
|
import fr.free.nrw.commons.wikidata.model.BaseModel;
|
||||||
import org.wikipedia.model.BaseModel;
|
|
||||||
|
|
||||||
public abstract class EditResult extends BaseModel implements Parcelable {
|
public abstract class EditResult extends BaseModel implements Parcelable {
|
||||||
private final String result;
|
private final String result;
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package org.wikipedia.gallery;
|
package fr.free.nrw.commons.wikidata.model.gallery;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
|
@ -7,7 +7,7 @@ import com.google.gson.annotations.SerializedName;
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
public class ExtMetadata {
|
public class ExtMetadata {
|
||||||
@SerializedName("DateTime") @Nullable private Values dateTime;
|
@SerializedName("DateTime") @Nullable private Values dateTime;
|
||||||
@SerializedName("ObjectName") @Nullable private Values objectName;
|
@SerializedName("ObjectName") @Nullable private Values objectName;
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package org.wikipedia.gallery;
|
package fr.free.nrw.commons.wikidata.model.gallery;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
|
@ -12,7 +12,7 @@ import java.io.Serializable;
|
||||||
/**
|
/**
|
||||||
* Gson POJO for a standard image info object as returned by the API ImageInfo module
|
* Gson POJO for a standard image info object as returned by the API ImageInfo module
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unused")
|
|
||||||
public class ImageInfo implements Serializable {
|
public class ImageInfo implements Serializable {
|
||||||
private int size;
|
private int size;
|
||||||
private int width;
|
private int width;
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package org.wikipedia.gallery;
|
package fr.free.nrw.commons.wikidata.model.gallery;
|
||||||
|
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
|
|
@ -10,7 +10,7 @@ import java.util.List;
|
||||||
* Gson POJO for a standard video info object as returned by the API VideoInfo module
|
* Gson POJO for a standard video info object as returned by the API VideoInfo module
|
||||||
*/
|
*/
|
||||||
public class VideoInfo extends ImageInfo {
|
public class VideoInfo extends ImageInfo {
|
||||||
@SuppressWarnings("unused") @Nullable private List<String> codecs;
|
@Nullable private List<String> codecs;
|
||||||
@SuppressWarnings("unused,NullableProblems") @Nullable private String name;
|
@SuppressWarnings("unused,NullableProblems") @Nullable private String name;
|
||||||
@SuppressWarnings("unused,NullableProblems") @Nullable @SerializedName("short_name") private String shortName;
|
@SuppressWarnings("unused,NullableProblems") @Nullable @SerializedName("short_name") private String shortName;
|
||||||
}
|
}
|
||||||
|
|
@ -0,0 +1,190 @@
|
||||||
|
package fr.free.nrw.commons.wikidata.model.notifications;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
|
import com.google.gson.JsonElement;
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import com.google.gson.annotations.SerializedName;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import fr.free.nrw.commons.utils.DateUtil;
|
||||||
|
import fr.free.nrw.commons.wikidata.GsonUtil;
|
||||||
|
|
||||||
|
import java.text.ParseException;
|
||||||
|
import java.util.Date;
|
||||||
|
import timber.log.Timber;
|
||||||
|
|
||||||
|
public class Notification {
|
||||||
|
@Nullable private String wiki;
|
||||||
|
private long id;
|
||||||
|
@Nullable private String type;
|
||||||
|
@Nullable private String category;
|
||||||
|
|
||||||
|
@Nullable private Title title;
|
||||||
|
@Nullable private Timestamp timestamp;
|
||||||
|
@SerializedName("*") @Nullable private Contents contents;
|
||||||
|
|
||||||
|
@NonNull public String wiki() {
|
||||||
|
return StringUtils.defaultString(wiki);
|
||||||
|
}
|
||||||
|
|
||||||
|
public long id() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(final long id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long key() {
|
||||||
|
return id + wiki().hashCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull public String type() {
|
||||||
|
return StringUtils.defaultString(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable public Title title() {
|
||||||
|
return title;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable public Contents getContents() {
|
||||||
|
return contents;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setContents(@Nullable final Contents contents) {
|
||||||
|
this.contents = contents;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull public Date getTimestamp() {
|
||||||
|
return timestamp != null ? timestamp.date() : new Date();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTimestamp(@Nullable final Timestamp timestamp) {
|
||||||
|
this.timestamp = timestamp;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull String getUtcIso8601() {
|
||||||
|
return StringUtils.defaultString(timestamp != null ? timestamp.utciso8601 : null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isFromWikidata() {
|
||||||
|
return wiki().equals("wikidatawiki");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public String toString() {
|
||||||
|
return Long.toString(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Title {
|
||||||
|
@Nullable private String full;
|
||||||
|
@Nullable private String text;
|
||||||
|
|
||||||
|
@NonNull public String text() {
|
||||||
|
return StringUtils.defaultString(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull public String full() {
|
||||||
|
return StringUtils.defaultString(full);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Timestamp {
|
||||||
|
@Nullable private String utciso8601;
|
||||||
|
|
||||||
|
public void setUtciso8601(@Nullable final String utciso8601) {
|
||||||
|
this.utciso8601 = utciso8601;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date date() {
|
||||||
|
try {
|
||||||
|
return DateUtil.iso8601DateParse(utciso8601);
|
||||||
|
} catch (ParseException e) {
|
||||||
|
Timber.e(e);
|
||||||
|
return new Date();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Link {
|
||||||
|
@Nullable private String url;
|
||||||
|
@Nullable private String label;
|
||||||
|
@Nullable private String tooltip;
|
||||||
|
@Nullable private String description;
|
||||||
|
@Nullable private String icon;
|
||||||
|
|
||||||
|
@NonNull public String getUrl() {
|
||||||
|
return StringUtils.defaultString(url);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUrl(@Nullable final String url) {
|
||||||
|
this.url = url;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull public String getTooltip() {
|
||||||
|
return StringUtils.defaultString(tooltip);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull public String getLabel() {
|
||||||
|
return StringUtils.defaultString(label);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull public String getIcon() {
|
||||||
|
return StringUtils.defaultString(icon);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Links {
|
||||||
|
@Nullable private JsonElement primary;
|
||||||
|
private Link primaryLink;
|
||||||
|
|
||||||
|
public void setPrimary(@Nullable final JsonElement primary) {
|
||||||
|
this.primary = primary;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable public Link getPrimary() {
|
||||||
|
if (primary == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (primaryLink == null && primary instanceof JsonObject) {
|
||||||
|
primaryLink = GsonUtil.getDefaultGson().fromJson(primary, Link.class);
|
||||||
|
}
|
||||||
|
return primaryLink;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Contents {
|
||||||
|
@Nullable private String header;
|
||||||
|
@Nullable private String compactHeader;
|
||||||
|
@Nullable private String body;
|
||||||
|
@Nullable private String icon;
|
||||||
|
@Nullable private Links links;
|
||||||
|
|
||||||
|
@NonNull public String getHeader() {
|
||||||
|
return StringUtils.defaultString(header);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull public String getCompactHeader() {
|
||||||
|
return StringUtils.defaultString(compactHeader);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCompactHeader(@Nullable final String compactHeader) {
|
||||||
|
this.compactHeader = compactHeader;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull public String getBody() {
|
||||||
|
return StringUtils.defaultString(body);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable public Links getLinks() {
|
||||||
|
return links;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLinks(@Nullable final Links links) {
|
||||||
|
this.links = links;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package org.wikipedia.page;
|
package fr.free.nrw.commons.wikidata.model.page;
|
||||||
|
|
||||||
import android.location.Location;
|
import android.location.Location;
|
||||||
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package org.wikipedia.page;
|
package fr.free.nrw.commons.wikidata.model.page;
|
||||||
|
|
||||||
import android.location.Location;
|
import android.location.Location;
|
||||||
|
|
||||||
|
|
@ -1,18 +1,9 @@
|
||||||
package org.wikipedia.page;
|
package fr.free.nrw.commons.wikidata.model.page;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import fr.free.nrw.commons.wikidata.model.EnumCode;
|
||||||
import org.wikipedia.dataclient.WikiSite;
|
import fr.free.nrw.commons.wikidata.model.EnumCodeMap;
|
||||||
import org.wikipedia.language.AppLanguageLookUpTable;
|
|
||||||
import org.wikipedia.model.CodeEnum;
|
|
||||||
import org.wikipedia.model.EnumCode;
|
|
||||||
import org.wikipedia.model.EnumCodeMap;
|
|
||||||
import org.wikipedia.staticdata.FileAliasData;
|
|
||||||
import org.wikipedia.staticdata.SpecialAliasData;
|
|
||||||
|
|
||||||
import java.util.Locale;
|
|
||||||
|
|
||||||
/** An enumeration describing the different possible namespace codes. Do not attempt to use this
|
/** An enumeration describing the different possible namespace codes. Do not attempt to use this
|
||||||
* class to preserve URL path information such as Talk: or User: or localization.
|
* class to preserve URL path information such as Talk: or User: or localization.
|
||||||
|
|
@ -146,48 +137,11 @@ public enum Namespace implements EnumCode {
|
||||||
GADGET_DEFINITION_TALK(2303),
|
GADGET_DEFINITION_TALK(2303),
|
||||||
TOPIC(2600);
|
TOPIC(2600);
|
||||||
|
|
||||||
public static final CodeEnum<Namespace> CODE_ENUM = Namespace::of;
|
|
||||||
|
|
||||||
private static final int TALK_MASK = 0x1;
|
private static final int TALK_MASK = 0x1;
|
||||||
private static final EnumCodeMap<Namespace> MAP = new EnumCodeMap<>(Namespace.class);
|
private static final EnumCodeMap<Namespace> MAP = new EnumCodeMap<>(Namespace.class);
|
||||||
|
|
||||||
private final int code;
|
private final int code;
|
||||||
|
|
||||||
/** Warning: this method returns an English translation for the current namespace. */
|
|
||||||
@Deprecated
|
|
||||||
@Nullable
|
|
||||||
public String toLegacyString() {
|
|
||||||
String string = this == MAIN ? null : this.name();
|
|
||||||
if (string != null) {
|
|
||||||
string = StringUtils.capitalize(string.toLowerCase(Locale.ENGLISH));
|
|
||||||
}
|
|
||||||
return string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Warning: this method is localized only for File and Special pages. */
|
|
||||||
@Deprecated @NonNull public static Namespace fromLegacyString(@NonNull WikiSite wiki,
|
|
||||||
@Nullable String name) {
|
|
||||||
if (FileAliasData.valueFor(wiki.languageCode()).equals(name)
|
|
||||||
|| FileAliasData.valueFor(AppLanguageLookUpTable.FALLBACK_LANGUAGE_CODE).equals(name)) {
|
|
||||||
return Namespace.FILE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (SpecialAliasData.valueFor(wiki.languageCode()).equals(name)
|
|
||||||
|| SpecialAliasData.valueFor(AppLanguageLookUpTable.FALLBACK_LANGUAGE_CODE).equals(name)) {
|
|
||||||
return Namespace.SPECIAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
// This works for the links provided by the app itself since they always have the English
|
|
||||||
// version of the namespace.
|
|
||||||
// TODO: It would be nice to add a mapping table, as is done for File and Special,
|
|
||||||
// so we can also handle links passed to the app.
|
|
||||||
if (name != null && name.contains("Talk")) {
|
|
||||||
return Namespace.TALK;
|
|
||||||
}
|
|
||||||
|
|
||||||
return Namespace.MAIN;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
public static Namespace of(int code) {
|
public static Namespace of(int code) {
|
||||||
return MAP.get(code);
|
return MAP.get(code);
|
||||||
|
|
@ -1,22 +1,16 @@
|
||||||
package org.wikipedia.page;
|
package fr.free.nrw.commons.wikidata.model.page;
|
||||||
|
|
||||||
import android.location.Location;
|
import android.location.Location;
|
||||||
import android.os.Parcel;
|
import android.os.Parcel;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
import org.wikipedia.AppAdapter;
|
|
||||||
import org.wikipedia.dataclient.page.PageLeadProperties;
|
|
||||||
|
|
||||||
import java.text.ParseException;
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
import static org.apache.commons.lang3.StringUtils.defaultString;
|
import static org.apache.commons.lang3.StringUtils.defaultString;
|
||||||
import static org.wikipedia.util.DateUtil.iso8601DateParse;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Immutable class that contains metadata associated with a PageTitle.
|
* Immutable class that contains metadata associated with a PageTitle.
|
||||||
|
|
@ -45,108 +39,10 @@ public class PageProperties implements Parcelable {
|
||||||
*/
|
*/
|
||||||
private final boolean canEdit;
|
private final boolean canEdit;
|
||||||
|
|
||||||
/**
|
|
||||||
* Side note: Should later be moved out of this class but I like the similarities with
|
|
||||||
* PageProperties(JSONObject).
|
|
||||||
*/
|
|
||||||
public PageProperties(PageLeadProperties core) {
|
|
||||||
pageId = core.getId();
|
|
||||||
namespace = core.getNamespace();
|
|
||||||
revisionId = core.getRevision();
|
|
||||||
displayTitleText = defaultString(core.getDisplayTitle());
|
|
||||||
titlePronunciationUrl = core.getTitlePronunciationUrl();
|
|
||||||
geo = core.getGeo();
|
|
||||||
editProtectionStatus = core.getFirstAllowedEditorRole();
|
|
||||||
languageCount = core.getLanguageCount();
|
|
||||||
|
|
||||||
// todo: don't hardcode this here
|
|
||||||
leadImageUrl = core.getLeadImageUrl(AppAdapter.get().getDesiredLeadImageDp());
|
|
||||||
|
|
||||||
leadImageName = core.getLeadImageFileName();
|
|
||||||
lastModified = new Date();
|
|
||||||
String lastModifiedText = core.getLastModified();
|
|
||||||
if (lastModifiedText != null) {
|
|
||||||
try {
|
|
||||||
lastModified.setTime(iso8601DateParse(lastModifiedText).getTime());
|
|
||||||
} catch (ParseException e) {
|
|
||||||
Log.d("PageProperties", "Failed to parse date: " + lastModifiedText);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// assume formatversion=2 is used so we get real booleans from the API
|
|
||||||
canEdit = core.isEditable();
|
|
||||||
|
|
||||||
isMainPage = core.isMainPage();
|
|
||||||
isDisambiguationPage = core.isDisambiguation();
|
|
||||||
wikiBaseItem = core.getWikiBaseItem();
|
|
||||||
descriptionSource = core.getDescriptionSource();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructor to be used when building a Page from a compilation. Initializes the title and
|
|
||||||
* namespace fields, and explicitly disables editing. All other fields initialized to defaults.
|
|
||||||
* @param title Title to which these properties apply.
|
|
||||||
*/
|
|
||||||
public PageProperties(@NonNull PageTitle title, boolean isMainPage) {
|
|
||||||
pageId = 0;
|
|
||||||
namespace = title.namespace();
|
|
||||||
revisionId = 0;
|
|
||||||
displayTitleText = title.getDisplayText();
|
|
||||||
titlePronunciationUrl = null;
|
|
||||||
geo = null;
|
|
||||||
editProtectionStatus = "";
|
|
||||||
languageCount = 1;
|
|
||||||
leadImageUrl = null;
|
|
||||||
leadImageName = "";
|
|
||||||
lastModified = new Date();
|
|
||||||
canEdit = false;
|
|
||||||
this.isMainPage = isMainPage;
|
|
||||||
isDisambiguationPage = false;
|
|
||||||
wikiBaseItem = null;
|
|
||||||
descriptionSource = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getPageId() {
|
public int getPageId() {
|
||||||
return pageId;
|
return pageId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull public Namespace getNamespace() {
|
|
||||||
return namespace;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getRevisionId() {
|
|
||||||
return revisionId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Date getLastModified() {
|
|
||||||
return lastModified;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDisplayTitle() {
|
|
||||||
return displayTitleText;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
public String getTitlePronunciationUrl() {
|
|
||||||
return titlePronunciationUrl;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
public Location getGeo() {
|
|
||||||
return geo;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getEditProtectionStatus() {
|
|
||||||
return editProtectionStatus;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getLanguageCount() {
|
|
||||||
return languageCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean canEdit() {
|
|
||||||
return canEdit;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isMainPage() {
|
public boolean isMainPage() {
|
||||||
return isMainPage;
|
return isMainPage;
|
||||||
}
|
}
|
||||||
|
|
@ -155,30 +51,6 @@ public class PageProperties implements Parcelable {
|
||||||
return isDisambiguationPage;
|
return isDisambiguationPage;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return Nullable URL with no scheme. For example, foo.bar.com/ instead of
|
|
||||||
* http://foo.bar.com/.
|
|
||||||
*/
|
|
||||||
@Nullable
|
|
||||||
public String getLeadImageUrl() {
|
|
||||||
return leadImageUrl;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
public String getLeadImageName() {
|
|
||||||
return leadImageName;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
public String getWikiBaseItem() {
|
|
||||||
return wikiBaseItem;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
public String getDescriptionSource() {
|
|
||||||
return descriptionSource;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int describeContents() {
|
public int describeContents() {
|
||||||
return 0;
|
return 0;
|
||||||
|
|
@ -1,23 +1,19 @@
|
||||||
package org.wikipedia.page;
|
package fr.free.nrw.commons.wikidata.model.page;
|
||||||
|
|
||||||
import android.os.Parcel;
|
import android.os.Parcel;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
import com.google.gson.annotations.SerializedName;
|
import com.google.gson.annotations.SerializedName;
|
||||||
|
import fr.free.nrw.commons.wikidata.model.WikiSite;
|
||||||
import org.wikipedia.dataclient.WikiSite;
|
|
||||||
import org.wikipedia.util.StringUtil;
|
|
||||||
|
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
|
import java.net.URLDecoder;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
|
import java.text.Normalizer;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
import timber.log.Timber;
|
||||||
import static org.wikipedia.util.UriUtil.decodeURL;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents certain vital information about a page, including the title, namespace,
|
* Represents certain vital information about a page, including the title, namespace,
|
||||||
|
|
@ -157,18 +153,23 @@ public class PageTitle implements Parcelable {
|
||||||
this.properties = properties;
|
this.properties = properties;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
/**
|
||||||
public String getNamespace() {
|
* Decodes a URL-encoded string into its UTF-8 equivalent. If the string cannot be decoded, the
|
||||||
return namespace;
|
* original string is returned.
|
||||||
}
|
* @param url The URL-encoded string that you wish to decode.
|
||||||
|
* @return The decoded string, or the input string if the decoding failed.
|
||||||
@NonNull public Namespace namespace() {
|
*/
|
||||||
if (properties != null) {
|
@NonNull private String decodeURL(@NonNull String url) {
|
||||||
return properties.getNamespace();
|
try {
|
||||||
|
return URLDecoder.decode(url, "UTF-8");
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
// Swallow IllegalArgumentException (can happen with malformed encoding), and just
|
||||||
|
// return the original string.
|
||||||
|
Timber.d("URL decoding failed. String was: %s", url);
|
||||||
|
return url;
|
||||||
|
} catch (UnsupportedEncodingException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Properties has the accurate namespace but it doesn't exist. Guess based on title.
|
|
||||||
return Namespace.fromLegacyString(wiki, namespace);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull public WikiSite getWikiSite() {
|
@NonNull public WikiSite getWikiSite() {
|
||||||
|
|
@ -257,34 +258,11 @@ public class PageTitle implements Parcelable {
|
||||||
public String getPrefixedText() {
|
public String getPrefixedText() {
|
||||||
|
|
||||||
// TODO: find a better way to check if the namespace is a ISO Alpha2 Code (two digits country code)
|
// TODO: find a better way to check if the namespace is a ISO Alpha2 Code (two digits country code)
|
||||||
return namespace == null ? getText() : StringUtil.addUnderscores(namespace) + ":" + getText();
|
return namespace == null ? getText() : addUnderscores(namespace) + ":" + getText();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private String addUnderscores(@NonNull String text) {
|
||||||
* Check if the Title represents a File:
|
return text.replace(" ", "_");
|
||||||
*
|
|
||||||
* @return true if it is a File page, false if not
|
|
||||||
*/
|
|
||||||
public boolean isFilePage() {
|
|
||||||
return namespace().file();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check if the Title represents a special page
|
|
||||||
*
|
|
||||||
* @return true if it is a special page, false if not
|
|
||||||
*/
|
|
||||||
public boolean isSpecial() {
|
|
||||||
return namespace().special();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check if the Title represents a talk page
|
|
||||||
*
|
|
||||||
* @return true if it is a talk page, false if not
|
|
||||||
*/
|
|
||||||
public boolean isTalkPage() {
|
|
||||||
return namespace().talk();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void writeToParcel(Parcel parcel, int flags) {
|
@Override public void writeToParcel(Parcel parcel, int flags) {
|
||||||
|
|
@ -305,7 +283,19 @@ public class PageTitle implements Parcelable {
|
||||||
|
|
||||||
PageTitle other = (PageTitle)o;
|
PageTitle other = (PageTitle)o;
|
||||||
// Not using namespace directly since that can be null
|
// Not using namespace directly since that can be null
|
||||||
return StringUtil.normalizedEquals(other.getPrefixedText(), getPrefixedText()) && other.wiki.equals(wiki);
|
return normalizedEquals(other.getPrefixedText(), getPrefixedText()) && other.wiki.equals(wiki);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Compare two strings based on their normalized form, using the Unicode Normalization Form C.
|
||||||
|
// This should be used when comparing or verifying strings that will be exchanged between
|
||||||
|
// different platforms (iOS, desktop, etc) that may encode strings using inconsistent
|
||||||
|
// composition, especially for accents, diacritics, etc.
|
||||||
|
private boolean normalizedEquals(@Nullable String str1, @Nullable String str2) {
|
||||||
|
if (str1 == null || str2 == null) {
|
||||||
|
return (str1 == null && str2 == null);
|
||||||
|
}
|
||||||
|
return Normalizer.normalize(str1, Normalizer.Form.NFC)
|
||||||
|
.equals(Normalizer.normalize(str2, Normalizer.Form.NFC));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public int hashCode() {
|
@Override public int hashCode() {
|
||||||
|
|
@ -1,11 +1,11 @@
|
||||||
package org.wikipedia.dataclient.mwapi;
|
package fr.free.nrw.commons.wikidata.mwapi;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
public class ImageDetails {
|
public class ImageDetails {
|
||||||
|
|
||||||
@SuppressWarnings("unused") private String name;
|
private String name;
|
||||||
@SuppressWarnings("unused") private String title;
|
private String title;
|
||||||
|
|
||||||
@NonNull public String getName() {
|
@NonNull public String getName() {
|
||||||
return name;
|
return name;
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package org.wikipedia.dataclient.mwapi;
|
package fr.free.nrw.commons.wikidata.mwapi;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
|
@ -12,33 +12,17 @@ import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
public class ListUserResponse {
|
public class ListUserResponse {
|
||||||
@SerializedName("name") @Nullable private String name;
|
@SerializedName("name") @Nullable private String name;
|
||||||
private long userid;
|
private long userid;
|
||||||
@Nullable private List<String> groups;
|
@Nullable private List<String> groups;
|
||||||
@Nullable private String cancreate;
|
|
||||||
@Nullable private List<UserResponseCreateError> cancreateerror;
|
|
||||||
|
|
||||||
@Nullable public String name() {
|
@Nullable public String name() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean canCreate() {
|
|
||||||
return cancreate != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull public Set<String> getGroups() {
|
@NonNull public Set<String> getGroups() {
|
||||||
return groups != null ? new ArraySet<>(groups) : Collections.emptySet();
|
return groups != null ? new ArraySet<>(groups) : Collections.emptySet();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class UserResponseCreateError {
|
|
||||||
@Nullable private String message;
|
|
||||||
@Nullable private String code;
|
|
||||||
@Nullable private String type;
|
|
||||||
|
|
||||||
@NonNull public String message() {
|
|
||||||
return StringUtils.defaultString(message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
@ -1,13 +1,12 @@
|
||||||
package org.wikipedia.dataclient.mwapi;
|
package fr.free.nrw.commons.wikidata.mwapi;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class MwException extends RuntimeException {
|
public class MwException extends RuntimeException {
|
||||||
@SuppressWarnings("unused") @Nullable private final MwServiceError error;
|
@Nullable private final MwServiceError error;
|
||||||
|
|
||||||
@SuppressWarnings("unused") @Nullable private final List<MwServiceError> errors;
|
@Nullable private final List<MwServiceError> errors;
|
||||||
|
|
||||||
public MwException(@Nullable MwServiceError error,
|
public MwException(@Nullable MwServiceError error,
|
||||||
@Nullable final List<MwServiceError> errors) {
|
@Nullable final List<MwServiceError> errors) {
|
||||||
|
|
@ -15,11 +14,6 @@ public class MwException extends RuntimeException {
|
||||||
this.errors = errors;
|
this.errors = errors;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
|
||||||
public List<MwServiceError> getErrors() {
|
|
||||||
return errors;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getErrorCode() {
|
public String getErrorCode() {
|
||||||
if(error!=null) {
|
if(error!=null) {
|
||||||
return error.getCode();
|
return error.getCode();
|
||||||
|
|
@ -1,19 +1,14 @@
|
||||||
package org.wikipedia.dataclient.mwapi;
|
package fr.free.nrw.commons.wikidata.mwapi;
|
||||||
|
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
public class MwPostResponse extends MwResponse {
|
public class MwPostResponse extends MwResponse {
|
||||||
@Nullable @SuppressWarnings("unused") private String options;
|
private int success;
|
||||||
@SuppressWarnings("unused") private int success;
|
|
||||||
|
|
||||||
public boolean success(@Nullable String result) {
|
public boolean success(@Nullable String result) {
|
||||||
return "success".equals(result);
|
return "success".equals(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable public String getOptions() {
|
|
||||||
return options;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getSuccessVal() {
|
public int getSuccessVal() {
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
@ -0,0 +1,229 @@
|
||||||
|
package fr.free.nrw.commons.wikidata.mwapi;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
|
import com.google.gson.annotations.SerializedName;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import fr.free.nrw.commons.wikidata.model.gallery.ImageInfo;
|
||||||
|
import fr.free.nrw.commons.wikidata.model.BaseModel;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A class representing a standard page object as returned by the MediaWiki API.
|
||||||
|
*/
|
||||||
|
public class MwQueryPage extends BaseModel {
|
||||||
|
private int pageid;
|
||||||
|
private int index;
|
||||||
|
@NonNull private String title;
|
||||||
|
@NonNull private CategoryInfo categoryinfo;
|
||||||
|
@Nullable private List<Revision> revisions;
|
||||||
|
@SerializedName("fileusage") @Nullable private List<FileUsage> fileUsages;
|
||||||
|
@SerializedName("globalusage") @Nullable private List<GlobalUsage> globalUsages;
|
||||||
|
@Nullable private List<Coordinates> coordinates;
|
||||||
|
@Nullable private List<Category> categories;
|
||||||
|
@Nullable private Thumbnail thumbnail;
|
||||||
|
@Nullable private String description;
|
||||||
|
@SerializedName("imageinfo") @Nullable private List<ImageInfo> imageInfo;
|
||||||
|
@Nullable private String redirectFrom;
|
||||||
|
@Nullable private String convertedFrom;
|
||||||
|
@Nullable private String convertedTo;
|
||||||
|
|
||||||
|
@NonNull public String title() {
|
||||||
|
return title;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull public CategoryInfo categoryInfo() {
|
||||||
|
return categoryinfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int index() {
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable public List<Revision> revisions() {
|
||||||
|
return revisions;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable public List<Category> categories() {
|
||||||
|
return categories;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable public List<Coordinates> coordinates() {
|
||||||
|
// TODO: Handle null values in lists during deserialization, perhaps with a new
|
||||||
|
// @RequiredElements annotation and corresponding TypeAdapter
|
||||||
|
if (coordinates != null) {
|
||||||
|
coordinates.removeAll(Collections.singleton(null));
|
||||||
|
}
|
||||||
|
return coordinates;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int pageId() {
|
||||||
|
return pageid;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable public String thumbUrl() {
|
||||||
|
return thumbnail != null ? thumbnail.source() : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable public String description() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable public ImageInfo imageInfo() {
|
||||||
|
return imageInfo != null ? imageInfo.get(0) : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void redirectFrom(@Nullable String from) {
|
||||||
|
redirectFrom = from;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void convertedFrom(@Nullable String from) {
|
||||||
|
convertedFrom = from;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void convertedTo(@Nullable String to) {
|
||||||
|
convertedTo = to;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void appendTitleFragment(@Nullable String fragment) {
|
||||||
|
title += "#" + fragment;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean checkWhetherFileIsUsedInWikis() {
|
||||||
|
if (globalUsages != null && globalUsages.size() > 0) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fileUsages == null || fileUsages.size() == 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
final int totalCount = fileUsages.size();
|
||||||
|
|
||||||
|
/* Ignore usage under https://commons.wikimedia.org/wiki/User:Didym/Mobile_upload/
|
||||||
|
which has been a gallery of all of our uploads since 2014 */
|
||||||
|
for (final FileUsage fileUsage : fileUsages) {
|
||||||
|
if ( ! fileUsage.title().contains("User:Didym/Mobile upload")) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Revision {
|
||||||
|
@SerializedName("revid") private long revisionId;
|
||||||
|
private String user;
|
||||||
|
@SerializedName("contentformat") @NonNull private String contentFormat;
|
||||||
|
@SerializedName("contentmodel") @NonNull private String contentModel;
|
||||||
|
@SerializedName("timestamp") @NonNull private String timeStamp;
|
||||||
|
@NonNull private String content;
|
||||||
|
|
||||||
|
@NonNull public String content() {
|
||||||
|
return content;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull public String timeStamp() {
|
||||||
|
return StringUtils.defaultString(timeStamp);
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getRevisionId() {
|
||||||
|
return revisionId;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
public String getUser() {
|
||||||
|
return StringUtils.defaultString(user);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Coordinates {
|
||||||
|
@Nullable private Double lat;
|
||||||
|
@Nullable private Double lon;
|
||||||
|
|
||||||
|
@Nullable public Double lat() {
|
||||||
|
return lat;
|
||||||
|
}
|
||||||
|
@Nullable public Double lon() {
|
||||||
|
return lon;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class CategoryInfo {
|
||||||
|
private boolean hidden;
|
||||||
|
private int size;
|
||||||
|
private int pages;
|
||||||
|
private int files;
|
||||||
|
private int subcats;
|
||||||
|
public boolean isHidden() {
|
||||||
|
return hidden;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static class Thumbnail {
|
||||||
|
private String source;
|
||||||
|
private int width;
|
||||||
|
private int height;
|
||||||
|
String source() {
|
||||||
|
return source;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class GlobalUsage {
|
||||||
|
@SerializedName("title") private String title;
|
||||||
|
@SerializedName("wiki")private String wiki;
|
||||||
|
@SerializedName("url") private String url;
|
||||||
|
|
||||||
|
public String getTitle() {
|
||||||
|
return title;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getWiki() {
|
||||||
|
return wiki;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUrl() {
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class FileUsage {
|
||||||
|
@SerializedName("pageid") private int pageid;
|
||||||
|
@SerializedName("ns") private int ns;
|
||||||
|
@SerializedName("title") private String title;
|
||||||
|
|
||||||
|
public int pageId() {
|
||||||
|
return pageid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int ns() {
|
||||||
|
return ns;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String title() {
|
||||||
|
return title;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Category {
|
||||||
|
private int ns;
|
||||||
|
@SuppressWarnings("unused,NullableProblems") @Nullable private String title;
|
||||||
|
private boolean hidden;
|
||||||
|
|
||||||
|
public int ns() {
|
||||||
|
return ns;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull public String title() {
|
||||||
|
return StringUtils.defaultString(title);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hidden() {
|
||||||
|
return hidden;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,26 @@
|
||||||
|
package fr.free.nrw.commons.wikidata.mwapi;
|
||||||
|
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
|
import com.google.gson.annotations.SerializedName;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class MwQueryResponse extends MwResponse {
|
||||||
|
|
||||||
|
@SerializedName("continue") @Nullable private Map<String, String> continuation;
|
||||||
|
|
||||||
|
@SerializedName("query") @Nullable private MwQueryResult query;
|
||||||
|
|
||||||
|
@Nullable public Map<String, String> continuation() {
|
||||||
|
return continuation;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable public MwQueryResult query() {
|
||||||
|
return query;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean success() {
|
||||||
|
return query != null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,27 +1,22 @@
|
||||||
package org.wikipedia.dataclient.mwapi;
|
package fr.free.nrw.commons.wikidata.mwapi;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
import com.google.gson.annotations.SerializedName;
|
import com.google.gson.annotations.SerializedName;
|
||||||
|
|
||||||
|
import fr.free.nrw.commons.wikidata.json.PostProcessingTypeAdapter;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.wikipedia.dataclient.WikiSite;
|
import fr.free.nrw.commons.wikidata.model.gallery.ImageInfo;
|
||||||
import org.wikipedia.gallery.ImageInfo;
|
import fr.free.nrw.commons.wikidata.model.BaseModel;
|
||||||
import org.wikipedia.gallery.VideoInfo;
|
import fr.free.nrw.commons.wikidata.model.notifications.Notification;
|
||||||
import org.wikipedia.json.PostProcessingTypeAdapter;
|
|
||||||
import org.wikipedia.model.BaseModel;
|
|
||||||
import org.wikipedia.notifications.Notification;
|
|
||||||
import org.wikipedia.page.PageTitle;
|
|
||||||
import org.wikipedia.settings.SiteInfo;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
public class MwQueryResult extends BaseModel implements PostProcessingTypeAdapter.PostProcessable {
|
public class MwQueryResult extends BaseModel implements PostProcessingTypeAdapter.PostProcessable {
|
||||||
@SerializedName("pages") @Nullable private List<MwQueryPage> pages;
|
@SerializedName("pages") @Nullable private List<MwQueryPage> pages;
|
||||||
@Nullable private List<Redirect> redirects;
|
@Nullable private List<Redirect> redirects;
|
||||||
|
|
@ -29,17 +24,8 @@ public class MwQueryResult extends BaseModel implements PostProcessingTypeAdapte
|
||||||
@SerializedName("userinfo") private UserInfo userInfo;
|
@SerializedName("userinfo") private UserInfo userInfo;
|
||||||
@Nullable private List<ListUserResponse> users;
|
@Nullable private List<ListUserResponse> users;
|
||||||
@Nullable private Tokens tokens;
|
@Nullable private Tokens tokens;
|
||||||
@SerializedName("authmanagerinfo") @Nullable private MwAuthManagerInfo amInfo;
|
|
||||||
@Nullable private MarkReadResponse echomarkread;
|
|
||||||
@Nullable private MarkReadResponse echomarkseen;
|
|
||||||
@Nullable private NotificationList notifications;
|
@Nullable private NotificationList notifications;
|
||||||
@Nullable private Map<String, Notification.UnreadNotificationWikiItem> unreadnotificationpages;
|
|
||||||
@SerializedName("general") @Nullable private SiteInfo generalSiteInfo;
|
|
||||||
@SerializedName("wikimediaeditortaskscounts") @Nullable private EditorTaskCounts editorTaskCounts;
|
|
||||||
@SerializedName("allimages") @Nullable private List<ImageDetails> allImages;
|
@SerializedName("allimages") @Nullable private List<ImageDetails> allImages;
|
||||||
@SerializedName("geosearch") @Nullable private List<GeoSearchItem> geoSearch;
|
|
||||||
@Nullable private List<MwQueryLogEvent> logevents;
|
|
||||||
|
|
||||||
|
|
||||||
@Nullable public List<MwQueryPage> pages() {
|
@Nullable public List<MwQueryPage> pages() {
|
||||||
return pages;
|
return pages;
|
||||||
|
|
@ -57,11 +43,6 @@ public class MwQueryResult extends BaseModel implements PostProcessingTypeAdapte
|
||||||
return allImages == null ? Collections.emptyList() : allImages;
|
return allImages == null ? Collections.emptyList() : allImages;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
|
||||||
public List<GeoSearchItem> geoSearch() {
|
|
||||||
return geoSearch == null ? Collections.emptyList() : geoSearch;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable public UserInfo userInfo() {
|
@Nullable public UserInfo userInfo() {
|
||||||
return userInfo;
|
return userInfo;
|
||||||
}
|
}
|
||||||
|
|
@ -70,10 +51,6 @@ public class MwQueryResult extends BaseModel implements PostProcessingTypeAdapte
|
||||||
return tokens != null ? tokens.csrf() : null;
|
return tokens != null ? tokens.csrf() : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable public String createAccountToken() {
|
|
||||||
return tokens != null ? tokens.createAccount() : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable public String loginToken() {
|
@Nullable public String loginToken() {
|
||||||
return tokens != null ? tokens.login() : null;
|
return tokens != null ? tokens.login() : null;
|
||||||
}
|
}
|
||||||
|
|
@ -82,26 +59,6 @@ public class MwQueryResult extends BaseModel implements PostProcessingTypeAdapte
|
||||||
return notifications;
|
return notifications;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable public Map<String, Notification.UnreadNotificationWikiItem> unreadNotificationWikis() {
|
|
||||||
return unreadnotificationpages;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable public MarkReadResponse getEchoMarkSeen() {
|
|
||||||
return echomarkseen;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable public String captchaId() {
|
|
||||||
String captchaId = null;
|
|
||||||
if (amInfo != null) {
|
|
||||||
for (MwAuthManagerInfo.Request request : amInfo.requests()) {
|
|
||||||
if ("CaptchaAuthenticationRequest".equals(request.id())) {
|
|
||||||
captchaId = request.fields().get("captchaId").value();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return captchaId;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable public ListUserResponse getUserResponse(@NonNull String userName) {
|
@Nullable public ListUserResponse getUserResponse(@NonNull String userName) {
|
||||||
if (users != null) {
|
if (users != null) {
|
||||||
for (ListUserResponse user : users) {
|
for (ListUserResponse user : users) {
|
||||||
|
|
@ -126,52 +83,6 @@ public class MwQueryResult extends BaseModel implements PostProcessingTypeAdapte
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull public Map<String, VideoInfo> videos() {
|
|
||||||
Map<String, VideoInfo> result = new HashMap<>();
|
|
||||||
if (pages != null) {
|
|
||||||
for (MwQueryPage page : pages) {
|
|
||||||
if (page.videoInfo() != null) {
|
|
||||||
result.put(page.title(), page.videoInfo());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull public List<PageTitle> langLinks() {
|
|
||||||
List<PageTitle> result = new ArrayList<>();
|
|
||||||
if (pages == null || pages.isEmpty() || pages.get(0).langLinks() == null) {
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
// noinspection ConstantConditions
|
|
||||||
for (MwQueryPage.LangLink link : pages.get(0).langLinks()) {
|
|
||||||
PageTitle title = new PageTitle(link.title(), WikiSite.forLanguageCode(link.lang()));
|
|
||||||
result.add(title);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull public List<NearbyPage> nearbyPages(@NonNull WikiSite wiki) {
|
|
||||||
List<NearbyPage> result = new ArrayList<>();
|
|
||||||
if (pages != null) {
|
|
||||||
for (MwQueryPage page : pages) {
|
|
||||||
NearbyPage nearbyPage = new NearbyPage(page, wiki);
|
|
||||||
if (nearbyPage.getLocation() != null) {
|
|
||||||
result.add(nearbyPage);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable public SiteInfo siteInfo() {
|
|
||||||
return generalSiteInfo;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable public EditorTaskCounts editorTaskCounts() {
|
|
||||||
return editorTaskCounts;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void postProcess() {
|
public void postProcess() {
|
||||||
resolveConvertedTitles();
|
resolveConvertedTitles();
|
||||||
|
|
@ -212,16 +123,11 @@ public class MwQueryResult extends BaseModel implements PostProcessingTypeAdapte
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
|
||||||
public List<MwQueryLogEvent> logevents() {
|
|
||||||
return logevents;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class Redirect {
|
private static class Redirect {
|
||||||
@SuppressWarnings("unused") private int index;
|
private int index;
|
||||||
@SuppressWarnings("unused") @Nullable private String from;
|
@Nullable private String from;
|
||||||
@SuppressWarnings("unused") @Nullable private String to;
|
@Nullable private String to;
|
||||||
@SuppressWarnings("unused") @SerializedName("tofragment") @Nullable private String toFragment;
|
@SerializedName("tofragment") @Nullable private String toFragment;
|
||||||
|
|
||||||
@Nullable public String to() {
|
@Nullable public String to() {
|
||||||
return to;
|
return to;
|
||||||
|
|
@ -237,8 +143,8 @@ public class MwQueryResult extends BaseModel implements PostProcessingTypeAdapte
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class ConvertedTitle {
|
public static class ConvertedTitle {
|
||||||
@SuppressWarnings("unused") @Nullable private String from;
|
@Nullable private String from;
|
||||||
@SuppressWarnings("unused") @Nullable private String to;
|
@Nullable private String to;
|
||||||
|
|
||||||
@Nullable public String to() {
|
@Nullable public String to() {
|
||||||
return to;
|
return to;
|
||||||
|
|
@ -270,40 +176,12 @@ public class MwQueryResult extends BaseModel implements PostProcessingTypeAdapte
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class MarkReadResponse {
|
|
||||||
@SuppressWarnings("unused") @Nullable private String result;
|
|
||||||
@SuppressWarnings("unused,NullableProblems") @Nullable private String timestamp;
|
|
||||||
|
|
||||||
@Nullable public String getResult() {
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable public String getTimestamp() {
|
|
||||||
return timestamp;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class NotificationList {
|
public static class NotificationList {
|
||||||
@SuppressWarnings("unused") private int count;
|
@Nullable
|
||||||
@SuppressWarnings("unused") private int rawcount;
|
private List<Notification> list;
|
||||||
@SuppressWarnings("unused") @Nullable private Notification.SeenTime seenTime;
|
@Nullable
|
||||||
@SuppressWarnings("unused") @Nullable private List<Notification> list;
|
public List<Notification> list() {
|
||||||
@SuppressWarnings("unused") @SerializedName("continue") @Nullable private String continueStr;
|
|
||||||
|
|
||||||
@Nullable public List<Notification> list() {
|
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable public String getContinue() {
|
|
||||||
return continueStr;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getCount() {
|
|
||||||
return count;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable public Notification.SeenTime getSeenTime() {
|
|
||||||
return seenTime;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,12 +1,12 @@
|
||||||
package org.wikipedia.dataclient.mwapi;
|
package fr.free.nrw.commons.wikidata.mwapi;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
import com.google.gson.annotations.SerializedName;
|
import com.google.gson.annotations.SerializedName;
|
||||||
|
|
||||||
import org.wikipedia.json.PostProcessingTypeAdapter;
|
import fr.free.nrw.commons.wikidata.json.PostProcessingTypeAdapter;
|
||||||
import org.wikipedia.model.BaseModel;
|
import fr.free.nrw.commons.wikidata.model.BaseModel;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
|
@ -0,0 +1,29 @@
|
||||||
|
package fr.free.nrw.commons.wikidata.mwapi;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import fr.free.nrw.commons.wikidata.model.BaseModel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gson POJO for a MediaWiki API error.
|
||||||
|
*/
|
||||||
|
public class MwServiceError extends BaseModel {
|
||||||
|
|
||||||
|
@Nullable private String code;
|
||||||
|
@Nullable private String text;
|
||||||
|
|
||||||
|
@NonNull public String getTitle() {
|
||||||
|
return StringUtils.defaultString(code);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull public String getDetails() {
|
||||||
|
return StringUtils.defaultString(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public String getCode() {
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,34 @@
|
||||||
|
package fr.free.nrw.commons.wikidata.mwapi;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
|
||||||
|
public class UserInfo {
|
||||||
|
@NonNull private String name;
|
||||||
|
@NonNull private int id;
|
||||||
|
|
||||||
|
//Block information
|
||||||
|
private int blockid;
|
||||||
|
private String blockedby;
|
||||||
|
private int blockedbyid;
|
||||||
|
private String blockreason;
|
||||||
|
private String blocktimestamp;
|
||||||
|
private String blockexpiry;
|
||||||
|
|
||||||
|
// Object type is any JSON type.
|
||||||
|
@SuppressWarnings("MismatchedQueryAndUpdateOfCollection")
|
||||||
|
@Nullable private Map<String, ?> options;
|
||||||
|
|
||||||
|
public int id() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
public String blockexpiry() {
|
||||||
|
if (blockexpiry != null)
|
||||||
|
return blockexpiry;
|
||||||
|
else return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -12,7 +12,6 @@ import org.mockito.Mock
|
||||||
import org.mockito.Mockito.`when`
|
import org.mockito.Mockito.`when`
|
||||||
import org.mockito.Mockito.mock
|
import org.mockito.Mockito.mock
|
||||||
import org.mockito.MockitoAnnotations
|
import org.mockito.MockitoAnnotations
|
||||||
import org.wikipedia.dataclient.mwapi.MwQueryResponse
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test methods in media data extractor
|
* Test methods in media data extractor
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.robolectric.RobolectricTestRunner;
|
import org.robolectric.RobolectricTestRunner;
|
||||||
import org.wikipedia.json.GsonUtil;
|
import fr.free.nrw.commons.wikidata.GsonUtil;
|
||||||
import retrofit2.Retrofit;
|
import retrofit2.Retrofit;
|
||||||
import retrofit2.converter.gson.GsonConverterFactory;
|
import retrofit2.converter.gson.GsonConverterFactory;
|
||||||
|
|
||||||
|
|
|
||||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue