Pengguna:Kenrick95/idwp-gpu.js: Perbedaan antara revisi
Konten dihapus Konten ditambahkan
kTidak ada ringkasan suntingan |
kTidak ada ringkasan suntingan |
||
(17 revisi perantara oleh pengguna yang sama tidak ditampilkan) | |||
Baris 1:
//<nowiki>
mw.loader.using("mediawiki.api", function() {
var api = new mw.Api();
var text =
"{{GP%year%/Usul\n" +
"| terpilih = <!-- JANGAN UBAH BARIS INI -->\n" +
"| gbr = %gbr%\n" +
"| head = %head%\n" +
"| des = %des%\n" +
"| ttd = ~~~~\n" +
"| vote = <!-- BERIKAN SUARA ANDA DI BAWAH BARIS INI -->\n" +
"\n" +
"}}\n";
var pageName = "Wikipedia:Gambar_pilihan/Usulan/%year%/Periode_%period%";
// bind "action" to .idwp-gpu-vote and .idwp-gpu-nom
// store "period" & "year" at "data-..." attribute
$(".idwp-gpu-nom").on("click", nominate);
function nominate() {
var year = $(this).data("year");
var period = parseInt($(this).data("period"), 10);
var section = parseInt($(this).data("section"), 10);
var endSlot = "{{GP%year%/Slot}}".replace(/%year%/, year);
var currentPageName = pageName
.replace(/%year%/, year)
.replace(/%period%/, period);
mw.loader.using("oojs-ui", function() {
var windowManager = new OO.ui.WindowManager();
var input = [];
input[0] = new OO.ui.TextInputWidget(
}
input[1] = new OO.ui.TextInputWidget(
}
input[2] = new OO.ui.TextInputWidget(
}
// Create a FieldsetLayout.
var fieldset = new OO.ui.FieldsetLayout(
label:
.replace(/%year%/, year)
classes: ["container"]
});
// Use the addItems() method to add FieldLayouts that contain the form // elements (the text inputs and submit button) to the FieldsetLayout:
fieldset.addItems(
new OO.ui.FieldLayout(
label: 'Nama berkas (tanpa awalan "Berkas:")',
align:
new OO.ui.FieldLayout(
label:
align:
new OO.ui.FieldLayout(
label:
align:
]
// /w/api.php?action=opensearch&format=json&search=example&namespace=6&suggest=1
// https://www.mediawiki.org/wiki/OOjs_UI/Windows/Process_Dialogs
// Add the FieldsetLayout to a FormLayout.
items: [fieldset]
});
// Subclass ProcessDialog.
function ProcessDialog(config) {
ProcessDialog.super.call(this, config);
}
OO.inheritClass(
// Specify a static title and actions.
ProcessDialog.static.
ProcessDialog.static.title = "Pengusulan Gambar Pilihan";
ProcessDialog.static.actions = [
];
// Use the initialize() method to add content to the dialog's $body,
// to initialize widgets, and to set up event handlers.
ProcessDialog.prototype.initialize = function
ProcessDialog.super.prototype.initialize.apply(
this.content = new OO.ui.PanelLayout(
$: this.$, padded: true, expanded: false });
this.content.$element.append( this.$body.append(
};
// Use the getActionProcess() method to specify a process to handle the
// actions (for the 'save' action, in this example).
ProcessDialog.prototype.getActionProcess = function
if (!head || head.length === 0) {
alert("Mohon isikan kolom deskripsi singkat!");
return;
}
if (!des || des.length === 0) {
alert("Mohon isikan kolom deskripsi panjang!");
return;
}
var filledText = text.replace(/%head%/, head);
filledText = filledText.replace(/%gbr%/, gbr);
filledText = filledText.replace(/%des%/, des);
filledText = filledText.replace(/%year%/, year);
api
.get({
action: "query",
meta: "tokens",
format: "json",
prop: "revisions",
rvprop: "content",
rvsection: section,
titles: currentPageName
})
.done(function(data) {
var token = data.query.tokens.csrftoken,
pageid = Object.keys(data.query.pages)[0],
content = data.query.pages[pageid].revisions[0]["*"];
var newText = content.replace(endSlot, "");
newText = newText + filledText + endSlot;
api
.post({
action: "edit",
title: currentPageName,
summary:
"Mengusulkan gambar pilihan periode ke-" +
period +
" tahun " +
year,
section: section,
token: token,
text: newText
})
.done(function() {
alert("Terima kasih telah mengusulkan gambar pilihan!");
});
});
dialog.close({ action: action });
});
}
// Fallback to parent handler.
return ProcessDialog.super.prototype.getActionProcess.call(
this,
action
);
};
// Get dialog height.
ProcessDialog.prototype.getBodyHeight = function
};
// Create and append the window manager.
$(
// Create a new dialog window.
var processDialog = new ProcessDialog({
size:
});
// Add windows to window manager using the addWindows() method.
windowManager.addWindows(
// Open the window.
windowManager.openWindow(
}
});
}
$(IdwpGpuHelper);
//</nowiki>
|