jenkins-bot has submitted this change and it was merged.
Change subject: Sanitize flickr descriptions before pre-filling
......................................................................
Sanitize flickr descriptions before pre-filling
Bug: T78336
Change-Id: I6b9a94ca3e67ab504868f70d766152d83adda17d
---
M resources/mw.FlickrChecker.js
M tests/qunit/mw.FlickrChecker.test.js
2 files changed, 47 insertions(+), 5 deletions(-)
Approvals:
Gilles: Looks good to me, approved
jenkins-bot: Verified
diff --git a/resources/mw.FlickrChecker.js b/resources/mw.FlickrChecker.js
index e82476f..568b784 100644
--- a/resources/mw.FlickrChecker.js
+++ b/resources/mw.FlickrChecker.js
@@ -405,7 +405,7 @@
$( 'li.ui-selected' ).each( function (
index, image ) {
image = $( this ).attr( 'id' );
image = image.split( '-' )[1];
- checker.setImageDescription(
image );
+ checker.setUploadDescription(
checker.imageUploads[image] );
checker.setImageURL( image );
} );
} );
@@ -477,13 +477,13 @@
licenseMessage: license.licenseMessage,
license: true,
author: photoAuthor,
- description: photo.description._content,
originalFormat: photo.originalformat,
date: photo.dates.taken,
location: photo.location,
photoId: photo.id,
sourceURL: sourceURL
};
+ checker.setUploadDescription( flickrUpload,
photo.description._content );
checker.imageUploads.push( flickrUpload );
checker.setImageURL( 0, checker );
checker.reserveFileName( fileName );
@@ -557,15 +557,25 @@
} );
},
- setImageDescription: function ( index ) {
- var upload = this.imageUploads[index],
+ setUploadDescription: function ( upload, description ) {
+ if ( description !== undefined ) {
+ // If a Flickr description has a | character in
it, it will
+ // mess up the MediaWiki description. Escape
them.
+ upload.description = description.replace(
/\|/g, '|' );
+ } else {
+ this.setImageDescription( upload );
+ }
+ },
+
+ setImageDescription: function ( upload ) {
+ var checker = this,
photoId = upload.photoId;
this.flickrRequest( {
method: 'flickr.photos.getInfo',
photo_id: photoId
} ).done( function ( data ) {
- upload.description =
data.photo.description._content;
+ checker.setUploadDescription( upload,
data.photo.description._content );
} );
},
diff --git a/tests/qunit/mw.FlickrChecker.test.js
b/tests/qunit/mw.FlickrChecker.test.js
index ceedcdb..c0e07e1 100644
--- a/tests/qunit/mw.FlickrChecker.test.js
+++ b/tests/qunit/mw.FlickrChecker.test.js
@@ -58,4 +58,36 @@
'foo - 123.jpg'
);
} );
+
+ QUnit.test( 'setUploadDescription', 9, function ( assert ) {
+ var flickrChecker = getInstance(),
+ upload = {},
+ sidstub = this.sandbox.stub( flickrChecker,
'setImageDescription' );
+
+ flickrChecker.setUploadDescription( upload );
+ assert.ok( sidstub.called );
+ assert.ok( !upload.description );
+
+ sidstub.reset();
+ upload = {};
+ flickrChecker.setUploadDescription( upload, 'Testing' );
+ assert.strictEqual( upload.description, 'Testing' );
+ assert.ok( !sidstub.called );
+
+ sidstub.reset();
+ upload = {};
+ flickrChecker.setUploadDescription( upload, 'Testing | 1234' );
+ assert.strictEqual( upload.description, 'Testing | 1234' );
+ assert.ok( !sidstub.called );
+
+ upload = {};
+ flickrChecker.setUploadDescription( upload, 'Testing | 1234 |
5678' );
+ assert.strictEqual( upload.description, 'Testing | 1234
| 5678' );
+
+ sidstub.reset();
+ upload = {};
+ flickrChecker.setUploadDescription( upload, '' );
+ assert.ok( !sidstub.called );
+ assert.strictEqual( upload.description, '' );
+ } );
} ( mediaWiki ) );
--
To view, visit https://gerrit.wikimedia.org/r/188823
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I6b9a94ca3e67ab504868f70d766152d83adda17d
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/UploadWizard
Gerrit-Branch: master
Gerrit-Owner: MarkTraceur <[email protected]>
Gerrit-Reviewer: Gilles <[email protected]>
Gerrit-Reviewer: MarkTraceur <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits