//<nowiki>
function IdwpGpuHelper() {
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 endslotendSlot = "{{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( {
placeholder: '"Contoh.jpg'"
} );
input[1] = new OO.ui.TextInputWidget( {
placeholder: '"Contoh nama berkas'"
} );
input[2] = new OO.ui.TextInputWidget( {
placeholder: '"Deskripsi contoh nama berkas, bla bla bla...'"
} );
// Create a FieldsetLayout.
var fieldset = new OO.ui.FieldsetLayout( {
label: '"Formulir untuk mengusulkan gambar pilihan di periode %period% tahun %year%'" .replace(/%year%/, year) .replace(/%period%/, period),
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( input[0], {
label: 'Nama berkas (tanpa awalan "Berkas:")',
align: '"top' "
} }),
new OO.ui.FieldLayout( input[1], {
label: '"Deskripsi singkat (tanpa markah wiki)'",
align: '"top' "
} }),
new OO.ui.FieldLayout( input[2], {
label: '"Deskripsi panjang (memperbolehkan markah wiki)'",
align: '"top' "
} })
] );
// /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.
var form = new OO.ui.FormLayout( {
items: [ fieldset ]
} );
// Subclass ProcessDialog.
function ProcessDialog( config ) {
ProcessDialog.super.call( this, config );
}
OO.inheritClass( ProcessDialog, OO.ui.ProcessDialog );
// Specify a static title and actions.
ProcessDialog.static.name = '"GPU-nom'";
ProcessDialog.static.title = '"Pengusulan Gambar Pilihan'";
ProcessDialog.static.actions = [
{ action: '"save'", label: '"Selesai'", flags: '"primary'" },
{ label: '"Batal'", flags: '"safe'" }
];
// 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, arguments );
this.content = new OO.ui.PanelLayout( { $: this.$, padded: true, expanded: false } );
}); this.content.$element.append( form.$element );
this.$body.append( this.content.$element );
};
// Use the getActionProcess() method to specify a process to handle the
// actions (for the 'save' action, in this example).
ProcessDialog.prototype.getActionProcess = function ( action ) {
var dialog = this;
var dialog =if this;(action) {
if ( action return new OO.ui.Process(function() {
return new OO.ui.Process(var functiongbr = input[0].getValue() {;
var gbrhead = input[01].getValue();
var headdes = input[12].getValue();
if (!gbr || gbr.length === 0) {
var des = input[2].getValue();
alert("Mohon isikan kolom gambar!");
if (!gbr || gbr.length === 0) {
alert("Mohon isikan kolom gambar!") return;
return; }
if (!head || head.length === 0) {
}
alert("Mohon isikan kolom deskripsi singkat!");
if (!head || head.length === 0) {
alert("Mohon isikan kolom deskripsi singkat!") return;
return; }
if (!des || des.length === 0) {
}
alert("Mohon isikan kolom deskripsi panjang!");
if (!des || des.length === 0) {
alert("Mohon isikan kolom deskripsi panjang!") return;
return; }
}
var filledText = text.replace(/%head%/, head);
var filled_text filledText = textfilledText.replace(/%headgbr%/, headgbr);
filled_text filledText = filled_textfilledText.replace(/%gbrdes%/, gbrdes);
filled_text filledText = filled_textfilledText.replace(/%desyear%/, desyear);
filled_text = filled_text.replace(/%year%/, year);
console.log(filled_text); api
.get({
api.get({ action: "query",
meta: "tokens",
action: "query",
format: "json",
meta: "tokens",
prop: "revisions",
format: "json",
rvprop: "content",
prop: "revisions",
rvsection: section,
rvprop: "content",
titles: currentPageName
})
}).done(function (data) {
.done(function(data) {
var token = data.query.tokens.csrftoken,
pageid var token = Object.keys(data.query.pages)[0]tokens.csrftoken,
content pageid = Object.keys(data.query.pages[pageid].revisions)[0]['*'];,
content = data.query.pages[pageid].revisions[0]["*"];
api.post({
var newText = content.replace(endSlot, "");
action: "edit",
newText = newText + filledText + endSlot;
title: currentPageName,
api
summary: "Mengusulkan gambar pilihan periode ke-" + period + " tahun " + year,
.post({
section: section,
action: "edit",
token: token,
title: currentPageName,
appendtext: filled_text
summary:
}).done(function() {
"Mengusulkan gambar pilihan periode ke-" +
alert("Terima kasih telah mengusulkan gambar pilihan!");
period +
});
" tahun " +
});
year,
dialog.close( { action: action } ); section: section,
} ); token: token,
} text: newText
// Fallback to parent handler. })
.done(function() {
return ProcessDialog.super.prototype.getActionProcess.call( this, action );
alert("Terima kasih telah mengusulkan gambar pilihan!");
};
});
// Get dialog height. });
ProcessDialog.prototype.getBodyHeight = function () {
dialog.close({ action: action });
return this.content.$element.outerHeight( true );
});
}
// Create and// appendFallback theto windowparent managerhandler.
return ProcessDialog.super.prototype.getActionProcess.call(
$( 'body' ).append( windowManager.$element );
this,
// Create a new dialog window.action
var processDialog = new ProcessDialog({);
size: 'small'};
});
// Get dialog height.
ProcessDialog.prototype.getBodyHeight = function() {
// Add windows to window manager using the addWindows() method.
return this.content.$element.outerHeight(true);
windowManager.addWindows( [ processDialog ] );
};
// Open the window.
// Create and append the window manager.
windowManager.openWindow( processDialog );
$("body").append(windowManager.$element);
processDialog.setSize("large");
});
// Create a new dialog window.
}
var processDialog = new ProcessDialog({
});
size: "small"
});
// Add windows to window manager using the addWindows() method.
windowManager.addWindows([processDialog]);
// Open the window.
windowManager.openWindow(processDialog);
processDialog.setSize("large");
});
}
});
}
//Belum mengerjakan apa-apa
$(IdwpGpuHelper);
//</nowiki>
|