From: Timo Tijhof Date: Mon, 27 Aug 2012 17:43:14 +0000 (+0200) Subject: Pass JSHint on resources/{mediawiki.api,jquery,mediawiki}/* X-Git-Tag: 1.31.0-rc.0~22478 X-Git-Url: https://git.heureux-cyclage.org/?a=commitdiff_plain;h=e9186da841917ec3055dbeb44aacd03d44f33fde;p=lhc%2Fweb%2Fwiklou.git Pass JSHint on resources/{mediawiki.api,jquery,mediawiki}/* Notes: * JSHint stuff * Code conventions * jQuery best practices * mediawiki.debug: - Append a text node instead of html. Though .append() does check if it looks "like" not-html and creates a text node, this is not more a sanity/security thing than a reliable documented feature. http://api.jquery.com/append/ : "HTML string, DOM element(s) or jQuery object". While at it: * Update .jshintignore to also cover: - resources/mediawiki.libs/CLDRPluralRuleParser.js * Update .jshintrc to set onevar back to true (was set to false temporarily but not removed). * Fix files in resources/mediawiki and resources/jquery as well. These dirs where already covered, perhaps these were missed or recently introduced, again. * Add missing dependencies: jquery.highlightText -> jquery.mwExtension ($.escapeRE) jquery.tablesorter -> jquery.mwExtension ($.escapeRE) mediawiki.page.watch.ajax -> jquery.mwExtension ($.escapeRE) Change-Id: I30a55717d0963ce23e51cef1f1df9e549e4c232e --- diff --git a/.jshintignore b/.jshintignore index 45f2da7f1f..026eaaaf85 100644 --- a/.jshintignore +++ b/.jshintignore @@ -16,6 +16,6 @@ resources/jquery/jquery.xmldom.js resources/jquery.effects resources/jquery.tipsy resources/jquery.ui -resources/mediawiki.libs/mediawiki.libs.jpegmeta.js +resources/mediawiki.libs tests/jasmine/lib/jasmine-1.0.1/jasmine-html.js tests/jasmine/lib/jasmine-1.0.1/jasmine.js diff --git a/.jshintrc b/.jshintrc index 4cf86b8e0d..b86ceb5f0c 100644 --- a/.jshintrc +++ b/.jshintrc @@ -26,5 +26,5 @@ "jquery": true, "nomen": true, - "onevar": false + "onevar": true } diff --git a/resources/Resources.php b/resources/Resources.php index 4443ece4eb..5156dd0437 100644 --- a/resources/Resources.php +++ b/resources/Resources.php @@ -160,6 +160,7 @@ return array( ), 'jquery.highlightText' => array( 'scripts' => 'resources/jquery/jquery.highlightText.js', + 'dependencies' => 'jquery.mwExtension', ), 'jquery.hoverIntent' => array( 'scripts' => 'resources/jquery/jquery.hoverIntent.js', @@ -216,6 +217,7 @@ return array( 'scripts' => 'resources/jquery/jquery.tablesorter.js', 'styles' => 'resources/jquery/jquery.tablesorter.css', 'messages' => array( 'sort-descending', 'sort-ascending' ), + 'dependencies' => 'jquery.mwExtension', ), 'jquery.textSelection' => array( 'scripts' => 'resources/jquery/jquery.textSelection.js', @@ -789,6 +791,7 @@ return array( 'mediawiki.api.watch', 'mediawiki.util', 'mediawiki.notify', + 'jquery.mwExtension', ), 'messages' => array( 'watch', diff --git a/resources/jquery/jquery.arrowSteps.js b/resources/jquery/jquery.arrowSteps.js index 1b414ddb60..488d106511 100644 --- a/resources/jquery/jquery.arrowSteps.js +++ b/resources/jquery/jquery.arrowSteps.js @@ -40,18 +40,18 @@ * * */ - ( function ( $ ) { $.fn.arrowSteps = function () { + var $steps, width, arrowWidth; this.addClass( 'arrowSteps' ); - var $steps = this.find( 'li' ); + $steps = this.find( 'li' ); - var width = parseInt( 100 / $steps.length, 10 ); + width = parseInt( 100 / $steps.length, 10 ); $steps.css( 'width', width + '%' ); // every step except the last one has an arrow at the right hand side. Also add in the padding // for the calculated arrow width. - var arrowWidth = parseInt( this.outerHeight(), 10 ); + arrowWidth = parseInt( this.outerHeight(), 10 ); $steps.filter( ':not(:last-child)' ).addClass( 'arrow' ) .find( 'div' ).css( 'padding-right', arrowWidth.toString() + 'px' ); @@ -60,8 +60,8 @@ }; $.fn.arrowStepsHighlight = function ( selector ) { - var $steps = this.data( 'arrowSteps' ); - var $previous; + var $previous, + $steps = this.data( 'arrowSteps' ); $.each( $steps, function ( i, step ) { var $step = $( step ); if ( $step.is( selector ) ) { diff --git a/resources/jquery/jquery.autoEllipsis.js b/resources/jquery/jquery.autoEllipsis.js index 23ba074052..04bb301c23 100644 --- a/resources/jquery/jquery.autoEllipsis.js +++ b/resources/jquery/jquery.autoEllipsis.js @@ -3,10 +3,12 @@ */ ( function ( $ ) { -// Cache ellipsed substrings for every string-width-position combination -var cache = { }; -// Use a separate cache when match highlighting is enabled -var matchTextCache = { }; +var + // Cache ellipsed substrings for every string-width-position combination + cache = { }, + + // Use a separate cache when match highlighting is enabled + matchTextCache = { }; $.fn.autoEllipsis = function ( options ) { options = $.extend( { @@ -19,7 +21,7 @@ $.fn.autoEllipsis = function ( options ) { $(this).each( function () { var $container, $trimmableText, text, trimmableText, w, pw, - l, r, i, side, + l, r, i, side, m, $el = $(this); if ( options.restoreText ) { if ( !$el.data( 'autoEllipsis.originalText' ) ) { @@ -90,7 +92,7 @@ $.fn.autoEllipsis = function ( options ) { l = 0; r = trimmableText.length; do { - var m = Math.ceil( ( l + r ) / 2 ); + m = Math.ceil( ( l + r ) / 2 ); $trimmableText.text( trimmableText.substr( 0, m ) + '...' ); if ( $trimmableText.width() + pw > w ) { // Text is too long diff --git a/resources/jquery/jquery.checkboxShiftClick.js b/resources/jquery/jquery.checkboxShiftClick.js index 3d7f94d3da..1990dc0d73 100644 --- a/resources/jquery/jquery.checkboxShiftClick.js +++ b/resources/jquery/jquery.checkboxShiftClick.js @@ -6,10 +6,9 @@ * @author Krinkle * @license GPL v2 */ -( function( $ ) { +( function ( $ ) { $.fn.checkboxShiftClick = function ( text ) { - var prevCheckbox = null; - var $box = this; + var prevCheckbox = null, $box = this; // When our boxes are clicked.. $box.click( function ( e ) { // And one has been clicked before... @@ -18,7 +17,7 @@ $box.slice( Math.min( $box.index( prevCheckbox ), $box.index( e.target ) ), Math.max( $box.index( prevCheckbox ), $box.index( e.target ) ) + 1 - ).prop( 'checked', e.target.checked ? true : false ); + ).prop( 'checked', !!e.target.checked ); } // Either way, update the prevCheckbox variable to the one clicked now prevCheckbox = e.target; diff --git a/resources/jquery/jquery.client.js b/resources/jquery/jquery.client.js index 26eea96404..24f8959ee1 100644 --- a/resources/jquery/jquery.client.js +++ b/resources/jquery/jquery.client.js @@ -32,7 +32,7 @@ * } */ profile: function ( nav ) { - /*jshint boss:true */ + /*jshint boss: true */ if ( nav === undefined ) { nav = window.navigator; diff --git a/resources/jquery/jquery.expandableField.js b/resources/jquery/jquery.expandableField.js index a3396a2156..063f260934 100644 --- a/resources/jquery/jquery.expandableField.js +++ b/resources/jquery/jquery.expandableField.js @@ -52,15 +52,15 @@ $.fn.expandableField = function () { // Multi-context fields - var returnValue; - var args = arguments; + var returnValue, + args = arguments; $( this ).each( function () { - var key; + var key, context; /* Construction / Loading */ - var context = $( this ).data( 'expandableField-context' ); + context = $( this ).data( 'expandableField-context' ); // TODO: Do we need to check both null and undefined? if ( context === undefined || context === null ) { diff --git a/resources/jquery/jquery.highlightText.js b/resources/jquery/jquery.highlightText.js index fa4416c6c7..0844da7c23 100644 --- a/resources/jquery/jquery.highlightText.js +++ b/resources/jquery/jquery.highlightText.js @@ -9,8 +9,9 @@ // Split our pattern string at spaces and run our highlight function on the results splitAndHighlight: function ( node, pat ) { - var patArray = pat.split( ' ' ); - for ( var i = 0; i < patArray.length; i++ ) { + var i, + patArray = pat.split( ' ' ); + for ( i = 0; i < patArray.length; i++ ) { if ( patArray[i].length === 0 ) { continue; } @@ -21,24 +22,25 @@ // scans a node looking for the pattern and wraps a span around each match innerHighlight: function ( node, pat ) { + var i, match, pos, spannode, middlebit, middleclone; // if this is a text node if ( node.nodeType === 3 ) { // TODO - need to be smarter about the character matching here. // non latin characters can make regex think a new word has begun: do not use \b // http://stackoverflow.com/questions/3787072/regex-wordwrap-with-utf8-characters-in-js // look for an occurrence of our pattern and store the starting position - var match = node.data.match( new RegExp( "(^|\\s)" + $.escapeRE( pat ), "i" ) ); + match = node.data.match( new RegExp( "(^|\\s)" + $.escapeRE( pat ), "i" ) ); if ( match ) { - var pos = match.index + match[1].length; // include length of any matched spaces + pos = match.index + match[1].length; // include length of any matched spaces // create the span wrapper for the matched text - var spannode = document.createElement( 'span' ); + spannode = document.createElement( 'span' ); spannode.className = 'highlight'; // shave off the characters preceding the matched text - var middlebit = node.splitText( pos ); + middlebit = node.splitText( pos ); // shave off any unmatched text off the end middlebit.splitText( pat.length ); // clone for appending to our span - var middleclone = middlebit.cloneNode( true ); + middleclone = middlebit.cloneNode( true ); // append the matched text node to the span spannode.appendChild( middleclone ); // replace the matched node, with our span-wrapped clone of the matched node @@ -47,7 +49,7 @@ // if this is an element with childnodes, and not a script, style or an element we created } else if ( node.nodeType === 1 && node.childNodes && !/(script|style)/i.test( node.tagName ) && !( node.tagName.toLowerCase() === 'span' && node.className.match( /\bhighlight/ ) ) ) { - for ( var i = 0; i < node.childNodes.length; ++i ) { + for ( i = 0; i < node.childNodes.length; ++i ) { // call the highlight function for each child node $.highlightText.innerHighlight( node.childNodes[i], pat ); } diff --git a/resources/jquery/jquery.mwExtension.js b/resources/jquery/jquery.mwExtension.js index 375739336e..bbffd7b7df 100644 --- a/resources/jquery/jquery.mwExtension.js +++ b/resources/jquery/jquery.mwExtension.js @@ -55,6 +55,7 @@ return true; }, compareObject: function ( objectA, objectB ) { + var prop, type; // Do a simple check if the types match if ( typeof objectA === typeof objectB ) { @@ -65,13 +66,12 @@ if ( objectA === objectB ) { return true; } else { - var prop; // Iterate over each property for ( prop in objectA ) { // Check if this property is also present in the other object if ( prop in objectB ) { // Compare the types of the properties - var type = typeof objectA[prop]; + type = typeof objectA[prop]; if ( type === typeof objectB[prop] ) { // Recursively check objects inside this one switch ( type ) { diff --git a/resources/jquery/jquery.placeholder.js b/resources/jquery/jquery.placeholder.js index 5ec05f21b8..aa356c4c50 100644 --- a/resources/jquery/jquery.placeholder.js +++ b/resources/jquery/jquery.placeholder.js @@ -13,14 +13,15 @@ $.fn.placeholder = function () { return this.each( function () { + var placeholder, $input; // If the HTML5 placeholder attribute is supported, use it if ( this.placeholder && 'placeholder' in document.createElement( this.tagName ) ) { return; } - var placeholder = this.getAttribute( 'placeholder' ); - var $input = $(this); + placeholder = this.getAttribute( 'placeholder' ); + $input = $(this); // Show initially, if empty if ( this.value === '' || this.value === placeholder ) { diff --git a/resources/jquery/jquery.qunit.completenessTest.js b/resources/jquery/jquery.qunit.completenessTest.js index d54e66c2a5..1475af2a2d 100644 --- a/resources/jquery/jquery.qunit.completenessTest.js +++ b/resources/jquery/jquery.qunit.completenessTest.js @@ -96,7 +96,7 @@ * other constructor. Otherwise "missingTests" will include all methods that * were not called from that instance. */ - var CompletenessTest = function ( masterVariable, ignoreFn ) { + function CompletenessTest( masterVariable, ignoreFn ) { // Keep track in these objects. Keyed by strings with the // method names (ie. 'my.foo', 'my.bar', etc.) values are boolean true. @@ -199,7 +199,7 @@ }); return this; - }; + } /* Static members */ CompletenessTest.ACTION_INJECT = 500; diff --git a/resources/jquery/jquery.textSelection.js b/resources/jquery/jquery.textSelection.js index 583c1eda85..abb0fa3f64 100644 --- a/resources/jquery/jquery.textSelection.js +++ b/resources/jquery/jquery.textSelection.js @@ -10,10 +10,11 @@ $.fn.extend({ focus: ( function ( jqFocus ) { return function () { + var $w, state, result; if ( arguments.length === 0 ) { - var $w = $( window ); - var state = {top: $w.scrollTop(), left: $w.scrollLeft()}; - var result = jqFocus.apply( this, arguments ); + $w = $( window ); + state = {top: $w.scrollTop(), left: $w.scrollLeft()}; + result = jqFocus.apply( this, arguments ); window.scrollTo( state.top, state.left ); return result; } @@ -63,17 +64,20 @@ * in some browsers (IE/Opera) */ getSelection: function () { - var e = this.get( 0 ); - var retval = ''; - if ( $(e).is( ':hidden' ) ) { + var retval, range, + el = this.get( 0 ); + + if ( $(el).is( ':hidden' ) ) { // Do nothing + retval = ''; } else if ( document.selection && document.selection.createRange ) { - activateElementOnIE( e ); - var range = document.selection.createRange(); + activateElementOnIE( el ); + range = document.selection.createRange(); retval = range.text; - } else if ( e.selectionStart || e.selectionStart === 0 ) { - retval = e.value.substring( e.selectionStart, e.selectionEnd ); + } else if ( el.selectionStart || el.selectionStart === 0 ) { + retval = el.value.substring( el.selectionStart, el.selectionEnd ); } + return retval; }, /** @@ -88,6 +92,7 @@ encapsulateSelection: function ( options ) { return this.each( function () { var selText, scrollTop, insertText, + isSample, range, range2, range3, startPos, endPos, pre = options.pre, post = options.post; @@ -120,9 +125,10 @@ * Wrap each line of the selected text with pre and post */ function doSplitLines( selText, pre, post ) { - var insertText = ''; - var selTextArr = selText.split( '\n' ); - for ( var i = 0; i < selTextArr.length; i++ ) { + var i, + insertText = '', + selTextArr = selText.split( '\n' ); + for ( i = 0; i < selTextArr.length; i++ ) { insertText += pre + selTextArr[i] + post; if ( i !== selTextArr.length - 1 ) { insertText += '\n'; @@ -131,7 +137,7 @@ return insertText; } - var isSample = false; + isSample = false; if ( this.style.display === 'none' ) { // Do nothing } else if ( document.selection && document.selection.createRange ) { @@ -150,7 +156,7 @@ selText = $(this).textSelection( 'getSelection' ); scrollTop = this.scrollTop; - var range = document.selection.createRange(); + range = document.selection.createRange(); checkSelectedText(); insertText = pre + selText + post; @@ -158,7 +164,7 @@ insertText = doSplitLines( selText, pre, post ); } if ( options.ownline && range.moveStart ) { - var range2 = document.selection.createRange(); + range2 = document.selection.createRange(); range2.collapse(); range2.moveStart( 'character', -1 ); // FIXME: Which check is correct? @@ -166,7 +172,7 @@ insertText = "\n" + insertText; pre += "\n"; } - var range3 = document.selection.createRange(); + range3 = document.selection.createRange(); range3.collapse( false ); range3.moveEnd( 'character', 1 ); if ( range3.text !== "\r" && range3.text !== "\n" && range3.text !== "" ) { @@ -192,8 +198,8 @@ } selText = $(this).textSelection( 'getSelection' ); - var startPos = this.selectionStart; - var endPos = this.selectionEnd; + startPos = this.selectionStart; + endPos = this.selectionEnd; scrollTop = this.scrollTop; checkSelectedText(); if ( options.selectionStart !== undefined @@ -263,26 +269,34 @@ // whatever we do later (bug 31847). activateElementOnIE( e ); - // IE Support - var preFinished = false; - var periFinished = false; - var postFinished = false; - var preText, rawPreText, periText; - var rawPeriText, postText, rawPostText; - // Create range containing text in the selection - var periRange = document.selection.createRange().duplicate(); - // Create range containing text before the selection - var preRange = rangeForElementIE( e ); + var + preText, rawPreText, periText, + rawPeriText, postText, rawPostText, + + // IE Support + preFinished = false, + periFinished = false, + postFinished = false, + // Range containing text in the selection + periRange = document.selection.createRange().duplicate(), + // Range containing text before the selection + preRange, + // Range containing text after the selection + postRange; + + preRange = rangeForElementIE( e ), // Move the end where we need it preRange.setEndPoint( 'EndToStart', periRange ); - // Create range containing text after the selection - var postRange = rangeForElementIE( e ); + + postRange = rangeForElementIE( e ); // Move the start where we need it postRange.setEndPoint( 'StartToEnd', periRange ); + // Load the text values we need to compare preText = rawPreText = preRange.text; periText = rawPeriText = periRange.text; postText = rawPostText = postRange.text; + /* * Check each range for trimmed newlines by shrinking the range by 1 * character and seeing if the text property has changed. If it has @@ -342,6 +356,7 @@ */ setSelection: function ( options ) { return this.each( function () { + var selection, length, newLines; if ( $(this).is( ':hidden' ) ) { // Do nothing } else if ( this.selectionStart || this.selectionStart === 0 ) { @@ -356,10 +371,10 @@ this.selectionEnd = options.end; } } else if ( document.body.createTextRange ) { - var selection = rangeForElementIE( this ); - var length = this.value.length; + selection = rangeForElementIE( this ); + length = this.value.length; // IE doesn't count \n when computing the offset, so we won't either - var newLines = this.value.match( /\n/g ); + newLines = this.value.match( /\n/g ); if ( newLines ) { length = length - newLines.length; } @@ -370,7 +385,7 @@ // Silence that error try { selection.select(); - } catch( e ) { } + } catch ( e ) { } } }); }, @@ -434,11 +449,12 @@ return ( $.client.profile().platform === 'mac' ? 13 : ( $.client.profile().platform === 'linux' ? 15 : 16 ) ) * row; } return this.each(function () { + var scroll, range, savedRange, pos, oldScrollTop; if ( $(this).is( ':hidden' ) ) { // Do nothing } else if ( this.selectionStart || this.selectionStart === 0 ) { // Mozilla - var scroll = getCaretScrollPosition( this ); + scroll = getCaretScrollPosition( this ); if ( options.force || scroll < $(this).scrollTop() || scroll > $(this).scrollTop() + $(this).height() ) { $(this).scrollTop( scroll ); @@ -453,10 +469,10 @@ * cover that case, we'll force it to act by moving one * character back and forth. */ - var range = document.body.createTextRange(); - var savedRange = document.selection.createRange(); - var pos = $(this).textSelection( 'getCaretPosition' ); - var oldScrollTop = this.scrollTop; + range = document.body.createTextRange(); + savedRange = document.selection.createRange(); + pos = $(this).textSelection( 'getCaretPosition' ); + oldScrollTop = this.scrollTop; range.moveToElementText( this ); range.collapse(); range.move( 'character', pos + 1); diff --git a/resources/mediawiki.api/mediawiki.api.category.js b/resources/mediawiki.api/mediawiki.api.category.js index c8c18e69fa..cc6f704f55 100644 --- a/resources/mediawiki.api/mediawiki.api.category.js +++ b/resources/mediawiki.api/mediawiki.api.category.js @@ -1,8 +1,7 @@ /** * Additional mw.Api methods to assist with API calls related to categories. */ - -( function( $, mw, undefined ) { +( function ( mw, $ ) { $.extend( mw.Api.prototype, { /** @@ -12,22 +11,23 @@ * @param err {Function} optional callback to run if api error * @return ajax call object */ - isCategory: function( title, success, err ) { - var params = { - prop: 'categoryinfo', - titles: title.toString() - }, - ok = function( data ) { - var exists = false; - if ( data.query && data.query.pages ) { - $.each( data.query.pages, function( id, page ) { - if ( page.categoryinfo ) { - exists = true; - } - } ); - } - success( exists ); - }; + isCategory: function ( title, success, err ) { + var params, ok; + params = { + prop: 'categoryinfo', + titles: title.toString() + }; + ok = function ( data ) { + var exists = false; + if ( data.query && data.query.pages ) { + $.each( data.query.pages, function ( id, page ) { + if ( page.categoryinfo ) { + exists = true; + } + } ); + } + success( exists ); + }; return this.get( params, { ok: ok, err: err } ); }, @@ -40,19 +40,18 @@ * @param err {Function} optional callback to run if api error * @return {jqXHR} */ - getCategoriesByPrefix: function( prefix, success, err ) { - - // fetch with allpages to only get categories that have a corresponding description page. - var params = { + getCategoriesByPrefix: function ( prefix, success, err ) { + // Fetch with allpages to only get categories that have a corresponding description page. + var params, ok; + params = { 'list': 'allpages', 'apprefix': prefix, 'apnamespace': mw.config.get('wgNamespaceIds').category }; - - var ok = function( data ) { + ok = function ( data ) { var texts = []; if ( data.query && data.query.allpages ) { - $.each( data.query.allpages, function( i, category ) { + $.each( data.query.allpages, function ( i, category ) { texts.push( new mw.Title( category.title ).getNameText() ); } ); } @@ -71,7 +70,7 @@ * @param async {Boolean} optional asynchronousness (default = true = async) * @return {jqXHR} */ - getCategories: function( title, success, err, async ) { + getCategories: function ( title, success, err, async ) { var params, ok; params = { prop: 'categories', @@ -80,15 +79,15 @@ if ( async === undefined ) { async = true; } - ok = function( data ) { + ok = function ( data ) { var ret = false; if ( data.query && data.query.pages ) { - $.each( data.query.pages, function( id, page ) { + $.each( data.query.pages, function ( id, page ) { if ( page.categories ) { if ( typeof ret !== 'object' ) { ret = []; } - $.each( page.categories, function( i, cat ) { + $.each( page.categories, function ( i, cat ) { ret.push( new mw.Title( cat.title ) ); } ); } @@ -102,4 +101,4 @@ } ); -} )( jQuery, mediaWiki ); +}( mediaWiki, jQuery ) ); diff --git a/resources/mediawiki.api/mediawiki.api.edit.js b/resources/mediawiki.api/mediawiki.api.edit.js index 5197396d2e..49af93758e 100644 --- a/resources/mediawiki.api/mediawiki.api.edit.js +++ b/resources/mediawiki.api/mediawiki.api.edit.js @@ -1,8 +1,7 @@ /** * Additional mw.Api methods to assist with API calls related to editing wiki pages. */ - -( function( $, mw, undefined ) { +( function ( mw, $ ) { // Cache token so we don't have to keep fetching new ones for every single request. var cachedToken = null; @@ -19,13 +18,14 @@ * @param err {Function} [optional] error callback * @return {jqXHR} */ - postWithEditToken: function( params, ok, err ) { - var api = this, useTokenToPost, getTokenIfBad; + postWithEditToken: function ( params, ok, err ) { + var useTokenToPost, getTokenIfBad, + api = this; if ( cachedToken === null ) { // We don't have a valid cached token, so get a fresh one and try posting. // We do not trap any 'badtoken' or 'notoken' errors, because we don't want // an infinite loop. If this fresh token is bad, something else is very wrong. - useTokenToPost = function( token ) { + useTokenToPost = function ( token ) { params.token = token; api.post( params, ok, err ); }; @@ -34,9 +34,10 @@ // We do have a token, but it might be expired. So if it is 'bad' then // start over with a new token. params.token = cachedToken; - getTokenIfBad = function( code, result ) { + getTokenIfBad = function ( code, result ) { if ( code === 'badtoken' ) { - cachedToken = null; // force a new token + // force a new token, clear any old one + cachedToken = null; api.postWithEditToken( params, ok, err ); } else { err( code, result ); @@ -58,12 +59,12 @@ * @param err {Function} error callback * @return {jqXHR} */ - getEditToken: function( tokenCallback, err ) { + getEditToken: function ( tokenCallback, err ) { var parameters = { action: 'tokens', type: 'edit' }, - ok = function( data ) { + ok = function ( data ) { var token; // If token type is not available for this user, // key 'edittoken' is missing or can contain Boolean false @@ -96,7 +97,7 @@ * @param err {Function} error handler * @return {jqXHR} */ - newSection: function( title, header, message, ok, err ) { + newSection: function ( title, header, message, ok, err ) { var params = { action: 'edit', section: 'new', @@ -110,4 +111,4 @@ } ); -} )( jQuery, mediaWiki ); +}( mediaWiki, jQuery ) ); diff --git a/resources/mediawiki.api/mediawiki.api.js b/resources/mediawiki.api/mediawiki.api.js index 080725af52..a184e3ca96 100644 --- a/resources/mediawiki.api/mediawiki.api.js +++ b/resources/mediawiki.api/mediawiki.api.js @@ -1,7 +1,7 @@ /** * mw.Api objects represent the API of a particular MediaWiki server. */ -( function( $, mw, undefined ) { +( function ( mw, $ ) { /** * @var defaultOptions {Object} @@ -47,7 +47,7 @@ * @param options {Object} See defaultOptions documentation above. Ajax options can also be * overridden for each individual request to jQuery.ajax() later on. */ - mw.Api = function( options ) { + mw.Api = function ( options ) { if ( options === undefined ) { options = {}; @@ -91,7 +91,7 @@ * @param {Object|Function} [optional] ajax options * @return {jQuery.Promise} */ - get: function( parameters, ajaxOptions ) { + get: function ( parameters, ajaxOptions ) { ajaxOptions = this.normalizeAjaxOptions( ajaxOptions ); ajaxOptions.type = 'GET'; return this.ajax( parameters, ajaxOptions ); @@ -105,7 +105,7 @@ * @param {Object|Function} [optional] ajax options * @return {jQuery.Promise} */ - post: function( parameters, ajaxOptions ) { + post: function ( parameters, ajaxOptions ) { ajaxOptions = this.normalizeAjaxOptions( ajaxOptions ); ajaxOptions.type = 'POST'; return this.ajax( parameters, ajaxOptions ); @@ -120,7 +120,7 @@ * - done: API response data as first argument * - fail: errorcode as first arg, details (string or object) as second arg. */ - ajax: function( parameters, ajaxOptions ) { + ajax: function ( parameters, ajaxOptions ) { var token, apiDeferred = $.Deferred(); @@ -246,4 +246,4 @@ 'exists' ]; -})( jQuery, mediaWiki ); +}( mediaWiki, jQuery ) ); diff --git a/resources/mediawiki.api/mediawiki.api.parse.js b/resources/mediawiki.api/mediawiki.api.parse.js index e784ef7581..e8d1b3e6cb 100644 --- a/resources/mediawiki.api/mediawiki.api.parse.js +++ b/resources/mediawiki.api/mediawiki.api.parse.js @@ -12,7 +12,7 @@ * @param err {Function} [optional] deprecated (error callback) * @return {jQuery.Promise} */ - parse: function( wikiText, ok, err ) { + parse: function ( wikiText, ok, err ) { var apiDeferred = $.Deferred(); // Backwards compatibility (< MW 1.20) @@ -39,4 +39,4 @@ } } ); -} )( mediaWiki, jQuery ); +}( mediaWiki, jQuery ) ); diff --git a/resources/mediawiki.api/mediawiki.api.titleblacklist.js b/resources/mediawiki.api/mediawiki.api.titleblacklist.js index 5435945b60..1f7e275aa8 100644 --- a/resources/mediawiki.api/mediawiki.api.titleblacklist.js +++ b/resources/mediawiki.api/mediawiki.api.titleblacklist.js @@ -2,7 +2,7 @@ * Additional mw.Api methods to assist with API calls to the API module of the TitleBlacklist extension. */ -( function( $, mw, undefined ) { +( function ( mw, $ ) { $.extend( mw.Api.prototype, { /** @@ -15,13 +15,13 @@ * @param err {Function} optional callback to run if api error * @return {jqXHR} */ - isBlacklisted: function( title, success, err ) { + isBlacklisted: function ( title, success, err ) { var params = { action: 'titleblacklist', tbaction: 'create', tbtitle: title.toString() }, - ok = function( data ) { + ok = function ( data ) { var result; // this fails open (if nothing valid is returned by the api, allows the title) @@ -48,4 +48,5 @@ } } ); -} )( jQuery, mediaWiki ); + +}( mediaWiki, jQuery ) ); diff --git a/resources/mediawiki.api/mediawiki.api.watch.js b/resources/mediawiki.api/mediawiki.api.watch.js index 302a2d31dc..d32344212e 100644 --- a/resources/mediawiki.api/mediawiki.api.watch.js +++ b/resources/mediawiki.api/mediawiki.api.watch.js @@ -2,7 +2,7 @@ * Additional mw.Api methods to assist with (un)watching wiki pages. * @since 1.19 */ -( function( $, mw ) { +( function ( mw, $ ) { /** * @context {mw.Api} @@ -53,4 +53,4 @@ } ); -} )( jQuery, mediaWiki ); +}( mediaWiki, jQuery ) ); diff --git a/resources/mediawiki/mediawiki.Title.js b/resources/mediawiki/mediawiki.Title.js index 6b6e58686d..9e030fad73 100644 --- a/resources/mediawiki/mediawiki.Title.js +++ b/resources/mediawiki/mediawiki.Title.js @@ -35,6 +35,11 @@ } var + /** + * Public methods (defined later) + */ + fn, + /** * Strip some illegal chars: control chars, colon, less than, greater than, * brackets, braces, pipe, whitespace and normal spaces. This still leaves some insanity @@ -221,7 +226,7 @@ var /* Public methods */ - var fn = { + fn = { constructor: Title, /** diff --git a/resources/mediawiki/mediawiki.debug.js b/resources/mediawiki/mediawiki.debug.js index 36628eb4fa..1ad1a623ab 100644 --- a/resources/mediawiki/mediawiki.debug.js +++ b/resources/mediawiki/mediawiki.debug.js @@ -94,7 +94,7 @@ * Constructs the HTML for the debugging toolbar */ buildHtml: function () { - var $container, $bits, panes, id; + var $container, $bits, panes, id, gitInfo; $container = $( '
' ); @@ -107,9 +107,9 @@ * @return {jQuery} */ function bitDiv( id ) { - return $( '
' ).attr({ + return $( '
' ).prop({ id: 'mw-debug-' + id, - 'class': 'mw-debug-bit' + className: 'mw-debug-bit' }) .appendTo( $bits ); } @@ -123,8 +123,8 @@ */ function paneLabel( id, text ) { return $( '' ) - .attr({ - 'class': 'mw-debug-panelabel', + .prop({ + className: 'mw-debug-panelabel', href: '#mw-debug-pane-' + id }) .text( text ); @@ -139,12 +139,12 @@ * @return {jQuery} */ function paneTriggerBitDiv( id, text, count ) { - if( count ) { + if ( count ) { text = text + ' (' + count + ')'; } - return $( '
' ).attr({ + return $( '
' ).prop({ id: 'mw-debug-' + id, - 'class': 'mw-debug-bit mw-debug-panelink' + className: 'mw-debug-bit mw-debug-panelink' }) .append( paneLabel( id, text ) ) .appendTo( $bits ); @@ -160,17 +160,19 @@ paneTriggerBitDiv( 'includes', 'PHP includes', this.data.includes.length ); - var gitInfo = ''; + gitInfo = ''; if ( this.data.gitRevision !== false ) { gitInfo = '(' + this.data.gitRevision.substring( 0, 7 ) + ')'; if ( this.data.gitViewUrl !== false ) { - gitInfo = $( '' ).attr( 'href', this.data.gitViewUrl ).text( gitInfo ); + gitInfo = $( '' ) + .attr( 'href', this.data.gitViewUrl ) + .text( gitInfo ); } } bitDiv( 'mwversion' ) - .append( $( '' ).text( 'MediaWiki' ) ) - .append( ': ' + this.data.mwVersion + ' ' ) + .append( $( 'MediaWiki' ) ) + .append( document.createTextNode( ': ' + this.data.mwVersion + ' ' ) ) .append( gitInfo ); if ( this.data.gitBranch !== false ) { @@ -205,8 +207,8 @@ } $( '
' ) - .attr({ - 'class': 'mw-debug-pane', + .prop({ + className: 'mw-debug-pane', id: 'mw-debug-pane-' + id }) .append( panes[id] ) @@ -224,9 +226,9 @@ $table = $( '' ); - $('').css( 'width', /*padding=*/20 + ( 10 * /*fontSize*/11 ) ).appendTo( $table ); - $('').appendTo( $table ); - $('').css( 'width', 350 ).appendTo( $table ); + $( '' ).css( 'width', /* padding = */ 20 + ( 10 * /* fontSize = */ 11 ) ).appendTo( $table ); + $( '' ).appendTo( $table ); + $( '' ).css( 'width', 350 ).appendTo( $table ); entryTypeText = function( entryType ) { @@ -249,7 +251,7 @@ $( '' ) .append( $( '' ) - .append( $('').css( 'width', '4em' ) ) - .append( $('') ) - .append( $('').css( 'width', '8em' ) ) - .append( $('').css( 'width', '18em' ) ) + .append( $( '' ).css( 'width', '4em' ) ) + .append( $( '' ) ) + .append( $( '' ).css( 'width', '8em' ) ) + .append( $( '' ).css( 'width', '18em' ) ) .appendTo( $table ); for ( i = 0, length = this.data.queries.length; i < length; i += 1 ) { @@ -299,7 +301,7 @@ for ( i = 0, length = this.data.debugLog.length; i < length; i += 1 ) { line = this.data.debugLog[i]; $( '
  • ' ) - .html( mw.html.escape( line ).replace( /\n/g, "
    \n" ) ) + .html( mw.html.escape( line ).replace( /\n/g, '
    \n' ) ) .appendTo( $list ); } diff --git a/resources/mediawiki/mediawiki.log.js b/resources/mediawiki/mediawiki.log.js index 9ce83054a1..4ea1a88158 100644 --- a/resources/mediawiki/mediawiki.log.js +++ b/resources/mediawiki/mediawiki.log.js @@ -33,7 +33,8 @@ // If there is no console, use our own log box mw.loader.using( 'jquery.footHovzer', function () { - var d = new Date(), + var hovzer, + d = new Date(), // Create HH:MM:SS.MIL timestamp time = ( d.getHours() < 10 ? '0' + d.getHours() : d.getHours() ) + ':' + ( d.getMinutes() < 10 ? '0' + d.getMinutes() : d.getMinutes() ) + @@ -48,7 +49,7 @@ backgroundColor: 'white', borderTop: 'solid 2px #ADADAD' } ); - var hovzer = $.getFootHovzer(); + hovzer = $.getFootHovzer(); hovzer.$.append( $log ); hovzer.update(); } diff --git a/resources/mediawiki/mediawiki.user.js b/resources/mediawiki/mediawiki.user.js index b5f124ba60..5c5c87e295 100644 --- a/resources/mediawiki/mediawiki.user.js +++ b/resources/mediawiki/mediawiki.user.js @@ -8,11 +8,12 @@ * User object */ function User( options, tokens ) { + var user, callbacks; /* Private Members */ - var that = this; - var callbacks = {}; + user = this; + callbacks = {}; /** * Gets the current user's groups or rights. @@ -61,9 +62,10 @@ * @return String: Random set of 32 alpha-numeric characters */ function generateId() { - var id = ''; - var seed = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; - for ( var i = 0, r; i < 32; i++ ) { + var i, r, + id = '', + seed = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; + for ( i = 0; i < 32; i++ ) { r = Math.floor( Math.random() * seed.length ); id += seed.substring( r, r + 1 ); } @@ -92,14 +94,14 @@ * @return Boolean */ this.isAnon = function () { - return that.getName() === null; + return user.getName() === null; }; /** * @deprecated since 1.20 use mw.user.isAnon() instead */ this.anonymous = function () { - return that.isAnon(); + return user.isAnon(); }; /** @@ -129,11 +131,12 @@ * @return String: User name or random session ID */ this.id = function() { - var name = that.getName(); + var id, + name = user.getName(); if ( name ) { return name; } - var id = $.cookie( 'mediaWiki.user.id' ); + id = $.cookie( 'mediaWiki.user.id' ); if ( typeof id === 'undefined' || id === null ) { id = generateId(); } @@ -169,37 +172,40 @@ * } ); */ this.bucket = function ( key, options ) { + var cookie, parts, version, bucket, + range, k, rand, total; + options = $.extend( { - 'buckets': {}, - 'version': 0, - 'tracked': false, - 'expires': 30 + buckets: {}, + version: 0, + tracked: false, + expires: 30 }, options || {} ); - var cookie = $.cookie( 'mediaWiki.user.bucket:' + key ); - var bucket = null; - var version = 0; + + cookie = $.cookie( 'mediaWiki.user.bucket:' + key ); + // Bucket information is stored as 2 integers, together as version:bucket like: "1:2" if ( typeof cookie === 'string' && cookie.length > 2 && cookie.indexOf( ':' ) > 0 ) { - var parts = cookie.split( ':' ); + parts = cookie.split( ':' ); if ( parts.length > 1 && Number( parts[0] ) === options.version ) { version = Number( parts[0] ); bucket = String( parts[1] ); } } - if ( bucket === null ) { + if ( bucket === undefined ) { if ( !$.isPlainObject( options.buckets ) ) { throw 'Invalid buckets error. Object expected for options.buckets.'; } version = Number( options.version ); // Find range - var range = 0, k; + range = 0; for ( k in options.buckets ) { range += options.buckets[k]; } // Select random value within range - var rand = Math.random() * range; + rand = Math.random() * range; // Determine which bucket the value landed in - var total = 0; + total = 0; for ( k in options.buckets ) { bucket = k; total += options.buckets[k];
  • ' ) .text( entry.typeText ) - .attr( 'class', 'mw-debug-console-' + entry.type ) + .addClass( 'mw-debug-console-' + entry.type ) ) .append( $( '' ).html( entry.msg ) ) .append( $( '' ).text( entry.caller ) ) @@ -268,10 +270,10 @@ $table = $( '
    ' ); $( '
    #SQLTimeCall#SQLTimeCall