Last modified: 2014-10-29 21:12:12 UTC
Just look at my mw.user.options table added below. 1 vs true vs "1". I'm in favor of using numbers over booleans here, but why do we have string values for numbers ? Worse yet, check the inconsistency in Gadgets. Gadgets enabled by default return 1 and gadgets enabled by the user return "1". We should really do a bit of clean up here, and possibly even cleanup the existing values in tables, this makes coding JS against these pages more fragile than needed. aftv5-last-filter: null ccmeonemails: 0 cols: "120" date: "mdy" diffonly: "1" disablemail: 0 disablesuggest: 0 echo-email-format: "html" echo-email-frequency: 0 echo-notify-show-link: true echo-show-alert: true echo-subscriptions-email-article-linked: false echo-subscriptions-email-edit-thank: false echo-subscriptions-email-edit-user-talk: 1 echo-subscriptions-email-mention: false echo-subscriptions-email-other: false echo-subscriptions-email-page-review: false echo-subscriptions-email-reverted: false echo-subscriptions-email-system: true echo-subscriptions-web-article-linked: "1" echo-subscriptions-web-edit-thank: true echo-subscriptions-web-edit-user-talk: true echo-subscriptions-web-mention: true echo-subscriptions-web-other: true echo-subscriptions-web-page-review: true echo-subscriptions-web-reverted: true echo-subscriptions-web-system: true editfont: "default" editondblclick: 0 editsection: 1 editsectiononrightclick: 0 enotifminoredits: 0 enotifrevealaddr: 0 enotifusertalkpages: 1 enotifwatchlistpages: 0 ep_bulkdelcourses: true ep_bulkdelorgs: false ep_showdyk: true ep_showtoplink: false extendwatchlist: 0 fancysig: "1" flaggedrevseditdiffs: true flaggedrevssimpleui: 1 flaggedrevsstable: 0 flaggedrevsviewdiffs: false forceeditsummary: "1" gadget-BugStatusUpdate: "1" gadget-DRN-wizard: 1 gadget-HotCat: "1" gadget-Navigation_popups: "1" gadget-NoAnimations: "1" gadget-PrintOptions: "1" gadget-ReferenceTooltips: 1 gadget-UTCLiveClock: "1" gadget-addsection-plus: "1" gadget-charinsert: 1 gadget-contribsrange: "1" gadget-edittop: "1" gadget-exlinks: "1" gadget-metadata: "1" gadget-mySandbox: 1 gadget-purgetab: "1" gadget-teahouse: 1 gadget-widensearch: "1" gadget-wikEd: "1" gadget-wikEdDiff: "1" gender: "male" gettingstarted-task-toolbar-show-intro: "" hideminor: 0 hidepatrolled: 0 imagesize: 2 justify: 0 language: "en" math: "6" mfWatchlistFilter: "all" mfWatchlistView: "feed" minordefault: 0 newpageshidepatrolled: 0 nocache: 0 noconvertlink: 0 norollbackdiff: 0 numberheadings: 0 previewonfirst: 0 previewontop: 1 rcdays: 7 rclimit: 50 rcshowwikidata: "1" rememberpassword: 0 rows: "30" searchNs0: true searchNs1: false searchNs2: false searchNs3: false searchNs4: false searchNs5: false searchNs6: false searchNs7: false searchNs8: false searchNs9: false searchNs10: false searchNs11: false searchNs12: false searchNs13: false searchNs14: "1" searchNs15: false searchNs100: false searchNs101: false searchNs108: false searchNs109: false searchNs446: false searchNs447: false searchNs710: false searchNs711: false searchNs828: false searchNs829: false searchlimit: 20 showhiddencats: "1" showjumplinks: 1 shownumberswatching: 1 showtoc: 1 showtoolbar: 1 skin: "vector" stubthreshold: "2000" thumbsize: 4 timecorrection: "ZoneInfo|120|Europe/Amsterdam" uls-preferences: "" underline: 2 usebetatoolbar: 1 usebetatoolbar-cgd: 1 useeditwarning: 1 uselivepreview: 0 usenewrc: "1" userjs-curationtoolbar: "hidden" variant: "en" vector-collapsiblenav: 1 vector-simplesearch: 1 visualeditor-betatempdisable: 0 visualeditor-enable: 1 watchcreations: 1 watchdefault: 0 watchdeletion: 0 watchlistdays: 3 watchlisthideanons: 0 watchlisthidebots: 0 watchlisthideliu: 0 watchlisthideminor: 0 watchlisthideown: 0 watchlisthidepatrolled: 0 watchmoves: 0 wikilove-enabled: 1 wllimit: 250 wlshowwikibase: "1"
Values that are actually saved in the database (ie, non-default ones) are always strings, and apparently usually equal to "1" (but for boolean prefs any truthy value is technically possible, especially if one uses the API to set them). Values that are default ones are equal to whatever the programmer decided, and as you can see they might be 1/0, true/false, "1"/"0" or null. You should just check for truthiness in this case. I'm not sure how to solve this, or whether we actually want to solve this; normalizing values of boolean prefs to true/false just before building this list (in ResourceLoaderUserOptionsModule#getScript) seems like the best way.
The integer came from $wgDefaultSettings. Set it to string there and it should work, except gadget and maybe the searchNs, because that are dynamically preferences, where the default is not stored in $wgDefaultSettings.
(In reply to Bartosz Dziewoński from comment #1) > ... > normalizing values of boolean prefs to true/false just before building this > list (in ResourceLoaderUserOptionsModule#getScript) seems like the best way. +1 for normalizing boolean preferences so that either > mw.user.options.get( 'anyBooleanPreference' ) === true > mw.user.options.get( 'anyBooleanPreference' ) === false and nothing else. The current behavior is ***very*** inconvenient: * If I do not set $wgDefaultUserOptions['usebetatoolbar'] (i.e., if I use WikiEditor's default): - If I don't change the preference mw.user.options.get( 'usebetatoolbar' ) === null - If I enable the preference mw.user.options.get( 'usebetatoolbar' ) === "1" * If I set $wgDefaultUserOptions['usebetatoolbar'] = 1 (as in WMF cluster[1]): - If I don't change the preference mw.user.options.get( 'usebetatoolbar' ) === 1 - If I disable the preference mw.user.options.get( 'usebetatoolbar' ) === "0" (non-empty string == true!) * On English Wikipedia - If I don't change the preference mw.user.options.get( 'usebetatoolbar' ) === 1 - If I disable the preference mw.user.options.get( 'usebetatoolbar' ) === "" (empty string!) [1] https://github.com/wikimedia/operations-mediawiki-config/blob/8178a4994c0137f5171798f3e831c0492c8cbc06/wmf-config/CommonSettings.php#L1641