* 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
* Note that additional code still lives in skins/common/upload.js
*/
-$( function() {
+jQuery( function( $ ) {
/**
* Is the FileAPI available with sufficient functionality?
*/
* @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;
}
/**
* @param {File} file
*/
function showPreview( file ) {
- var previewSize = 180;
-
- var thumb = $( '<div id="mw-upload-thumbnail" class="thumb tright">' +
+ var previewSize = 180,
+ thumb = $( '<div id="mw-upload-thumbnail" class="thumb tright">' +
'<div class="thumbinner">' +
'<canvas width="' + previewSize + '" height="' + previewSize + '" ></canvas>' +
'<div class="thumbcaption"><div class="filename"></div><div class="fileinfo"></div></div>' +
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 ) {
} else {
mw.util.$content = $( '#content' );
}
-
+
/* Enable makeCollapse */
$( '.mw-collapsible' ).makeCollapsible();
mw.util.toggleToc( $(this) );
} );
$tocTitle.append( $tocToggleLink.wrap( '<span class="toctoggle">' ).parent().prepend( ' [' ).append( '] ' ) );
-
+
if ( hideTocCookie == '1' ) {
// Cookie says user want toc hidden
$tocToggleLink.click();
*/
'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() ) {
* 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;
+ }
},
/**
* @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
return false;
}
}
-
+
if ( className ) {
$messageDiv.attr( 'class', 'mw-js-message-' + className );
}
-
+
if ( typeof message === 'object' ) {
$messageDiv.empty();
$messageDiv.append( message ); // Append new content
return true;
}
},
-
+
/**
* Validate a string as representing a valid e-mail address
* according to HTML5 specification. Please note the specification
if( mailtxt === '' ) {
return null;
}
-
+
/**
* HTML5 defines a string as valid e-mail address if it matches
* the ABNF:
*
* (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
"~"
*/
var rfc5322_atext = "a-z0-9!#$%&'*+-/=?^_`{|}~",
-
+
/**
* Next define the RFC 1034 'ldh-str'
* <domain> ::= <subdomain> | " "
* <let-dig> ::= <letter> | <digit>
*/
rfc1034_ldh_str = "a-z0-9-",
-
+
HTML5_email_regexp = new RegExp(
// start of string
'^'
* @author Krinkle <krinklemail@gmail.com>
*/
-(function ($, mw) {
+( function( $, mw ) {
mediaWiki.test = {
* 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( '<tr><td>' + mw.html.escape(code).replace(/ /g, ' ' )
- + '</td><td>' + mw.html.escape(result).replace(/ /g, ' ' )
+ this.$table.append( '<tr><td>' + mw.html.escape( code ).replace(/ /g, ' ' )
+ + '</td><td>' + mw.html.escape( result ).replace(/ /g, ' ' )
+ '</td><td></td><td>?</td></tr>' );
},
/* 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(
'<p>Below is a list of tests to confirm proper functionality of the mediaWiki.util functions</p>'
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++;
$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++;
numberofpartials + ' partially passed test(s). </p>' );
}
- });
+ } );
}
}
};
mediaWiki.test.init();
-})(jQuery, mediaWiki);
+} )(jQuery, mediaWiki);
\ No newline at end of file
* @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;