summaryrefslogtreecommitdiff
path: root/resources/mediawiki/mediawiki.log.js
diff options
context:
space:
mode:
Diffstat (limited to 'resources/mediawiki/mediawiki.log.js')
-rw-r--r--resources/mediawiki/mediawiki.log.js65
1 files changed, 60 insertions, 5 deletions
diff --git a/resources/mediawiki/mediawiki.log.js b/resources/mediawiki/mediawiki.log.js
index ee08b12b..75e4c961 100644
--- a/resources/mediawiki/mediawiki.log.js
+++ b/resources/mediawiki/mediawiki.log.js
@@ -1,4 +1,4 @@
-/**
+/*!
* Logger for MediaWiki javascript.
* Implements the stub left by the main 'mediawiki' module.
*
@@ -9,15 +9,20 @@
( function ( mw, $ ) {
/**
+ * @class mw.log
+ * @singleton
+ */
+
+ /**
* Logs a message to the console.
*
* In the case the browser does not have a console API, a console is created on-the-fly by appending
- * a <div id="mw-log-console"> element to the bottom of the body and then appending this and future
+ * a `<div id="mw-log-console">` element to the bottom of the body and then appending this and future
* messages to that, instead of the console.
*
- * @param {String} First in list of variadic messages to output to console.
+ * @param {string...} msg Messages to output to console.
*/
- mw.log = function ( /* logmsg, logmsg, */ ) {
+ mw.log = function () {
// Turn arguments into an array
var args = Array.prototype.slice.call( arguments ),
// Allow log messages to use a configured prefix to identify the source window (ie. frame)
@@ -54,7 +59,7 @@
hovzer.update();
}
$log.append(
- $( '<div></div>' )
+ $( '<div>' )
.css( {
borderBottom: 'solid 1px #DDDDDD',
fontSize: 'small',
@@ -68,4 +73,54 @@
} );
};
+ /**
+ * Write a message the console's warning channel.
+ * Also logs a stacktrace for easier debugging.
+ * Each action is silently ignored if the browser doesn't support it.
+ *
+ * @param {string...} msg Messages to output to console
+ */
+ mw.log.warn = function () {
+ var console = window.console;
+ if ( console && console.warn ) {
+ console.warn.apply( console, arguments );
+ if ( console.trace ) {
+ console.trace();
+ }
+ }
+ };
+
+ /**
+ * Create a property in a host object that, when accessed, will produce
+ * a deprecation warning in the console with backtrace.
+ *
+ * @param {Object} obj Host object of deprecated property
+ * @param {string} key Name of property to create in `obj`
+ * @param {Mixed} val The value this property should return when accessed
+ * @param {string} [msg] Optional text to include in the deprecation message.
+ */
+ mw.log.deprecate = !Object.defineProperty ? function ( obj, key, val ) {
+ obj[key] = val;
+ } : function ( obj, key, val, msg ) {
+ msg = 'MWDeprecationWarning: Use of "' + key + '" property is deprecated.' +
+ ( msg ? ( ' ' + msg ) : '' );
+ try {
+ Object.defineProperty( obj, key, {
+ configurable: true,
+ enumerable: true,
+ get: function () {
+ mw.log.warn( msg );
+ return val;
+ },
+ set: function ( newVal ) {
+ mw.log.warn( msg );
+ val = newVal;
+ }
+ } );
+ } catch ( err ) {
+ // IE8 can throw on Object.defineProperty
+ obj[key] = val;
+ }
+ };
+
}( mediaWiki, jQuery ) );