From: Mark Holmquist Date: Wed, 7 Oct 2015 16:55:48 +0000 (-0500) Subject: Quick fixes for mw.ForeignUpload X-Git-Tag: 1.31.0-rc.0~9502^2 X-Git-Url: https://git.cyclocoop.org/%7B%24admin_url%7Dcompta/operations/modifier.php?a=commitdiff_plain;h=2814053cb0c27bda0a76b21ffc9eeb31ef9726b1;p=lhc%2Fweb%2Fwiklou.git Quick fixes for mw.ForeignUpload Message name tweaks, and default fixes for the targets. Remove useless tests. Change-Id: I327050a5fec0df3ccd68ba777d6dc12b833fc13a --- diff --git a/languages/i18n/en.json b/languages/i18n/en.json index 29013931c8..25781d183f 100644 --- a/languages/i18n/en.json +++ b/languages/i18n/en.json @@ -1431,9 +1431,9 @@ "foreign-structured-upload-form-label-own-work-message-default": "I understand that I am uploading this file to a shared repository. I confirm that I am doing so following the terms of service and licensing policies there.", "foreign-structured-upload-form-label-not-own-work-message-default": "If you are not able to upload this file under the policies of the shared repository, please close this dialog and try another method.", "foreign-structured-upload-form-label-not-own-work-local-default": "You may also want to try using [[Special:Upload|the upload page on {{SITENAME}}]], if this file can be uploaded there under their policies.", - "foreign-structured-upload-form-label-own-work-message-wikimediacommons": "I attest that I own the copyright on this file, and agree to irrevocably release this file to Wikimedia Commons under the [https://creativecommons.org/licenses/by-sa/4.0/ Creative Commons Attribution-ShareAlike 4.0] license, and I agree to the [https://wikimediafoundation.org/wiki/Terms_of_Use Terms of Use].", - "foreign-structured-upload-form-label-not-own-work-message-wikimediacommons": "If you do not own the copyright on this file, or you wish to release it under a different license, consider using the [https://commons.wikimedia.org/wiki/Special:UploadWizard Commons Upload Wizard].", - "foreign-structured-upload-form-label-not-own-work-local-wikimediacommons": "You may also want to try using [[Special:Upload|the upload page on {{SITENAME}}]], if the site allows the upload of this file under their policies.", + "foreign-structured-upload-form-label-own-work-message-shared": "I attest that I own the copyright on this file, and agree to irrevocably release this file to Wikimedia Commons under the [https://creativecommons.org/licenses/by-sa/4.0/ Creative Commons Attribution-ShareAlike 4.0] license, and I agree to the [https://wikimediafoundation.org/wiki/Terms_of_Use Terms of Use].", + "foreign-structured-upload-form-label-not-own-work-message-shared": "If you do not own the copyright on this file, or you wish to release it under a different license, consider using the [https://commons.wikimedia.org/wiki/Special:UploadWizard Commons Upload Wizard].", + "foreign-structured-upload-form-label-not-own-work-local-shared": "You may also want to try using [[Special:Upload|the upload page on {{SITENAME}}]], if the site allows the upload of this file under their policies.", "backend-fail-stream": "Could not stream file \"$1\".", "backend-fail-backup": "Could not backup file \"$1\".", "backend-fail-notexists": "The file $1 does not exist.", diff --git a/languages/i18n/qqq.json b/languages/i18n/qqq.json index e464d93169..e04b0bfcb0 100644 --- a/languages/i18n/qqq.json +++ b/languages/i18n/qqq.json @@ -1604,9 +1604,9 @@ "foreign-structured-upload-form-label-own-work-message-default": "Message shown by default when a user affirms that they are allowed to upload a file to a remote wiki.", "foreign-structured-upload-form-label-not-own-work-message-default": "Message shown by default when a user cannot upload a file to a remote wiki.", "foreign-structured-upload-form-label-not-own-work-local-default": "Suggests uploading a file locally instead of to a remote wiki.", - "foreign-structured-upload-form-label-own-work-message-wikimediacommons": "Legal message to show when the work is made by the uploader.", - "foreign-structured-upload-form-label-not-own-work-message-wikimediacommons": "Message to show when the work isn't owned by the uploader.", - "foreign-structured-upload-form-label-not-own-work-local-wikimediacommons": "Message suggesting the user might want to upload a file locally instead of to Wikimedia Commons. $1 is the name of the local wiki.", + "foreign-structured-upload-form-label-own-work-message-shared": "Legal message to show when the work is made by the uploader.", + "foreign-structured-upload-form-label-not-own-work-message-shared": "Message to show when the work isn't owned by the uploader.", + "foreign-structured-upload-form-label-not-own-work-local-shared": "Message suggesting the user might want to upload a file locally instead of to Wikimedia Commons. $1 is the name of the local wiki.", "backend-fail-stream": "Parameters:\n* $1 - a filename", "backend-fail-backup": "Parameters:\n* $1 - a filename", "backend-fail-notexists": "Parameters:\n* $1 - a filename", diff --git a/resources/Resources.php b/resources/Resources.php index 5504fd7857..4a4ad862e7 100644 --- a/resources/Resources.php +++ b/resources/Resources.php @@ -1255,9 +1255,12 @@ return array( 'foreign-structured-upload-form-label-own-work-message-default', 'foreign-structured-upload-form-label-not-own-work-message-default', 'foreign-structured-upload-form-label-not-own-work-local-default', - 'foreign-structured-upload-form-label-own-work-message-wikimediacommons', - 'foreign-structured-upload-form-label-not-own-work-message-wikimediacommons', - 'foreign-structured-upload-form-label-not-own-work-local-wikimediacommons', + 'foreign-structured-upload-form-label-own-work-message-shared', + 'foreign-structured-upload-form-label-not-own-work-message-shared', + 'foreign-structured-upload-form-label-not-own-work-local-shared', + 'foreign-structured-upload-form-label-own-work-message-local', + 'foreign-structured-upload-form-label-not-own-work-message-local', + 'foreign-structured-upload-form-label-not-own-work-local-local', ), ), 'mediawiki.toc' => array( diff --git a/resources/src/mediawiki/mediawiki.ForeignStructuredUpload.BookletLayout.js b/resources/src/mediawiki/mediawiki.ForeignStructuredUpload.BookletLayout.js index 0807215583..825e738699 100644 --- a/resources/src/mediawiki/mediawiki.ForeignStructuredUpload.BookletLayout.js +++ b/resources/src/mediawiki/mediawiki.ForeignStructuredUpload.BookletLayout.js @@ -19,7 +19,7 @@ * @uses mw.ForeignStructuredUpload * @extends mw.Upload.BookletLayout * @cfg {string} [targetHost] Used to set up the target wiki. - * If nothing is passed, the {@link mw.ForeignUpload#property-targetHost default} is used. + * If nothing is passed, the {@link mw.ForeignUpload#property-target default} is used. */ mw.ForeignStructuredUpload.BookletLayout = function ( config ) { config = config || {}; diff --git a/resources/src/mediawiki/mediawiki.ForeignUpload.js b/resources/src/mediawiki/mediawiki.ForeignUpload.js index a367ee05d5..38c910606c 100644 --- a/resources/src/mediawiki/mediawiki.ForeignUpload.js +++ b/resources/src/mediawiki/mediawiki.ForeignUpload.js @@ -8,12 +8,12 @@ * Subclassed to upload to a foreign API, with no other goodies. Use * this for a generic foreign image repository on your wiki farm. * - * Note you can provide the {@link #targetHost targetHost} or not - if the first argument is + * Note you can provide the {@link #target target} or not - if the first argument is * an object, we assume you want the default, and treat it as apiconfig * instead. * * @constructor - * @param {string} [target="local"] Used to set up the target + * @param {string} [target] Used to set up the target * wiki. If not remote, this class behaves identically to mw.Upload (unless further subclassed) * Use the same names as set in $wgForeignFileRepos for this. Also, * make sure there is an entry in the $wgForeignUploadTargets array @@ -30,9 +30,7 @@ target = undefined; } - // Resolve defaults etc. - if target isn't passed in, we use - // the default. - this.target = target || this.target; + this.target = target; // Now we have several different options. // If the local wiki is the target, then we can skip a bunch of steps @@ -41,7 +39,11 @@ // However, if the target is a remote wiki, we must check the API // to confirm that the target is one that this site is configured to // support. - if ( this.target !== 'local' ) { + if ( this.target === 'local' ) { + // We'll ignore the CORS and centralauth stuff if the target is + // the local wiki. + this.apiPromise = $.Deferred().resolve( new mw.Api( apiconfig ) ); + } else { api = new mw.Api(); this.apiPromise = api.get( { action: 'query', @@ -51,27 +53,38 @@ var i, repo, repos = data.query.repos; + // First pass - try to find the passed-in target and check + // that it's configured for uploads. for ( i in repos ) { repo = repos[ i ]; - if ( repo.name === upload.target ) { - // This is our target repo. - if ( !repo.canUpload ) { - // But it's not configured correctly. - return $.Deferred().reject( 'repo-cannot-upload' ); - } + // Skip repos that are not our target, or if they + // are the target, cannot be uploaded to. + if ( repo.name === upload.target && repo.canUpload ) { + return new mw.ForeignApi( + repo.scriptDirUrl + '/api.php', + apiconfig + ); + } + } + // Second pass - none of the configured repos were our + // passed-in target, just look for the first one that would + // work. + for ( i in repos ) { + repo = repos[ i ]; + + if ( repo.canUpload ) { return new mw.ForeignApi( repo.scriptDirUrl + '/api.php', apiconfig ); } } + + // No luck finding the correct foreign repo, default to local. + return $.Deferred().resolve( new mw.Api( apiconfig ) ); } ); - } else { - // We'll ignore the CORS and centralauth stuff if the target is - // the local wiki. - this.apiPromise = $.Deferred().resolve( new mw.Api( apiconfig ) ); } // Build the upload object without an API - this class overrides the @@ -83,14 +96,16 @@ OO.inheritClass( ForeignUpload, mw.Upload ); /** - * @property targetHost + * @property {string} target * Used to specify the target repository of the upload. * * If you set this to something that isn't 'local', you must be sure to * add that target to $wgForeignUploadTargets in LocalSettings, and the * repository must be set up to use CORS and CentralAuth. + * + * Most wikis use "shared" to refer to Wikimedia Commons, we assume that + * in this class and in the messages linked to it. */ - ForeignUpload.prototype.target = 'local'; /** * Override from mw.Upload to make sure the API info is found and allowed diff --git a/tests/qunit/QUnitTestResources.php b/tests/qunit/QUnitTestResources.php index 0a29af5b43..f9ddcf2746 100644 --- a/tests/qunit/QUnitTestResources.php +++ b/tests/qunit/QUnitTestResources.php @@ -71,8 +71,6 @@ return array( 'tests/qunit/suites/resources/mediawiki/mediawiki.storage.test.js', 'tests/qunit/suites/resources/mediawiki/mediawiki.template.test.js', 'tests/qunit/suites/resources/mediawiki/mediawiki.test.js', - 'tests/qunit/suites/resources/mediawiki/mediawiki.ForeignUpload.test.js', - 'tests/qunit/suites/resources/mediawiki/mediawiki.ForeignStructuredUpload.test.js', 'tests/qunit/suites/resources/mediawiki/mediawiki.Title.test.js', 'tests/qunit/suites/resources/mediawiki/mediawiki.toc.test.js', 'tests/qunit/suites/resources/mediawiki/mediawiki.track.test.js', @@ -116,8 +114,6 @@ return array( 'mediawiki.api.upload', 'mediawiki.api.watch', 'mediawiki.ForeignApi.core', - 'mediawiki.ForeignUpload', - 'mediawiki.ForeignStructuredUpload', 'mediawiki.jqueryMsg', 'mediawiki.messagePoster', 'mediawiki.RegExp', diff --git a/tests/qunit/suites/resources/mediawiki/mediawiki.ForeignStructuredUpload.test.js b/tests/qunit/suites/resources/mediawiki/mediawiki.ForeignStructuredUpload.test.js deleted file mode 100644 index 3007416f35..0000000000 --- a/tests/qunit/suites/resources/mediawiki/mediawiki.ForeignStructuredUpload.test.js +++ /dev/null @@ -1,30 +0,0 @@ -( function ( mw ) { - QUnit.module( 'mediawiki.ForeignStructuredUpload', QUnit.newMwEnvironment( {} ) ); - - QUnit.test( 'Constructor check', function ( assert ) { - QUnit.expect( 3 ); - var upload = new mw.ForeignStructuredUpload(); - - assert.ok( upload, 'The ForeignUpload constructor is working.' ); - assert.ok( upload.descriptions, 'The descriptions array was initialized properly' ); - assert.ok( upload.categories, 'The categories array was initialized properly' ); - } ); - - QUnit.test( 'getText', function ( assert ) { - QUnit.expect( 1 ); - - var upload = new mw.ForeignStructuredUpload(); - - // Set basic information - upload.addDescription( 'en', 'Test description one two three' ); - upload.addDescription( 'en-x-piglatin', 'Esttay escriptionday unway ootay eethray' ); - upload.setDate( '1776-07-04' ); - upload.addCategories( [ 'Test 1', 'Test 2' ] ); - upload.addCategories( [ 'Test 3' ] ); - - // Fake the user - this.sandbox.stub( upload, 'getUser' ).returns( 'Test user' ); - - assert.strictEqual( upload.getText().trim(), '{{Information\n|description={{en|Test description one two three}}\n{{en-x-piglatin|Esttay escriptionday unway ootay eethray}}\n|date=1776-07-04\n|source=Test user\n|author=Test user\n}}\n\n\n\n[[Category:Test 1]]\n[[Category:Test 2]]\n[[Category:Test 3]]' ); - } ); -}( mediaWiki ) ); diff --git a/tests/qunit/suites/resources/mediawiki/mediawiki.ForeignUpload.test.js b/tests/qunit/suites/resources/mediawiki/mediawiki.ForeignUpload.test.js deleted file mode 100644 index 169ae37194..0000000000 --- a/tests/qunit/suites/resources/mediawiki/mediawiki.ForeignUpload.test.js +++ /dev/null @@ -1,12 +0,0 @@ -( function ( mw ) { - QUnit.module( 'mediawiki.ForeignUpload', QUnit.newMwEnvironment( {} ) ); - - QUnit.test( 'Constructor check', function ( assert ) { - QUnit.expect( 3 ); - var upload = new mw.ForeignUpload(); - - assert.ok( upload, 'The ForeignUpload constructor is working.' ); - assert.strictEqual( upload.target, 'local', 'Default target host is correct' ); - assert.ok( upload.api instanceof mw.Api, 'API is local because default target is local.' ); - } ); -}( mediaWiki ) );