mediawiki-extensions-Visual.../modules/ve/init/mw/ve.init.mw.Platform.js
Timo Tijhof 23c5b0d02c Make use of new jshint options
* Restricting "camelcase":
  No changes, we were passing all of these already

* Explicitly unrestricting "forin" and "plusplus"
  These are off by default in node-jshint, but some distro of jshint
  and editors that use their own wrapper around jshint instead of
  node-jshint (Eclipse?) may have different defaults. Therefor
  setting them to false explicitly. This also serves as a reminder
  for the future so we'll always know we don't pass that, in case
  we would want to change that.

* Fix order ("quotemark" before "regexp")

* Restricting "unused"
  We're not passing all of this, which is why I've set it to false
  for now. But I did put it in .jshintrc as placeholder.
  I've fixed most of them, there's some left where there is no clean
  solution.

* While at it fix a few issues:
 - Unused variables ($target, $window)
 - Bad practices (using jQuery context for find instead of creation)
 - Redundant /*global */ comments
 - Parameters that are not used and don't have documentation either
 - Lines longer than 100 chars @ 4 spaces/tab

* Note:
 - ve.ce.Surface.prototype.onChange takes two arguments but never
   uses the former. And even the second one can be null/undefined.
   Aside from that, the .change() function emits
   another event for the transaction already. Looks like this
   should be refactored a bit, two more separated events probably
   or one that is actually used better.
 - Also cleaned up a lot of comments, some of which were missing,
   others were incorrect
 - Reworked the contentChange event so we are no longer using the
   word new as an object key; expanded a complex object into multiple
   arguments being passed through the event to make it easier to work
   with and document

Change-Id: I8490815a508c6c379d5f9a743bb4aefd14576aa6
2012-08-10 02:50:30 +02:00

85 lines
2 KiB
JavaScript

/*global mw */
/**
* VisualEditor MediaWiki initialization Target class.
*
* @copyright 2011-2012 VisualEditor Team and others; see AUTHORS.txt
* @license The MIT License (MIT); see LICENSE.txt
*/
/**
* MediaWiki platform.
*
* @class
* @constructor
* @param {String} pageName Name of target page
*/
ve.init.mw.Platform = function () {
// Inheritance
ve.init.Platform.call( this );
// Properties
this.externalLinkUrlProtocolsRegExp = new RegExp( '^' + mw.config.get( 'wgUrlProtocols' ) );
this.modulesUrl = mw.config.get( 'wgExtensionAssetsPath' ) + '/VisualEditor/modules';
};
/* Methods */
/**
* Gets a regular expression that matches allowed external link URLs.
*
* Uses the mw.config wgUrlProtocols variable.
*
* @method
* @returns {RegExp} Regular expression object
*/
ve.init.mw.Platform.prototype.getExternalLinkUrlProtocolsRegExp = function () {
return this.externalLinkUrlProtocolsRegExp;
};
/**
* Gets a remotely accessible URL to the modules directory.
*
* Uses MediaWiki's {wgExtensionAssetsPath} variable.
*
* @method
* @returns {String} Remote modules URL
*/
ve.init.mw.Platform.prototype.getModulesUrl = function () {
return this.modulesUrl;
};
/**
* Adds multiple messages to the localization system.
*
* Wrapper for mw.msg system.
*
* @method
* @param {Object} messages Map of message-key/message-string pairs
*/
ve.init.mw.Platform.prototype.addMessages = function ( messages ) {
return mw.messages.set( messages );
};
/**
* Gets a message from the localization system.
*
* Wrapper for mw.msg system.
*
* @method
* @param {String} key Message key
* @param {Mixed} [...] List of arguments which will be injected at $1, $2, etc. in the messaage
* @returns {String} Localized message
*/
ve.init.mw.Platform.prototype.getMessage = function () {
return mw.msg.apply( mw.msg, arguments );
};
/* Inheritance */
ve.extendClass( ve.init.mw.Platform, ve.init.Platform );
/* Initialization */
ve.init.platform = new ve.init.mw.Platform();