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
+ '|' + 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 for ( i
= 0; i
< this.categories
.length
; i
++ ) {
160 cat
= this.categories
[ i
];
161 categoryLinks
.push( '[[Category:' + cat
+ ']]' );
164 return categoryLinks
.join( '\n' );
168 * Gets the wikitext for the license of the upload.
173 ForeignStructuredUpload
.prototype.getLicense = function () {
174 // Make sure this matches the messages for different targets in
175 // mw.ForeignStructuredUpload.BookletLayout.prototype.renderUploadForm
176 return this.target
=== 'shared' ? '{{self|cc-by-sa-4.0}}' : '';
180 * Get the source. This should be some sort of localised text for "Own work".
185 ForeignStructuredUpload
.prototype.getSource = function () {
195 ForeignStructuredUpload
.prototype.getUser = function () {
196 var username
= mw
.config
.get( 'wgUserName' );
197 // Do not localise 'User:', we don't know the language of target wiki
198 return '[[User:' + username
+ '|' + username
+ ']]';
201 mw
.ForeignStructuredUpload
= ForeignStructuredUpload
;
202 }( mediaWiki
, OO
) );