[Bug]: WikiSite treats the /w/ script path as a language variant, producing a bogus "w" language code
Maintainers usually reply within 1 day
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 72/100
Research direction
The bug is in getLanguageVariantFromUri() in app/src/main/java/fr/free/nrw/commons/wikidata/model/WikiSite.kt, where only the "wiki" path segment is excluded from language-variant detection. Start by reproducing with a Robolectric test on WikiSite("https://en.wikipedia.org/w/index.php") and checking languageCode(), subdomain() and mobileUrl(). Done when the /w/ path yields "en" and mobileUrl() returns the mobile host, with equals/hashCode consistent with the bare domain.
Written by the indexing model from the issue text.
Description
Summary
WikiSite's language-variant detection treats any first URI path segment as a language variant code, except wiki. The canonical MediaWiki script path /w/ (used by index.php, api.php, etc.) is not excluded, so a perfectly normal URL like https://en.wikipedia.org/w/index.php produces languageCode() == "w" — a non-existent language — instead of "en".
The same applies to any other first path segment (api, static, …).
Steps to reproduce
Verified on current main (caa5c9d8d) with a Robolectric unit test:
val site = WikiSite("https://en.wikipedia.org/w/index.php")
site.languageCode() // actual: "w"
// expected: "en"
site.subdomain() // actual: "w"
// expected: "en"
site.mobileAuthority() // actual: "en.wikipedia.org" (mobile subdomain lost!)
// expected: "en.m.wikipedia.org"
site.mobileUrl() // actual: "https://en.wikipedia.org" — silently returns the DESKTOP URL
// expected: "https://en.m.wikipedia.org"
Root cause
WikiSite.kt getLanguageVariantFromUri():
val parts = StringUtils.split(StringUtils.defaultString(uri.path), '/')
return if (parts.size > 1 && parts[0] != "wiki") parts[0] else ""
Only "wiki" is excluded. For /w/index.php, parts[0] is "w", which is then taken as the language variant and overrides the correct subdomain-derived code "en" (lines 66-72).
Why it matters
languageCode()/subdomain()return"w", which feeds language-dependent logic throughout the app.mobileAuthority()regex-replaces^"w"\.?againsten.wikipedia.org, finds no match, and returns the authority unchanged — somobileUrl()silently yields the desktop URL for a site that was parsed from a script-path URL.equals()/hashCode()also diverge:WikiSite("https://en.wikipedia.org")≠WikiSite("https://en.wikipedia.org/w/index.php")even though they denote the same site.
Suggested fix direction
Only treat the first path segment as a variant when it actually is a known language-variant code (e.g. matches zh-* or an ISO language code), or additionally exclude w alongside wiki. Happy to pick this up if a maintainer agrees it's worth fixing.
- Dominant language
- Kotlin
- Stars
- 1.2k
- Forks
- 1.4k
- Avg merge
- 1d 4h
- Merged PRs (30d)
- 156
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from commons-app/apps-android-commons
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
commons-app/apps-android-commons#7486 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
commons-app/apps-android-commons#7464 · 2 comments ·
Maintainers usually reply within 1 day
-
[Bug]: Media detail page crashes on file pages with unclosed [[Category: markupPossibly taken @dkrrish9 claimed this 3 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
commons-app/apps-android-commons#7423 · 7 comments · 1 assignee ·
Maintainers usually reply within 1 day
-
test: unit tests for WikiSite (sub-issue of #6630)Possibly taken @Seyamalam claimed this 5 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
commons-app/apps-android-commons#7419 · 1 assignee ·
Maintainers usually reply within 1 day
-
Detekt: document why the Dagger provider modules exceed TooManyFunctionsMay be free again @harshkumar3117-svg claimed this 14 days ago, and no pull request is open. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
commons-app/apps-android-commons#7113 · 3 comments ·
Maintainers usually reply within 1 day
All issues in commons-app/apps-android-commons
Similar issues
-
Location search keeps showing stale "Open-Meteo can't find ..." message after clearing search queryOpenBug Needs review
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
breezy-weather/breezy-weather#3082 ·
Maintainers usually reply within 2 days
-
area: ci area: local-media area: startup area: ui platform: bilibili platform: netease platform: youtube status: needs-triage
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
cwuom/NeriPlayer#794 ·
Maintainers usually reply within 1 day
-
area:android area:ui bug priority:P2
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
meraxes89/streamify-apk#449 ·
Maintainers usually reply within 1 day
-
easy first-contributor first-contributors good first issue help wanted kotlin up-for-grabs
Difficulty 1/5 Under an hour Newbie friendliness 95/100
fork-commit-merge/fork-commit-merge#8752 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 67/100
MetrolistGroup/Metrolist#5559 · 2 comments · 1 reaction ·
Maintainers usually reply within 1 day