Why remove the user preference
Since T290941: Preserve open/collapsed state of the accordion [M], IPInfo has used a user preference to save the expanded state of the infobox.
In general, we should be conservative about adding user preferences, as outlined in:
- https://www.mediawiki.org/wiki/Best_practices_for_extensions#Code_architecture
- https://www.mediawiki.org/wiki/Just_make_it_a_user_preference
A preference for remembering UI state seems to contravene these guidelines. (NB IPInfo also adds a few other user preferences, but the others are mandated by legal requirements (T291582) or temporary (T292802).)
We do have a URL parameter openInfobox that forces the infobox to be open, which is used when clicking through from the IPInfo popup (T293723), and could also be added when sharing URLs.
User localStorage instead
Removing the preference would mean that the infobox would no longer default to open, without the URL parameter. We should instead do this in local storage.
localStorage is documented here: https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage
Using localStorage in MediaWiki is documented here: https://doc.wikimedia.org/mediawiki-core/master/js/#!/api/mw.storage - note that mw.storage has no expiry, and localStorage has limited space.
Acceptance criteria
- A user preference is no longer set true when the infobox is expanded
- The user preference is set false when the infobox is collapsed, as this removes it from the database. This should be commented clearly in the code.
- A key is added to mw.storage when the infobox is expanded
- The key is removed from mw.storage when the infobox is collapsed
- A comment is added, that if we ever remove this feature, we should call mw.storage.remove(<our-key>) here to free up space
- mw.storage is checked when deciding whether the infobox should be expanded or collapsed. (The URL parameter openInfobox should still take precedence.)
What changes will the user see?
- There is currently a bug where there can be a delay between the database being updated with the user preference, and the next page refresh. This bug will be fixed.
- The preference for an expanded/collapsed infobox will only persist as long as localStorage persists
- Before this task, the preference was saved per user; after, it will persist across users until the browser is closed