My phone’s data plan is 500/MB per month. This low cap makes me think very conservatively about what gets sent across the modem as I’m going about my day.
While a good source of information, the OpenStreetMap Wiki is not viewable offline. There is no native app nor a PWA to use. The ZIM files from Kiwix are very outdated (at the time of writing).
A clever solution is to retrofit the existing Wikipedia App for Android, which already has a “Save page offline” feature and a very nice interface. It might even be as simple as changing the urls. After all, most Wiki sites share a similar backend and API, called Mediawiki, and I was hoping to hook into this feature.
Progress
The primary reason for this retrofit’s difficulty is Wikipedia’s different (slightly proprietary) rest API. It isn’t shared with the mediawiki suite. This is outlined very clearly in the API comparison table.
OK, so a lot more needs to change for OSM to wriggle its way into this app.
‘Simply’ Changing the URLs
I had some promising results after changing the base rest_api
URL to the ‘old’ Mediawiki target. Search now works immediately.
However, internal pages didn’t work. Each wiki page in the app expects a well formatted summary from the API.
I could get around this by changing the request for a /summary
to the full /html
of that article, and now we’re getting closer.
Of course there were some other bugs that needed to be ironed out, but those didn’t seem critical. Mainly CSS and indexing issues.
Save to Offline did not work, I’m not sure why yet.
What do
At this point I’m unsure if retrofitting the Wikipedia app is worth it. Rigging the app enough to do what I want would entail only a few more things:
- Custom CSS injection to fix the worst of the
/html
responses. - Figure out why Save Offline doesn’t work.
I’m working on this now in my little free time.
100% by-the-booke correct
To do this properly, and not rigged just enough for Quinn’s phone, we would need way more. All the following:
- A well-formatted response (or converted response) from the Mediawiki API that is not in a Wiki format nor the ugly HTML. Markdown with inline images would be great.
- The remainder of the
rest_v1
endpoints converted in the App’s RestService.kt and subsequent serializers. - Reworking the Save to Offline feature, adapting the new (old) responses to the underlying SQLite schema.
I’m not jazzed at those prospects, even less so when you consider keeping up to date with upstream.
I’ll continue to try rigging it.
My Other Idea for Offline OSM Wiki
I’d like to investigate .zim
files.
- How Kiwix packages wikis into openZIM format.
- If I can do this for OpenStreetMap on a more regular basis.
- If I can build a slightly nicer app to parse custom
.zims
. - What do
.zims
know, do they know things? Let’s find out.
Relevant links
- https://github.com/wikimedia/apps-android-wikipedia/blob/dc37d97ec30036a62527fb9896ae2875a12b328f/app/src/main/java/org/wikipedia/dataclient/Service.kt
- https://wiki.openstreetmap.org/w/api.php?action=help&modules=wbgetentities
- https://wiki.openstreetmap.org/w/api.php?format=json&formatversion=2&errorformat=html&errorsuselocal=1&action=wbgetentities&titles=Tag:tourism%3Dpicnic_site&sites=wiki
- https://www.mediawiki.org/wiki/Wikimedia_Apps/Team/Android/App_hacking
- https://github.com/qcasey/apps-android-wikipedia
- https://wiki.openstreetmap.org/wiki/Special:Export