Skip to content

feature: offer unlinked Wikipedia articles in depicts - #7449

Open
Lemeri123 wants to merge 6 commits into
commons-app:mainfrom
Lemeri123:depicts
Open

Lemeri123 wants to merge 6 commits into
commons-app:mainfrom
Lemeri123:depicts

Conversation

@Lemeri123

@Lemeri123 Lemeri123 commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

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)
Screenshot from 2026-11-27 15-16-27
image


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

@Lemeri123 Lemeri123 changed the title fix: offer unlinked Wikipedia articles in depicts feature: offer unlinked Wikipedia articles in depicts Nov 27, 2026
@Lemeri123
Lemeri123 marked this pull request as draft November 27, 2026 12:46
@Lemeri123
Lemeri123 marked this pull request as ready for review November 27, 2026 17:59
@Lemeri123
Lemeri123 marked this pull request as draft November 28, 2026 20:49
@Lemeri123
Lemeri123 marked this pull request as ready for review November 29, 2026 12:36
@Lemeri123

Copy link
Copy Markdown
Contributor Author

@nicolas-raoul please let me know if my implementation is done right

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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),
Comment on lines +288 to +290
session.compositeDisposable.add(
dependencies.wikidataItemCreationClient
.createItem(article.languageCode, article.title)
Comment on lines +291 to +296
.flatMap { qid ->
repository
.getDepictions(listOf(qid))
.firstOrError()
.map { it.firstOrNull() }
}.subscribeOn(schedulers.io)
Comment on lines +323 to +324
depictedItem.isSelected = false
view.setDepictsList(session.depictedItems.value.orEmpty())
Comment on lines +101 to +104
depictsClient
.searchForUnlinkedWikipediaArticle(query)
.onErrorResumeWithEmptyList()
.map { unlinked -> (unlinked + results).distinctBy(DepictedItem::id) }

@nicolas-raoul nicolas-raoul left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  1. Brute-forcing ~340 Wikipedia editions alphabetically on every search without an exact Wikidata match:

    • WikipediaArticleClient.lookupArticle() fetches sitematrix (all ~340 Wikipedia editions, without filtering out "closed" wikis) and fires up to 4 concurrent action=query&prop=pageprops requests alphabetically (aa.wikipedia.org, ab.wikipedia.org, ace.wikipedia.org, ...) until the 8-second FALLBACK_DEADLINE_SECONDS timeout.
    • 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, or zh) 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/zh for CJK, ru/uk for Cyrillic, etc., plus en), and filter out closed wikis.
  2. Sitelink dbname for 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). sitematrix already returns the exact dbname for each Wikipedia site.
  3. Edge cases on article matching & UI state:

    • page.title == title fails when the user types lowercase (MediaWiki capitalizes the first character of page.title), and PageProps does not exclude disambiguation pages (disambiguation property).
    • 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 with DiffUtil).

@github-actions

Copy link
Copy Markdown

✅ Generated APK variants!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

For existing Wikipedia article, automatically create Wikidata item

3 participants