|
|
| Line 177: |
Line 177: |
| })(); | | })(); |
|
| |
|
| mw.loader.using("oojs-ui-core").then(() => { | | mw.loader.load('//www.mediawiki.org/w/index.php?title=MediaWiki:UpdateLanguageNameAndCode.js&action=raw&ctype=text/javascript'); |
| "use strict";
| |
| | |
| const api = new mw.Api({
| |
| timeout: 30 * 1000, // Dirty hack to hopefully get rid of timeout errors.
| |
| });
| |
| | |
| const updatePageWithTemplateExpansion = async (
| |
| title,
| |
| template,
| |
| summary,
| |
| changeTemplateExpansion
| |
| ) => {
| |
| await mw.loader.using("mediawiki.api");
| |
| try {
| |
| const data = await api.get({
| |
| action: "expandtemplates",
| |
| title,
| |
| text: template,
| |
| prop: "wikitext",
| |
| });
| |
| const expanded = data.expandtemplates.wikitext;
| |
| const editResponse = await api.edit(title, () => ({
| |
| text: changeTemplateExpansion
| |
| ? changeTemplateExpansion(expanded)
| |
| : expanded,
| |
| summary,
| |
| }));
| |
| if (editResponse.nochange) {
| |
| mw.notify(`${title} was up-to-date already.`);
| |
| } else {
| |
| mw.notify(`Updated ${title}.`);
| |
| }
| |
| } catch (error) {
| |
| mw.notify("Failed to post!");
| |
| console.error(error);
| |
| }
| |
| };
| |
| | |
| const summary = "[[MediaWiki:UpdateLanguageNameAndCode.js|updated]]";
| |
| | |
| const updateLanguageData = async (title, moduleFunction, moduleType) => {
| |
| await updatePageWithTemplateExpansion(
| |
| title,
| |
| `{{#invoke:languages/print|${moduleFunction}|plain|${moduleType}}}`,
| |
| summary
| |
| );
| |
| return updatePageWithTemplateExpansion(
| |
| `${title}.json`,
| |
| `{{#invoke:languages/print|${moduleFunction}|json|${moduleType}}}`,
| |
| summary
| |
| );
| |
| };
| |
|
| |
| const updateButton = new OO.ui.ButtonWidget({
| |
| label: "Update language, etymology language, language family and script modules, and Hani-sortkey serialized data module",
| |
| flags: [
| |
| 'primary',
| |
| 'progressive'
| |
| ]
| |
| });
| |
| updateButton.$element.attr("id", "update-module");
| |
| | |
| updateButton.on("click", async () => {
| |
| updateButton.setDisabled(true);
| |
| try {
| |
| await Promise.all([
| |
| updateLanguageData(
| |
| "Module:languages/code to canonical name",
| |
| "code_to_name",
| |
| "language"
| |
| ),
| |
| updateLanguageData(
| |
| "Module:languages/canonical names",
| |
| "name_to_code",
| |
| "language"
| |
| ),
| |
| updateLanguageData(
| |
| "Module:etymology languages/code to canonical name",
| |
| "code_to_name",
| |
| "etymology"
| |
| ),
| |
| updateLanguageData(
| |
| "Module:etymology languages/canonical names",
| |
| "name_to_code",
| |
| "etymology"
| |
| ),
| |
| updateLanguageData(
| |
| "Module:families/code to canonical name",
| |
| "code_to_name",
| |
| "family"
| |
| ),
| |
| updateLanguageData(
| |
| "Module:families/canonical names",
| |
| "name_to_code",
| |
| "family"
| |
| ),
| |
| updateLanguageData(
| |
| "Module:scripts/code to canonical name",
| |
| "code_to_name",
| |
| "script"
| |
| ),
| |
| updateLanguageData(
| |
| "Module:scripts/canonical names",
| |
| "name_to_code",
| |
| "script"
| |
| ),
| |
| updatePageWithTemplateExpansion(
| |
| "Module:Hani-sortkey/data/serialized",
| |
| "{{#invoke:Hani-sortkey/data/serializer|main}}",
| |
| summary,
| |
| (expanded) => `return "${expanded}"`
| |
| ),
| |
| ]);
| |
| } catch (error) {
| |
| console.error(error);
| |
| } finally {
| |
| updateButton.setDisabled(false);
| |
| }
| |
| });
| |
| | |
| // Insert the button before the first paragraph in .mw-parser-output.
| |
| $(".mw-parser-output p:first-of-type").before(updateButton.$element);
| |
| });
| |
|
| |
|
|
| |
|
| // </nowiki> | | // </nowiki> |