The reading list API stores page titles as opaque strings with no normalization. The DB unique constraint on (rle_rl_id, rle_rlp_id, rle_title) only prevents exact-string duplicates.
Different clients submit titles with different formats:
- Desktop / mobile web saves pages with underscores (wgPageName), via the action API
- Android saves with underscores (prefixedText) and handles normalizing on the client
- iOS saves page titles with spaces to the reading list.
This can result in having duplicate entries "United Arab Emirates" and "United_Arab_Emirates" both in the reading list for the @local wiki. This makes it more difficult to check if a page is bookmarked (to show the bookmark button as "Save" or "Unsave"), among other issues.
As well, when reading list entries are retrieved from the API by iOS, the API returns the page title with however it was stored in the database, so it might have underscores or might not. The Android app appears to account for this and formats the page titles for display without underscores, but the iOS app does not do this.
Proposed fix
Add server-side normalization for ReadingLists titles so the backend no longer depends on clients sending the page titles in a particular format.
- Convert spaces to underscores in page titles when storing reading list entries in the database.
- When performing a look up in the database, convert the page title to have underscores as input to lookup DB queries.
- In API responses, convert page titles to have spaces, which is more display friendly and common approach for MediaWiki APIs. This would allow us to implement these changes, while not impacting mobile apps.
- We should implement and run a maintenance script to cleanup of existing mixed-format rows and then remove workaround where we check the database or account for page titles stored in both formats.
Possible follow-up:
- for @local entries only, consider stronger normalization via Title::newFromText()->getPrefixedDBkey()
For mobile apps, we should make sure to return pages in the api with spaces so that pages saved on web will appear in the reading lists on iOS and Android.