Repository navigation
Conversation
|
@nicolas-raoul please let me know if my implementation is done right |
There was a problem hiding this comment.
🟡 Changes recommended
Active issues can delay useful search results for minutes, lose newly created item IDs on lookup failure or view teardown, and leave checkboxes inconsistent with repository selections.
5 open issues
What changed in this PR
This PR extends the depicts picker to offer exact-title Wikipedia articles without linked Wikidata items, addressing #6982. Selecting an article creates a Wikidata item and uses its QID as the depiction.
Changes:
- Adds Wikipedia edition discovery, article lookup, and Wikidata item creation.
- Integrates pending depictions, login checks, creation messages, and save guards.
- Adds tests for lookup, creation, selection, and in-progress behavior.
| File | Description |
|---|---|
app/src/test/kotlin/fr/free/nrw/commons/wikidata/WikidataItemCreationClientTest.kt |
Tests creation payloads and missing-entity responses. |
app/src/test/kotlin/fr/free/nrw/commons/upload/structure/depictions/DepictModelTest.kt |
Tests fallback search and exact-match handling. |
app/src/test/kotlin/fr/free/nrw/commons/upload/DepictsPresenterTest.kt |
Tests login checks, creation, selection, and save guards. |
app/src/test/kotlin/fr/free/nrw/commons/explore/depictions/WikipediaArticleClientTest.kt |
Tests article eligibility, language lookup, and pending IDs. |
app/src/test/kotlin/fr/free/nrw/commons/explore/depictions/DepictsClientTest.kt |
Tests conversion into pending depictions. |
app/src/main/res/values/strings.xml |
Adds article descriptions and creation messages. |
app/src/main/res/values-qq/strings.xml |
Documents the new strings for translators. |
app/src/main/java/fr/free/nrw/commons/wikidata/WikipediaArticleInterface.kt |
Defines page-properties and site-matrix requests. |
app/src/main/java/fr/free/nrw/commons/wikidata/WikidataItemCreationClient.kt |
Creates items with article labels and sitelinks. |
app/src/main/java/fr/free/nrw/commons/wikidata/WikidataInterface.kt |
Adds the item-creation endpoint. |
app/src/main/java/fr/free/nrw/commons/wikidata/model/WikipediaArticleResponse.kt |
Models article existence and Wikidata links. |
app/src/main/java/fr/free/nrw/commons/wikidata/model/WbCreateEntityResponse.kt |
Models the created entity response. |
app/src/main/java/fr/free/nrw/commons/upload/structure/depictions/DepictModel.kt |
Adds Wikipedia fallback to depiction searches. |
app/src/main/java/fr/free/nrw/commons/upload/depicts/DepictsPresenter.kt |
Handles creation, selection, and pending-operation guards. |
app/src/main/java/fr/free/nrw/commons/upload/depicts/DepictsFragment.kt |
Displays creation feedback as toasts. |
app/src/main/java/fr/free/nrw/commons/upload/depicts/DepictsContract.kt |
Adds the creation-message view method. |
app/src/main/java/fr/free/nrw/commons/explore/depictions/WikipediaArticleClient.kt |
Finds unlinked articles across Wikipedia editions. |
app/src/main/java/fr/free/nrw/commons/explore/depictions/DepictsClient.kt |
Converts articles into pending depiction results. |
app/src/main/java/fr/free/nrw/commons/di/NetworkingModule.kt |
Provides the Wikipedia API service. |
Review effort: Balanced
| Flowable.fromIterable(primary).concatMapMaybe { findOnWikipedia(it, title) }, | ||
| Flowable | ||
| .fromIterable(remaining) | ||
| .flatMap({ findOnWikipedia(it, title).toFlowable() }, false, MAX_CONCURRENT_LOOKUPS), |
| session.compositeDisposable.add( | ||
| dependencies.wikidataItemCreationClient | ||
| .createItem(article.languageCode, article.title) |
| .flatMap { qid -> | ||
| repository | ||
| .getDepictions(listOf(qid)) | ||
| .firstOrError() | ||
| .map { it.firstOrNull() } | ||
| }.subscribeOn(schedulers.io) |
| depictedItem.isSelected = false | ||
| view.setDepictsList(session.depictedItems.value.orEmpty()) |
| depictsClient | ||
| .searchForUnlinkedWikipediaArticle(query) | ||
| .onErrorResumeWithEmptyList() | ||
| .map { unlinked -> (unlinked + results).distinctBy(DepictedItem::id) } |
nicolas-raoul
left a comment
There was a problem hiding this comment.
Thanks for tackling #6982 @Lemeri123! Good progress addressing the streaming and lifecycle recovery items from Copilot's review. Before testing on device, there are a few important issues in the lookup and creation logic:
-
Brute-forcing ~340 Wikipedia editions alphabetically on every search without an exact Wikidata match:
WikipediaArticleClient.lookupArticle()fetchessitematrix(all ~340 Wikipedia editions, without filtering out"closed"wikis) and fires up to 4 concurrentaction=query&prop=pagepropsrequests alphabetically (aa.wikipedia.org,ab.wikipedia.org,ace.wikipedia.org, ...) until the 8-secondFALLBACK_DEADLINE_SECONDStimeout.- Because most typed depicts queries do not match an existing Wikidata label verbatim, almost every search will blast dozens to hundreds of requests to small/closed Wikimedia subdomains — violating Wikimedia API etiquette, wasting mobile data/battery, and timing out before reaching major editions later in the alphabet (such as
ja,ko,ru, orzh) on an English-locale phone (including the exact Japanese Wikipedia example from #6982). - Please replace the full-sitematrix scan with a bounded, targeted language set (e.g., device/app language, user's recent languages, script-detected candidate languages such as
ja/zhfor CJK,ru/ukfor Cyrillic, etc., plusen), and filter out closed wikis.
-
Sitelink
dbnamefor hyphenated/special Wikipedia codes (WikidataItemCreationClient.kt:43):val site = "${languageCode}wiki"produces invalid sitelink IDs for hyphenated editions (e.g.zh-min-nan→zh_min_nanwiki,bat-smg→bat_smgwiki,be-x-old→be_x_oldwiki).sitematrixalready returns the exactdbnamefor each Wikipedia site.
-
Edge cases on article matching & UI state:
page.title == titlefails when the user types lowercase (MediaWiki capitalizes the first character ofpage.title), andPagePropsdoes not exclude disambiguation pages (disambiguationproperty).- In
DepictsPresenter.revertPendingDepiction, when creation fails or the user is logged out, the adapter has already toggled the checkbox visually — please verify the row actually unchecks in the RecyclerView (Copilot's note on shared item mutation withDiffUtil).
|
✅ Generated APK variants! |

Description (required)
Fixes #6982
When the depicts search finds no Wikidata item, the app now checks Wikipedia editions for an exact article title match with no linked Wikidata item. It offers that article as a pending depiction, creates a Wikidata item from the article label and sitelink when selected, then selects the created QID as the depiction. Logged out users and creation failures get an inline message, and duplicate or save actions are blocked while creation is in progress.
Tests performed (required)
Tested ProdDebug on emulator with API level 35.
All tests pass
Screenshots (for UI changes only)


Note: Please ensure that you have read CONTRIBUTING.md if this is your first pull request.