From 929c1f2d4126e09568d71432a7d8f503feecb3f7 Mon Sep 17 00:00:00 2001 From: Krinkle Date: Wed, 19 Jan 2011 16:26:31 +0000 Subject: [PATCH] Fix bug in mw.Map + fix bug 26801 + wrapper mediawiki.special.upload.js * Map.prototype.exists was checking the type of the wrong variable. Fixed now, checking multiple at once is now possible (as documented) * bug 26801: No references to legacy globals, use mw.config everywhere in core (grep search for 'wg' in /resources returned only * Addressed some JS Lint warnings (combining var statements, faster and less code); * Removed trailing tabs and spaces --- .../mediawiki.special.upload.js | 23 ++++++------ resources/mediawiki.util/mediawiki.util.js | 37 +++++++++++-------- .../mediawiki.util/mediawiki.util.test.js | 27 +++++++------- resources/mediawiki/mediawiki.js | 2 +- 4 files changed, 48 insertions(+), 41 deletions(-) diff --git a/resources/mediawiki.special/mediawiki.special.upload.js b/resources/mediawiki.special/mediawiki.special.upload.js index aa26a9e0bf..468a0c67d0 100644 --- a/resources/mediawiki.special/mediawiki.special.upload.js +++ b/resources/mediawiki.special/mediawiki.special.upload.js @@ -3,7 +3,7 @@ * Note that additional code still lives in skins/common/upload.js */ -$( function() { +jQuery( function( $ ) { /** * Is the FileAPI available with sufficient functionality? */ @@ -21,9 +21,9 @@ $( function() { * @return boolean */ function fileIsPreviewable( file ) { - var known = ['image/png', 'image/gif', 'image/jpeg', 'image/svg+xml']; - var tooHuge = 10 * 1024 * 1024; - return ($.inArray( file.type, known ) !== -1) && file.size > 0 && file.size < tooHuge; + var known = ['image/png', 'image/gif', 'image/jpeg', 'image/svg+xml'], + tooHuge = 10 * 1024 * 1024; + return ( $.inArray( file.type, known ) !== -1 ) && file.size > 0 && file.size < tooHuge; } /** @@ -39,9 +39,8 @@ $( function() { * @param {File} file */ function showPreview( file ) { - var previewSize = 180; - - var thumb = $( '
' + + var previewSize = 180, + thumb = $( '
' + '
' + '' + '
' + @@ -50,18 +49,18 @@ $( function() { thumb.find( '.filename' ).text( file.name ).end() .find( '.fileinfo' ).text( prettySize( file.size ) ).end(); - var ctx = thumb.find( 'canvas' )[0].getContext( '2d' ); - var spinner = new Image(); + var ctx = thumb.find( 'canvas' )[0].getContext( '2d' ), + spinner = new Image(); spinner.onload = function() { ctx.drawImage( spinner, (previewSize - spinner.width) / 2, (previewSize - spinner.height) / 2 ); }; - spinner.src = wgScriptPath + '/skins/common/images/spinner.gif'; + spinner.src = mw.config.get( 'wgScriptPath' ) + '/skins/common/images/spinner.gif'; $( '#mw-htmlform-source' ).parent().prepend( thumb ); fetchPreview( file, function( dataURL ) { - var img = new Image(); - var rotation = 0; + var img = new Image(), + rotation = 0; img.onload = function() { // Fit the image within the previewSizexpreviewSize box if ( img.width > img.height ) { diff --git a/resources/mediawiki.util/mediawiki.util.js b/resources/mediawiki.util/mediawiki.util.js index c8c2114a3c..472730a484 100644 --- a/resources/mediawiki.util/mediawiki.util.js +++ b/resources/mediawiki.util/mediawiki.util.js @@ -65,7 +65,7 @@ } else { mw.util.$content = $( '#content' ); } - + /* Enable makeCollapse */ $( '.mw-collapsible' ).makeCollapsible(); @@ -81,7 +81,7 @@ mw.util.toggleToc( $(this) ); } ); $tocTitle.append( $tocToggleLink.wrap( '' ).parent().prepend( ' [' ).append( '] ' ) ); - + if ( hideTocCookie == '1' ) { // Cookie says user want toc hidden $tocToggleLink.click(); @@ -147,7 +147,7 @@ */ 'toggleToc' : function( $toggleLink ) { var $tocList = $( '#toc ul:first' ); - + // This function shouldn't be called if there's no TOC, // but just in case... if ( $tocList.size() ) { @@ -177,9 +177,16 @@ * Get the full URL to a page name * * @param str Page name to link to + * @return Full URL for page with name of 'str' or false on error */ 'wikiGetlink' : function( str ) { - return wgServer + wgArticlePath.replace( '$1', this.wikiUrlencode( str ) ); + + // Exist check is needed since replace() can only be called on a string + if ( mw.config.exists( ['wgServer', 'wgArticlePath'] ) ) { + return mw.config.get( 'wgServer' ) + mw.config.get( 'wgArticlePath' ).replace( '$1', this.wikiUrlencode( str ) ); + } else { + return false; + } }, /** @@ -382,12 +389,12 @@ * @return boolean True on success, false on failure */ 'jsMessage' : function( message, className ) { - + if ( !arguments.length || message === '' || message === null ) { - + $( '#mw-js-message' ).empty().hide(); - return true; // Emptying and hiding message is intended behaviour, return true - + return true; // Emptying and hiding message is intended behaviour, return true + } else { // We special-case skin structures provided by the software. Skins that // choose to abandon or significantly modify our formatting can just define @@ -401,11 +408,11 @@ return false; } } - + if ( className ) { $messageDiv.attr( 'class', 'mw-js-message-' + className ); } - + if ( typeof message === 'object' ) { $messageDiv.empty(); $messageDiv.append( message ); // Append new content @@ -417,7 +424,7 @@ return true; } }, - + /** * Validate a string as representing a valid e-mail address * according to HTML5 specification. Please note the specification @@ -429,7 +436,7 @@ if( mailtxt === '' ) { return null; } - + /** * HTML5 defines a string as valid e-mail address if it matches * the ABNF: @@ -440,7 +447,7 @@ * * (see STD 68 / RFC 5234 http://tools.ietf.org/html/std68): */ - + /** * First, define the RFC 5322 'atext' which is pretty easy : * atext = ALPHA / DIGIT / ; Printable US-ASCII @@ -456,7 +463,7 @@ "~" */ var rfc5322_atext = "a-z0-9!#$%&'*+-/=?^_`{|}~", - + /** * Next define the RFC 1034 'ldh-str' * ::= | " " @@ -467,7 +474,7 @@ * ::= | */ rfc1034_ldh_str = "a-z0-9-", - + HTML5_email_regexp = new RegExp( // start of string '^' diff --git a/resources/mediawiki.util/mediawiki.util.test.js b/resources/mediawiki.util/mediawiki.util.test.js index 0a65c26119..4cea825e82 100644 --- a/resources/mediawiki.util/mediawiki.util.test.js +++ b/resources/mediawiki.util/mediawiki.util.test.js @@ -6,7 +6,7 @@ * @author Krinkle */ -(function ($, mw) { +( function( $, mw ) { mediaWiki.test = { @@ -25,26 +25,27 @@ * if result is different but does contain this it will not return ERROR but PARTIALLY */ 'addTest' : function( code, result, contain ) { - if (!contain) { + if ( !contain ) { contain = result; } this.addedTests.push( [code, result, contain] ); - this.$table.append( '' + mw.html.escape(code).replace(/ /g, '  ' ) - + '' + mw.html.escape(result).replace(/ /g, '  ' ) + this.$table.append( '' + mw.html.escape( code ).replace(/ /g, '  ' ) + + '' + mw.html.escape( result ).replace(/ /g, '  ' ) + '?' ); }, /* Initialisation */ 'initialised' : false, - 'init' : function () { + 'init' : function() { if ( this.initialised === false ) { this.initialised = true; - $(function () { - if ( wgCanonicalSpecialPageName == 'Blankpage' + // jQuery document ready + $( function() { + if ( mw.config.get( 'wgCanonicalSpecialPageName' ) == 'Blankpage' && mw.util.getParamValue( 'action' ) === 'mwutiltest' ) { // Build page - document.title = 'mediaWiki.util JavaScript Test - ' + wgSiteName; + document.title = 'mediaWiki.util JavaScript Test - ' + mw.config.get( 'wgSiteName' ); $( '#firstHeading' ).text( 'mediaWiki.util JavaScript Test' ); mw.util.$content.html( '

Below is a list of tests to confirm proper functionality of the mediaWiki.util functions

' @@ -133,8 +134,8 @@ numberofpasseds = 0, numberofpartials = 0, numberoferrors = 0, - $testrows; - $testrows = mw.test.$table.find( 'tr' ); + $testrows = mw.test.$table.find( 'tr' ); + $.each( mw.test.addedTests, function( i ) { numberoftests++; @@ -146,7 +147,7 @@ $thisrow = $testrows.eq( i + 1 ); $thisrow.find( '> td' ).eq(2).html( mw.html.escape( doesreturn ).replace(/ /g, '  ' ) ); - if (doesreturn.indexOf(shouldcontain) !== -1) { + if ( doesreturn.indexOf( shouldcontain ) !== -1 ) { if (doesreturn == shouldreturn){ $thisrow.find( '> td' ).eq(3).css( 'background', '#EFE' ).text( 'OK' ); numberofpasseds++; @@ -165,11 +166,11 @@ numberofpartials + ' partially passed test(s).

' ); } - }); + } ); } } }; mediaWiki.test.init(); -})(jQuery, mediaWiki); +} )(jQuery, mediaWiki); \ No newline at end of file diff --git a/resources/mediawiki/mediawiki.js b/resources/mediawiki/mediawiki.js index 7533c1e227..50e51ef690 100644 --- a/resources/mediawiki/mediawiki.js +++ b/resources/mediawiki/mediawiki.js @@ -195,7 +195,7 @@ window.mediaWiki = new ( function( $ ) { * @return boolean Existence of key(s) */ Map.prototype.exists = function( selection ) { - if ( typeof keys === 'object' ) { + if ( typeof selection === 'object' ) { for ( var s = 0; s < selection.length; s++ ) { if ( !( selection[s] in this.values ) ) { return false; -- 2.20.1