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( targetHost
, apiconfig
) {
20 this.date
= undefined;
21 this.descriptions
= [];
24 mw
.ForeignUpload
.call( this, targetHost
, 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 * Add a description to the upload.
46 * @param {string} language The language code for the description's language. Must have a template on the target wiki to work properly.
47 * @param {string} description The description of the file.
49 ForeignStructuredUpload
.prototype.addDescription = function ( language
, description
) {
50 this.descriptions
.push( {
57 * Set the date of creation for the upload.
61 ForeignStructuredUpload
.prototype.setDate = function ( date
) {
66 * Get the text of the file page, to be created on upload. Brings together
67 * several different pieces of information to create useful text.
71 ForeignStructuredUpload
.prototype.getText = function () {
74 this.getTemplateName() +
76 this.getDescriptions() +
91 * Gets the wikitext for the creation date of this upload.
96 ForeignStructuredUpload
.prototype.getDate = function () {
101 return this.date
.toString();
105 * Gets the name of the template to use for creating the file metadata.
106 * Override in subclasses for other templates.
111 ForeignStructuredUpload
.prototype.getTemplateName = function () {
112 return 'Information';
116 * Fetches the wikitext for any descriptions that have been added
122 ForeignStructuredUpload
.prototype.getDescriptions = function () {
123 var i
, desc
, templateCalls
= [];
125 for ( i
= 0; i
< this.descriptions
.length
; i
++ ) {
126 desc
= this.descriptions
[ i
];
127 templateCalls
.push( '{{' + desc
.language
+ '|' + desc
.text
+ '}}' );
130 return templateCalls
.join( '\n' );
134 * Fetches the wikitext for the categories to which the upload will
140 ForeignStructuredUpload
.prototype.getCategories = function () {
141 var i
, cat
, categoryLinks
= [];
143 for ( i
= 0; i
< this.categories
.length
; i
++ ) {
144 cat
= this.categories
[ i
];
145 categoryLinks
.push( '[[Category:' + cat
+ ']]' );
148 return categoryLinks
.join( '\n' );
152 * Gets the wikitext for the license of the upload. Abstract for now.
157 ForeignStructuredUpload
.prototype.getLicense = function () {
167 ForeignStructuredUpload
.prototype.getUser = function () {
168 return mw
.config
.get( 'wgUserName' );
171 mw
.ForeignStructuredUpload
= ForeignStructuredUpload
;
172 }( mediaWiki
, OO
) );