r111599 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r111598‎ | r111599 | r111600 >
Date:23:44, 15 February 2012
Author:reedy
Status:ok
Tags:
Comment:
Modified paths:
  • /branches/wmf/1.19wmf1 (modified) (history)
  • /branches/wmf/1.19wmf1/includes (modified) (history)
  • /branches/wmf/1.19wmf1/includes/OutputPage.php (modified) (history)
  • /branches/wmf/1.19wmf1/resources/mediawiki/mediawiki.js (modified) (history)

Diff [purge]

Index: branches/wmf/1.19wmf1/resources/mediawiki/mediawiki.js
@@ -620,14 +620,14 @@
621621
622622 /**
623623 * Adds a script tag to the DOM, either using document.write or low-level DOM manipulation,
624 - * depending on whether document-ready has occured yet and whether we are in blocking mode.
 624+ * depending on whether document-ready has occured yet and whether we are in async mode.
625625 *
626626 * @param src String: URL to script, will be used as the src attribute in the script tag
627627 * @param callback Function: Optional callback which will be run when the script is done
628628 */
629 - function addScript( src, callback, blocking ) {
 629+ function addScript( src, callback, async ) {
630630 var done = false, script, head;
631 - if ( ready || !blocking ) {
 631+ if ( ready || async ) {
632632 // jQuery's getScript method is NOT better than doing this the old-fashioned way
633633 // because jQuery will eval the script's code, and errors will not have sane
634634 // line numbers.
@@ -738,7 +738,7 @@
739739 callback();
740740 }
741741 };
742 - nestedAddScript = function ( arr, callback, blocking, i ) {
 742+ nestedAddScript = function ( arr, callback, async, i ) {
743743 // Recursively call addScript() in its own callback
744744 // for each element of arr.
745745 if ( i >= arr.length ) {
@@ -748,13 +748,13 @@
749749 }
750750
751751 addScript( arr[i], function() {
752 - nestedAddScript( arr, callback, blocking, i + 1 );
753 - }, blocking );
 752+ nestedAddScript( arr, callback, async, i + 1 );
 753+ }, async );
754754 };
755755
756756 if ( $.isArray( script ) ) {
757757 registry[module].state = 'loading';
758 - nestedAddScript( script, markModuleReady, registry[module].blocking, 0 );
 758+ nestedAddScript( script, markModuleReady, registry[module].async, 0 );
759759 } else if ( $.isFunction( script ) ) {
760760 script( $ );
761761 markModuleReady();
@@ -777,10 +777,10 @@
778778 * @param dependencies string module name or array of string module names
779779 * @param ready function callback to execute when all dependencies are ready
780780 * @param error function callback to execute when any dependency fails
781 - * @param blocking (optional) If true, load modules in a blocking fashion if
782 - * document ready has not yet occurred
 781+ * @param async (optional) If true, load modules asynchronously even if
 782+ * document ready has not yet occurred
783783 */
784 - function request( dependencies, ready, error, blocking ) {
 784+ function request( dependencies, ready, error, async ) {
785785 var regItemDeps, regItemDepLen, n;
786786
787787 // Allow calling by single module name
@@ -812,9 +812,9 @@
813813 for ( n = 0; n < dependencies.length; n += 1 ) {
814814 if ( $.inArray( dependencies[n], queue ) === -1 ) {
815815 queue[queue.length] = dependencies[n];
816 - if ( blocking ) {
817 - // Mark this module as blocking in the registry
818 - registry[dependencies[n]].blocking = true;
 816+ if ( async ) {
 817+ // Mark this module as async in the registry
 818+ registry[dependencies[n]].async = true;
819819 }
820820 }
821821 }
@@ -855,9 +855,9 @@
856856 * @param moduleMap {Object}: Module map, see buildModulesString()
857857 * @param currReqBase {Object}: Object with other parameters (other than 'modules') to use in the request
858858 * @param sourceLoadScript {String}: URL of load.php
859 - * @param blocking {Boolean}: If true, use a blocking request if document ready has not yet occurred
 859+ * @param async {Boolean}: If true, use an asynchrounous request even if document ready has not yet occurred
860860 */
861 - function doRequest( moduleMap, currReqBase, sourceLoadScript, blocking ) {
 861+ function doRequest( moduleMap, currReqBase, sourceLoadScript, async ) {
862862 var request = $.extend(
863863 { 'modules': buildModulesString( moduleMap ) },
864864 currReqBase
@@ -865,7 +865,7 @@
866866 request = sortQuery( request );
867867 // Asynchronously append a script tag to the end of the body
868868 // Append &* to avoid triggering the IE6 extension check
869 - addScript( sourceLoadScript + '?' + $.param( request ) + '&*', null, blocking );
 869+ addScript( sourceLoadScript + '?' + $.param( request ) + '&*', null, async );
870870 }
871871
872872 /* Public Methods */
@@ -877,7 +877,7 @@
878878 var reqBase, splits, maxQueryLength, q, b, bSource, bGroup, bSourceGroup,
879879 source, group, g, i, modules, maxVersion, sourceLoadScript,
880880 currReqBase, currReqBaseLength, moduleMap, l,
881 - lastDotIndex, prefix, suffix, bytesAdded, blocking;
 881+ lastDotIndex, prefix, suffix, bytesAdded, async;
882882
883883 // Build a list of request parameters common to all requests.
884884 reqBase = {
@@ -954,7 +954,7 @@
955955
956956 currReqBase = $.extend( { 'version': formatVersionNumber( maxVersion ) }, reqBase );
957957 currReqBaseLength = $.param( currReqBase ).length;
958 - blocking = false;
 958+ async = true;
959959 // We may need to split up the request to honor the query string length limit,
960960 // so build it piece by piece.
961961 l = currReqBaseLength + 9; // '&modules='.length == 9
@@ -976,26 +976,26 @@
977977 if ( maxQueryLength > 0 && !$.isEmptyObject( moduleMap ) && l + bytesAdded > maxQueryLength ) {
978978 // This request would become too long, create a new one
979979 // and fire off the old one
980 - doRequest( moduleMap, currReqBase, sourceLoadScript, blocking );
 980+ doRequest( moduleMap, currReqBase, sourceLoadScript, async );
981981 moduleMap = {};
982 - blocking = false;
 982+ async = true;
983983 l = currReqBaseLength + 9;
984984 }
985985 if ( moduleMap[prefix] === undefined ) {
986986 moduleMap[prefix] = [];
987987 }
988988 moduleMap[prefix].push( suffix );
989 - if ( registry[modules[i]].blocking ) {
 989+ if ( !registry[modules[i]].async ) {
990990 // If this module is blocking, make the entire request blocking
991991 // This is slightly suboptimal, but in practice mixing of blocking
992 - // and non-blocking modules will only occur in debug mode.
993 - blocking = true;
 992+ // and async modules will only occur in debug mode.
 993+ async = false;
994994 }
995995 l += bytesAdded;
996996 }
997997 // If there's anything left in moduleMap, request that too
998998 if ( !$.isEmptyObject( moduleMap ) ) {
999 - doRequest( moduleMap, currReqBase, sourceLoadScript, blocking );
 999+ doRequest( moduleMap, currReqBase, sourceLoadScript, async );
10001000 }
10011001 }
10021002 }
@@ -1177,10 +1177,11 @@
11781178 * @param type {String} mime-type to use if calling with a URL of an
11791179 * external script or style; acceptable values are "text/css" and
11801180 * "text/javascript"; if no type is provided, text/javascript is assumed.
1181 - * @param blocking {Boolean} (optional) If true, load modules in a blocking
1182 - * fashion if document ready has not yet occurred
 1181+ * @param async {Boolean} (optional) If true, load modules asynchronously
 1182+ * even if document ready has not yet occurred. If false (default),
 1183+ * block before document ready and load async after
11831184 */
1184 - load: function ( modules, type, blocking ) {
 1185+ load: function ( modules, type, async ) {
11851186 var filtered, m;
11861187
11871188 // Validate input
@@ -1199,7 +1200,7 @@
12001201 } ) );
12011202 return;
12021203 } else if ( type === 'text/javascript' || type === undefined ) {
1203 - addScript( modules, null, blocking );
 1204+ addScript( modules, null, async );
12041205 return;
12051206 }
12061207 // Unknown type
@@ -1232,7 +1233,7 @@
12331234 }
12341235 // Since some modules are not yet ready, queue up a request
12351236 else {
1236 - request( filtered, null, null, blocking );
 1237+ request( filtered, null, null, async );
12371238 return;
12381239 }
12391240 },
Index: branches/wmf/1.19wmf1/includes/OutputPage.php
@@ -2501,7 +2501,7 @@
25022502 * @param $only String ResourceLoaderModule TYPE_ class constant
25032503 * @param $useESI boolean
25042504 * @param $extraQuery Array with extra query parameters to add to each request. array( param => value )
2505 - * @param $loadCall boolean If true, output a mw.loader.load() call rather than a <script src="..."> tag
 2505+ * @param $loadCall boolean If true, output an (asynchronous) mw.loader.load() call rather than a <script src="..."> tag
25062506 * @return string html <script> and <style> tags
25072507 */
25082508 protected function makeResourceLoaderLink( $modules, $only, $useESI = false, array $extraQuery = array(), $loadCall = false ) {
@@ -2644,7 +2644,7 @@
26452645 } else if ( $loadCall ) {
26462646 $link = Html::inlineScript(
26472647 ResourceLoader::makeLoaderConditionalScript(
2648 - Xml::encodeJsCall( 'mw.loader.load', array( $url ) )
 2648+ Xml::encodeJsCall( 'mw.loader.load', array( $url, 'text/javascript', true ) )
26492649 )
26502650 );
26512651 } else {
@@ -2697,7 +2697,7 @@
26982698 if ( $modules ) {
26992699 $scripts .= Html::inlineScript(
27002700 ResourceLoader::makeLoaderConditionalScript(
2701 - Xml::encodeJsCall( 'mw.loader.load', array( $modules, null, true ) )
 2701+ Xml::encodeJsCall( 'mw.loader.load', array( $modules ) )
27022702 )
27032703 );
27042704 }
@@ -2739,7 +2739,7 @@
27402740 if ( $modules ) {
27412741 $scripts .= Html::inlineScript(
27422742 ResourceLoader::makeLoaderConditionalScript(
2743 - Xml::encodeJsCall( 'mw.loader.load', array( $modules ) )
 2743+ Xml::encodeJsCall( 'mw.loader.load', array( $modules, null, true ) )
27442744 )
27452745 );
27462746 }
Property changes on: branches/wmf/1.19wmf1/includes/OutputPage.php
___________________________________________________________________
Modified: svn:mergeinfo
27472747 Merged /trunk/phase3/includes/OutputPage.php:r111597
Property changes on: branches/wmf/1.19wmf1/includes
___________________________________________________________________
Modified: svn:mergeinfo
27482748 Merged /trunk/phase3/includes:r111597
Property changes on: branches/wmf/1.19wmf1
___________________________________________________________________
Modified: svn:mergeinfo
27492749 Merged /trunk/phase3:r111597

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r111597Followup r110592: rename 'blocking' to 'async', and invert the logic everywhe...catrope23:38, 15 February 2012

Status & tagging log