[Bug]: Editing categories of a file without category links replaces the whole file page

Open Beginner friendly
#7,486 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
78/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
android, kotlin
Domain
mobile

Research direction

Start with CategoryEditHelper.addCategory() and its related when branch; the issue names this logic and reports a unit test that calls makeCategoryEdit(). Check how the page text is retained for pages with no category link, lowercase {{uncategorized}}, and descriptions containing “Uncategorized.” Done when category edits preserve the existing page content in all three cases, with a unit test covering them.

Written by the indexing model from the issue text.

Description

Summary

When a file page has no [[Category:...]] link and no "Uncategorized" text, CategoryEditHelper.addCategory() keeps "" as the page text (the else -> "" branch), so saving a category edit from media details replaces the whole page (description, license, templates) with just the category links.

Two related cases in the same when:

  • {{uncategorized|...}} written with a lowercase "u" is not matched, so the page is replaced the same way.
  • The check looks for the word "Uncategorized" anywhere, so a description containing that word cuts the page at that point.

I found this while working on #7473 and confirmed it with a unit test that calls makeCategoryEdit() (results below). I have not tried it on a real file page, because it would wipe it.

Steps to reproduce
  1. Log in and open media details of a file whose page has no [[Category:...]] links and no {{Uncategorized}} template.
  2. Tap the category edit button, add a category and save.
Expected behaviour

The category is added and the rest of the file page stays as it was.

Actual behaviour

Text sent to pageEditClient.edit() in the unit test, with "Bridges" (or "Libraries", "Books") selected:

  • Page with {{Information}} and {{self|cc-by-sa-4.0}} but no categories → [[Category:Bridges]] only. Description and license are gone.
  • Same page with {{uncategorized|year=2026}} → [[Category:Bridges]] only.
  • Description "Shelf of Uncategorized books in a library" plus [[Category:Libraries]] → {{Information|description={{en|Shelf of [[Category:Libraries]] [[Category:Books]], cut in the middle of the description.
Device name

No response

Android version

Not device-specific (logic in CategoryEditHelper)

Commons app version

main (15059919a), prodDebug unit test

Device logs

No response

Screenshots

No response

Would you like to work on the issue?

None

Dominant language
Kotlin
Stars
1.2k
Forks
1.4k
Avg merge
1d 4h
Merged PRs (30d)
156

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from commons-app/apps-android-commons

All issues in commons-app/apps-android-commons

Similar issues

More Kotlin issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.