ميدياويكي:Gadget-delete-talk.js
ملاحظة: بعد الحفظ، قد يلزمك إفراغ الكاش لرؤية التغييرات.
/**
* Add Page to Deletion Talk with one step
* @developer User:حبيشان at arwiki
*
* Dependencies: mediawiki.util, mediawiki.api, oojs-ui-core, oojs-ui-windows, mediawiki.Title
*
* @source https://ar.wikipedia.org/wiki/User:حبيشان/Gadget-delete-talk.js
* @revision
*/
mw.loader.using(['mediawiki.user', 'oojs-ui-core', 'oojs-ui-windows', 'mediawiki.Title'], function () {
const base_delete_talk = 'أرابيكا:نقاش الحذف/';
const page_title = mw.config.get('wgPageName').replaceAll('_',' ');
var delete_talk_number = 1;
var page_title_number = page_title;
var page_to_edit = page_title;
var createAction = false;
var api = new mw.Api();
function GetOldDeleteTalks() {
delete_talk_title = base_delete_talk + page_title;
api.get({
action: 'query',
list: 'prefixsearch',
pssearch: delete_talk_title,
pslimit: 20
}).then(function (data) {
var pages = [];
for (var i=1; i<data.query.prefixsearch.length;i++) {
pages.push(data.query.prefixsearch[i].title);
}
while (pages.includes(delete_talk_title)) {
delete_talk_number++;
page_title_number = page_title + ' (' + delete_talk_number + ')';
delete_talk_title = base_delete_talk + page_title_number;
}
});
}
function GetPagetoEdit(){
if (mw.config.get('wgNamespaceNumber')==828 || ['css', 'json'].includes(new mw.Title(page_title).getExtension())) {
page_to_edit = page_to_edit + "/شرح";
api.get({
action: "query",
format: "json",
titles: page_to_edit,
formatversion: 2
}).then(function (data) {
if (!("pageid" in data.query.pages[0])) {
createAction=true;
}
});
}
}
function MyProcessDialog(config) {
MyProcessDialog.super.call(this, config);
}
OO.inheritClass(MyProcessDialog, OO.ui.ProcessDialog);
MyProcessDialog.static.name = 'GadgetDeletionTalk';
MyProcessDialog.static.title = 'ترشيح للحذف';
MyProcessDialog.static.actions = [
{
action: 'doit',
label: 'تنفيذ',
flags: ['primary', 'progressive']
}, {
action: 'cancel',
label: 'إلغاء',
flags: 'safe'
}
];
MyProcessDialog.static.size = 'large';
var fieldset = new OO.ui.FieldsetLayout();
var ReasonTextInput = new OO.ui.TextInputWidget({
autocomplete: false,
autofocus: true,
id: ['gdt-deletereasonbox'],
label: '',
value: '',
placeholder: 'اكتب سبب الحذف'
});
fieldset.addItems([
new OO.ui.FieldLayout(ReasonTextInput, { label: new OO.ui.HtmlSnippet('<h3>سبب ترشيح الحذف:</h3>'), align: 'inline' }),
]);
MyProcessDialog.prototype.initialize = function () {
MyProcessDialog.super.prototype.initialize.apply(this, arguments);
this.content = new OO.ui.PanelLayout({ padded: true, expanded: false, });
this.content.$element.append(fieldset.$element);
this.$body.append(this.content.$element);
};
MyProcessDialog.prototype.getActionProcess = function (action) {
var mReason = ReasonTextInput.getValue();
var dialog = this;
if (action) {
if (action === 'cancel') {
return new OO.ui.Process(function () {
this.close({ action: action });
}, this);
} else if (action == 'doit') {
return MyProcessDialog.super.prototype.getActionProcess.call(this, action).next(function () {
var t_txt = "\{\{نسخ:حذف|" + mReason + ((delete_talk_number > 1) ? '|' + delete_talk_number : '') + "\}\}";
if (createAction) {
return new mw.Api().create(page_to_edit,
{summary: ":ترشيح الصفحة للحذف بسبب " + mReason},
t_txt
);
} else {
if (mw.config.get('wgNamespaceNumber') == 10 && !(['css', 'json'].includes(new mw.Title(page_title).getExtension()))) {
t_txt = "<noinclude>" + t_txt + "</noinclude>";
}
return new mw.Api().edit(page_to_edit, function (revision) {
return {
text: t_txt + "\n" + revision.content,
summary: ":ترشيح الصفحة للحذف بسبب " + mReason
};
});
}
}, this).next(function () {
return new mw.Api().create(delete_talk_title,
{ summary: 'اقتراح حذف «' + page_title + '»'},
"\{\{نسخ:قالب:مقالة للحذف/سبب الاقتراح|سبب الحذف=" + mReason + "\}\}"
);
}, this).next(function () {
return new mw.Api().edit("أرابيكا:نقاش الحذف", function (revision) {
return {
text: revision.content.replace('-->','-->\n'+ '{{حذف/للحذف|' + page_title_number + '|\{\{نسخ:CURRENTDAY\}\} \{\{نسخ:CURRENTMONTHNAME\}\} \{\{نسخ:CURRENTYEAR\}\}\}\}'),
summary: "إضافة «" + page_title + "» إلى نقاش الحذف"
};
});
}, this).execute().then(
function () {
mw.notify('نجح فتحك لنقاش الحذف');
dialog.close();
setTimeout(function () { location.reload(); }, 1000);
},
function (_, data) {
dialog.close();
mw.notify(api.getErrorMessage(data), { type: 'error' });
}
);
}
}
return MyProcessDialog.super.prototype.getActionProcess.call(this, action);
};
var windowManager = new OO.ui.WindowManager();
if (mw.config.get( 'wgIsProbablyEditable' )) {
mw.util.addPortletLink(((mw.config.get('skin')=='minerva')? 'p-tb': 'p-cactions'), "#", 'ترشيح للحذف', 'button-DeleteTalk', 'طلب حذف الصفحة عبر النقاش');
$("#button-DeleteTalk").click(function () {
$(document.body).append(windowManager.$element);
GetOldDeleteTalks();
GetPagetoEdit();
var dialog = new MyProcessDialog();
windowManager.addWindows([dialog]);
windowManager.openWindow(dialog);
});
}
} );