Prefer console.error over console.log for exception logging
[lhc/web/wiklou.git] / resources / mediawiki / mediawiki.js
index a9fa1fd..793cf22 100644 (file)
@@ -626,17 +626,21 @@ var mw = ( function ( $, undefined ) {
 
                        /**
                         * Log a message to window.console, if possible. Useful to force logging of some
-                        * errors that are otherwise hard to detect, even if mw.log is not available. (I.e.,
-                        * this logs also if not in debug mode.)
+                        * errors that are otherwise hard to detect (I.e., this logs also in production mode).
+                        * Gets console references in each invocation, so that delayed debugging tools work
+                        * fine. No need for optimization here, which would only result in losing logs.
                         *
-                        * @param msg String text for the log entry
-                        * @param e   Error [optional] to also log.
+                        * @param msg String text for the log entry.
+                        * @param e Error [optional] to also log.
                         */
                        function log( msg, e ) {
-                               if ( window.console && typeof window.console.log === 'function' ) {
+                               var console = window.console;
+                               if ( console && console.log ) {
                                        console.log( msg );
+                                       // console.error triggers the proper handling of exception objects in
+                                       // consoles that support it. Fallback to passing as plain object to log().
                                        if ( e ) {
-                                               console.log( e );
+                                               (console.error || console.log).call( console, e );
                                        }
                                }
                        }
@@ -1050,6 +1054,10 @@ var mw = ( function ( $, undefined ) {
                                                        }
 
                                                        currReqBase = $.extend( { 'version': formatVersionNumber( maxVersion ) }, reqBase );
+                                                       // For user modules append a user name to the request.
+                                                       if ( group === "user" && mw.config.get( 'wgUserName' ) !== null ) {
+                                                               currReqBase.user = mw.config.get( 'wgUserName' );
+                                                       }
                                                        currReqBaseLength = $.param( currReqBase ).length;
                                                        async = true;
                                                        // We may need to split up the request to honor the query string length limit,