Wikipedia talk:WikiProject User scripts/preferences

Initial version

edit

The initial version is fairly straightforward (but it is far from ready for deployment at this stage). The basic overview of usage would be:

1. The main module would be put into MediaWiki:Gadget-jsprefs.js (however, it should not be added to MediaWiki:Gadgets-definition, so possibly a less ambiguous name should be chosen).

2. Any script that will utilize the variable system should load that script via document.write (importScript() will not work) , as well as define some variables (prefixed with "scriptname-", eg:

 if (window.jsPrefsSettable) {
   jsPrefsSettable[jsPrefsSettable.length] = {
     'name': 'navpopups-enablesomeoption',
     'desc': 'enable foobarbaz',
     'type': 'boolean',
     'defval': true};
 }

3. The script should then check the state of the options via eg: getjsPref('navpopups-enablesomeoption'). This first test tells if the option is defined. If defined, a second test comparing the actual contents is then done. Note that getjsPref() works with a literal cookie name, *or* with an attribute of the jsPrefs object. So for example this same option could be hard-coded via jsPrefs['navpopups-enablesomeoption'] = true; in the user/skin.js as an alterative (for users with multiple browsers or workstations).

4. If a user loads that script, they will see a a link in their toolbox for configuring various JS options. From there they can enable/disable options via cookie (or change string or number values, such as a default edit summary or block reason for batch jobs), and helpful instructions (eventually) on how to set the variable in user/skin.js

Problems with initial version

edit
  • the config UI sucks, I wrote it quickly.
  • There should be a way to group the prefs by the extension they are from.
  • Dropdown boxes of select/option tags would be problematic but not impossible, and somewhat useful. The value of the selection would probably be stored as an integer, eg .selectionIndex
  • The load order is a problem, requiring the jsPrefsSettable to be set after document load. Possibly the globals could be defined in each gadget, then each gadget could immediately begin defining the possibles. The check on the variables still seems to need to be done after document load (why?).
if(!window.jsPrefs) var jsPrefs = [];
if(!window.jsPrefsSettable) var jsPrefsSettable = [];
  • importScript in Common.js cannot be used, as gadgets are loaded before site-wide js, and document.write is nice and compact (for now).
  • not yet checked for cross-browser friendliness. Proof-of-concept stage so far.

Examples

edit

The test.wikipedia has two bare-bones gadgets in MediaWiki:Gadgets-definition, which utilize this initial version. You can create a user, go to prefernces, and enable test 1 (an alert test, bit annoying) or test 2 (a [google] button adder), and then fiddle with your "Script preferences" in the toolbox).

Thoughts

edit

Worth pursuing any further? --Splarka (rant) 04:59, 29 December 2007 (UTC)Reply