Message name tweaks, and default fixes for the targets.
Remove useless tests.
Change-Id: I327050a5fec0df3ccd68ba777d6dc12b833fc13a
"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.",
"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",
'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(
* @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 || {};
* 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
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
// 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',
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
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
'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',
'mediawiki.api.upload',
'mediawiki.api.watch',
'mediawiki.ForeignApi.core',
- 'mediawiki.ForeignUpload',
- 'mediawiki.ForeignStructuredUpload',
'mediawiki.jqueryMsg',
'mediawiki.messagePoster',
'mediawiki.RegExp',
+++ /dev/null
-( 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 ) );
+++ /dev/null
-( 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 ) );