From 0efe57292ae227daf7d6ee4e5326d265fc6d3d4f Mon Sep 17 00:00:00 2001 From: Trevor Parscal Date: Thu, 16 Sep 2010 20:53:06 +0000 Subject: [PATCH] Fixed bug that cause ResourceLoader to generate mediaWiki.loader.implement calls with an empty array for the style parameter when no styles were present, which caused issues in JavaScript land - also made mediaWiki.loader more resilliant to this kind of abuse. --- includes/ResourceLoader.php | 6 +++++- resources/Resources.php | 30 ++++++++++++++++++------------ resources/mediawiki/mediawiki.js | 4 ++-- 3 files changed, 25 insertions(+), 15 deletions(-) diff --git a/includes/ResourceLoader.php b/includes/ResourceLoader.php index 61077fccd9..889fbbbff2 100644 --- a/includes/ResourceLoader.php +++ b/includes/ResourceLoader.php @@ -323,7 +323,11 @@ class ResourceLoader { } else if ( $context->getOnly() === 'messages' ) { echo "mediaWiki.msg.set( $messages );\n"; } else { - $styles = FormatJson::encode( $styles ); + if ( count( $styles ) ) { + $styles = FormatJson::encode( $styles ); + } else { + $styles = 'null'; + } echo "mediaWiki.loader.implement( '$name', function() {{$scripts}},\n$styles,\n$messages );\n"; } } diff --git a/resources/Resources.php b/resources/Resources.php index a9c970b8e3..09d5e945b1 100644 --- a/resources/Resources.php +++ b/resources/Resources.php @@ -80,24 +80,22 @@ return array( ) ), 'jquery.ui.widget' => new ResourceLoaderFileModule( array( 'scripts' => 'resources/jquery.ui/jquery.ui.widget.js', - 'dependencies' => 'jquery.ui.core', ) ), 'jquery.ui.mouse' => new ResourceLoaderFileModule( array( 'scripts' => 'resources/jquery.ui/jquery.ui.mouse.js', - 'dependencies' => 'jquery', + 'dependencies' => 'jquery.ui.widget', ) ), 'jquery.ui.position' => new ResourceLoaderFileModule( array( 'scripts' => 'resources/jquery.ui/jquery.ui.position.js', - 'dependencies' => 'jquery', ) ), // Interactions 'jquery.ui.draggable' => new ResourceLoaderFileModule( array( 'scripts' => 'resources/jquery.ui/jquery.ui.draggable.js', - 'dependencies' => 'jquery.ui.core', + 'dependencies' => array( 'jquery.ui.core', 'jquery.ui.mouse', 'jquery.ui.widget' ), ) ), 'jquery.ui.droppable' => new ResourceLoaderFileModule( array( 'scripts' => 'resources/jquery.ui/jquery.ui.droppable.js', - 'dependencies' => array( 'jquery.ui.core', 'jquery.ui.draggable' ), + 'dependencies' => array( 'jquery.ui.core', 'jquery.ui.mouse', 'jquery.ui.widget', 'jquery.ui.draggable' ), ) ), 'jquery.ui.resizable' => new ResourceLoaderFileModule( array( 'scripts' => 'resources/jquery.ui/jquery.ui.resizable.js', @@ -105,7 +103,7 @@ return array( 'default' => 'resources/jquery.ui/themes/default/jquery.ui.resizable.css', 'vector' => 'resources/jquery.ui/themes/vector/jquery.ui.resizable.css', ), - 'dependencies' => 'jquery.ui.core', + 'dependencies' => array( 'jquery.ui.core', 'jquery.ui.widget', 'jquery.ui.mouse' ), ) ), 'jquery.ui.selectable' => new ResourceLoaderFileModule( array( 'scripts' => 'resources/jquery.ui/jquery.ui.selectable.js', @@ -113,16 +111,16 @@ return array( 'default' => 'resources/jquery.ui/themes/default/jquery.ui.selectable.css', 'vector' => 'resources/jquery.ui/themes/vector/jquery.ui.selectable.css', ), - 'dependencies' => 'jquery.ui.core', + 'dependencies' => array( 'jquery.ui.core', 'jquery.ui.widget', 'jquery.ui.mouse' ), ) ), 'jquery.ui.sortable' => new ResourceLoaderFileModule( array( 'scripts' => 'resources/jquery.ui/jquery.ui.sortable.js', - 'dependencies' => 'jquery.ui.core', + 'dependencies' => array( 'jquery.ui.core', 'jquery.ui.widget', 'jquery.ui.mouse' ), ) ), // Widgets 'jquery.ui.accordion' => new ResourceLoaderFileModule( array( 'scripts' => 'resources/jquery.ui/jquery.ui.accordion.js', - 'dependencies' => 'jquery.ui.core', + 'dependencies' => array( 'jquery.ui.core', 'jquery.ui.widget' ), 'skinStyles' => array( 'default' => 'resources/jquery.ui/themes/default/jquery.ui.accordion.css', 'vector' => 'resources/jquery.ui/themes/vector/jquery.ui.accordion.css', @@ -208,7 +206,15 @@ return array( ) ), 'jquery.ui.dialog' => new ResourceLoaderFileModule( array( 'scripts' => 'resources/jquery.ui/jquery.ui.dialog.js', - 'dependencies' => 'jquery.ui.core', + 'dependencies' => array( + 'jquery.ui.core', + 'jquery.ui.widget', + 'jquery.ui.button', + 'jquery.ui.draggable', + 'jquery.ui.mouse', + 'jquery.ui.position', + 'jquery.ui.resizable', + ), 'skinStyles' => array( 'default' => 'resources/jquery.ui/themes/default/jquery.ui.dialog.css', 'vector' => 'resources/jquery.ui/themes/vector/jquery.ui.dialog.css', @@ -216,7 +222,7 @@ return array( ) ), 'jquery.ui.progressbar' => new ResourceLoaderFileModule( array( 'scripts' => 'resources/jquery.ui/jquery.ui.progressbar.js', - 'dependencies' => 'jquery.ui.core', + 'dependencies' => array( 'jquery.ui.core', 'jquery.ui.widget' ), 'skinStyles' => array( 'default' => 'resources/jquery.ui/themes/default/jquery.ui.progressbar.css', 'vector' => 'resources/jquery.ui/themes/vector/jquery.ui.progressbar.css', @@ -232,7 +238,7 @@ return array( ) ), 'jquery.ui.tabs' => new ResourceLoaderFileModule( array( 'scripts' => 'resources/jquery.ui/jquery.ui.tabs.js', - 'dependencies' => 'jquery.ui.core', + 'dependencies' => array( 'jquery.ui.core', 'jquery.ui.widget' ), 'skinStyles' => array( 'default' => 'resources/jquery.ui/themes/default/jquery.ui.tabs.css', 'vector' => 'resources/jquery.ui/themes/vector/jquery.ui.tabs.css', diff --git a/resources/mediawiki/mediawiki.js b/resources/mediawiki/mediawiki.js index feba5764f9..282c52ae64 100644 --- a/resources/mediawiki/mediawiki.js +++ b/resources/mediawiki/mediawiki.js @@ -360,7 +360,7 @@ window.mediaWiki = new ( function( $ ) { // Add style sheet to document if ( typeof registry[module].style === 'string' && registry[module].style.length ) { $( 'head' ).append( '' ); - } else if ( typeof registry[module].style === 'object' ) { + } else if ( typeof registry[module].style === 'object' && !( registry[module].style instanceof Array ) ) { for ( var media in registry[module].style ) { $( 'head' ).append( '' @@ -600,7 +600,7 @@ window.mediaWiki = new ( function( $ ) { registry[module].state = 'loaded'; // Attach components registry[module].script = script; - if ( typeof style === 'string' || typeof style === 'object' ) { + if ( typeof style === 'string' || typeof style === 'object' && !( style instanceof Array ) ) { registry[module].style = style; } if ( typeof localization === 'object' ) { -- 2.20.1