mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 12:23:58 +01:00
Skip used images (#5160)
* Only Review Images That Has No Usage * Coding Standard Related Changes * Coding Standard Changes - 1 * small change
This commit is contained in:
parent
b917fe3229
commit
496933654b
6 changed files with 109 additions and 5 deletions
|
|
@ -6,6 +6,7 @@ import android.content.Intent;
|
|||
import android.graphics.PorterDuff;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
|
|
@ -161,14 +162,31 @@ public class ReviewActivity extends BaseActivity {
|
|||
hasNonHiddenCategories = false;
|
||||
progressBar.setVisibility(View.VISIBLE);
|
||||
reviewPager.setCurrentItem(0);
|
||||
// Finds non-hidden categories from Media instance
|
||||
compositeDisposable.add(reviewHelper.getRandomMedia()
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(media -> {
|
||||
.subscribe(this::checkWhetherFileIsUsedInWikis));
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether media is used or not in any Wiki Page
|
||||
*/
|
||||
@SuppressLint("CheckResult")
|
||||
private void checkWhetherFileIsUsedInWikis(final Media media) {
|
||||
compositeDisposable.add(reviewHelper.checkFileUsage(media.getFilename())
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(result -> {
|
||||
// result false indicates media is not used in any wiki
|
||||
if (!result) {
|
||||
// Finds non-hidden categories from Media instance
|
||||
findNonHiddenCategories(media);
|
||||
}));
|
||||
return true;
|
||||
} else {
|
||||
runRandomizer();
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -100,6 +100,19 @@ public class ReviewHelper {
|
|||
.map(response -> response.query().firstPage().revisions().get(0));
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks Whether Given File is used in any Wiki page or not
|
||||
* by calling api for given file
|
||||
*
|
||||
* @param filename
|
||||
* @return
|
||||
*/
|
||||
Observable<Boolean> checkFileUsage(final String filename) {
|
||||
return reviewInterface.getGlobalUsageInfo(filename)
|
||||
.map(mwQueryResponse -> mwQueryResponse.query().firstPage()
|
||||
.checkWhetherFileIsUsedInWikis());
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the change is reviewable or not.
|
||||
* - checks the type and revisionId of the change
|
||||
|
|
|
|||
|
|
@ -15,4 +15,7 @@ public interface ReviewInterface {
|
|||
|
||||
@GET("w/api.php?action=query&format=json&formatversion=2&prop=revisions&rvprop=timestamp|ids|user&rvdir=newer&rvlimit=1")
|
||||
Observable<MwQueryResponse> getFirstRevisionOfFile(@Query("titles") String titles);
|
||||
|
||||
@GET("w/api.php?action=query&format=json&formatversion=2&prop=fileusage|globalusage")
|
||||
Observable<MwQueryResponse> getGlobalUsageInfo(@Query("titles") String title);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,6 +25,8 @@ public class MwQueryPage extends BaseModel {
|
|||
@SuppressWarnings("unused,NullableProblems") @NonNull private CategoryInfo categoryinfo;
|
||||
@SuppressWarnings("unused") @Nullable private List<LangLink> langlinks;
|
||||
@SuppressWarnings("unused") @Nullable private List<Revision> revisions;
|
||||
@SuppressWarnings("unused") @SerializedName("fileusage") @Nullable private List<FileUsage> fileUsages;
|
||||
@SuppressWarnings("unused") @SerializedName("globalusage") @Nullable private List<GlobalUsage> globalUsages;
|
||||
@SuppressWarnings("unused") @Nullable private List<Coordinates> coordinates;
|
||||
@SuppressWarnings("unused") @Nullable private List<Category> categories;
|
||||
@SuppressWarnings("unused") @Nullable private PageProps pageprops;
|
||||
|
|
@ -67,6 +69,14 @@ public class MwQueryPage extends BaseModel {
|
|||
return categories;
|
||||
}
|
||||
|
||||
@Nullable public List<GlobalUsage> globalUsages() {
|
||||
return globalUsages;
|
||||
}
|
||||
|
||||
@Nullable public List<FileUsage> fileUsages() {
|
||||
return fileUsages;
|
||||
}
|
||||
|
||||
@Nullable public List<Coordinates> coordinates() {
|
||||
// TODO: Handle null values in lists during deserialization, perhaps with a new
|
||||
// @RequiredElements annotation and corresponding TypeAdapter
|
||||
|
|
@ -141,6 +151,28 @@ public class MwQueryPage extends BaseModel {
|
|||
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;
|
||||
|
|
@ -228,6 +260,44 @@ public class MwQueryPage extends BaseModel {
|
|||
}
|
||||
}
|
||||
|
||||
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 {
|
||||
@SuppressWarnings("unused") private int ns;
|
||||
@SuppressWarnings("unused,NullableProblems") @Nullable private String title;
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ public class MwQueryResponse extends MwResponse {
|
|||
|
||||
@SuppressWarnings("unused") @SerializedName("continue") @Nullable private Map<String, String> continuation;
|
||||
|
||||
@Nullable private MwQueryResult query;
|
||||
@SerializedName("query") @Nullable private MwQueryResult query;
|
||||
|
||||
public boolean batchComplete() {
|
||||
return batchComplete;
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ import java.util.Map;
|
|||
|
||||
@SuppressWarnings("unused")
|
||||
public class MwQueryResult extends BaseModel implements PostProcessingTypeAdapter.PostProcessable {
|
||||
@Nullable private List<MwQueryPage> pages;
|
||||
@SerializedName("pages") @Nullable private List<MwQueryPage> pages;
|
||||
@Nullable private List<Redirect> redirects;
|
||||
@Nullable private List<ConvertedTitle> converted;
|
||||
@SerializedName("userinfo") private UserInfo userInfo;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue