Page MenuHomePhabricator

Update the example of (non) legacy code wich uses the array wgRestrictionEdit
Closed, InvalidPublic


At DefaultSettings.php#L3709, there is

if ( window.wgRestrictionEdit ) { ... }


if ( mw.config.exists('wgRestrictionEdit') ) { ... }

However this variable is an array, not a boolean (see T133289), so it should be checking the length of the array instead:

if ( mw.config.exists('wgRestrictionEdit').length ) { ... }

Event Timeline

This will always be undefined in this case. Please see the exact code of the example:
if ( mw.config.exists('wgRestrictionEdit') ) { ... }

it does not use mw.config.get(...) which will return an array for wgRestrictionEdit, however, it uses mw.config.exists, which:
Check if one or more keys exist.
and, per doc, will always return a boolean:
exists( selection ) : boolean

So checking for a boolean here is correct, as we're not checking that there're any entries in the array, but instead checking, if the config variable even exists (~ is defined).

This looks like to be invalid then?