Wikipedysta:Ptjackyll/poczekalnia.js i MediaWiki:Gadget-DelReqHandler.js: Różnica pomiędzy stronami
Wygląd
(Różnica między stronami)
Usunięta treść Dodana treść
Maintenance: Replacing legacy global variable (phab:T72470) |
underscore and api safety • Wikiploy |
||
Linia 1: | Linia 1: | ||
/* eslint-disable no-unused-vars */ |
|||
/* eslint-disable no-useless-escape */ |
|||
/* eslint-disable array-bracket-newline */ |
|||
/* eslint-disable no-mixed-spaces-and-tabs */ |
|||
/* eslint-disable indent */ |
|||
/* global $, mw, OO */ |
|||
/* global moveToSandboxGadget */ |
|||
// <nowiki> |
// <nowiki> |
||
importScript ('MediaWiki:MD5.js'); |
|||
importScript ('MediaWiki:Utilities.js'); |
|||
importScript ('MediaWiki:Gadget-Lupo-Utilities.js') |
|||
/* |
/* |
||
Support for quick deletions and closing of deletion requests at Polish Wikipedia. |
Support for quick deletions and closing of deletion requests at Polish Wikipedia. |
||
[[WP:Poczekalnia]] |
|||
Author: [[User:Lupo]], October 2007 - January 2008 |
Author: [[User:Lupo]], October 2007 - January 2008 |
||
full list of authors: http://commons.wikimedia.org/w/index.php?title=MediaWiki:Gadget-DelReqHandler.js&action=history |
full list of initial authors: |
||
http://commons.wikimedia.org/w/index.php?title=MediaWiki:Gadget-DelReqHandler.js&action=history |
|||
Adaptation for pl.wiki: [[User:Lampak]] |
Adaptation for pl.wiki: [[User:Lampak]], [[User:Wargo]], [[User:Nux]] |
||
full list of current authors: |
|||
https://pl.wikipedia.org/w/index.php?title=MediaWiki:Gadget-DelReqHandler.js&action=history |
|||
Contains parts of code (possibly modified) of commons:MediaWiki:AjaxQuickDelete.js |
Contains parts of code (possibly modified) of commons:MediaWiki:AjaxQuickDelete.js |
||
by [[User:Ilmari Karonen]], [[User:DieBuche]] |
by [[User:Ilmari Karonen]], [[User:DieBuche]] |
||
full list of authors: http://commons.wikimedia.org/w/index.php?title=MediaWiki:AjaxQuickDelete.js&action=history |
full list of authors: http://commons.wikimedia.org/w/index.php?title=MediaWiki:AjaxQuickDelete.js&action=history |
||
Tested only in Firefox. |
|||
*/ |
*/ |
||
$(document).ready(function() { |
|||
/**** Guard against double inclusions */ |
|||
if ('object' === typeof DelReqHandler ) { |
|||
if (typeof (DelReqHandler) == 'undefined') { |
|||
return; |
|||
} |
|||
/**** Some things may not be defined in some cases */ |
|||
var DelReqUtils = |
|||
{ |
|||
// The following function is defined in several places, and unfortunately, it is defined |
|||
// wrongly in some places. (For instance, in [[:en:User:Lupin/popups.js]]: it should use |
|||
// decodeURIComponent, not decodeURI!!!) Make sure we've got the right version here: |
|||
getParamValue : function (paramName, href) |
|||
{ |
|||
var cmdRe = RegExp ('[&?]' + paramName + '=([^&]*)'); |
|||
var h = href || document.location.href; |
|||
var m = cmdRe.exec (h); |
|||
if (m) { |
|||
try { |
|||
return decodeURIComponent (m[1]); |
|||
} catch (someError) {} |
|||
} |
|||
return null; |
|||
} |
|||
var isAdmin = mw.config.get('wgUserGroups', []).indexOf('sysop') >= 0; |
|||
}; // End of DelReqUtils |
|||
var DelReqHandler = |
var DelReqHandler = |
||
Linia 48: | Linia 36: | ||
/*------------------------------------------------------------------------------------------ |
/*------------------------------------------------------------------------------------------ |
||
Deletion request closing: add " |
Deletion request closing: add "[del]" and "[keep]" links to the left of the section edit |
||
links of a deletion request. |
links of a deletion request. They open the deletion request for editing in a new window |
||
(or tab), add |
(or tab), add "Deleted." or "Kept." plus the signature (four tildes) |
||
and |
and don't save and close the |
||
window, so that the user may enter an additional comment. |
window, so that the user may enter an additional comment. |
||
------------------------------------------------------------------------------------------*/ |
------------------------------------------------------------------------------------------*/ |
||
fakeaction_close_del : 'close_del', |
|||
fakeaction_close_keep : 'close_keep', |
|||
fakeaction_close_no_result : 'close_no_result', |
|||
fakeaction_close_repaired : 'close_repaired', |
|||
fakeaction_close_eject : 'close_eject', |
|||
fakeaction_move_reanimation : 'move_reanimation', |
|||
close_del_summary : 'Usunięto.', |
close_del_summary : 'Usunięto.', |
||
close_keep_summary : 'Zostawiono.', |
close_keep_summary : 'Zostawiono.', |
||
close_no_result_summary : 'Nie osiągnięto konsensusu.', |
close_no_result_summary : 'Nie osiągnięto konsensusu.', |
||
close_eject_summary: 'Wycofano.', |
|||
close_repaired_summary: 'Do załatwionych.', |
|||
close_move2repair_summary: 'Przeniesiono do reanimacji.', |
|||
deletion_request_pages : ['Wikipedia:Poczekalnia/artykuły', 'Wikipedia:Poczekalnia/biografie', 'Wikipedia:Poczekalnia/kwestie_techniczne', 'Wikipedia:Poczekalnia/naprawa', 'Wikipedia:Poczekalnia/zgłoszenia'], |
|||
close_repaired_summary: 'Naprawiono.', |
|||
repair_request_page : 'Wikipedia:Poczekalnia/naprawa', |
|||
close_draft_summary: 'Przeniesiono do brudnopisu.', |
|||
close_redir_summary: 'Przekierowano do innego artykułu.', |
|||
// Note! Use undescore instead of space |
|||
deletion_request_pages : [ |
|||
'Wikipedia:Poczekalnia/artykuły', |
|||
'Wikipedia:Poczekalnia/biografie', |
|||
'Wikipedia:Poczekalnia/kwestie_techniczne', |
|||
'Wikipedia:Poczekalnia/reanimacja', |
|||
'Wikipedia:Poczekalnia/zgłoszenia', |
|||
'Wikipedysta:'+mw.config.get('wgUserName')+'/test_poczekalni', |
|||
], |
|||
archive_section_line : '<!-- Zakończone dyskusje wstawiaj poniżej tej linii -->', |
archive_section_line : '<!-- Zakończone dyskusje wstawiaj poniżej tej linii -->', |
||
reanimation_section_line : '<!-- Nowe zgłoszenia wstawiaj poniżej tej linii. Nie usuwaj tej linii -->', |
|||
archive_edit_summary : '[[$1]] − dyskusja zakończona', |
archive_edit_summary : '[[$1]] − dyskusja zakończona', |
||
script_dependencies : [ |
script_dependencies : [], |
||
current_pagename : mw.config.get('wgPageName'), |
|||
loading_progress : 0, |
|||
api : new mw.Api(/*{parameters:{errorformat: 'html', formatversion: 2}}*/), |
|||
progressDialog: null, |
|||
windowManager: null, |
|||
beginLoading : function() |
beginLoading : function() |
||
{ |
{ |
||
var wgAction = mw.config.get('wgAction'); |
|||
var notoldid = document.URL.search (/[?&]oldid=/) < 0; |
|||
if ((wgAction == 'view' || wgAction == 'purge') && this.isItDelReqPage() && notoldid) |
|||
{ |
{ |
||
var o = this; |
var o = this; |
||
mw.loader.using(this.script_dependencies, function() { |
mw.loader.using(this.script_dependencies, function() { |
||
$(document).ready(function() { |
$(document).ready(function() { |
||
o.closeRequestLinks(); |
o.closeRequestLinks(); |
||
}); |
}); |
||
}); |
}); |
||
} |
} |
||
else if ( |
else if (wgAction == 'edit') |
||
this.maybeSetupForm(); |
this.maybeSetupForm(); |
||
}, |
}, |
||
Linia 88: | Linia 96: | ||
isItDelReqPage : function() |
isItDelReqPage : function() |
||
{ |
{ |
||
var current = this.current_pagename.replace(/ /g, '_'); |
|||
for (var i = 0; i < this.deletion_request_pages.length; i++) |
for (var i = 0; i < this.deletion_request_pages.length; i++) |
||
if ( |
if (current.indexOf(this.deletion_request_pages[i]) == 0) |
||
return true; |
return true; |
||
return false; |
return false; |
||
}, |
}, |
||
isSubpage : function(table, subpage) |
|||
{ |
{ |
||
var searched = 'Wikipedia:Poczekalnia/' + table.replace(/ /g, '_') + '/'; |
|||
for (var i = 0; i < this.deletion_request_pages.length; i++) |
|||
if (subpage.replace(/ /g, '_').indexOf(searched) == 0) { |
|||
{ |
|||
return true; |
|||
var searched = encodeURIComponent(this.deletion_request_pages[i] + '/'). |
|||
replace(/\%3A/g, ':').replace(/\%20/g, '_').replace(/\(/g, '%28'). |
|||
replace(/\)/g, '%29').replace(/\%2F/g, '/'); |
|||
if(href.indexOf(searched) > 0) |
|||
return true; |
|||
} |
} |
||
return false; |
return false; |
||
}, |
}, |
||
/** Action button (for the section). */ |
|||
closeRequestLinks : function () |
|||
createActionButton: function(action, button_o, dnuTemplate, subpage, fakeaction) { |
|||
{ |
|||
var button = new OO.ui.ButtonWidget(button_o); |
|||
function addRequestLinks (name, href, before, parent) |
|||
{ |
|||
parent.insertBefore (document.createTextNode ('['), before); |
|||
parent.insertBefore (makeRawLink ( |
|||
name.substring (0, 1), |
|||
href + DelReqHandler.lupo_quick_closure, |
|||
'_blank' |
|||
), before); |
|||
parent.insertBefore (document.createTextNode (']'), before); |
|||
button.$element.click((e) => { |
|||
parent.insertBefore (document.createTextNode ('['), before); |
|||
e.preventDefault(); |
|||
parent.insertBefore (makeRawLink (name, href, '_blank'), before); |
|||
parent.insertBefore (document.createTextNode (']'), before); |
|||
} |
|||
if(action == this.actionMap.redirect) |
|||
var is_repair_page = mw.config.get('wgPageName').indexOf(this.repair_request_page) == 0; |
|||
var edit_lks = $('.editsection').get(); |
|||
var lk_number = 0; |
|||
for (i = 0; i < edit_lks.length; i++) { |
|||
// Find the A within: |
|||
var anchors = edit_lks[i].getElementsByTagName ('a'); |
|||
if (anchors != null && anchors.length > 0) { |
|||
var anchor = anchors[0]; |
|||
var href = anchor.getAttribute ('href'); |
|||
if (//href.indexOf ('Wikipedia:Poczekalnia/20') < 0 && //I can't see any point in it... |
|||
this.isLinkToSubpage(href)) |
|||
{ |
{ |
||
OO.ui.prompt( 'Podaj stronę docelową przekierowania', { textInput: { placeholder: 'Tytuł docelowy' } } ).done((result) => { |
|||
var offset = href.indexOf ('§ion=1'); |
|||
if ( result !== null && result.length ) { |
|||
var len = 10; |
|||
this.inputfield = result; |
|||
if (offset < 0) { |
|||
this.buttonClicked(action, dnuTemplate, subpage, fakeaction); |
|||
offset = href.indexOf ('§ion=T-1'); // Fix for MW 1.13alpha |
|||
len = 12; |
|||
} |
|||
if (offset > 0 && offset + len == href.length) { |
|||
// It's really an edit lk to a deletion request subpage, and not a section |
|||
// edit for a daily subpage or something else |
|||
//bold the edit button |
|||
anchor.style.fontWeight = 'bold'; |
|||
var orig_bracket = edit_lks[i].firstChild; |
|||
var close_href = href.substring (0, offset); |
|||
close_href = encodeURIComponent(close_href); //encode ampersands etc. |
|||
//get deletion reason |
|||
var subpage = href.substring (href.indexOf ('title=') + 6); |
|||
var idx = subpage.indexOf ("&"); |
|||
if (idx >= 0) subpage = subpage.substring (0, idx); |
|||
// |
|||
// buttons |
|||
// |
|||
//delete |
|||
var link_id = "drh-del-" + lk_number; |
|||
var link = makeActiveLink( |
|||
'usuń' |
|||
, 'DelReqHandler.buttonClicked(' |
|||
+ '0, ' |
|||
+ "'" + link_id + "', " |
|||
+ "'" + subpage + "', " |
|||
+ "'" + close_href + '&fakeaction=' + DelReqHandler.lupo_close_del + "'" |
|||
+ ');' |
|||
); |
|||
link.id = link_id; |
|||
edit_lks[i].insertBefore(document.createTextNode('['), orig_bracket); |
|||
edit_lks[i].insertBefore(link, orig_bracket); |
|||
edit_lks[i].insertBefore(document.createTextNode('] ['), orig_bracket); |
|||
if (!is_repair_page) |
|||
{ |
|||
//not for the repair section |
|||
//keep |
|||
link_id = "drh-keep-" + lk_number; |
|||
link = makeActiveLink( |
|||
'zostaw' |
|||
, 'DelReqHandler.buttonClicked(' |
|||
+ '1, ' |
|||
+ "'" + link_id + "', " |
|||
+ "'" + subpage + "', " |
|||
+ "'" + close_href + '&fakeaction=' + DelReqHandler.lupo_close_keep + "'" |
|||
+ ');' |
|||
); |
|||
link.id = link_id; |
|||
edit_lks[i].insertBefore(link, orig_bracket); |
|||
edit_lks[i].insertBefore(document.createTextNode('] ['), orig_bracket); |
|||
//no result |
|||
link_id = "drh-noresult-" + lk_number; |
|||
link = makeActiveLink( |
|||
'brak wyniku' |
|||
, 'DelReqHandler.buttonClicked(' |
|||
+ '2, ' |
|||
+ "'" + link_id + "', " |
|||
+ "'" + subpage + "', " |
|||
+ "'" + close_href + '&fakeaction=' + DelReqHandler.lupo_close_no_result + "'" |
|||
+ ');' |
|||
); |
|||
link.id = link_id; |
|||
edit_lks[i].insertBefore(link, orig_bracket); |
|||
edit_lks[i].insertBefore(document.createTextNode('] ['), orig_bracket); |
|||
} |
} |
||
}); |
|||
} |
|||
else |
|||
//only for the repair section |
|||
{ |
|||
if(confirm("Czy na pewno wykonać akcję?")) |
|||
link_id = "drh-repaired-" + lk_number; |
|||
this.buttonClicked(action, dnuTemplate, subpage, fakeaction); |
|||
link = makeActiveLink( |
|||
} |
|||
'naprawiono' |
|||
}); |
|||
, 'DelReqHandler.buttonClicked(' |
|||
+ '3, ' |
|||
return button; |
|||
+ "'" + link_id + "', " |
|||
}, |
|||
+ "'" + subpage + "', " |
|||
+ "'" + close_href + '&fakeaction=' + DelReqHandler.lupo_close_repaired + "'" |
|||
/** Prepare action links in sections. */ |
|||
+ ');' |
|||
closeRequestLinks : function () |
|||
); |
|||
{ |
|||
const dnuTemplates = document.querySelectorAll('#bodyContent .sz-ln-dnu'); |
|||
let hasItems = false; |
|||
for (let dnuTemplate of dnuTemplates) { |
|||
edit_lks[i].insertBefore(link, orig_bracket); |
|||
const subpageEl = dnuTemplate.querySelector('.sz-ln-dnu .dnu-self-page'); |
|||
edit_lks[i].insertBefore(document.createTextNode('] ['), orig_bracket); |
|||
if (!subpageEl) { |
|||
} |
|||
console.warn('dnu-self-page not found', {dnuTemplate}); |
|||
continue; |
|||
} |
|||
// full subpage title |
|||
const subpage = subpageEl.textContent.trim().replace(/ /g, '_'); |
|||
// buttons |
|||
const buttonGroup = this.createButtons(dnuTemplate, subpage); |
|||
link_id = "drh-archive-" + lk_number; |
|||
$(dnuTemplate).append( $('<div class="dnu-actions">').append(buttonGroup.$element) ); |
|||
link = makeActiveLink( |
|||
'do arch.' |
|||
, 'DelReqHandler.buttonClicked(' |
|||
+ '4, ' |
|||
+ "'" + link_id + "', " |
|||
+ "'" + subpage + "', " |
|||
+ "'" + close_href + "'" |
|||
+ ');' |
|||
); |
|||
// done |
|||
link.id = link_id; |
|||
// $(dnuTemplate).addClass('header-has-delreq'); |
|||
edit_lks[i].insertBefore(link, orig_bracket); |
|||
hasItems = true; |
|||
edit_lks[i].insertBefore(document.createTextNode('] '), orig_bracket); |
|||
} |
|||
if (hasItems) { |
|||
lk_number++; |
|||
mw.util.addCSS(/*css*/` |
|||
} |
|||
.dnu-actions .oo-ui-buttonGroupWidget { |
|||
display: flex; |
|||
flex-wrap: wrap; |
|||
align-items: flex-start; |
|||
} |
} |
||
.dnu-actions .oo-ui-buttonGroupWidget .oo-ui-buttonWidget { |
|||
} |
|||
margin-left: 0 !important; |
|||
} |
|||
`); |
|||
mw.hook('userjs.delreq.reader').fire(DelReqHandler); |
|||
} |
} |
||
}, |
}, |
||
/** Create a group of buttons for the section. */ |
|||
createButtons: function (dnuTemplate, subpage) { |
|||
var items = []; |
|||
if (isAdmin) { |
|||
items.push(this.createActionButton(this.actionMap.delete, {label: 'Usuń', icon: 'trash', flags: 'destructive', framed: false}, dnuTemplate, subpage, this.fakeaction_close_del)); |
|||
} |
|||
if (!this.isSubpage('reanimacja', subpage)) { |
|||
items.push(this.createActionButton(this.actionMap.keep, {label: 'zostaw', icon: 'articleCheck', flags: 'progressive', framed: false}, dnuTemplate, subpage, this.fakeaction_close_keep)); |
|||
items.push(this.createActionButton(this.actionMap.noResult, {label: 'brak wyniku', icon: 'help', flags: 'progressive', framed: false}, dnuTemplate, subpage, this.fakeaction_close_no_result)); |
|||
items.push(this.createActionButton(this.actionMap.toArchive, {label: 'do arch.', icon: 'tray', flags: 'progressive', framed: false}, dnuTemplate, subpage, '')); |
|||
items.push(this.createActionButton(this.actionMap.reject, {label: 'wycofaj', icon: 'undo', flags: 'progressive', framed: false}, dnuTemplate, subpage, '')); |
|||
items.push(this.createActionButton(this.actionMap.draft, {label: 'brudnopis', icon: 'sandbox', flags: 'progressive', framed: false}, dnuTemplate, subpage, 'close_draft')); |
|||
items.push(this.createActionButton(this.actionMap.redirect, {label: 'redir', icon: 'articleRedirect', flags: 'progressive', framed: false}, dnuTemplate, subpage, 'close_redir')); |
|||
} else { |
|||
items.push(this.createActionButton(this.actionMap.repaired, {label: 'naprawiono', icon: 'articleCheck', flags: 'progressive', framed: false}, dnuTemplate, subpage, this.fakeaction_close_repaired)); |
|||
} |
|||
if (this.isSubpage('artykuły', subpage) || this.isSubpage('biografie', subpage)) { |
|||
// icons?: clock, labFlask, ongoingConversation |
|||
items.push(this.createActionButton(this.actionMap.reanimation, {label: 'reanimacja', icon: 'labFlask', flags: 'progressive', framed: false}, dnuTemplate, subpage, this.fakeaction_move_reanimation)); |
|||
} |
|||
var buttonGroup = new OO.ui.ButtonGroupWidget({ |
|||
items: items, |
|||
}); |
|||
return buttonGroup; |
|||
}, |
|||
/*------------------------------------------------------------------------------------------ |
/*------------------------------------------------------------------------------------------ |
||
Links on every non-deleted |
Links on every non-deleted article mentioned on a deletion request page. The "[del]" link |
||
triggers deletion (auto-completed!) of the |
triggers deletion (auto-completed!) of the article, with a deletion summary linking to the |
||
deletion request. If the |
deletion request. If the article has a talk page, it is deleted as well. The "[keep]" link |
||
automatically removes the "delete" template from the |
automatically removes the "delete" template from the article and adds the "kept" template |
||
to the |
to the article talk page, both linking back to the deletion request. |
||
------------------------------------------------------------------------------------------*/ |
------------------------------------------------------------------------------------------*/ |
||
// TODO: use this in other places... |
|||
/* |
|||
/** Action map for buttons. */ |
|||
* buttonClicked |
|||
actionMap: { |
|||
* |
|||
delete: 0, |
|||
* Called when the user clicked one of the links |
|||
keep: 1, |
|||
* |
|||
noResult: 2, |
|||
* action - which of the links has been pressed? |
|||
repaired: 3, // used in reanimation |
|||
* 0 - delete |
|||
toArchive: 4, // move to archive |
|||
* 1 - keep |
|||
reject: 5, |
|||
* 2 - no result |
|||
draft: 6, // move to user's draft |
|||
* 3 - repaired |
|||
redirect: 7, // replace with redirect |
|||
* 4 - to archive |
|||
reanimation: 8, // move to reanimation |
|||
* id - id of the link pressed |
|||
}, |
|||
* subpage - subpage of the request |
|||
* old_style_href - URL which marks the request as closed |
|||
/** |
|||
* Button action. |
|||
buttonClicked : function (action, id, sub, old_style_href) |
|||
* |
|||
* Called when the user clicked one of the links. |
|||
* |
|||
* @param {Number} action Which of the links has been pressed: see `actionMap`. |
|||
* @param {Element} dnuTemplate Reference to lnDNU with article titles and action links. |
|||
* @param {String} sub Subpage of the del request. |
|||
* @param {String} close_href Edit link for the del req. |
|||
* @returns |
|||
*/ |
|||
buttonClicked : function (action, dnuTemplate, subpage, fakeaction) |
|||
{ |
{ |
||
const articleTitleEl = dnuTemplate.querySelector('.sz-ln-dnu a:first-of-type'); |
|||
this.startDate = new Date (); |
|||
const articleTitle = !articleTitleEl ? '' : articleTitleEl.textContent.trim(); |
|||
this.subpage = sub; |
|||
if (!articleTitle.length) { |
|||
this.reason = '[[' + sub + ']]'; |
|||
alert('Nie udało się znaleźć linka w szablonie lnDNU. Spróbuj odświeżyć stronę lub sprawdź czy szablon jest wypełniony poprawnie.'); |
|||
this.keep_summary = 'Zostawiono po dyskusji: ' + this.reason; |
|||
console.error('DNU close failed.', {action, dnuTemplate, subpage}); |
|||
this.close_href = old_style_href; |
|||
//find the link |
|||
var el = document.getElementById(id); |
|||
if (!el) |
|||
{ |
|||
//no such link |
|||
alert("Error - link not found"); |
|||
return; |
return; |
||
} |
|||
//go up to the header |
|||
while (el.tagName.search('H\\d') < 0) |
|||
{ |
|||
el = el.parentNode; |
|||
if (el == document) |
|||
{ |
|||
alert("Error - link outside a header"); |
|||
return; |
|||
} |
|||
} |
} |
||
this.startDate = new Date (); |
|||
//find the header line |
|||
this.subpage = subpage; |
|||
var els = $(el).find('.mw-headline').get(); |
|||
this.reason = '[[' + subpage + ']]'; |
|||
this.keep_summary = 'Zostawiono po dyskusji: ' + this.reason; |
|||
this.close_href = mw.util.getUrl(subpage, {action:'edit', fakeaction}); |
|||
this.pages_to_process = [articleTitle]; |
|||
if (els.length > 1) |
|||
{ |
|||
//more then one headline in a header - something's wrong. |
|||
alert("Error!"); |
|||
return; |
|||
} |
|||
el = els[0]; |
|||
var header = el; //remember for moveToArchive() |
|||
this.pages_to_process = []; |
|||
//find all links in the header |
|||
els = el.getElementsByTagName('a'); |
|||
for (var i = 0; i < els.length; i++) |
|||
{ |
|||
///make keep_href and open |
|||
el = $(els[i]); |
|||
if (el.hasClass('new')) |
|||
//red link |
|||
continue; |
|||
var href = el.attr('href'); |
|||
this.pages_to_process.push(titleFromHref(href)); |
|||
} |
|||
//move the subpage to the 24h archive |
|||
this.subpage_title = titleFromHref(old_style_href); |
|||
this.tasks = []; |
this.tasks = []; |
||
this.addTask('showProgress'); |
this.addTask('showProgress'); |
||
this.addTask('getEditToken'); |
|||
if(typeof DelReqHandler_debug !== "undefined") |
|||
{ |
|||
console.log("Omawiane strony: ", this.pages_to_process); |
|||
return; |
|||
} |
|||
switch(action) |
switch(action) |
||
{ |
{ |
||
case |
case this.actionMap.delete: |
||
this.addTask('deletePages'); |
this.addTask('deletePages'); |
||
this.addTask('addSubpageToArchive'); |
|||
break; |
break; |
||
case |
case this.actionMap.keep: |
||
case 2: //noresult |
|||
case 1: //keep |
|||
this.addTask('removeTemplate'); |
this.addTask('removeTemplate'); |
||
this.template_param = 'zostawiono'; |
|||
switch(action) |
|||
this.addTask('addSubpageToArchive'); |
|||
{ |
|||
break; |
|||
case 1: //kept |
|||
case this.actionMap.noResult: |
|||
this.template_param = 'zostawiono'; |
|||
this.addTask('removeTemplate'); |
|||
break; |
|||
this.template_param = 'brak wyniku'; |
|||
case 2: //no result |
|||
this.addTask('addSubpageToArchive'); |
|||
break; |
|||
case this.actionMap.repaired: |
|||
this.addTask('removeTemplate'); |
|||
this.template_param = 'naprawiono'; |
|||
break; |
|||
this.addTask('addSubpageToArchive'); |
|||
} |
|||
break; |
|||
case this.actionMap.toArchive: |
|||
this.addTask('addSubpageToArchive'); |
|||
break; |
|||
case this.actionMap.reject: |
|||
this.addTask('removeTemplate'); |
|||
this.addTask('addSubpageToArchive'); |
|||
break; |
|||
case this.actionMap.draft: |
|||
this.addTask('moveToDraft'); |
|||
this.addTask('addSubpageToArchive'); |
|||
break; |
|||
case this.actionMap.redirect: |
|||
this.addTask('makeRedirect'); |
|||
this.addTask('addSubpageToArchive'); |
|||
break; |
|||
case this.actionMap.reanimation: |
|||
this.addTask('addSubpageToReanimation'); |
|||
break; |
break; |
||
} |
} |
||
this.addTask('addSubpageToArchive'); |
|||
this.addTask('removeSubpage'); |
this.addTask('removeSubpage'); |
||
this.addTask('openSubpageForEdit'); |
this.addTask('openSubpageForEdit'); |
||
Linia 367: | Linia 314: | ||
this.nextTask(); |
this.nextTask(); |
||
}, |
|||
moveToDraft : function () |
|||
{ |
|||
this.page_processed = this.pages_to_process.shift();//TODO: masowo do brudnopisu |
|||
var article = this.page_processed; |
|||
mw.loader.using('ext.gadget.move-to-sandbox', function (){ |
|||
moveToSandboxGadget.moveSource = article; |
|||
moveToSandboxGadget.initialReason = 'Przeniesiono do brudnopisu po dyskusji: ' + DelReqHandler.reason; |
|||
moveToSandboxGadget.open( function(status) { |
|||
if(status) |
|||
{ |
|||
DelReqHandler.pages_to_process.push(moveToSandboxGadget.moveDestination); |
|||
DelReqHandler.nextTask(); |
|||
} |
|||
else |
|||
{ |
|||
DelReqHandler.fail('Anulowano przenosiny'); |
|||
} |
|||
}, DelReqHandler.reason); |
|||
}); |
|||
}, |
|||
makeRedirect : function () |
|||
{ |
|||
this.page_processed = this.pages_to_process.shift();//TODO: wszystkie strony z jednego zgłoszenia |
|||
this.updateProgress('Zamieniam stronę '+this.page_processed+' na przekierowanie'); |
|||
this.api.postWithEditToken({action: 'edit', title: this.page_processed, summary: 'Zamiana na przekierowanie po dyskusji w '+this.reason, text: '#PATRZ [['+DelReqHandler.inputfield+']]'}) |
|||
.fail(function(code, error){ |
|||
return DelReqHandler.apiFail( code, error, "makeRedirect" ); |
|||
}) |
|||
.done(function(data){ |
|||
DelReqHandler.nextTask(); |
|||
}); |
|||
}, |
}, |
||
Linia 379: | Linia 363: | ||
this.page_processed = this.pages_to_process.shift(); |
this.page_processed = this.pages_to_process.shift(); |
||
this.updateProgress('Usuwam szablon {{DNU}} ze strony „' + this.page_processed + '”'); |
this.updateProgress('Usuwam szablon {{DNU}} ze strony „' + this.page_processed + '”'); |
||
var that = this; |
|||
this.api.edit( |
|||
this.fetchPage(this.page_processed, 'removeTemplateCB'); |
|||
this.page_processed, |
|||
}, |
|||
function ( revision ) { |
|||
var text = revision.content; |
|||
var start = text.indexOf ('\{\{DNU'); |
|||
if (start < 0) start = text.indexOf ('\{\{dNU'); |
|||
if (start < 0) start = text.indexOf ('\{\{poczSDU'); |
|||
if (start < 0) start = text.indexOf ('\{\{PoczSDU'); |
|||
if (start < 0) start = text.indexOf ('\{\{PoczSdU'); |
|||
if (start < 0) start = text.indexOf ('\{\{poczSdU'); |
|||
if (start >= 0) { |
|||
var level = 0; |
|||
var curr = start + 2; |
|||
var end = 0; |
|||
while (curr < text.length && end == 0) { |
|||
var opening = text.indexOf ('\{\{', curr); |
|||
var closing = text.indexOf ('\}\}', curr); |
|||
if (opening >= 0 && opening < closing) { |
|||
level = level + 1; |
|||
curr = opening + 2; |
|||
} else { |
|||
if (closing < 0) { |
|||
// No closing braces found |
|||
curr = text.length; |
|||
} else { |
|||
if (level > 0) level = level - 1; |
|||
else end = closing + 2; |
|||
curr = closing + 2; |
|||
} |
|||
} |
|||
} |
|||
if (end > start) { |
|||
// Also strip whitespace after the "delete" template |
|||
if (start > 0) { |
|||
//text = text.substring (0, start) |
|||
// + text.substring (end).replace(/^\s*/, ''); |
|||
var beginning = text.substring(0,start); |
|||
var ending = text.substring(end); |
|||
//strip <noinclude>, if the template is the only thing in it |
|||
if (beginning.search(/<noinclude>\s*$/) >= 0 |
|||
&& ending.search(/^\s*<\/noinclude>/) >= 0) |
|||
{ |
|||
beginning = beginning.replace(/<noinclude>\s*$/, ''); |
|||
ending = ending.replace(/^\s*<\/noinclude>/, ''); |
|||
} |
|||
else |
|||
ending = ending.replace('^\\s*', ''); |
|||
text = beginning + ending; |
|||
} else { |
|||
text = text.substring (end).replace(/^\s*/, ''); |
|||
} |
|||
var success = true; |
|||
removeTemplateCB : function(result) |
|||
{ |
|||
var text = this.extractPageText(result); |
|||
var start = text.indexOf ('\{\{DNU'); |
|||
if (start < 0) start = text.indexOf ('\{\{dNU'); |
|||
if (start < 0) start = text.indexOf ('\{\{poczSDU'); |
|||
if (start < 0) start = text.indexOf ('\{\{PoczSDU'); |
|||
if (start < 0) start = text.indexOf ('\{\{PoczSdU'); |
|||
if (start < 0) start = text.indexOf ('\{\{poczSdU'); |
|||
if (start >= 0) { |
|||
var level = 0; |
|||
var curr = start + 2; |
|||
var end = 0; |
|||
while (curr < text.length && end == 0) { |
|||
var opening = text.indexOf ('\{\{', curr); |
|||
var closing = text.indexOf ('\}\}', curr); |
|||
if (opening >= 0 && opening < closing) { |
|||
level = level + 1; |
|||
curr = opening + 2; |
|||
} else { |
|||
if (closing < 0) { |
|||
// No closing braces found |
|||
curr = text.length; |
|||
} else { |
} else { |
||
that.addWarning ('Nie znaleziono zamknięcia szablonu na stronie ' + that.page_processed + '.'); |
|||
if (level > 0) level = level - 1; |
|||
else end = closing + 2; |
|||
curr = closing + 2; |
|||
} |
} |
||
} |
|||
} |
|||
if (end > start) { |
|||
// Also strip whitespace after the "delete" template |
|||
if (start > 0) { |
|||
//text = text.substring (0, start) |
|||
// + text.substring (end).replace(/^\s*/, ''); |
|||
var beginning = text.substring(0,start); |
|||
var ending = text.substring(end); |
|||
//strip <noinclude>, if the template is the only thing in it |
|||
if (beginning.search(/<noinclude>\s*$/) >= 0 |
|||
&& ending.search(/^\s*<\/noinclude>/) >= 0) |
|||
{ |
|||
beginning = beginning.replace(/<noinclude>\s*$/, ''); |
|||
ending = ending.replace(/^\s*<\/noinclude>/, ''); |
|||
} |
|||
else |
|||
ending = ending.replace('^\\s*', ''); |
|||
text = beginning + ending; |
|||
} else { |
} else { |
||
that.addWarning ('Nie znaleziono szablonu DNU na stronie ' + that.page_processed + '.'); |
|||
text = text.substring (end).replace(/^\s*/, ''); |
|||
} |
} |
||
return { |
|||
page.title = this.page_processed; |
|||
text: text, |
|||
page.editType = 'text'; |
|||
summary: that.keep_summary |
|||
page.text = text; |
|||
}; |
|||
this.savePage ( |
|||
} |
|||
) |
|||
this.keep_summary, |
|||
.fail(function(code, error){ |
|||
'addKeepToTalk' |
|||
return DelReqHandler.apiFail( code, error, "removeTemplate" ); |
|||
); |
|||
}) |
|||
success = true; |
|||
.then( function () { |
|||
try { |
|||
this.addWarning ('Nie znaleziono zamknięcia szablonu na stronie ' + this.page_processed + '.'); |
|||
that.addKeepToTalk(); |
|||
} |
} |
||
catch (e) { |
|||
return DelReqHandler.fail(e); |
|||
this.addWarning ('Nie znaleziono szablonu DNU na stronie ' + this.page_processed + '.'); |
|||
} |
|||
this.addKeepToTalk(); |
|||
} |
} ); |
||
}, |
}, |
||
addKeepToTalk : function () |
addKeepToTalk : function () |
||
{ |
{ |
||
// |
|||
var talk_title = this.findTalkPage(this.page_processed); |
var talk_title = this.findTalkPage(this.page_processed); |
||
var text; |
|||
var that = this; |
|||
this.updateProgress('Dodaję szablon {{DNU}} na stronie dyskusji „' + talk_title + '”.'); |
this.updateProgress('Dodaję szablon {{DNU}} na stronie dyskusji „' + talk_title + '”.'); |
||
var text; |
|||
try { |
try { |
||
text = '\{\{DNU|' + this.template_param + '|zakończenie=' |
text = '\{\{DNU|' + this.template_param + '|zakończenie=' |
||
+ this.formatDate('YYYY-MM-DD'); |
+ this.formatDate('YYYY-MM-DD'); |
||
text = text + '|podstrona=' + this.subpage + '\}\}\n'; |
text = text + '|podstrona=' + this.subpage + '\}\}\n'; |
||
success = true; |
var success = true; |
||
} catch (ex) { |
} catch (ex) { |
||
// Swallow |
// Swallow |
||
Linia 477: | Linia 468: | ||
text = '\{\{DNU|' + this.template_param + '|podstrona=' + this.subpage + '\}\}\n'; |
text = '\{\{DNU|' + this.template_param + '|podstrona=' + this.subpage + '\}\}\n'; |
||
} |
} |
||
this.api.postWithEditToken({action: 'edit', title: talk_title, prependtext: text, summary: this.keep_summary}) |
|||
var page = {}; |
|||
.fail(function(code, error){ |
|||
page.editType = 'prependtext'; |
|||
return DelReqHandler.apiFail( code, error, "addKeepToTalk" ); |
|||
page.text = text; |
|||
}) |
|||
page.title = talk_title; |
|||
.then( function () { |
|||
this.savePage(page, this.keep_summary, 'removeTemplate'); |
|||
try { |
|||
that.removeTemplate(); |
|||
} |
|||
catch (e) { |
|||
return DelReqHandler.fail(e); |
|||
} |
|||
} ); |
|||
}, |
}, |
||
Linia 492: | Linia 490: | ||
{ |
{ |
||
var result; |
var result; |
||
var subpage = page_name.replace(/ /g, '_'); |
|||
for (var i = 0; i < this.deletion_request_pages.length; i++) |
for (var i = 0; i < this.deletion_request_pages.length; i++) |
||
{ |
{ |
||
var page = this.deletion_request_pages[i]; |
var page = this.deletion_request_pages[i]; |
||
if ( |
if (subpage.indexOf(page) == 0) |
||
if (result == null || page.length > result.length) |
if (result == null || page.length > result.length) |
||
result = page; |
result = page; |
||
Linia 503: | Linia 502: | ||
findTalkPage : function (title) { |
findTalkPage : function (title) { |
||
var t = new mw.Title(title); |
|||
//wgNamespaceIds doesn't contain canonical namespace names (bug 25375) |
|||
return t.getTalkPage().getPrefixedText(); |
|||
//create our own table then. |
|||
var namespaceIds = { |
|||
'talk' : 1, |
|||
'user' : 2, |
|||
'user_talk' : 3, |
|||
'project' : 4, |
|||
'project_talk' : 5, |
|||
'file' : 6, |
|||
'file_talk' : 7, |
|||
'mediawiki' : 8, |
|||
'mediawiki_talk' : 9, |
|||
'template' : 10, |
|||
'template_talk' : 11, |
|||
'help' : 12, |
|||
'help_talk' : 13, |
|||
'category' : 14, |
|||
'category' : 15 |
|||
}; |
|||
for (var n in mw.config.get('wgNamespaceIds')) |
|||
namespaceIds[n] = mw.config.get('wgNamespaceIds')[n]; |
|||
var talk_title; |
|||
var idx = title.indexOf(':'); |
|||
if (idx < 0) |
|||
//no colon - main namespace |
|||
talk_title = 'Dyskusja:' + title; |
|||
else |
|||
{ |
|||
var namespace = title.substring(0, idx).toLowerCase().replace(/ /g, '_'); |
|||
if (namespaceIds[namespace] == null) |
|||
//no such namespace - main namespace |
|||
talk_title = 'Dyskusja:' + title; |
|||
else |
|||
{ |
|||
var id = namespaceIds[namespace]; |
|||
if (id % 2 == 1) |
|||
{ |
|||
//already a link to a talk page? |
|||
talk_title = title; |
|||
} |
|||
else |
|||
talk_title = mw.config.get('wgFormattedNamespaces')[id+1] + ':' + title.substring(idx+1); |
|||
} |
|||
} |
|||
return talk_title; |
|||
}, |
}, |
||
Linia 568: | Linia 523: | ||
this.parent_page = this.findParentPage(this.subpage); |
this.parent_page = this.findParentPage(this.subpage); |
||
this.archive_page = this.parent_page + ' załatwione 24'; |
this.archive_page = this.parent_page + ' załatwione 24'; |
||
var that = this; |
|||
this.api.edit( |
|||
this.archive_page, |
|||
function ( revision ) { |
|||
var subpage = that.subpage; |
|||
var text = revision.content; |
|||
//if it's possible - strip the prefix |
|||
this.fetchPage(this.archive_page, 'addSubpageToArchiveCB'); |
|||
var idx = subpage.indexOf(DelReqHandler.archivePageName); |
|||
if (idx == 0) |
|||
subpage = subpage.substr(DelReqHandler.archivePageName.length); |
|||
subpage = '{{' + subpage + '}}'; |
|||
if (text.indexOf(DelReqHandler.archive_section_line) >= 0) |
|||
text = text.replace( |
|||
DelReqHandler.archive_section_line, |
|||
DelReqHandler.archive_section_line + '\n' + subpage |
|||
); |
|||
else |
|||
//no archive line - just append |
|||
//do not add an extra line break if the current text ends with one |
|||
text = |
|||
text |
|||
+ (text[text.length-1] == '\n' ? '' : '\n') |
|||
+ subpage; |
|||
return { |
|||
text: text, |
|||
summary: '+ {{[[' + that.subpage + ']]}}' |
|||
}; |
|||
} |
|||
) |
|||
.fail(function(code, error){ |
|||
return DelReqHandler.apiFail( code, error, "addSubpageToArchive" ); |
|||
}) |
|||
.then( function () { |
|||
that.nextTask(); |
|||
} ); |
|||
}, |
}, |
||
/** Moves the given subpage to the Reanimation project. */ |
|||
addSubpageToArchiveCB : function(result) |
|||
addSubpageToReanimation : function() |
|||
{ |
{ |
||
this.updateProgress('Dodaję podstronę do stolika reanimacja...'); |
|||
var text = this.extractPageText(result); |
|||
var subpage = this.subpage; |
|||
this.parent_page = this.findParentPage(this.subpage); |
|||
//if it's possible - strip the prefix |
|||
this.to_page = 'Wikipedia:Poczekalnia/reanimacja'; |
|||
var idx = subpage.indexOf(DelReqHandler.archivePageName); |
|||
if (idx == 0) |
|||
var that = this; |
|||
subpage = subpage.substr(DelReqHandler.archivePageName.length); |
|||
this.api.edit( |
|||
this.to_page, |
|||
function ( revision ) { |
|||
var subpage = that.subpage; |
|||
var text = revision.content; |
|||
subpage = '{{' + subpage + '}}'; |
subpage = '{{' + subpage + '}}'; |
||
if (text.indexOf(DelReqHandler. |
if (text.indexOf(DelReqHandler.reanimation_section_line) >= 0) |
||
text = text.replace( |
text = text.replace( |
||
DelReqHandler.reanimation_section_line, |
|||
DelReqHandler.reanimation_section_line + '\n' + subpage |
|||
); |
|||
else |
else |
||
//no |
//no reanimation line - just append |
||
//do not add an extra line break if the current text ends with one |
//do not add an extra line break if the current text ends with one |
||
text = |
text = |
||
text |
text |
||
+ (text[text.length-1] == '\n' ? '' : '\n') |
+ (text[text.length-1] == '\n' ? '' : '\n') |
||
+ subpage; |
+ subpage; |
||
return { |
|||
text: text, |
|||
page.title = this.archive_page; |
|||
summary: '+ {{[[' + that.subpage + ']]}}' |
|||
page.editType = 'text'; |
|||
}; |
|||
} |
|||
this.savePage( |
|||
) |
|||
page, |
|||
.fail(function(code, error){ |
|||
'+ {{[[' + this.subpage + ']]}}', |
|||
return DelReqHandler.apiFail( code, error, "addSubpageToReanimation" ); |
|||
'nextTask' |
|||
) |
}) |
||
.then( function () { |
|||
that.nextTask(); |
|||
} ); |
|||
}, |
}, |
||
Linia 612: | Linia 615: | ||
{ |
{ |
||
this.updateProgress(); |
this.updateProgress(); |
||
var that = this; |
|||
this.fetchPage(this.parent_page, 'removeSubpageCB'); |
|||
}, |
|||
this.api.edit( |
|||
removeSubpageCB : function (result) |
|||
this.parent_page, |
|||
{ |
|||
function ( revision ) { |
|||
var text = this.extractPageText(result); |
|||
var text = revision.content; |
|||
//find the subpage inclusion |
//find the subpage inclusion |
||
var searched = "{{" + |
var searched = "{{" + that.subpage + "}}\n"; |
||
var idx = text.indexOf(searched); |
var idx = text.indexOf(searched); |
||
if (idx < 0) |
|||
if (idx < 0) |
|||
{ |
|||
//not found - try with spaces instead of underscores |
|||
searched = searched.replace(/_/g, ' '); |
|||
idx = text.indexOf(searched); |
|||
if (idx < 0) |
|||
{ |
|||
//not found - but the inclusion may still look like {{/subpage}} |
|||
if (this.subpage.indexOf(this.subpage) == 0) |
|||
{ |
{ |
||
//not found - try with spaces instead of underscores |
|||
searched = this.subpage.substr(this.parent_page.length); |
|||
searched = |
searched = searched.replace(/_/g, ' '); |
||
idx = text.indexOf(searched); |
idx = text.indexOf(searched); |
||
if (idx < 0) |
if (idx < 0) |
||
{ |
{ |
||
//not found - |
//not found - but the inclusion may still look like {{/subpage}} |
||
if (that.subpage.indexOf(that.subpage) == 0) |
|||
searched = searched.replace('_', ' '); |
|||
{ |
|||
idx = text.indexOf(searched); |
|||
searched = that.subpage.substr(that.parent_page.length); |
|||
searched = "{{" + searched + "}}\n"; |
|||
idx = text.indexOf(searched); |
|||
if (idx < 0) |
|||
{ |
|||
//not found - try with spaces instead of underscores |
|||
searched = searched.replace('_', ' '); |
|||
idx = text.indexOf(searched); |
|||
} |
|||
} |
|||
} |
} |
||
} |
} |
||
if (idx >= 0) |
|||
} |
|||
{ |
|||
//inclusion found - cut it out |
|||
if (idx >= 0) |
|||
text = text.substr(0, idx) + text.substr(idx + searched.length); |
|||
{ |
|||
//inclusion found - cut it out |
|||
text = text.substr(0, idx) + text.substr(idx + searched.length); |
|||
} |
|||
var page = {}; |
|||
return { |
|||
page.title = this.parent_page; |
|||
text: text, |
|||
summary: '- {{[[' + that.subpage + ']]}}' |
|||
page.editType = 'text'; |
|||
}; |
|||
} |
|||
this.savePage( |
|||
) |
|||
page, |
|||
.fail(function(code, error){ |
|||
'{{[[' + this.subpage + ']]}} - przeniesione do archiwum', |
|||
return DelReqHandler.apiFail( code, error, "removeSubpage" ); |
|||
'nextTask' |
|||
}) |
|||
.then( function () { |
|||
} |
|||
that.nextTask(); |
|||
else |
|||
} ); |
|||
this.nextTask(); |
|||
} |
|||
}, |
}, |
||
Linia 673: | Linia 677: | ||
maybeSetupForm : function() |
maybeSetupForm : function() |
||
{ |
{ |
||
var param = |
var param = mw.util.getParamValue ('fakeaction'); |
||
if (param == null) |
if (param == null) |
||
return; |
return; |
||
Linia 679: | Linia 683: | ||
var summary = null; |
var summary = null; |
||
var result_param = null; |
var result_param = null; |
||
if (param == DelReqHandler.lupo_close_del) { |
|||
switch(param) |
|||
summary = DelReqHandler.close_del_summary; |
|||
{ |
|||
result_param = 'usunięto'; |
|||
case DelReqHandler.fakeaction_close_del: |
|||
summary = DelReqHandler. |
summary = DelReqHandler.close_del_summary; |
||
result_param = ' |
result_param = 'usunięto'; |
||
break; |
|||
} else if (param == DelReqHandler.lupo_close_no_result) { |
|||
summary = DelReqHandler.close_no_result_summary; |
|||
case DelReqHandler.fakeaction_close_keep: |
|||
result_param = 'brak wyniku'; |
|||
summary = DelReqHandler.close_keep_summary; |
|||
result_param = 'zostawiono'; |
|||
summary = DelReqHandler.close_repaired_summary; |
|||
break; |
|||
result_param = 'naprawiono'; |
|||
case DelReqHandler.fakeaction_close_no_result: |
|||
summary = DelReqHandler.close_no_result_summary; |
|||
result_param = 'brak wyniku'; |
|||
break; |
|||
case DelReqHandler.fakeaction_close_repaired: |
|||
summary = DelReqHandler.close_repaired_summary; |
|||
result_param = 'naprawiono'; |
|||
break; |
|||
case DelReqHandler.fakeaction_close_eject: |
|||
summary = DelReqHandler.close_eject_summary; |
|||
result_param = 'wycofano'; |
|||
break; |
|||
case 'close_draft': |
|||
summary = DelReqHandler.close_draft_summary; |
|||
result_param = 'zostawiono';//dodać do lnDNU |
|||
break; |
|||
case 'close_redir': |
|||
summary = DelReqHandler.close_redir_summary; |
|||
result_param = 'zostawiono';//dodać do lnDNU |
|||
break; |
|||
case DelReqHandler.fakeaction_move_reanimation: |
|||
//summary = DelReqHandler.close_move2repair_summary; |
|||
result_param = 'reanimacja'; |
|||
break; |
|||
} |
} |
||
if (summary !== null && result_param !== null) { |
if (summary !== null && result_param !== null) { |
||
$('#wpSummary').val(summary); |
$('#wpSummary').val(summary); |
||
let textbox = document.editform.wpTextbox1; |
|||
let text = textbox.value + '\n\'\'\'' + summary + '\'\'\' \~\~\~\~'; |
|||
text = text.replace(/(\{\{lnDNU)\|rezultat=[^\|]+\|data zakończenia=[^\|]+/, '$1'); |
|||
text = text.replace(/(\{\{lnDNU)/gi, '$1|rezultat=' + result_param + '|data zakończenia=' + this.formatDate("YYYY-MM-DD")); |
text = text.replace(/(\{\{lnDNU)/gi, '$1|rezultat=' + result_param + '|data zakończenia=' + this.formatDate("YYYY-MM-DD")); |
||
textbox.value = text; |
|||
// Don't close the window so the user can add a comment. |
|||
if (text.scrollHeight > text.clientHeight) { |
|||
text.scrollTop = text.scrollHeight - text.clientHeight; |
|||
} |
|||
textbox.focus(); |
|||
} else if (result_param === 'reanimacja') { |
|||
$('#wpSummary').val(DelReqHandler.close_move2repair_summary); |
|||
let textbox = document.editform.wpTextbox1; |
|||
let text = textbox.value + '\n</div>\n\n\'\'\'Do naprawy:\'\'\'\n\* ...\n\* ...\n\~\~\~\~'; |
|||
text = text.replace(/(\}\})(\n+[^\n:])/, '$1\n\n{{licznik czasu|zdarzenie=Czas przewidziany na reanimację|start={{subst:#timel:Y-m-d H:i:s}}|dni=60}}\n\n<div style="padding:20px; background:#dee; border:1px solid #aaa;">\n$2'); |
|||
textbox.value = text; |
textbox.value = text; |
||
Linia 720: | Linia 770: | ||
this.updateProgress('Usuwam stronę ' + this.page_processed + '...'); |
this.updateProgress('Usuwam stronę ' + this.page_processed + '...'); |
||
this.deletePage(this.page_processed, 'Usunięto po dyskusji: ' + this.reason, 'deleteTalkPage'); |
this.deletePage(this.page_processed, 'Usunięto po dyskusji: ' + this.reason, 'deleteTalkPage', true); |
||
}, |
}, |
||
Linia 729: | Linia 779: | ||
this.updateProgress('Usuwam stronę dyskusji ' + talk_title + '...'); |
this.updateProgress('Usuwam stronę dyskusji ' + talk_title + '...'); |
||
this.deletePage(talk_title, 'Strona dyskusji artykułu usuniętego po dyskusji: ' + this.reason, 'deletePages'); |
this.deletePage(talk_title, 'Strona dyskusji artykułu usuniętego po dyskusji: ' + this.reason, 'deletePages', false); |
||
}, |
}, |
||
Linia 744: | Linia 794: | ||
{ |
{ |
||
window.open(this.close_href, '_blank'); |
window.open(this.close_href, '_blank'); |
||
this.windowManager.closeWindow( this.progressDialog ); |
|||
$('#del-req-progress').dialog("close"); |
|||
document.body.style.cursor = ''; |
document.body.style.cursor = ''; |
||
} |
} |
||
Linia 770: | Linia 820: | ||
//reload |
//reload |
||
var title = encodeURIComponent(this.destination || |
var title = encodeURIComponent(this.destination || this.current_pagename). |
||
replace(/\%3A/g, ':').replace(/\%20/g, '_'). |
|||
replace(/\(/g, '%28').replace(/\)/g, '%29'). |
|||
replace(/\%2F/g, '/'); |
|||
location.href = mw.config.get('wgServer') + mw.config.get('wgArticlePath').replace("$1", title); |
location.href = mw.config.get('wgServer') + mw.config.get('wgArticlePath').replace("$1", title); |
||
}, |
}, |
||
deletePage : function (page, reason, callback, must_exists) |
|||
/** |
|||
* Submit an edited page. |
|||
**/ |
|||
savePage : function (page, summary, callback) { |
|||
var edit = { |
|||
action : 'edit', |
|||
summary : summary, |
|||
watchlist : (page.watchlist || 'preferences'), |
|||
title : page.title, |
|||
token : this.edittoken |
|||
}; |
|||
edit[page.editType]=page.text; |
|||
this.doAPICall( edit, callback ); |
|||
}, |
|||
/** |
|||
* Get the page text. |
|||
**/ |
|||
fetchPage : function (page, callback) { |
|||
var query = { |
|||
action : 'query', |
|||
prop : 'revisions', |
|||
rvprop : 'content', |
|||
titles : page, |
|||
indexpageids : '1' |
|||
}; |
|||
this.doAPICall(query, callback); |
|||
}, |
|||
deletePage : function (page, reason, callback) |
|||
{ |
{ |
||
var |
var that = this; |
||
action : 'delete', |
|||
this.api.postWithEditToken({action: 'delete', title: page, reason: reason}) |
|||
title : page, |
|||
.fail(function(code, error){ |
|||
token : this.edittoken, //delete token is equal to edit token |
|||
if(code != 'missingtitle' || must_exists) |
|||
reason : reason |
|||
return DelReqHandler.fail("Błąd usuwania strony \""+page+"\":<br />" + error.error.info + "<br />Error code is " + code + ", function: deletePage"); |
|||
}; |
|||
else |
|||
this.doAPICall(query, callback, true); |
|||
that[callback](); |
|||
}) |
|||
.done(function(data){ |
|||
that[callback](); |
|||
extractPageText : function(res) |
|||
{ |
|||
if (res.query.pageids[0] < 0) return ''; //no such page exists |
|||
return res.query.pages[ res.query.pageids[0] ].revisions[0]['*']; |
|||
}, |
|||
//Only for speedy deletion. Reporting for discussion obtains the token while performing other tasks. |
|||
getEditToken : function () { |
|||
var query = { |
|||
action : 'query', |
|||
prop : 'info|revisions', |
|||
rvprop : 'timestamp', |
|||
intoken : 'edit', |
|||
titles : mw.config.get('wgPageName') |
|||
}; |
|||
this.doAPICall( query, 'getEditTokenCB' ); |
|||
}, |
|||
getEditTokenCB : function (result) { |
|||
var pages = result.query.pages; |
|||
for (var id in pages) { // there should be only one, but we don't know its ID |
|||
// The edittoken only changes between logins |
|||
this.edittoken=pages[id].edittoken; |
|||
this.starttimestamp = pages[id].starttimestamp; |
|||
this.timestamp = pages[id].revisions[0]['timestamp']; |
|||
} |
|||
this.updateProgress( this.i18n.preparingToEdit.replace('%COUNT%', '') ); |
|||
this.nextTask(); |
|||
}, |
|||
/** |
|||
* Does a MediaWiki API request and passes the result to the supplied callback (method name). |
|||
* Uses POST requests for everything for simplicity. |
|||
* TODO: better error handling |
|||
**/ |
|||
doAPICall : function ( params, callback, ignore_missing_title ) { |
|||
var o = this; |
|||
params.format='json'; |
|||
$.ajax( { |
|||
url: this.apiURL, |
|||
cache: false, |
|||
dataType: 'json', |
|||
data: params, |
|||
type: 'POST', |
|||
success: function(result, status, x) { |
|||
if (!result) return o.fail( "Receive empty API response:\n" + x.responseText ); |
|||
// In case we get the mysterious 231 unknown error, just try again |
|||
if (result.error && result.error.info.indexOf('231') != -1) return setTimeout(function() { |
|||
o.doAPICall(params, callback); |
|||
},500); |
|||
if (result.error) { |
|||
if (result.error.code != 'missingtitle' || !ignore_missing_title) |
|||
return o.fail( "API request failed (" + result.error.code + "): " + result.error.info ); |
|||
} |
|||
if (result.edit && result.edit.spamblacklist) return o.fail( "The edit failed because " + result.edit.spamblacklist + " is on the Spam Blacklist"); |
|||
try { |
|||
o[callback](result); |
|||
} |
|||
catch (e) { |
|||
return o.fail(e); |
|||
} |
|||
}, |
|||
error: function(x, status, error) { |
|||
return o.fail( "API request returned code " + x.status + " " + status + "Error code is " + error); |
|||
} |
|||
}); |
}); |
||
}, |
}, |
||
apiURL: mw.config.get('wgServer') + mw.config.get('wgScriptPath') + "/api.php", |
|||
/** |
/** |
||
* Simple task queue. addTask() adds a new task to the queue, nextTask() executes |
* Simple task queue. addTask() adds a new task to the queue, nextTask() executes |
||
Linia 918: | Linia 868: | ||
document.body.style.cursor = 'wait'; |
document.body.style.cursor = 'wait'; |
||
function MyDialog( config ) { |
|||
$progress = $('<div id="del-req-progress"></div>') |
|||
MyDialog.super.call( this, config ); |
|||
.html('<div><div id="feedbackContainer">Szykuję się do edytowania...</div><div id="ajax-delete-warnings></div></div>') |
|||
} |
|||
.dialog( { |
|||
OO.inheritClass( MyDialog, OO.ui.Dialog ); |
|||
width: 600, |
|||
height: 200, |
|||
MyDialog.static.name = 'myDialog'; |
|||
minHeight: 90, |
|||
MyDialog.static.title = 'Trwa wykonywanie...'; |
|||
modal: false, |
|||
resizable: false, |
|||
MyDialog.prototype.initialize = function () { |
|||
draggable: false, |
|||
MyDialog.super.prototype.initialize.call( this ); |
|||
closeOnEscape: false, |
|||
this.content = new OO.ui.PanelLayout( { |
|||
dialogClass: "ajaxDeleteFeedback", |
|||
padded: true, |
|||
expanded: false |
|||
$(this).dialog("destroy"); |
|||
} ); |
|||
this.content.$element.append( '<div><div id="feedbackContainer">Szykuję się do edytowania...</div><div id="ajax-delete-warnings></div></div>' ); |
|||
} |
|||
this.$body.append( this.content.$element ); |
|||
}); |
|||
}; |
|||
$('.ui-dialog-titlebar').hide(); |
|||
MyDialog.prototype.getBodyHeight = function () { |
|||
return this.content.$element.outerHeight( true ); |
|||
}; |
|||
this.progressDialog = new MyDialog( { |
|||
size: 'medium' |
|||
} ); |
|||
this.windowManager = new OO.ui.WindowManager(); |
|||
$( document.body ).append( this.windowManager.$element ); |
|||
// Add the window to the window manager using the addWindows() method. |
|||
this.windowManager.addWindows( [ this.progressDialog ] ); |
|||
this.windowManager.openWindow( this.progressDialog ); |
|||
this.nextTask(); |
this.nextTask(); |
||
}, |
}, |
||
updateProgress : function (message) { |
updateProgress : function (message) { |
||
$('#feedbackContainer').html(message); |
$('#feedbackContainer').html(message); |
||
}, |
|||
/** |
|||
* Common API fail handler. |
|||
* @param {String} code |
|||
* @param {Object} error API response indicating an error (or an exception result). |
|||
*/ |
|||
apiFail : function ( code, errorData, functionName ) { |
|||
console.error('[dnu] API fail:', code, errorData, functionName); |
|||
const codeInfo = typeof code === 'string' || typeof code === 'number' ? code : JSON.stringify(code); |
|||
const errorInfo = typeof errorData === 'object' ? this.api.getErrorMessage( errorData ) : JSON.stringify(errorData); |
|||
return this.fail("API request returned error: " + errorInfo + " Error code is " + codeInfo + " Function: " + functionName); |
|||
}, |
}, |
||
Linia 949: | Linia 926: | ||
**/ |
**/ |
||
fail : function ( err ) { |
fail : function ( err ) { |
||
var that = this; |
|||
document.body.style.cursor = 'default'; |
document.body.style.cursor = 'default'; |
||
var msg = this.i18n.taskFailure[this.currentTask] || this.i18n.genericFailure; |
var msg = this.i18n.taskFailure[this.currentTask] || this.i18n.genericFailure; |
||
var fix = '';//(this.templateAdded ? this.i18n.completeRequestByHand : this.i18n.addTemplateByHand ); |
var fix = '';//(this.templateAdded ? this.i18n.completeRequestByHand : this.i18n.addTemplateByHand ); |
||
$('#feedbackContainer').html(msg + " " + fix + "<br>" + this.i18n.errorDetails + "< |
$('#feedbackContainer').html(msg + " " + fix + "<br>" + this.i18n.errorDetails + "<hr>" + mw.html.escape(err) + "<hr><a id=\"feedbackContainerfeedback\" href=\"" + mw.config.get('wgServer') + "/wiki/Dyskusja MediaWiki:Gadget-DelReqHandler.js\">" + this.i18n.errorReport +"</a>"); |
||
$('#feedbackContainer').addClass('ajaxDeleteError'); |
$('#feedbackContainer').addClass('ajaxDeleteError'); |
||
this.progressDialog.$body.resize(); |
|||
$('#feedbackContainerfeedback').click(function(e){ |
|||
e.preventDefault(); |
|||
mw.loader.using('mediawiki.feedback', function(){ |
|||
var feedback = new mw.Feedback({bugsLink: mw.config.get('wgServer') + "/wiki/Dyskusja MediaWiki:Gadget-DelReqHandler.js", title: new mw.Title("Dyskusja MediaWiki:Gadget-DelReqHandler.js")}); |
|||
feedback.launch({subject: 'Błąd', message: 'Wyświetla mi błąd podczas usuwania "'+that.page_processed+'" na "'+that.subpage+'"\n<pre>'+err+'</pre>'}); |
|||
}); |
|||
}); |
|||
// Allow some time to read the message |
// Allow some time to read the message |
||
Linia 993: | Linia 981: | ||
// Errors |
// Errors |
||
preparingToEdit : "Szykuję się do edytowania... ", |
preparingToEdit : "Szykuję się do edytowania... ", |
||
genericFailure : " |
genericFailure : "Wystąpił błąd.", |
||
taskFailure : { |
taskFailure : { |
||
}, |
}, |
||
errorDetails : "Szczegółowy opis błędu:", |
errorDetails : "Szczegółowy opis błędu:", |
||
errorReport : " |
errorReport : "Prześlij zgłoszenie" |
||
} |
} |
||
Linia 1004: | Linia 992: | ||
DelReqHandler.beginLoading(); |
DelReqHandler.beginLoading(); |
||
}) |
|||
} // End of idempotency check |
|||
// </nowiki> |
// </nowiki> |