Skip to content

Commit 67beb94

Browse files
Hidden categories are not showed in suggested categories (commons-app#3853)
1 parent 8630ba8 commit 67beb94

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

app/src/main/java/fr/free/nrw/commons/category/CategoryClient.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,9 @@ class CategoryClient @Inject constructor(private val categoryInterface: Category
9292
it.query()?.pages() ?: emptyList()
9393
}
9494
.map {
95-
it.map { page -> page.title().replace(CATEGORY_PREFIX, "") }
95+
it.filter {
96+
page -> page.categoryInfo() == null || !page.categoryInfo().isHidden
97+
}.map { page -> page.title().replace(CATEGORY_PREFIX, "") }
9698
}
9799
}
98-
99100
}

app/src/main/java/fr/free/nrw/commons/category/CategoryInterface.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Single<MwQueryResponse> searchCategories(@Query("gsrsearch") String filter,
3232
* @return
3333
*/
3434
@GET("w/api.php?action=query&format=json&formatversion=2"
35-
+ "&generator=allcategories")
35+
+ "&generator=allcategories&prop=categoryinfo")
3636
Single<MwQueryResponse> searchCategoriesForPrefix(@Query("gacprefix") String prefix,
3737
@Query("gaclimit") int itemLimit, @Query("gacoffset") int offset);
3838

data-client/src/main/java/org/wikipedia/dataclient/mwapi/MwQueryPage.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public class MwQueryPage extends BaseModel {
2222
@SuppressWarnings("unused") private int ns;
2323
@SuppressWarnings("unused") private int index;
2424
@SuppressWarnings("unused,NullableProblems") @NonNull private String title;
25+
@SuppressWarnings("unused,NullableProblems") @NonNull private CategoryInfo categoryinfo;
2526
@SuppressWarnings("unused") @Nullable private List<LangLink> langlinks;
2627
@SuppressWarnings("unused") @Nullable private List<Revision> revisions;
2728
@SuppressWarnings("unused") @Nullable private List<Coordinates> coordinates;
@@ -42,6 +43,10 @@ public class MwQueryPage extends BaseModel {
4243
return title;
4344
}
4445

46+
@NonNull public CategoryInfo categoryInfo() {
47+
return categoryinfo;
48+
}
49+
4550
public int index() {
4651
return index;
4752
}
@@ -185,6 +190,17 @@ public static class Coordinates {
185190
}
186191
}
187192

193+
public static class CategoryInfo {
194+
@SuppressWarnings("unused") private boolean hidden;
195+
@SuppressWarnings("unused") private int size;
196+
@SuppressWarnings("unused") private int pages;
197+
@SuppressWarnings("unused") private int files;
198+
@SuppressWarnings("unused") private int subcats;
199+
public boolean isHidden() {
200+
return hidden;
201+
}
202+
}
203+
188204
static class Thumbnail {
189205
@SuppressWarnings("unused") private String source;
190206
@SuppressWarnings("unused") private int width;

0 commit comments

Comments
 (0)