jenkins-bot has submitted this change and it was merged.
Change subject: Restore content after having gone back
......................................................................
Restore content after having gone back
Bug: T122923
Change-Id: I48192be75aa227e5301415c042e2a85518f37c47
---
M resources/controller/uw.controller.Deed.js
M resources/controller/uw.controller.Details.js
M resources/details/uw.DeedChooserDetailsWidget.js
M resources/mw.UploadWizard.js
M resources/mw.UploadWizardDeed.js
M resources/mw.UploadWizardDeedChooser.js
M resources/mw.UploadWizardDeedOwnWork.js
M resources/mw.UploadWizardDeedThirdParty.js
M resources/mw.UploadWizardDetails.js
M resources/mw.UploadWizardLicenseInput.js
M tests/qunit/controller/uw.controller.Details.test.js
11 files changed, 297 insertions(+), 71 deletions(-)
Approvals:
Bartosz Dziewoński: Looks good to me, approved
jenkins-bot: Verified
diff --git a/resources/controller/uw.controller.Deed.js
b/resources/controller/uw.controller.Deed.js
index 5e48e57..ce348bf 100644
--- a/resources/controller/uw.controller.Deed.js
+++ b/resources/controller/uw.controller.Deed.js
@@ -33,6 +33,8 @@
);
this.stepName = 'deeds';
+
+ this.deeds = {};
};
OO.inheritClass( uw.controller.Deed, uw.controller.Step );
@@ -40,8 +42,7 @@
uw.controller.Deed.prototype.moveNext = function () {
var
deedController = this,
- valid = true,
- fields;
+ valid, fields;
if ( !this.deedChooser ) {
uw.controller.Step.prototype.moveNext.call( this );
@@ -78,27 +79,40 @@
* Move to this step.
*/
uw.controller.Deed.prototype.moveTo = function ( uploads ) {
- var customDeed, deeds,
+ var customDeed, previousDeed, fromStepName,
showDeed = false,
step = this;
- uw.controller.Step.prototype.moveTo.call( this, uploads );
-
- $.each( this.uploads, function ( i, upload ) {
+ $.each( uploads, function ( i, upload ) {
+ fromStepName = upload.state;
if ( !upload.fromURL ) {
showDeed = true;
return false;
}
} );
+ uw.controller.Step.prototype.moveTo.call( this, uploads );
+
// If all of the uploads are from URLs, then we know the
licenses
// already, we don't need this step.
if ( !showDeed ) {
- this.moveNext();
+ // this is a bit of a hack: when images from flickr are
uploaded, we
+ // don't get to choose the license anymore, and this
step will be
+ // skipped ... but we could reach this step from either
direction
+ if ( fromStepName === 'details' ) {
+ this.movePrevious();
+ } else {
+ this.moveNext();
+ }
return;
}
- deeds = mw.UploadWizard.getLicensingDeeds( this.uploads.length,
this.config );
+ // grab a serialized copy of previous deeds' details (if any)
+ if ( this.deedChooser ) {
+ previousDeed = this.deedChooser.getSerialized();
+ }
+
+ this.deeds = mw.UploadWizard.getLicensingDeeds(
this.uploads.length, this.config );
// if we have multiple uploads, also give them the option to set
// licenses individually
@@ -106,13 +120,13 @@
customDeed = $.extend( new mw.UploadWizardDeed(), {
name: 'custom'
} );
- deeds.push( customDeed );
+ this.deeds[ customDeed.name ] = customDeed;
}
this.deedChooser = new mw.UploadWizardDeedChooser(
this.config,
'#mwe-upwiz-deeds',
- deeds,
+ this.deeds,
this.uploads
);
@@ -128,6 +142,11 @@
} );
this.deedChooser.onLayoutReady();
+
+ // restore the previous input (if any) for all deeds
+ if ( previousDeed ) {
+ this.deedChooser.setSerialized( previousDeed );
+ }
};
/**
diff --git a/resources/controller/uw.controller.Details.js
b/resources/controller/uw.controller.Details.js
index bb9a94a..8058203 100644
--- a/resources/controller/uw.controller.Details.js
+++ b/resources/controller/uw.controller.Details.js
@@ -62,15 +62,26 @@
successes = uploads.length - failures;
$.each( uploads, function ( i, upload ) {
+ var serialized;
+
if ( upload === undefined ) {
return;
}
+ // get existing details
+ serialized = upload.details ?
upload.details.getSerialized() : null;
+
upload.createDetails();
- if ( upload.fromURL || upload.chosenDeed.name ===
'custom' ) {
+ if ( upload.fromURL || ( upload.deedChooser &&
upload.deedChooser.deed.name === 'custom' ) ) {
upload.details.useCustomDeedChooser();
}
+
+ // restore earlier details (user may have started
inputting details,
+ // then went back some steps, and now got here again)
+ if ( serialized ) {
+ upload.details.setSerialized( serialized );
+ }
} );
// Show the widget allowing to copy selected metadata if
there's more than one successful upload
diff --git a/resources/details/uw.DeedChooserDetailsWidget.js
b/resources/details/uw.DeedChooserDetailsWidget.js
index 58ad744..83df787 100644
--- a/resources/details/uw.DeedChooserDetailsWidget.js
+++ b/resources/details/uw.DeedChooserDetailsWidget.js
@@ -22,7 +22,20 @@
// Defining own deedChooser for uploads coming from external
service
if ( upload.fromURL ) {
// XXX can be made a seperate class as
mw.UploadFromUrlDeedChooser
- this.deedChooser = upload.deedChooser = { valid:
function () { return true; } };
+ this.deedChooser = upload.deedChooser = {
+ deed: {},
+ valid: function () {
+ return true;
+ },
+ getSerialized: function () {
+ return this.deed ?
this.deed.getSerialized() : {};
+ },
+ setSerialized: function ( serialized ) {
+ if ( this.deed.setSerialized ) {
+ this.deed.setSerialized(
serialized );
+ }
+ }
+ };
if ( upload.providedFile.license ) {
// XXX need to add code in the remaining
functions
@@ -86,6 +99,12 @@
},
getLicenseWikiText: function () {
return upload.providedFile.licenseValue;
+ },
+ getSerialized: function () {
+ return {};
+ },
+ setSerialized: function ( serialized ) {
+ /* jshint unused:false */
}
}, overrides );
};
@@ -103,4 +122,24 @@
return $.Deferred().resolve( errors ).promise();
};
+ /**
+ * @return {Object}
+ */
+ uw.DeedChooserDetailsWidget.prototype.getSerialized = function () {
+ if ( this.deedChooser ) {
+ return this.deedChooser.getSerialized();
+ }
+
+ return {};
+ };
+
+ /**
+ * @param {Object} serialized
+ */
+ uw.DeedChooserDetailsWidget.prototype.setSerialized = function (
serialized ) {
+ if ( this.deedChooser ) {
+ this.deedChooser.setSerialized( serialized );
+ }
+ };
+
} )( mediaWiki, mediaWiki.uploadWizard, jQuery, OO );
diff --git a/resources/mw.UploadWizard.js b/resources/mw.UploadWizard.js
index 6db73ba..1783abc 100644
--- a/resources/mw.UploadWizard.js
+++ b/resources/mw.UploadWizard.js
@@ -472,7 +472,8 @@
* @return {mw.UploadWizardDeed[]}
*/
mw.UploadWizard.getLicensingDeeds = function ( uploadsLength, config ) {
- var deeds = [],
+ var deed,
+ deeds = {},
doOwnWork = false,
doThirdParty = false;
@@ -487,10 +488,12 @@
}
if ( doOwnWork ) {
- deeds.push( new mw.UploadWizardDeedOwnWork(
uploadsLength, this.api, config ) );
+ deed = new mw.UploadWizardDeedOwnWork( uploadsLength,
this.api, config );
+ deeds[ deed.name ] = deed;
}
if ( doThirdParty ) {
- deeds.push( new mw.UploadWizardDeedThirdParty(
uploadsLength, this.api, config ) );
+ deed = new mw.UploadWizardDeedThirdParty(
uploadsLength, this.api, config );
+ deeds[ deed.name ] = deed;
}
return deeds;
diff --git a/resources/mw.UploadWizardDeed.js b/resources/mw.UploadWizardDeed.js
index 18755df..18d9378 100644
--- a/resources/mw.UploadWizardDeed.js
+++ b/resources/mw.UploadWizardDeed.js
@@ -41,6 +41,24 @@
*/
getLicenseWikiText: function () {
return this.licenseInput.getWikiText();
+ },
+
+ /**
+ * @return {Object}
+ */
+ getSerialized: function () {
+ return {
+ name: this.name
+ };
+ },
+
+ /**
+ * @param {Object} serialized
+ */
+ setSerialized: function ( serialized ) {
+ if ( serialized.name ) {
+ this.name = serialized.name;
+ }
}
};
diff --git a/resources/mw.UploadWizardDeedChooser.js
b/resources/mw.UploadWizardDeedChooser.js
index f841658..af4ad18 100644
--- a/resources/mw.UploadWizardDeedChooser.js
+++ b/resources/mw.UploadWizardDeedChooser.js
@@ -12,6 +12,7 @@
var chooser = this;
this.$selector = $( selector );
this.uploads = uploads === undefined ? [] : uploads;
+ this.deeds = deeds;
// name for radio button set
mw.UploadWizardDeedChooser.prototype.widgetCount++;
@@ -19,7 +20,7 @@
this.onLayoutReady = function () {};
- $.each( deeds, function ( i, deed ) {
+ $.each( this.deeds, function ( i, deed ) {
var id = chooser.name + '-' + deed.name,
$deedInterface = $(
'<div class="mwe-upwiz-deed
mwe-upwiz-deed-' + deed.name + '">' +
@@ -39,22 +40,15 @@
deed.setFormFields( $deedInterface.find(
'.mwe-upwiz-deed-form' ) );
- function selectDeedFunction() {
- chooser.choose( deed );
- chooser.selectDeedInterface( $deedInterface );
- $deedInterface.find(
'span.mwe-upwiz-deed-header input' ).prop( 'checked', true );
- }
-
if ( deeds.length === 1 ) {
- chooser.onLayoutReady = selectDeedFunction;
+ chooser.onLayoutReady =
chooser.selectDeed.bind( chooser, deed );
} else {
if ( config.licensing.defaultType === deed.name
) {
- chooser.onLayoutReady =
selectDeedFunction;
+ chooser.onLayoutReady =
chooser.selectDeed.bind( chooser, deed );
}
$deedInterface.find(
'span.mwe-upwiz-deed-header input' ).click( function () {
if ( $( this ).is( ':checked' ) ) {
- chooser.choose( deed );
- chooser.selectDeedInterface(
$deedInterface );
+ chooser.selectDeed( deed );
}
} );
}
@@ -65,7 +59,6 @@
};
mw.UploadWizardDeedChooser.prototype = {
-
/**
* How many deed choosers there are (important for creating
unique ids, element names)
*/
@@ -85,13 +78,20 @@
*/
uploads: [],
+ selectDeed: function ( deed ) {
+ var $deedInterface = this.$selector.find(
'.mwe-upwiz-deed.mwe-upwiz-deed-' + deed.name );
+
+ this.choose( deed );
+ this.selectDeedInterface( $deedInterface );
+ $deedInterface.find( 'span.mwe-upwiz-deed-header input'
).prop( 'checked', true );
+ },
+
choose: function ( deed ) {
var chooser = this;
this.deed = deed;
$.each( this.uploads, function ( i, upload ) {
- upload.chosenDeed = deed;
upload.deedChooser = chooser;
} );
@@ -136,6 +136,26 @@
remove: function () {
this.$selector.html( '' );
+ },
+
+ /**
+ * @return {Object}
+ */
+ getSerialized: function () {
+ return this.valid() ? this.deed.getSerialized() : {};
+ },
+
+ /**
+ * @param {Object} serialized
+ */
+ setSerialized: function ( serialized ) {
+ var deed;
+
+ if ( serialized.name && serialized.name in this.deeds )
{
+ deed = this.deeds[ serialized.name ];
+ deed.setSerialized( serialized );
+ this.selectDeed( deed );
+ }
}
};
diff --git a/resources/mw.UploadWizardDeedOwnWork.js
b/resources/mw.UploadWizardDeedOwnWork.js
index 9d929ce..df5664b 100644
--- a/resources/mw.UploadWizardDeedOwnWork.js
+++ b/resources/mw.UploadWizardDeedOwnWork.js
@@ -70,23 +70,22 @@
return fields;
},
- getLicenseWikiText: function () {
- var defaultLicense,
- defaultType =
config.licensing.defaultType;
-
- if ( defaultType === 'ownwork' ) {
- defaultLicense =
config.licensing.ownWork.defaults;
+ getDefaultLicense: function () {
+ if ( config.licensing.defaultType === 'ownwork'
) {
+ return
config.licensing.ownWork.defaults;
} else {
- defaultLicense =
config.licensing.ownWork.licenses[ 0 ];
+ return
config.licensing.ownWork.licenses[ 0 ];
}
+ },
+ getLicenseWikiText: function () {
if ( this.showCustomDiv &&
this.licenseInput.getWikiText() !== '' ) {
return this.licenseInput.getWikiText();
} else {
return '{{' +
config.licensing.ownWork.template +
'|' +
- defaultLicense +
+
this.getDefaultLicense() +
'}}';
}
},
@@ -110,18 +109,13 @@
setFormFields: function ( $selector ) {
var $customDiv, $formFields, $toggler,
crossfaderWidget, defaultLicense,
defaultLicenseURL, defaultLicenseMsg,
defaultLicenseExplainMsg,
- defaultLicenseLink, $standardDiv,
$crossfader, thisDeed, languageCode, defaultType;
+ defaultLicenseLink, $standardDiv,
$crossfader, thisDeed, languageCode;
this.$selector = $selector;
thisDeed = this;
languageCode = mw.config.get( 'wgUserLanguage'
);
- defaultType = config.licensing.defaultType;
- if ( defaultType === 'ownwork' ) {
- defaultLicense =
config.licensing.ownWork.defaults;
- } else {
- defaultLicense =
config.licensing.ownWork.licenses[ 0 ];
- }
+ defaultLicense = this.getDefaultLicense();
defaultLicenseURL = config.licenses[
defaultLicense ].url === undefined ?
'#missing license URL' :
@@ -132,7 +126,7 @@
this.$form = $( '<form>' );
- $standardDiv = $( '<div />' ).append(
+ $standardDiv = $( '<div
class="mwe-upwiz-standard" />' ).append(
$( '<p></p>' ).msg(
defaultLicenseMsg,
uploadCount,
@@ -145,10 +139,10 @@
uploadCount
)
);
- $crossfader = $( '<div />' ).append(
$standardDiv );
+ $crossfader = $( '<div
class="mwe-upwiz-crossfader" />' ).append( $standardDiv );
if ( this.showCustomDiv ) {
- $customDiv = $( '<div />' ).append(
+ $customDiv = $( '<div
class="mwe-upwiz-custom" />' ).append(
$( '<p></p>' ).msg(
'mwe-upwiz-source-ownwork-assert-custom',
uploadCount,
this.fakeAuthorInput.$element )
@@ -198,24 +192,9 @@
.msg(
'mwe-upwiz-license-show-all' )
.click( function () {
if ( $crossfader.data(
'crossfadeDisplay' ).get( 0 ) === $customDiv.get( 0 ) ) {
-
thisDeed.licenseInput.setDefaultValues();
-
$crossfader.morphCrossfade( $standardDiv )
-
.promise().done( function () {
-
swapNodes( thisDeed.authorInput.$element[ 0 ],
thisDeed.fakeAuthorInput.$element[ 0 ] );
- } );
-
deed.licenseInputField.$element
-
.slideUp()
-
.animate( { opacity: 0 }, { queue: false, easing: 'linear' } );
- $( this ).msg(
'mwe-upwiz-license-show-all' );
+
thisDeed.standardLicense();
} else {
-
$crossfader.morphCrossfade( $customDiv )
-
.promise().done( function () {
-
swapNodes( thisDeed.authorInput.$element[ 0 ],
thisDeed.fakeAuthorInput.$element[ 0 ] );
- } );
-
deed.licenseInputField.$element
-
.slideDown()
- .css( {
opacity: 0 } ).animate( { opacity: 1 }, { queue: false, easing: 'linear' } );
- $( this ).msg(
'mwe-upwiz-license-show-recommended' );
+
thisDeed.customLicense();
}
} ) );
@@ -239,6 +218,79 @@
return false;
}
} );
+ },
+
+ 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 () {
+ 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' );
+ },
+
+ 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 () {
+ 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' );
+ },
+
+ /**
+ * @return {Object}
+ */
+ getSerialized: function () {
+ var serialized = $.extend(
mw.UploadWizardDeed.prototype.getSerialized.call( this ), {
+ author: this.authorInput.getValue()
+ } );
+
+ if ( this.showCustomDiv ) {
+ serialized.license =
this.licenseInput.getSerialized();
+ }
+
+ return serialized;
+ },
+
+ /**
+ * @param {Object} serialized
+ */
+ setSerialized: function ( serialized ) {
+
mw.UploadWizardDeed.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 );
+ }
+ }
}
} );
};
diff --git a/resources/mw.UploadWizardDeedThirdParty.js
b/resources/mw.UploadWizardDeedThirdParty.js
index 5260e33..973125d 100644
--- a/resources/mw.UploadWizardDeedThirdParty.js
+++ b/resources/mw.UploadWizardDeedThirdParty.js
@@ -172,6 +172,34 @@
*/
getFields: function () {
return [ this.authorInputField,
this.sourceInputField, this.licenseInputField ];
+ },
+
+ /**
+ * @return {Object}
+ */
+ getSerialized: function () {
+ return $.extend(
mw.UploadWizardDeed.prototype.getSerialized.call( this ), {
+ source: this.sourceInput.getValue(),
+ author: this.authorInput.getValue(),
+ license:
this.licenseInput.getSerialized()
+ } );
+ },
+
+ /**
+ * @param {Object} serialized
+ */
+ setSerialized: function ( serialized ) {
+
mw.UploadWizardDeed.prototype.setSerialized.call( this, serialized );
+
+ if ( serialized.source ) {
+ this.sourceInput.setValue(
serialized.source );
+ }
+ if ( serialized.author ) {
+ this.authorInput.setValue(
serialized.author );
+ }
+ if ( serialized.license ) {
+ this.licenseInput.setSerialized(
serialized.license );
+ }
}
} );
};
diff --git a/resources/mw.UploadWizardDetails.js
b/resources/mw.UploadWizardDetails.js
index 0406f03..75673ee 100644
--- a/resources/mw.UploadWizardDetails.js
+++ b/resources/mw.UploadWizardDetails.js
@@ -582,7 +582,8 @@
other: this.otherDetails.getSerialized(),
campaigns: this.campaignDetailsFields.map(
function ( field ) {
return
field.fieldWidget.getSerialized();
- } )
+ } ),
+ deed: this.deedChooserDetails.getSerialized()
};
},
@@ -619,6 +620,9 @@
this.campaignDetailsFields[ i
].fieldWidget.setSerialized( serialized.campaigns[ i ] );
}
}
+ if ( serialized.deed ) {
+ this.deedChooserDetails.setSerialized(
serialized.deed );
+ }
},
/**
diff --git a/resources/mw.UploadWizardLicenseInput.js
b/resources/mw.UploadWizardLicenseInput.js
index 20cf615..cc48e11 100644
--- a/resources/mw.UploadWizardLicenseInput.js
+++ b/resources/mw.UploadWizardLicenseInput.js
@@ -374,8 +374,16 @@
setInputsIndividually: function ( values ) {
var input = this;
$.each( this.inputs, function ( i, $input ) {
- var licenseName = $input.data( 'licenseName' );
- input.setInput( $input, values[ licenseName ] );
+ var licenseName = $input.data( 'licenseName' ),
+ value = licenseName in values &&
values[ licenseName ] !== false;
+
+ input.setInput( $input, value );
+
+ // if value was a string, it doesn't just mean
that we should
+ // select the checkbox, but also fill out the
textarea it comes with
+ if ( value && typeof values[ licenseName ] ===
'string' ) {
+ $input.data( 'textarea' ).val( values[
licenseName ] );
+ }
} );
},
@@ -632,6 +640,28 @@
}
this.api.parse( wikiText ).done( show ).fail( error );
+ },
+
+ /**
+ * @return {Object}
+ */
+ getSerialized: function () {
+ var i,
+ values = {},
+ $inputs = this.getSelectedInputs();
+
+ for ( i = 0; i < $inputs.length; i++ ) {
+ values[ $inputs[ i ].data( 'licenseName' ) ] =
this.getInputTextAreaVal( $inputs[ i ] ) || true;
+ }
+
+ return values;
+ },
+
+ /**
+ * @param {Object} serialized
+ */
+ setSerialized: function ( serialized ) {
+ this.setValues( serialized );
}
} );
diff --git a/tests/qunit/controller/uw.controller.Details.test.js
b/tests/qunit/controller/uw.controller.Details.test.js
index ca649fc..fb845ec 100644
--- a/tests/qunit/controller/uw.controller.Details.test.js
+++ b/tests/qunit/controller/uw.controller.Details.test.js
@@ -21,20 +21,22 @@
function createTestUpload( sandbox, customDeedChooser, aborted ) {
var stubs = {
cd: sandbox.stub(),
- ucdc: sandbox.stub()
+ ucdc: sandbox.stub(),
+ getSerialized: sandbox.stub(),
+ SetSerialized: sandbox.stub()
};
return {
- chosenDeed: {
- name: customDeedChooser ? 'custom' :
'cc-by-sa-4.0'
- },
+ deedChooser: { deed: { name: customDeedChooser ?
'custom' : 'cc-by-sa-4.0' } },
on: $.noop,
createDetails: stubs.cd,
details: {
- useCustomDeedChooser: stubs.ucdc
+ useCustomDeedChooser: stubs.ucdc,
+ getSerialized: stubs.getSerialized,
+ SetSerialized: stubs.setSerialized
},
state: aborted ? 'aborted' : 'stashed',
--
To view, visit https://gerrit.wikimedia.org/r/320611
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I48192be75aa227e5301415c042e2a85518f37c47
Gerrit-PatchSet: 8
Gerrit-Project: mediawiki/extensions/UploadWizard
Gerrit-Branch: master
Gerrit-Owner: Matthias Mullie <[email protected]>
Gerrit-Reviewer: Bartosz Dziewoński <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits