Florianschmidtwelzow has uploaded a new change for review. https://gerrit.wikimedia.org/r/202069
Change subject: Add support to deprecate a module ...................................................................... Add support to deprecate a module If a module is depreacted (or it has a new name and the old on eis kept for compatibility), you can depreacte the module and a depreaction warning will appear in the browser console. Usage: Instead of registering a module with: M.define( 'context', context, ); use: M.define( 'context', context, true, 'contextNew' ); (e.g. to deprecate the module context and replacing it with contextNew). Change-Id: I5ddc099ba2d215137c385a27d36aff5f6f35cbb3 --- M javascripts/modules.js 1 file changed, 17 insertions(+), 2 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MobileFrontend refs/changes/69/202069/1 diff --git a/javascripts/modules.js b/javascripts/modules.js index c80b414..00d4729 100644 --- a/javascripts/modules.js +++ b/javascripts/modules.js @@ -36,12 +36,27 @@ * * @param {String} id Defined module id. * @param {Object} obj Defined module body, can be any JavaScript object. + * @param {Boolean} deprecated If true, this module is depreacted and shouldn't be used anymore + * (logs an depreacted error in the browser console when required) + * @param {String} replacement Module to use instead, if this is depreacted. */ - define: function ( id, obj ) { + define: function ( id, obj, deprecated, replacement ) { + var depreacteMsg; + if ( this._register.hasOwnProperty( id ) ) { throw new Error( 'Module already exists: ' + id ); } - this._register[ id ] = obj; + // if this module is depreacted and shouldn't be used anymore, use mw.log.depreacte to log the error in + // the browser console + if ( deprecated ) { + depreacteMsg = 'Module ' + id + ' is depreacted.'; + if ( replacement ) { + depreacteMsg += ' Use ' + replacement + ' instead.'; + } + mw.log.deprecate( this._register, id, obj, depreacteMsg ); + } else { + this._register[ id ] = obj; + } } }; -- To view, visit https://gerrit.wikimedia.org/r/202069 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I5ddc099ba2d215137c385a27d36aff5f6f35cbb3 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/MobileFrontend Gerrit-Branch: master Gerrit-Owner: Florianschmidtwelzow <florian.schmidt.wel...@t-online.de> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits