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:
Arin Modi 2023-03-07 11:16:36 +05:30 committed by GitHub
parent b917fe3229
commit 496933654b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 109 additions and 5 deletions

View file

@ -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;

View file

@ -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;

View file

@ -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;