jenkins-bot has submitted this change and it was merged.
Change subject: Create title in file NS and validate as such
......................................................................
Create title in file NS and validate as such
When uploading files, the Wizard should check for the actual
destination and not for pages in the gallery or other namespaces,
dependent on the user's input.
Bug: 66366
Change-Id: I1ed825b05ea80b41a2819a06024accd334ad5e19
---
M UploadWizardHooks.php
M resources/mw.UploadWizardDetails.js
A tests/qunit/mw.UploadWizardDetails.test.js
3 files changed, 64 insertions(+), 2 deletions(-)
Approvals:
Gilles: Looks good to me, but someone else must approve
Gergő Tisza: Looks good to me, approved
jenkins-bot: Verified
diff --git a/UploadWizardHooks.php b/UploadWizardHooks.php
index 6b4df9f..a380e16 100644
--- a/UploadWizardHooks.php
+++ b/UploadWizardHooks.php
@@ -831,6 +831,7 @@
'tests/qunit/mw.UploadWizardUpload.test.js',
'tests/qunit/mw.UploadWizardLicenseInput.test.js',
'tests/qunit/mw.FlickrChecker.test.js',
+ 'tests/qunit/mw.UploadWizardDetails.test.js',
'tests/qunit/mw.UtilitiesTime.test.js',
),
'dependencies' => array(
diff --git a/resources/mw.UploadWizardDetails.js
b/resources/mw.UploadWizardDetails.js
index 2048288..f598f63 100644
--- a/resources/mw.UploadWizardDetails.js
+++ b/resources/mw.UploadWizardDetails.js
@@ -481,6 +481,24 @@
} );
};
+ /**
+ * Reliably turn input into a MediaWiki title that is located in the
File: namespace
+ *
+ * var title = mw.UploadWizardDetails.makeTitleInFileNS(
'filename.ext' );
+ *
+ * @static
+ * @param {string} filename Desired file name; optionally with File:
namespace prefixed
+ * @return {mw.Title|null}
+ */
+ mw.UploadWizardDetails.makeTitleInFileNS = function ( filename ) {
+ var mwTitle = mw.Title.newFromText( filename, fileNsId );
+ if ( mwTitle && mwTitle.getNamespaceId() !== fileNsId ) {
+ // Force file namespace
+ mwTitle = mw.Title.newFromText( 'File:' + filename );
+ }
+ return mwTitle;
+ };
+
mw.UploadWizardDetails.prototype = {
// Has this details object been attached to the DOM already?
@@ -950,7 +968,7 @@
$( this.titleInput ).data( 'valid', false );
try {
- titleString = new mw.Title( result.title,
fileNsId ).toString();
+ titleString =
mw.UploadWizardDetails.makeTitleInFileNS( result.title ).toString();
} catch ( e ) {
// unparseable result from unique test?
titleString = '[unparseable name]';
@@ -1672,7 +1690,7 @@
re = new RegExp( '\\.' +
this.upload.title.getExtension() + '$', 'i' ),
cleaned = $.trim( s.replace( re, '' ) );
- this.upload.title = mw.Title.newFromText( cleaned + '.'
+ ext, fileNsId ) || this.upload.title;
+ this.upload.title =
mw.UploadWizardDetails.makeTitleInFileNS( cleaned + '.' + ext ) ||
this.upload.title;
return this.upload.title;
}
};
diff --git a/tests/qunit/mw.UploadWizardDetails.test.js
b/tests/qunit/mw.UploadWizardDetails.test.js
new file mode 100644
index 0000000..ad4cce2
--- /dev/null
+++ b/tests/qunit/mw.UploadWizardDetails.test.js
@@ -0,0 +1,43 @@
+( function ( mw, $ ) {
+ 'use strict';
+
+ QUnit.module( 'ext.uploadWizard/mw.UploadWizardDetails.test.js',
QUnit.newMwEnvironment() );
+
+ var makeTitleInFileNSCases = [ {
+ filename: 'foo.png',
+ prefixedText: 'File:Foo.png',
+ desc: 'filename without namespace starting with a lower case
letter'
+ }, {
+ filename: 'foo_bar-baz.jpg',
+ prefixedText: 'File:Foo bar-baz.jpg',
+ desc: 'filename without namespace with space in it'
+ }, {
+ filename: 'Media:foo_bar.jpg',
+ prefixedText: 'File:Media:foo bar.jpg',
+ desc: 'filename starting with Media:'
+ }, {
+ filename: 'MediaWiki:foo_bar.jpg',
+ prefixedText: 'File:MediaWiki:foo bar.jpg',
+ desc: 'filename starting with MediaWiki:'
+ }, {
+ filename: 'File:foo_bar.jpg',
+ prefixedText: 'File:Foo bar.jpg',
+ desc: 'filename starting with File:'
+ }, {
+ filename: 'file:foo_bar.jpg',
+ prefixedText: 'File:Foo bar.jpg',
+ desc: 'filename starting with file:'
+ } ];
+
+ QUnit.test( 'makeTitleInFileNS()', makeTitleInFileNSCases.length,
function () {
+ var makeTitleInFileNS =
mw.UploadWizardDetails.makeTitleInFileNS;
+
+ $.each( makeTitleInFileNSCases, function ( i, test ) {
+ QUnit.equal(
+ makeTitleInFileNS( test.filename
).getPrefixedText(),
+ test.prefixedText,
+ test.desc
+ );
+ } );
+ } );
+} ( mediaWiki, jQuery ) );
--
To view, visit https://gerrit.wikimedia.org/r/139592
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I1ed825b05ea80b41a2819a06024accd334ad5e19
Gerrit-PatchSet: 9
Gerrit-Project: mediawiki/extensions/UploadWizard
Gerrit-Branch: master
Gerrit-Owner: Rillke <[email protected]>
Gerrit-Reviewer: Gergő Tisza <[email protected]>
Gerrit-Reviewer: Gilles <[email protected]>
Gerrit-Reviewer: Jackmcbarn <[email protected]>
Gerrit-Reviewer: Krinkle <[email protected]>
Gerrit-Reviewer: MarkTraceur <[email protected]>
Gerrit-Reviewer: Rillke <[email protected]>
Gerrit-Reviewer: TheDJ <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits