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.
31 * @param {string[]} categories Array of categories to which this upload will be added.
33 ForeignStructuredUpload
.prototype.addCategories = function ( categories
) {
36 for ( i
= 0; i
< categories
.length
; i
++ ) {
37 category
= categories
[ i
];
38 this.categories
.push( category
);
43 * Add a description to the upload.
44 * @param {string} language The language code for the description's language. Must have a template on the target wiki to work properly.
45 * @param {string} description The description of the file.
47 ForeignStructuredUpload
.prototype.addDescription = function ( language
, description
) {
48 this.descriptions
.push( {
55 * Set the date of creation for the upload.
58 ForeignStructuredUpload
.prototype.setDate = function ( date
) {
63 * Get the text of the file page, to be created on upload. Brings together
64 * several different pieces of information to create useful text.
67 ForeignStructuredUpload
.prototype.getText = function () {
70 this.getTemplateName() +
72 this.getDescriptions() +
87 * Gets the wikitext for the creation date of this upload.
91 ForeignStructuredUpload
.prototype.getDate = function () {
96 return this.date
.toString();
100 * Gets the name of the template to use for creating the file metadata.
101 * Override in subclasses for other templates.
105 ForeignStructuredUpload
.prototype.getTemplateName = function () {
106 return 'Information';
110 * Fetches the wikitext for any descriptions that have been added
115 ForeignStructuredUpload
.prototype.getDescriptions = function () {
116 var i
, desc
, templateCalls
= [];
118 for ( i
= 0; i
< this.descriptions
.length
; i
++ ) {
119 desc
= this.descriptions
[ i
];
120 templateCalls
.push( '{{' + desc
.language
+ '|' + desc
.text
+ '}}' );
123 return templateCalls
.join( '\n' );
127 * Fetches the wikitext for the categories to which the upload will
132 ForeignStructuredUpload
.prototype.getCategories = function () {
133 var i
, cat
, categoryLinks
= [];
135 for ( i
= 0; i
< this.categories
.length
; i
++ ) {
136 cat
= this.categories
[ i
];
137 categoryLinks
.push( '[[Category:' + cat
+ ']]' );
140 return categoryLinks
.join( '\n' );
144 * Gets the wikitext for the license of the upload. Abstract for now.
148 ForeignStructuredUpload
.prototype.getLicense = function () {
157 ForeignStructuredUpload
.prototype.getUser = function () {
158 return mw
.config
.get( 'wgUserName' );
161 mw
.ForeignStructuredUpload
= ForeignStructuredUpload
;
162 }( mediaWiki
, OO
) );