Page MenuHomePhabricator

Diff-type preference: save diff-type user selection as a preference
Closed, ResolvedPublic3 Estimated Story Points

Description

Save the state of inline toggle as a hidden user preference

Feature Summary

A user will have the ability to switch between inline and table formats when Wikidiff2 is installed. Add a user preference that tracks this selection so the system can remember the format to load.

Implementation Details

No JS implementation options:

  1. Drop no-JS support
  2. Wrap the existing no-JS controls with a form that posts to a new special endpoint, which sets the preference and then redirects back to the diff page, which will then show the newly selected format. Similar to watch star.
  3. Make the preference be a non-hidden preference.
  4. Retain the diff-type query string parameter. Don't actually set the preference in no-JS mode.

Anonymous options:

  1. Just be broken
  2. Apologise for broken behaviour
  3. Retain diff-type query parameter stickiness and use it for this.
    • In JS mode, refresh the page as if in no-JS mode, or rewrite self-links to include diff-type.
  4. Add a core concept of user-or-session options. On read, if the user cannot have user options, merge values from the current session with site defaults. Callers opt in. In ApiOptions, if the user cannot have user options, set a session cookie if necessary and write to the session. Clients opt in.
    • Variant: same but specific to diff types. Add a new API module just for setting the diff type.
  5. Use localStorage like T339268. Generate the complete diff in the wrong format on the server side and have the client replace it on DOM ready, to work around the lack of anonymous server-side preferences.
  6. Use a cookie just for anonymous diff type.

Event Timeline

Restricted Application added a subscriber: Aklapper. ยท View Herald TranscriptMay 16 2023, 12:07 AM
KSiebert set the point value for this task to 3.
dmaza renamed this task from Diff-type preference: add diff-type user preference to Diff-type preference: save diff-type user selection as a preference.Jun 1 2023, 2:52 PM
dmaza updated the task description. (Show Details)
tstarling updated the task description. (Show Details)
tstarling updated the task description. (Show Details)

Change 938470 had a related patch set uploaded (by Tim Starling; author: Tim Starling):

[mediawiki/core@master] Add an API-only user preference for diff type

https://gerrit.wikimedia.org/r/938470

Regarding 5, when T341720 is merged you'll be able to do the following:

  • Output both inline diff and side by side diff in the page HTML
  • Add a class mw-diff-mode-1 to the document element. This will act as a binary toggle to control which is visible.
  • Add some kind of CSS like so:
.mw-diff-mode-0  .inline-diff { display: none; }
.mw-diff-mode-1  .side-by-side-diff { display: none; }

Then you'll be able to store and manipulate the preference without a flash of unstyled content using

// API is subject to change based on T341720 but the parameters and results are fixed so you can depend-on that patch to try this out.
mw.storage.preferences.set( 'mw-diff-mode', 0 ); // set default to inline
mw.storage.preferences.set( 'mw-diff-mode', 1 ); // set default to side by side

// Future use cases:
mw.storage.preferences.set( 'mw-diff-mode', 2 ); // some new kind of diff

Let me know if you have any questions.

Change 938470 merged by jenkins-bot:

[mediawiki/core@master] Add an API-only user preference for diff type

https://gerrit.wikimedia.org/r/938470

@tstarling I did not encounter any issues as seen in the screenshots below. I will move this to Done. Thank you for your work!

Logged User w/JS- Switching between articles, it kept the same user preference Inline to Inline as a logged-in User

JSResult
T336713_BetterDiffs_Inline_Pref1.png (1ร—3 px, 440 KB)
T336713_BetterDiffs_Inline_Pref2.png (1ร—3 px, 482 KB)

Logged User w/ No-JS- Able to switch from newer to older edits

No JSResult*
T336713_BetterDiffs_Inline_Pref3.png (1ร—3 px, 423 KB)
T336713_BetterDiffs_Inline_Pref4.png (1ร—3 px, 432 KB)

Mobile- Visual is gone when JS is disabled

Logged User JSLogged User No-JS
T336713_BetterDiffs_Inline_Mobile_NoJS.png (1ร—1 px, 245 KB)
T336713_BetterDiffs_Inline_Mobile_NoJS2.png (1ร—1 px, 210 KB)

Anonymous User w/JS- Switching between articles, DID NOT keep the same user preferences as an anonymous user

JSResult
T336713_BetterDiffs_Inline_Anony1.png (1ร—3 px, 435 KB)
T336713_BetterDiffs_Inline_Anony2.png (1ร—3 px, 508 KB)

Anonymous User w/ No-JS- Able to switch from newer to older edits

No JSResult*
T336713_BetterDiffs_Inline_Anony3.png (1ร—3 px, 475 KB)
T336713_BetterDiffs_Inline_Anony4.png (1ร—3 px, 570 KB)

Is this task a duplicate of T240608 ? This was one of the blockers for us getting rid of the mobile diff page, so great news if so!