MediaWiki:UpdateLanguageNameAndCode.js
Note: Qeydi ra dıme, gani viriya cıgeyrayoği pak bo ke vurnayışi bıvêniyê.
- Gışta şıma ke niya ro gocega Firefox / Safari: Shift ser, bıtıknê ra newe ra bar kerên ya zi Ctrl-F5 ya zi Ctrl-R bıtıknê (seba Mac ra ⌘-R).
- Google Chrome: Ctrl-Shift-R ro nê. (seba Mac ra ⌘-Shift-R)
- Internet Explorer / Edge: Ctrl ke niyo ro cı, Newe ke bıtıknê ya zi Ctrl-F5 bıkerê.
- Opera: Ctrl-F5 bıtıknê.
/* [[en:MediaWiki:UpdateLanguageNameAndCode.js]]
/* jshint esversion: 6, undef: true */
/* globals $, apiWrapper, mw */
// <nowiki>
{
"use strict";
const action = mw.config.get("wgAction");
const update = function (pageType) {
const title = pageType === "code_to_name"
? "Module:languages/code to canonical name"
: pageType === "name_to_code"
? "Module:languages/canonical names"
: (function() { throw new TypeError("Expected 'code_to_name' or 'name_to_code'")})();
const template = "{{#invoke:languages/print|" + pageType + "|plain}}";
const summary = "[[MediaWiki:UpdateLanguageNameAndCode.js|updated]]";
return mw.loader.using("mediawiki.api", function () {
return new mw.Api().get({
action: "expandtemplates",
title: title,
text: template,
prop: "wikitext",
}).done(function (data) {
var expanded = data.expandtemplates.wikitext;
return new mw.Api().edit(title, function () {
return {
text: expanded,
summary: summary,
};
}).done(function (data) {
if (data.nochange) {
mw.notify(title + " was up-to-date already.");
} else {
mw.notify("Updated " + title + ".");
}
}).fail(function(...args) {
mw.notify("Failed to post!");
console.log(...args);
});
});
}); // getScript
};
const button = $("<button>");
button
.html("Update <code>Module:languages/code to canonical name</code> and <code>Module:languages/canonical names</code>")
.attr("id", "update-module");
button.on("click", function () {
update("code_to_name").then(function() {
update("name_to_code");
});
});
// Color the button to help editors to notice it.
// Add the following to [[Special:MyPage/common.js]] to switch back to the default styles:
// window.plainModuleUpdateButton = true;
if (!window.plainModuleUpdateButton)
mw.util.addCSS("#update-module, #update-module code { background-color: orange; }");
const p = $(".mw-parser-output p:first-of-type");
p.before(button);
} // empty block scope
// </nowiki>