1 ( function ( mw, OO ) {
3 * @class mw.ForeignStructuredUpload
4 * @extends mw.ForeignUpload
6 * Used to represent an upload in progress on the frontend.
8 * This subclass will upload to a wiki using a structured metadata
9 * system similar to (or identical to) the one on Wikimedia Commons.
11 * See <https://commons.wikimedia.org/wiki/Commons:Structured_data> for
12 * a more detailed description of how that system works.
14 * **TODO: This currently only supports uploads under CC-BY-SA 4.0,
15 * and should really have support for more licenses.**
19 function ForeignStructuredUpload( target, apiconfig ) {
20 this.date = undefined;
21 this.descriptions = [];
24 mw.ForeignUpload.call( this, target, apiconfig );
27 OO.inheritClass( ForeignStructuredUpload, mw.ForeignUpload );
30 * Add categories to the upload.
32 * @param {string[]} categories Array of categories to which this upload will be added.
34 ForeignStructuredUpload.prototype.addCategories = function ( categories ) {
37 for ( i = 0; i < categories.length; i++ ) {
38 category = categories[ i ];
39 this.categories.push( category );
44 * Empty the list of categories for the upload.
46 ForeignStructuredUpload.prototype.clearCategories = function () {
51 * Add a description to the upload.
53 * @param {string} language The language code for the description's language. Must have a template on the target wiki to work properly.
54 * @param {string} description The description of the file.
56 ForeignStructuredUpload.prototype.addDescription = function ( language, description ) {
57 this.descriptions.push( {
64 * Empty the list of descriptions for the upload.
66 ForeignStructuredUpload.prototype.clearDescriptions = function () {
67 this.descriptions = [];
71 * Set the date of creation for the upload.
75 ForeignStructuredUpload.prototype.setDate = function ( date ) {
80 * Get the text of the file page, to be created on upload. Brings together
81 * several different pieces of information to create useful text.
85 ForeignStructuredUpload.prototype.getText = function () {
87 '== {{int:filedesc}} ==\n' +
89 this.getTemplateName() +
91 this.getDescriptions() +
99 '== {{int:license-header}} ==\n' +
107 * Gets the wikitext for the creation date of this upload.
112 ForeignStructuredUpload.prototype.getDate = function () {
117 return this.date.toString();
121 * Gets the name of the template to use for creating the file metadata.
122 * Override in subclasses for other templates.
127 ForeignStructuredUpload.prototype.getTemplateName = function () {
128 return 'Information';
132 * Fetches the wikitext for any descriptions that have been added
138 ForeignStructuredUpload.prototype.getDescriptions = function () {
139 var i, desc, templateCalls = [];
141 for ( i = 0; i < this.descriptions.length; i++ ) {
142 desc = this.descriptions[ i ];
143 templateCalls.push( '{{' + desc.language + '|1=' + desc.text + '}}' );
146 return templateCalls.join( '\n' );
150 * Fetches the wikitext for the categories to which the upload will
156 ForeignStructuredUpload.prototype.getCategories = function () {
157 var i, cat, categoryLinks = [];
159 if ( this.categories.length === 0 ) {
160 return '{{subst:unc}}';
163 for ( i = 0; i < this.categories.length; i++ ) {
164 cat = this.categories[ i ];
165 categoryLinks.push( '[[Category:' + cat + ']]' );
168 return categoryLinks.join( '\n' );
172 * Gets the wikitext for the license of the upload.
177 ForeignStructuredUpload.prototype.getLicense = function () {
178 // Make sure this matches the messages for different targets in
179 // mw.ForeignStructuredUpload.BookletLayout.prototype.renderUploadForm
180 return this.target === 'shared' ? '{{self|cc-by-sa-4.0}}' : '';
184 * Get the source. This should be some sort of localised text for "Own work".
189 ForeignStructuredUpload.prototype.getSource = function () {
199 ForeignStructuredUpload.prototype.getUser = function () {
200 var username, namespace;
201 // Do not localise, we don't know the language of target wiki
203 username = mw.config.get( 'wgUserName' );
205 // The user is not logged in locally. However, they might be logged in on the foreign wiki.
206 // We should record their username there. (If they're not logged in there either, this will
207 // record the IP address.) It's also possible that the user opened this dialog, got an error
208 // about not being logged in, logged in in another browser tab, then continued uploading.
209 username = '{{subst:REVISIONUSER}}';
211 return '[[' + namespace + ':' + username + '|' + username + ']]';
214 mw.ForeignStructuredUpload = ForeignStructuredUpload;
215 }( mediaWiki, OO ) );