MediaWiki:WgMessageWallsExist.js

/** * wgMessageWallsExist * * This script provides a new wgVariable that provides information on whether * or not the current wiki provides MessageWalls. * * This is done by making an AJAX request to a Wikia controller or falling back * to selectors if that cannot be done. * * @NOTE: *    This variable returns a Promise which means it cannot be used like the *    rest of the other config variables. Please see the usage below for more *    information on how to use this. * * @Contributors: *    - KockaAdmiralac *    - Speedit *    - Colouratura * * @Usage: *    mw.config.get('wgMessageWallsExist').then( *         function  { *             // Message walls do exist on this wiki *         }, *         function  { *             // Message walls do not exist on this wiki *         } *     ); */ mediaWiki.config.values['wgMessageWallsExist'] = function (name) { return new Promise(function (resolve, reject) {       $.nirvana            .getJson('WikiFeaturesSpecialController', 'index')            .done(function (d) { var disabled = d.features.filter(function (t) {                       return t.name === 'wgEnableWallExt' && t.enabled;                    }).length === 0; if (disabled) { reject; } else { resolve; }           })            .error(function  { var wall = '.wds-global-navigation__dropdown-link[data-tracking-label="account.message-wall"]'; if ($(wall).length === 0) { reject; } else { resolve; }           });    }); }(mw.config.get('wgUserName'));