build: Enable jscs rules 'requireSpacesInside*Brackets' and make pass
[lhc/web/wiklou.git] / resources / src / mediawiki.legacy / wikibits.js
index 32cd79a..7d1f6d7 100644 (file)
@@ -85,7 +85,7 @@
 
                // Execute the queued functions
                for ( i = 0; i < functs.length; i++ ) {
-                       functs[i]();
+                       functs[ i ]();
                }
        } );
 
         * See https://www.mediawiki.org/wiki/ResourceLoader/Legacy_JavaScript#wikibits.js
         */
 
-       function importScript( page ) {
-               var uri = mw.config.get( 'wgScript' ) + '?title=' +
-                       mw.util.wikiUrlencode( page ) +
-                       '&action=raw&ctype=text/javascript';
-               return importScriptURI( uri );
-       }
-
        /**
         * @deprecated since 1.17 Use mw.loader instead. Warnings added in 1.25.
         */
        function importScriptURI( url ) {
-               if ( loadedScripts[url] ) {
+               if ( loadedScripts[ url ] ) {
                        return null;
                }
-               loadedScripts[url] = true;
+               loadedScripts[ url ] = true;
                var s = document.createElement( 'script' );
                s.setAttribute( 'src', url );
                s.setAttribute( 'type', 'text/javascript' );
-               document.getElementsByTagName( 'head' )[0].appendChild( s );
+               document.getElementsByTagName( 'head' )[ 0 ].appendChild( s );
                return s;
        }
 
-       function importStylesheet( page ) {
+       function importScript( page ) {
                var uri = mw.config.get( 'wgScript' ) + '?title=' +
                        mw.util.wikiUrlencode( page ) +
-                       '&action=raw&ctype=text/css';
-               return importStylesheetURI( uri );
+                       '&action=raw&ctype=text/javascript';
+               return importScriptURI( uri );
        }
 
        /**
                if ( media ) {
                        l.media = media;
                }
-               document.getElementsByTagName( 'head' )[0].appendChild( l );
+               document.getElementsByTagName( 'head' )[ 0 ].appendChild( l );
                return l;
        }
 
+       function importStylesheet( page ) {
+               var uri = mw.config.get( 'wgScript' ) + '?title=' +
+                       mw.util.wikiUrlencode( page ) +
+                       '&action=raw&ctype=text/css';
+               return importStylesheetURI( uri );
+       }
+
        msg = 'Use mw.loader instead.';
        mw.log.deprecate( win, 'loadedScripts', loadedScripts, msg );
        mw.log.deprecate( win, 'importScriptURI', importScriptURI, msg );
        win.importScript = importScript;
        win.importStylesheet = importStylesheet;
 
+       // Replace document.write/writeln with basic html parsing that appends
+       // to the <body> to avoid blanking pages. Added JavaScript will not run.
+       $.each( [ 'write', 'writeln' ], function ( idx, method ) {
+               mw.log.deprecate( document, method, function () {
+                       $( 'body' ).append( $.parseHTML( Array.prototype.join.call( arguments, '' ) ) );
+               }, 'Use jQuery or mw.loader.load instead.' );
+       } );
+
 }( mediaWiki, jQuery ) );