|
1 | 1 | package fr.free.nrw.commons.mwapi;
|
2 | 2 |
|
3 | 3 | import android.text.TextUtils;
|
| 4 | + |
4 | 5 | import androidx.annotation.NonNull;
|
5 | 6 | import androidx.annotation.Nullable;
|
| 7 | + |
6 | 8 | import com.google.gson.Gson;
|
7 | 9 | import com.google.gson.reflect.TypeToken;
|
| 10 | + |
| 11 | +import org.apache.commons.lang3.StringUtils; |
| 12 | +import org.wikipedia.dataclient.mwapi.MwQueryPage; |
| 13 | +import org.wikipedia.dataclient.mwapi.MwQueryResponse; |
| 14 | + |
| 15 | +import java.io.IOException; |
| 16 | +import java.lang.reflect.Type; |
| 17 | +import java.util.ArrayList; |
| 18 | +import java.util.Date; |
| 19 | +import java.util.List; |
| 20 | +import java.util.Locale; |
| 21 | +import java.util.Map; |
| 22 | + |
| 23 | +import javax.inject.Inject; |
| 24 | +import javax.inject.Singleton; |
| 25 | + |
8 | 26 | import fr.free.nrw.commons.Media;
|
9 | 27 | import fr.free.nrw.commons.achievements.FeaturedImages;
|
10 | 28 | import fr.free.nrw.commons.achievements.FeedbackResponse;
|
|
20 | 38 | import fr.free.nrw.commons.wikidata.model.GetWikidataEditCountResponse;
|
21 | 39 | import io.reactivex.Observable;
|
22 | 40 | import io.reactivex.Single;
|
23 |
| -import java.io.IOException; |
24 |
| -import java.lang.reflect.Type; |
25 |
| -import java.util.ArrayList; |
26 |
| -import java.util.Date; |
27 |
| -import java.util.List; |
28 |
| -import java.util.Locale; |
29 |
| -import java.util.Map; |
30 |
| -import java.util.Random; |
31 |
| -import javax.inject.Inject; |
32 |
| -import javax.inject.Singleton; |
33 | 41 | import okhttp3.HttpUrl;
|
34 | 42 | import okhttp3.OkHttpClient;
|
35 | 43 | import okhttp3.Request;
|
36 | 44 | import okhttp3.Response;
|
37 |
| -import org.apache.commons.lang3.StringUtils; |
38 |
| -import org.wikipedia.dataclient.mwapi.MwQueryPage; |
39 |
| -import org.wikipedia.dataclient.mwapi.MwQueryResponse; |
40 |
| -import org.wikipedia.dataclient.mwapi.RecentChange; |
41 |
| -import org.wikipedia.util.DateUtil; |
42 | 45 | import timber.log.Timber;
|
43 | 46 |
|
44 | 47 | /**
|
@@ -418,80 +421,4 @@ private void putContinueValues(String keyword, Map<String, String> values) {
|
418 | 421 | private Map<String, String> getContinueValues(String keyword) {
|
419 | 422 | return defaultKvStore.getJson("query_continue_" + keyword, mapType);
|
420 | 423 | }
|
421 |
| - |
422 |
| - /** |
423 |
| - * Returns recent changes on commons |
424 |
| - * |
425 |
| - * @return list of recent changes made |
426 |
| - */ |
427 |
| - @Nullable |
428 |
| - public Single<List<RecentChange>> getRecentFileChanges() { |
429 |
| - final int RANDOM_SECONDS = 60 * 60 * 24 * 30; |
430 |
| - final String FILE_NAMESPACE = "6"; |
431 |
| - Random r = new Random(); |
432 |
| - Date now = new Date(); |
433 |
| - Date startDate = new Date(now.getTime() - r.nextInt(RANDOM_SECONDS) * 1000L); |
434 |
| - |
435 |
| - String rcStart = DateUtil.iso8601DateFormat(startDate); |
436 |
| - HttpUrl.Builder urlBuilder = HttpUrl |
437 |
| - .parse(commonsBaseUrl) |
438 |
| - .newBuilder() |
439 |
| - .addQueryParameter("action", "query") |
440 |
| - .addQueryParameter("format", "json") |
441 |
| - .addQueryParameter("formatversion", "2") |
442 |
| - .addQueryParameter("list", "recentchanges") |
443 |
| - .addQueryParameter("rcstart", rcStart) |
444 |
| - .addQueryParameter("rcnamespace", FILE_NAMESPACE) |
445 |
| - .addQueryParameter("rcprop", "title|ids") |
446 |
| - .addQueryParameter("rctype", "new|log") |
447 |
| - .addQueryParameter("rctoponly", "1"); |
448 |
| - |
449 |
| - Request request = new Request.Builder() |
450 |
| - .url(urlBuilder.build()) |
451 |
| - .build(); |
452 |
| - |
453 |
| - return Single.fromCallable(() -> { |
454 |
| - Response response = okHttpClient.newCall(request).execute(); |
455 |
| - if (response.body() != null && response.isSuccessful()) { |
456 |
| - String json = response.body().string(); |
457 |
| - MwQueryResponse mwQueryPage = gson.fromJson(json, MwQueryResponse.class); |
458 |
| - return mwQueryPage.query().getRecentChanges(); |
459 |
| - } |
460 |
| - return new ArrayList<>(); |
461 |
| - }); |
462 |
| - } |
463 |
| - |
464 |
| - /** |
465 |
| - * Returns the first revision of the file |
466 |
| - * |
467 |
| - * @return Revision object |
468 |
| - */ |
469 |
| - @Nullable |
470 |
| - public Single<MwQueryPage.Revision> getFirstRevisionOfFile(String filename) { |
471 |
| - HttpUrl.Builder urlBuilder = HttpUrl |
472 |
| - .parse(commonsBaseUrl) |
473 |
| - .newBuilder() |
474 |
| - .addQueryParameter("action", "query") |
475 |
| - .addQueryParameter("format", "json") |
476 |
| - .addQueryParameter("formatversion", "2") |
477 |
| - .addQueryParameter("prop", "revisions") |
478 |
| - .addQueryParameter("rvprop", "timestamp|ids|user") |
479 |
| - .addQueryParameter("titles", filename) |
480 |
| - .addQueryParameter("rvdir", "newer") |
481 |
| - .addQueryParameter("rvlimit", "1"); |
482 |
| - |
483 |
| - Request request = new Request.Builder() |
484 |
| - .url(urlBuilder.build()) |
485 |
| - .build(); |
486 |
| - |
487 |
| - return Single.fromCallable(() -> { |
488 |
| - Response response = okHttpClient.newCall(request).execute(); |
489 |
| - if (response.body() != null && response.isSuccessful()) { |
490 |
| - String json = response.body().string(); |
491 |
| - MwQueryResponse mwQueryPage = gson.fromJson(json, MwQueryResponse.class); |
492 |
| - return mwQueryPage.query().firstPage().revisions().get(0); |
493 |
| - } |
494 |
| - return null; |
495 |
| - }); |
496 |
| - } |
497 | 424 | }
|
0 commit comments