User:Evad37/Covery.js: Difference between revisions

Content deleted Content added
Version 1.2.0: Support lowercased infobox names, fill publisher and developer in infobox
Version 1.3.0: add platform input field
Line 3:
var SCRIPT = {
name: 'Covery',
version: '1.23.0',
ad: ' (using [[User:Evad37/Covery|Covery]])'
};
Line 182:
};
 
/**
var makeDescriptionText = function makeDescriptionText(articleTitle, developer, publisher) {
*
* @param {String} articleTitle
* @param {String} developer
* @param {String} publisher
* @param {String[]} platforms
*/
var makeDescriptionText = function makeDescriptionText(articleTitle, developer, publisher) {
articleTitle,
developer,
publisher,
platforms
) {
var platformsParams = platforms.reduce(function(params, platform) {
return params + '|' + platform;
}, '');
return (
'==Summary==\n{{Non-free use rationale video game cover\n' +
Line 195 ⟶ 210:
developer +
'\n}}\n' +
'==Licensing==\n{{Non-free video game cover}}' +
platformsParams +
'}}'
);
};
Line 427 ⟶ 444:
this.developerInput = new OO.ui.TextInputWidget({ required: true });
this.publisherInput = new OO.ui.TextInputWidget({ required: true });
this.platformInput = new OO.ui.MenuTagMultiselectWidget({
inputPosition: 'inline',
allowDisplayInvalidTags: true,
allowArbitrary: true
});
 
this.fileSelectField = new OO.ui.FieldLayout(this.fileSelect, {
Line 460 ⟶ 482:
this.publisherInputField = new OO.ui.FieldLayout(this.publisherInput, {
label: 'Publisher',
align: 'left'
});
this.platformInputField = new OO.ui.FieldLayout(this.platformInput, {
label: 'Platform(s)',
align: 'left'
});
Line 471 ⟶ 497:
this.altTextInputField,
this.developerInputField,
this.publisherInputField,
this.platformInputField
]);
 
Line 511 ⟶ 538:
{ change: 'onRequiredInputChange' }
);
this.platformInput.connect(
this,
{ add: 'onPlatformInputAdd' }
);
(function(self) {
self.platformInput.$element.find('input').on('blur', function() {
self.onPlatformInputBlur.call(self);
});
})(this);
};
 
Line 605 ⟶ 641:
}
);
};
 
CoveryDialog.prototype.onPlatformInputAdd = function(item) {
this.api
.get({
action: 'query',
format: 'json',
titles: 'Category:' + item.data + ' game covers'
})
.then(function(response) {
return $.map(response.query.pages, function(page) {
return page.missing !== '';
})[0];
})
.then(function(isValid) {
item.toggleValid(isValid);
});
};
 
CoveryDialog.prototype.onPlatformInputBlur = function() {
this.platformInput.doInputEnter();
};
 
Line 646 ⟶ 703:
});
});
var self = this;
data.api
.get({
action: 'query',
format: 'json',
list: 'categorymembers',
cmtitle: 'Category:Video game covers',
cmprop: 'title',
cmtype: 'subcat',
cmlimit: 'max'
})
.then(function(response) {
return response.query.categorymembers
.map(function(category) {
return category.title;
})
.map(function(categoryTitle) {
return {
data: categoryTitle.replace(/Category\:(.+) game covers/, '$1')
};
});
})
.then(function(platforms) {
self.platformInput.addOptions(platforms);
});
}, this);
};
Line 677 ⟶ 759:
var fileTitle = mw.Title.newFromFileName(this.titleInput.getValue());
return new OO.ui.Process(function() {
var platformValues = this.platformInput.getItems().map(function(item) {
return item.getData();
});
return (
this.uploaded ||
Line 685 ⟶ 770:
new mw.Title(this.pageName),
this.developerInput.getValue(),
this.publisherInput.getValue(),
platformValues
),
fileTitle