Page MenuHomePhabricator

[Spike] Preliminary investigation for migration to options instead of on-wiki config
Closed, ResolvedPublic3 Estimated Story PointsSpike

Description

  • How will the options be saved?
  • How will the options be made available to the javascript
  • How will the options be registered (do they need to be)?
  • How will the options be stored in the database (onwiki currently stringified json)
  • Hooks?
  • Logging?

Event Timeline

DannyS712 triaged this task as Medium priority.Jun 17 2020, 6:32 AM
DannyS712 created this task.
Restricted Application added a project: User-DannyS712. · View Herald TranscriptJun 17 2020, 6:32 AM
Restricted Application added a subscriber: Aklapper. · View Herald Transcript
DannyS712 moved this task from Unsorted to In progress on the User-DannyS712 board.
DannyS712 updated the task description. (Show Details)

Registered / ensuring they aren't deleted accidentally:

DeleteUnknownPreferences hook
Need to decide on a constant option name, probably something like globalwatchlist-settings
Ref: https://www.mediawiki.org/wiki/Manual:Hooks/DeleteUnknownPreferences

Don't register a default, don't show on Special:Preferences
Should the settings saved be versioned?
Should the settings saved include the default sub-options (i.e. filters, etc) - for other settings defaults aren't stored, but here in would only be a partial default

DannyS712 added a comment.EditedJun 17 2020, 6:53 AM

Passing to javascript: two options

The hook is probably better from a performance standpoint
Where should the defaults / missing options be handled?

Searching through what other extensions do, will:

  • include the defaults in what is saved, if a user has settings saved (very small defaults)
  • stringify json
  • include a version, in case we need to change the preferences structure (eg requested feature of multiple filters, like normal watchlists)

Implementation:
Inject a UserOptionsManager into the SettingsManager
Define CURRENT_SETTINGS_VERSION constant to include in the setting for saving

Add hook for MakeGlobalVariablesScript
Get the user's settings, convert from json, and inject them into mw.config

At some point, the providing to js may need to include conditional logic based on the version

Since storing it on wiki makes it easier to test and verify during development, won't implement until everything else is (at least almost) complete

DannyS712 closed this task as Resolved.Jun 18 2020, 12:03 PM

Okay, going to call this resolved. Seems pretty doable:

Add a new preference with a constant name, eg globalwatchlist-settings

Use the DeleteUnknownPreferences hook to ensure that it is a "known" preference
Ref: https://www.mediawiki.org/wiki/Manual:Hooks/DeleteUnknownPreferences

Use the MakeGlobalVariablesScript hook to pass the user's current options to the special pages
Defaults are handled server-side
Exposed to javascript in mw.config
Ref: https://www.mediawiki.org/wiki/Manual:Hooks/MakeGlobalVariablesScript

Saving the user's options:
Inject a UserOptionsManager into the SettingsManager
Save the stringified JSON of the user's setting choices (converting true and false to 0 and 1)
Define CURRENT_SETTINGS_VERSION constant to include

Use the DeleteUnknownPreferences hook to ensure that it is a "known" preference
Ref: https://www.mediawiki.org/wiki/Manual:Hooks/DeleteUnknownPreferences

This should be unnecessary if you implement https://www.mediawiki.org/wiki/Manual:Hooks/GetPreferences correctly.

Use the MakeGlobalVariablesScript hook to pass the user's current options to the special pages
Defaults are handled server-side
Exposed to javascript in mw.config
Ref: https://www.mediawiki.org/wiki/Manual:Hooks/MakeGlobalVariablesScript

The user's options should already be available via the user.options module.

Use the DeleteUnknownPreferences hook to ensure that it is a "known" preference
Ref: https://www.mediawiki.org/wiki/Manual:Hooks/DeleteUnknownPreferences

This should be unnecessary if you implement https://www.mediawiki.org/wiki/Manual:Hooks/GetPreferences correctly.

Use the MakeGlobalVariablesScript hook to pass the user's current options to the special pages
Defaults are handled server-side
Exposed to javascript in mw.config
Ref: https://www.mediawiki.org/wiki/Manual:Hooks/MakeGlobalVariablesScript

The user's options should already be available via the user.options module.

I considered that, but it would mean that the defaults would be handled client-side, and would add a dependency on the user options javascript

I considered that, but it would mean that the defaults would be handled client-side, and would add a dependency on the user options javascript

What do you mean about the defaults? Pretty sure practically every page already loads user.options because of the search autocomplete.

I considered that, but it would mean that the defaults would be handled client-side, and would add a dependency on the user options javascript

What do you mean about the defaults? Pretty sure practically every page already loads user.options because of the search autocomplete.

I mean if a user doesn't have any settings saved, the extension supplies default settings for the global watchlist (show edits, log entries, and new pages, sitelist is the current site, etc.)

You set the default value through $wgDefaultUserOptions.

You set the default value through $wgDefaultUserOptions.

Hmm, hadn't thought of that. Looks like using the user options may be the way to go

DannyS712 set Final Story Points to 5.Jun 25 2020, 1:46 AM

You set the default value through $wgDefaultUserOptions.

Except we want the default to vary based on the site (by default it should just show the specific site being viewed) so the UserLoadOptions hook might be a better option (set the default to something like - and detect that and change it)