' ).msg(
defaultLicenseMsg,
this.uploadCount,
this.authorInput.$element,
defaultLicenseLink,
mw.user
),
$( '
' ).msg( 'mwe-upwiz-source-ownwork-assert-custom',
this.uploadCount,
this.fakeAuthorInput.$element )
);
$crossfader.append( $customDiv );
}
crossfaderWidget = new OO.ui.Widget();
crossfaderWidget.$element.append( $crossfader );
// See uw.DetailsWidget
crossfaderWidget.getErrors = this.getAuthorErrors.bind( this, this.authorInput );
crossfaderWidget.getWarnings = this.getAuthorWarnings.bind( this, this.authorInput );
this.authorInputField = new uw.FieldLayout( crossfaderWidget );
// Aggregate 'change' event
this.authorInput.on( 'change', OO.ui.debounce( function () {
crossfaderWidget.emit( 'change' );
}, 500 ) );
$formFields = $( '
' ).attr( { target: '_blank', href: this.config.patents.url.legalcode } );
$patentDiv = $( '' ).append(
$( '' ).msg(
patentMsg,
this.threeDCount,
this.patentAuthorInput.$element,
patentLink,
mw.user
)
);
patentWidget = new OO.ui.Widget();
patentWidget.$element.append( $patentDiv );
// See uw.DetailsWidget
patentWidget.getErrors = this.getAuthorErrors.bind( this, this.patentAuthorInput );
patentWidget.getWarnings = this.getAuthorWarnings.bind( this, this.patentAuthorInput );
this.patentAuthorInputField = new uw.FieldLayout( patentWidget );
deed.patentAuthorInput.on( 'change', OO.ui.debounce( function () {
patentWidget.emit( 'change' );
}, 500 ) );
$formFields.append( this.patentAuthorInputField.$element );
$formFields.append( this.patentAgreementField.$element );
}
this.$form.append( $formFields ).appendTo( $selector );
// done after added to the DOM, so there are true heights
$crossfader.morphCrossfader();
if ( this.showCustomDiv ) {
// choose default licenses
this.licenseInput.setDefaultValues();
}
$.each( this.config.licensing.ownWork.licenses, function ( i, license ) {
if ( license === defaultLicense ) {
$( '#license1_' + i ).prop( 'checked', true );
return false;
}
} );
};
/**
* @inheritdoc
*/
uw.deed.OwnWork.prototype.getSourceWikiText = function () {
return '{{own}}';
};
/**
* @inheritdoc
*/
uw.deed.OwnWork.prototype.getAuthorWikiText = function () {
var author = this.authorInput.getValue();
if ( author.indexOf( '[' ) >= 0 || author.indexOf( '{' ) >= 0 ) {
return author;
}
return '[[User:' + mw.config.get( 'wgUserName' ) + '|' + author + ']]';
};
/**
* @inheritdoc
*/
uw.deed.OwnWork.prototype.getLicenseWikiText = function ( upload ) {
var wikitext = '';
if ( this.showCustomDiv && this.licenseInput.getWikiText() !== '' ) {
wikitext += this.licenseInput.getWikiText();
} else {
wikitext += '{{' +
this.config.licensing.ownWork.template +
'|' +
this.getDefaultLicense() +
'}}';
}
if ( this.needsPatentAgreement( upload ) ) {
wikitext += '\n{{' + this.config.patents.template + '|ownwork}}';
}
return wikitext;
};
/**
* @return {Object}
*/
uw.deed.OwnWork.prototype.getSerialized = function () {
var serialized = $.extend( uw.deed.Abstract.prototype.getSerialized.call( this ), {
author: this.authorInput.getValue()
} );
if ( this.showCustomDiv ) {
serialized.license = this.licenseInput.getSerialized();
}
if ( this.threeDCount > 0 ) {
serialized.patentAuthor = this.patentAuthorInput.getValue();
}
return serialized;
};
/**
* @param {Object} serialized
*/
uw.deed.OwnWork.prototype.setSerialized = function ( serialized ) {
uw.deed.Abstract.prototype.setSerialized.call( this, serialized );
if ( serialized.author ) {
this.authorInput.setValue( serialized.author );
}
if ( this.showCustomDiv && serialized.license ) {
// only need to set license if it's not the default license
if ( !( this.getDefaultLicense() in serialized.license ) ) {
// expand licenses container
this.customLicense();
this.licenseInput.setSerialized( serialized.license );
}
}
if ( this.threeDCount > 0 && serialized.patentAuthor ) {
this.patentAuthorInput.setValue( serialized.patentAuthor );
}
};
uw.deed.OwnWork.prototype.swapNodes = function ( a, b ) {
var
parentA = a.parentNode,
parentB = b.parentNode,
nextA = a.nextSibling,
nextB = b.nextSibling;
// This is not correct if a and b are siblings, or if one is a child of the
// other, or if they're detached, or maybe in other cases, but we don't care
parentA[ nextA ? 'insertBefore' : 'appendChild' ]( b, nextA );
parentB[ nextB ? 'insertBefore' : 'appendChild' ]( a, nextB );
};
uw.deed.OwnWork.prototype.getDefaultLicense = function () {
if ( this.config.licensing.defaultType === 'ownwork' ) {
return this.config.licensing.ownWork.defaults;
} else {
return this.config.licensing.ownWork.licenses[ 0 ];
}
};
uw.deed.OwnWork.prototype.standardLicense = function () {
var deed = this,
$crossfader = this.$selector.find( '.mwe-upwiz-crossfader' ),
$standardDiv = this.$selector.find( '.mwe-upwiz-standard' ),
$toggler = this.$selector.find( '.mwe-more-options a' );
this.licenseInput.setDefaultValues();
$crossfader.morphCrossfade( $standardDiv )
.promise().done( function () {
deed.swapNodes( deed.authorInput.$element[ 0 ], deed.fakeAuthorInput.$element[ 0 ] );
} );
this.licenseInputField.$element
.slideUp()
.animate( { opacity: 0 }, { queue: false, easing: 'linear' } );
$toggler.msg( 'mwe-upwiz-license-show-all' );
};
uw.deed.OwnWork.prototype.customLicense = function () {
var deed = this,
$crossfader = this.$selector.find( '.mwe-upwiz-crossfader' ),
$customDiv = this.$selector.find( '.mwe-upwiz-custom' ),
$toggler = this.$selector.find( '.mwe-more-options a' );
$crossfader.morphCrossfade( $customDiv )
.promise().done( function () {
deed.swapNodes( deed.authorInput.$element[ 0 ], deed.fakeAuthorInput.$element[ 0 ] );
} );
this.licenseInputField.$element
.slideDown()
.css( { opacity: 0 } ).animate( { opacity: 1 }, { queue: false, easing: 'linear' } );
$toggler.msg( 'mwe-upwiz-license-show-recommended' );
};
/**
* @param {OO.ui.InputWidget} input
* @return {jQuery.Promise}
*/
uw.deed.OwnWork.prototype.getAuthorErrors = function ( input ) {
var
errors = [],
minLength = this.config.minAuthorLength,
maxLength = this.config.maxAuthorLength,
text = input.getValue().trim();
if ( text === '' ) {
errors.push( mw.message( 'mwe-upwiz-error-signature-blank' ) );
} else if ( text.length < minLength ) {
errors.push( mw.message( 'mwe-upwiz-error-signature-too-short', minLength ) );
} else if ( text.length > maxLength ) {
errors.push( mw.message( 'mwe-upwiz-error-signature-too-long', maxLength ) );
}
return $.Deferred().resolve( errors ).promise();
};
/**
* @return {jQuery.Promise}
*/
uw.deed.OwnWork.prototype.getAuthorWarnings = function () {
return $.Deferred().resolve( [] ).promise();
};
/**
* @param {mw.UploadWizardUpload[]} uploads
* @return {uw.PatentDialog}
*/
uw.deed.OwnWork.prototype.getPatentDialog = function ( uploads ) {
var config = { panels: [ 'warranty', 'license' ] };
// Only show filename list when in "details" step & we're showing the dialog for individual files
if ( uploads[ 0 ] && uploads[ 0 ].state === 'details' ) {
config.panels.unshift( 'filelist' );
}
return new uw.PatentDialog( config, this.config, uploads );
};
}( mediaWiki, mediaWiki.uploadWizard, jQuery, OO ) );