MediaWiki:Gadget-twinkleunlink.js: Difference between revisions
Jump to navigation
Jump to search
Content added Content deleted
(per w:en:Special:Diff/890787793 to avoid hardcoding maximum API limits) |
(update per enwiki) |
||
Line 1: | Line 1: | ||
//<nowiki> |
// <nowiki> |
||
(function($){ |
(function($) { |
||
Line 15: | Line 15: | ||
Twinkle.unlink = function twinkleunlink() { |
Twinkle.unlink = function twinkleunlink() { |
||
if |
if (mw.config.get('wgNamespaceNumber') < 0 || mw.config.get('wgPageName') === 'The Sims Wiki:Sandbox') { |
||
return; |
return; |
||
} |
} |
||
if (Morebits.userIsInGroup('content-moderator') || Morebits.userIsInGroup('sysop')) { |
if (Morebits.userIsInGroup('content-moderator') || Morebits.userIsInGroup('sysop')) { |
||
Twinkle.addPortletLink( |
Twinkle.addPortletLink(Twinkle.unlink.callback, 'Unlink', 'tw-unlink', 'Unlink backlinks'); |
||
} |
|||
}; |
}; |
||
Twinkle.unlink.getChecked2 = function twinkleunlinkGetChecked2( |
Twinkle.unlink.getChecked2 = function twinkleunlinkGetChecked2(nodelist) { |
||
if |
if (!(nodelist instanceof NodeList) && !(nodelist instanceof HTMLCollection)) { |
||
return nodelist.checked ? [ nodelist.values ] : []; |
return nodelist.checked ? [ nodelist.values ] : []; |
||
} |
} |
||
var result = []; |
var result = []; |
||
for(var i |
for (var i = 0; i < nodelist.length; ++i) { |
||
if( |
if (nodelist[i].checked) { |
||
result.push( |
result.push(nodelist[i].values); |
||
} |
} |
||
} |
} |
||
Line 38: | Line 38: | ||
// the parameter is used when invoking unlink from admin speedy |
// the parameter is used when invoking unlink from admin speedy |
||
Twinkle.unlink.callback = function(presetReason) { |
Twinkle.unlink.callback = function(presetReason) { |
||
var Window = new Morebits.simpleWindow( |
var Window = new Morebits.simpleWindow(600, 440); |
||
Window.setTitle( |
Window.setTitle('Unlink backlinks' + (mw.config.get('wgNamespaceNumber') === 6 ? ' and file usages' : '')); |
||
Window.setScriptName( |
Window.setScriptName('Twinkle'); |
||
Window.addFooterLink( |
Window.addFooterLink('Twinkle help', 'TSW:TW/DOC#unlink'); |
||
var form = new Morebits.quickForm( |
var form = new Morebits.quickForm(Twinkle.unlink.callback.evaluate); |
||
// prepend some basic documentation |
// prepend some basic documentation |
||
var node1 = Morebits.htmlNode( |
var node1 = Morebits.htmlNode('code', '[[' + Morebits.pageNameNorm + '|link text]]'); |
||
var node2 = Morebits.htmlNode( |
var node2 = Morebits.htmlNode('code', 'link text'); |
||
node1.style.fontFamily = node2.style.fontFamily = |
node1.style.fontFamily = node2.style.fontFamily = 'monospace'; |
||
node1.style.fontStyle = node2.style.fontStyle = |
node1.style.fontStyle = node2.style.fontStyle = 'normal'; |
||
form.append( |
form.append({ |
||
type: 'div', |
type: 'div', |
||
style: 'margin-bottom: 0.5em', |
style: 'margin-bottom: 0.5em', |
||
label: [ |
label: [ |
||
'This tool allows you to unlink all incoming links ("backlinks") that point to this page' + |
'This tool allows you to unlink all incoming links ("backlinks") that point to this page' + |
||
(mw.config.get('wgNamespaceNumber') === 6 ? |
(mw.config.get('wgNamespaceNumber') === 6 ? ', and/or hide all inclusions of this file by wrapping them in <!-- --> comment markup' : '') + |
||
'. For instance, ', |
|||
node1, |
node1, |
||
' would become ', |
|||
node2, |
node2, |
||
'. Use it with caution.' |
|||
] |
] |
||
} |
}); |
||
form.append( |
form.append({ |
||
type: 'input', |
type: 'input', |
||
name: 'reason', |
name: 'reason', |
||
label: 'Reason: ', |
label: 'Reason: ', |
||
value: |
value: presetReason ? presetReason : '', |
||
size: 60 |
size: 60 |
||
} |
}); |
||
var query; |
var query; |
||
if(mw.config.get('wgNamespaceNumber') === 6) { // File: |
if (mw.config.get('wgNamespaceNumber') === 6) { // File: |
||
query = { |
query = { |
||
'action': 'query', |
'action': 'query', |
||
Line 96: | Line 96: | ||
}; |
}; |
||
} |
} |
||
var wikipedia_api = new Morebits.wiki.api( |
var wikipedia_api = new Morebits.wiki.api('Grabbing backlinks', query, Twinkle.unlink.callbacks.display.backlinks); |
||
wikipedia_api.params = { form: form, Window: Window, image: mw.config.get('wgNamespaceNumber') === 6 }; |
wikipedia_api.params = { form: form, Window: Window, image: mw.config.get('wgNamespaceNumber') === 6 }; |
||
wikipedia_api.post(); |
wikipedia_api.post(); |
||
var root = document.createElement( |
var root = document.createElement('div'); |
||
root.style.padding = '15px'; // just so it doesn't look broken |
root.style.padding = '15px'; // just so it doesn't look broken |
||
Morebits.status.init( |
Morebits.status.init(root); |
||
wikipedia_api.statelem.status( |
wikipedia_api.statelem.status('loading...'); |
||
Window.setContent( |
Window.setContent(root); |
||
Window.display(); |
Window.display(); |
||
}; |
}; |
||
Line 111: | Line 111: | ||
var reason = event.target.reason.value; |
var reason = event.target.reason.value; |
||
if (!reason) { |
if (!reason) { |
||
alert( |
alert('You must specify a reason for unlinking.'); |
||
return; |
return; |
||
} |
} |
||
var backlinks = [], imageusage = []; |
var backlinks = [], imageusage = []; |
||
if( |
if (event.target.backlinks) { |
||
backlinks = Twinkle.unlink.getChecked2(event.target.backlinks); |
backlinks = Twinkle.unlink.getChecked2(event.target.backlinks); |
||
} |
} |
||
if( |
if (event.target.imageusage) { |
||
imageusage = Twinkle.unlink.getChecked2(event.target.imageusage); |
imageusage = Twinkle.unlink.getChecked2(event.target.imageusage); |
||
} |
} |
||
Morebits.simpleWindow.setButtonsEnabled( |
Morebits.simpleWindow.setButtonsEnabled(false); |
||
Morebits.status.init( |
Morebits.status.init(event.target); |
||
var pages = Morebits.array.uniq(backlinks.concat(imageusage)); |
var pages = Morebits.array.uniq(backlinks.concat(imageusage)); |
||
var unlinker = new Morebits.batchOperation( |
var unlinker = new Morebits.batchOperation('Unlinking backlinks' + (imageusage ? ' and instances of file usage' : '')); |
||
unlinker.setOption( |
unlinker.setOption('preserveIndividualStatusLines', true); |
||
unlinker.setPageList(pages); |
unlinker.setPageList(pages); |
||
var params = { reason: reason, unlinker: unlinker }; |
var params = { reason: reason, unlinker: unlinker }; |
||
unlinker.run(function(pageName) { |
unlinker.run(function(pageName) { |
||
var wikipedia_page = new Morebits.wiki.page(pageName, |
var wikipedia_page = new Morebits.wiki.page(pageName, 'Unlinking in article "' + pageName + '"'); |
||
wikipedia_page.setBotEdit(true); // unlink considered a floody operation |
wikipedia_page.setBotEdit(true); // unlink considered a floody operation |
||
var innerParams = $.extend({}, params); |
var innerParams = $.extend({}, params); |
||
Line 150: | Line 150: | ||
var list, namespaces, i; |
var list, namespaces, i; |
||
if( |
if (apiobj.params.image) { |
||
var imageusage = $(xmlDoc).find('query imageusage iu'); |
var imageusage = $(xmlDoc).find('query imageusage iu'); |
||
list = []; |
list = []; |
||
for ( |
for (i = 0; i < imageusage.length; ++i) { |
||
var usagetitle = imageusage[i].getAttribute('title'); |
var usagetitle = imageusage[i].getAttribute('title'); |
||
list.push( |
list.push({ label: usagetitle, value: usagetitle, checked: true }); |
||
} |
} |
||
if (!list.length) |
if (!list.length) { |
||
⚫ | |||
{ |
} else { |
||
⚫ | |||
⚫ | |||
} |
|||
else |
|||
{ |
|||
⚫ | |||
namespaces = []; |
namespaces = []; |
||
$.each(Twinkle.getPref('unlinkNamespaces'), function(k, v) { |
$.each(Twinkle.getPref('unlinkNamespaces'), function(k, v) { |
||
namespaces.push( |
namespaces.push(v === '0' ? '(Article)' : mw.config.get('wgFormattedNamespaces')[v]); |
||
}); |
}); |
||
apiobj.params.form.append( |
apiobj.params.form.append({ |
||
type: 'div', |
type: 'div', |
||
label: |
label: 'Selected namespaces: ' + namespaces.join(', '), |
||
tooltip: |
tooltip: 'You can change this with your Twinkle preferences, at [[TSW:TWPREFS]]' |
||
}); |
}); |
||
if ($(xmlDoc).find('query-continue').length) { |
if ($(xmlDoc).find('query-continue').length) { |
||
apiobj.params.form.append( |
apiobj.params.form.append({ |
||
type: 'div', |
type: 'div', |
||
label: |
label: 'First ' + list.length.toString() + ' file usages shown.' |
||
}); |
}); |
||
} |
} |
||
apiobj.params.form.append({ |
apiobj.params.form.append({ |
||
type: 'button', |
type: 'button', |
||
label: |
label: 'Select All', |
||
event: function(e) { |
event: function(e) { |
||
$(Morebits.quickForm.getElements(e.target.form, |
$(Morebits.quickForm.getElements(e.target.form, 'imageusage')).prop('checked', true); |
||
} |
} |
||
}); |
}); |
||
apiobj.params.form.append({ |
apiobj.params.form.append({ |
||
type: 'button', |
type: 'button', |
||
label: |
label: 'Deselect All', |
||
event: function(e) { |
event: function(e) { |
||
$(Morebits.quickForm.getElements(e.target.form, |
$(Morebits.quickForm.getElements(e.target.form, 'imageusage')).prop('checked', false); |
||
} |
} |
||
}); |
}); |
||
Line 203: | Line 200: | ||
var backlinks = $(xmlDoc).find('query backlinks bl'); |
var backlinks = $(xmlDoc).find('query backlinks bl'); |
||
if( |
if (backlinks.length > 0) { |
||
list = []; |
list = []; |
||
for ( |
for (i = 0; i < backlinks.length; ++i) { |
||
var title = backlinks[i].getAttribute('title'); |
var title = backlinks[i].getAttribute('title'); |
||
list.push( |
list.push({ label: title, value: title, checked: true }); |
||
} |
} |
||
apiobj.params.form.append( |
apiobj.params.form.append({ type: 'header', label: 'Backlinks' }); |
||
namespaces = []; |
namespaces = []; |
||
$.each(Twinkle.getPref('unlinkNamespaces'), function(k, v) { |
$.each(Twinkle.getPref('unlinkNamespaces'), function(k, v) { |
||
namespaces.push( |
namespaces.push(v === '0' ? '(Article)' : mw.config.get('wgFormattedNamespaces')[v]); |
||
}); |
}); |
||
apiobj.params.form.append( |
apiobj.params.form.append({ |
||
type: 'div', |
type: 'div', |
||
label: |
label: 'Selected namespaces: ' + namespaces.join(', '), |
||
tooltip: |
tooltip: 'You can change this with your Twinkle preferences, at [[TSW:TWPREFS]]' |
||
}); |
}); |
||
if ($(xmlDoc).find('query-continue').length) { |
if ($(xmlDoc).find('query-continue').length) { |
||
apiobj.params.form.append( |
apiobj.params.form.append({ |
||
type: 'div', |
type: 'div', |
||
label: |
label: 'First ' + list.length.toString() + ' backlinks shown.' |
||
}); |
}); |
||
} |
} |
||
apiobj.params.form.append({ |
apiobj.params.form.append({ |
||
type: 'button', |
type: 'button', |
||
label: |
label: 'Select All', |
||
event: function(e) { |
|||
$(Morebits.quickForm.getElements(e.target.form, 'backlinks')).prop('checked', true); |
|||
} |
|||
}); |
}); |
||
apiobj.params.form.append({ |
apiobj.params.form.append({ |
||
type: 'button', |
type: 'button', |
||
label: |
label: 'Deselect All', |
||
event: function(e) { |
|||
$(Morebits.quickForm.getElements(e.target.form, 'backlinks')).prop('checked', false); |
|||
} |
|||
}); |
}); |
||
apiobj.params.form.append({ |
apiobj.params.form.append({ |
||
Line 245: | Line 242: | ||
}); |
}); |
||
havecontent = true; |
havecontent = true; |
||
} |
} else { |
||
⚫ | |||
else |
|||
{ |
|||
⚫ | |||
} |
} |
||
if (havecontent) { |
if (havecontent) { |
||
apiobj.params.form.append( |
apiobj.params.form.append({ type: 'submit' }); |
||
} |
} |
||
var result = apiobj.params.form.render(); |
var result = apiobj.params.form.render(); |
||
apiobj.params.Window.setContent( |
apiobj.params.Window.setContent(result); |
||
Morebits.checkboxShiftClickSupport($("input[name='imageusage']", result)); |
Morebits.checkboxShiftClickSupport($("input[name='imageusage']", result)); |
||
Line 268: | Line 263: | ||
var wikiPage = new Morebits.wikitext.page(oldtext); |
var wikiPage = new Morebits.wikitext.page(oldtext); |
||
var summaryText = |
var summaryText = '', warningString = false; |
||
var text; |
var text; |
||
Line 277: | Line 272: | ||
// did we actually make any changes? |
// did we actually make any changes? |
||
if (text === oldtext) { |
if (text === oldtext) { |
||
warningString = |
warningString = 'file usages'; |
||
} else { |
} else { |
||
summaryText = |
summaryText = 'Commenting out use(s) of file'; |
||
oldtext = text; |
oldtext = text; |
||
} |
} |
||
Line 290: | Line 285: | ||
// did we actually make any changes? |
// did we actually make any changes? |
||
if (text === oldtext) { |
if (text === oldtext) { |
||
warningString = |
warningString = warningString ? 'backlinks or file usages' : 'backlinks'; |
||
} else { |
} else { |
||
summaryText = (summaryText ? |
summaryText = (summaryText ? summaryText + ' / ' : '') + 'Removing link(s) to'; |
||
oldtext = text; |
oldtext = text; |
||
} |
} |
||
Line 299: | Line 294: | ||
if (warningString) { |
if (warningString) { |
||
// nothing to do! |
// nothing to do! |
||
pageobj.getStatusElement().error("Didn't find any " + warningString + |
pageobj.getStatusElement().error("Didn't find any " + warningString + ' on the page.'); |
||
params.unlinker.workerFailure(pageobj); |
params.unlinker.workerFailure(pageobj); |
||
return; |
return; |
||
Line 305: | Line 300: | ||
pageobj.setPageText(text); |
pageobj.setPageText(text); |
||
pageobj.setEditSummary(summaryText + |
pageobj.setEditSummary(summaryText + ' "' + Morebits.pageNameNorm + '": ' + params.reason + '.' + Twinkle.getPref('summaryAd')); |
||
pageobj.setCreateOption('nocreate'); |
pageobj.setCreateOption('nocreate'); |
||
pageobj.save(params.unlinker.workerSuccess, params.unlinker.workerFailure); |
pageobj.save(params.unlinker.workerSuccess, params.unlinker.workerFailure); |
||
Line 313: | Line 308: | ||
//</nowiki> |
// </nowiki> |
Latest revision as of 21:12, 19 August 2019
// <nowiki>
(function($) {
/*
****************************************
*** twinkleunlink.js: Unlink module
****************************************
* Mode of invocation: Tab ("Unlink")
* Active on: Non-special pages, except Wikipedia:Sandbox
* Config directives in: TwinkleConfig
*/
Twinkle.unlink = function twinkleunlink() {
if (mw.config.get('wgNamespaceNumber') < 0 || mw.config.get('wgPageName') === 'The Sims Wiki:Sandbox') {
return;
}
if (Morebits.userIsInGroup('content-moderator') || Morebits.userIsInGroup('sysop')) {
Twinkle.addPortletLink(Twinkle.unlink.callback, 'Unlink', 'tw-unlink', 'Unlink backlinks');
}
};
Twinkle.unlink.getChecked2 = function twinkleunlinkGetChecked2(nodelist) {
if (!(nodelist instanceof NodeList) && !(nodelist instanceof HTMLCollection)) {
return nodelist.checked ? [ nodelist.values ] : [];
}
var result = [];
for (var i = 0; i < nodelist.length; ++i) {
if (nodelist[i].checked) {
result.push(nodelist[i].values);
}
}
return result;
};
// the parameter is used when invoking unlink from admin speedy
Twinkle.unlink.callback = function(presetReason) {
var Window = new Morebits.simpleWindow(600, 440);
Window.setTitle('Unlink backlinks' + (mw.config.get('wgNamespaceNumber') === 6 ? ' and file usages' : ''));
Window.setScriptName('Twinkle');
Window.addFooterLink('Twinkle help', 'TSW:TW/DOC#unlink');
var form = new Morebits.quickForm(Twinkle.unlink.callback.evaluate);
// prepend some basic documentation
var node1 = Morebits.htmlNode('code', '[[' + Morebits.pageNameNorm + '|link text]]');
var node2 = Morebits.htmlNode('code', 'link text');
node1.style.fontFamily = node2.style.fontFamily = 'monospace';
node1.style.fontStyle = node2.style.fontStyle = 'normal';
form.append({
type: 'div',
style: 'margin-bottom: 0.5em',
label: [
'This tool allows you to unlink all incoming links ("backlinks") that point to this page' +
(mw.config.get('wgNamespaceNumber') === 6 ? ', and/or hide all inclusions of this file by wrapping them in <!-- --> comment markup' : '') +
'. For instance, ',
node1,
' would become ',
node2,
'. Use it with caution.'
]
});
form.append({
type: 'input',
name: 'reason',
label: 'Reason: ',
value: presetReason ? presetReason : '',
size: 60
});
var query;
if (mw.config.get('wgNamespaceNumber') === 6) { // File:
query = {
'action': 'query',
'list': [ 'backlinks', 'imageusage' ],
'bltitle': mw.config.get('wgPageName'),
'iutitle': mw.config.get('wgPageName'),
'bllimit': 'max', // 500 is max for normal users, 5000 for bots and sysops
'iulimit': 'max', // 500 is max for normal users, 5000 for bots and sysops
'blnamespace': Twinkle.getPref('unlinkNamespaces'),
'iunamespace': Twinkle.getPref('unlinkNamespaces'),
'rawcontinue': true
};
} else {
query = {
'action': 'query',
'list': 'backlinks',
'bltitle': mw.config.get('wgPageName'),
'blfilterredir': 'nonredirects',
'bllimit': 'max', // 500 is max for normal users, 5000 for bots and sysops
'blnamespace': Twinkle.getPref('unlinkNamespaces'),
'rawcontinue': true
};
}
var wikipedia_api = new Morebits.wiki.api('Grabbing backlinks', query, Twinkle.unlink.callbacks.display.backlinks);
wikipedia_api.params = { form: form, Window: Window, image: mw.config.get('wgNamespaceNumber') === 6 };
wikipedia_api.post();
var root = document.createElement('div');
root.style.padding = '15px'; // just so it doesn't look broken
Morebits.status.init(root);
wikipedia_api.statelem.status('loading...');
Window.setContent(root);
Window.display();
};
Twinkle.unlink.callback.evaluate = function twinkleunlinkCallbackEvaluate(event) {
var reason = event.target.reason.value;
if (!reason) {
alert('You must specify a reason for unlinking.');
return;
}
var backlinks = [], imageusage = [];
if (event.target.backlinks) {
backlinks = Twinkle.unlink.getChecked2(event.target.backlinks);
}
if (event.target.imageusage) {
imageusage = Twinkle.unlink.getChecked2(event.target.imageusage);
}
Morebits.simpleWindow.setButtonsEnabled(false);
Morebits.status.init(event.target);
var pages = Morebits.array.uniq(backlinks.concat(imageusage));
var unlinker = new Morebits.batchOperation('Unlinking backlinks' + (imageusage ? ' and instances of file usage' : ''));
unlinker.setOption('preserveIndividualStatusLines', true);
unlinker.setPageList(pages);
var params = { reason: reason, unlinker: unlinker };
unlinker.run(function(pageName) {
var wikipedia_page = new Morebits.wiki.page(pageName, 'Unlinking in article "' + pageName + '"');
wikipedia_page.setBotEdit(true); // unlink considered a floody operation
var innerParams = $.extend({}, params);
innerParams.doBacklinks = backlinks && backlinks.indexOf(pageName) !== -1;
innerParams.doImageusage = imageusage && imageusage.indexOf(pageName) !== -1;
wikipedia_page.setCallbackParameters(innerParams);
wikipedia_page.load(Twinkle.unlink.callbacks.unlinkBacklinks);
});
};
Twinkle.unlink.callbacks = {
display: {
backlinks: function twinkleunlinkCallbackDisplayBacklinks(apiobj) {
var xmlDoc = apiobj.responseXML;
var havecontent = false;
var list, namespaces, i;
if (apiobj.params.image) {
var imageusage = $(xmlDoc).find('query imageusage iu');
list = [];
for (i = 0; i < imageusage.length; ++i) {
var usagetitle = imageusage[i].getAttribute('title');
list.push({ label: usagetitle, value: usagetitle, checked: true });
}
if (!list.length) {
apiobj.params.form.append({ type: 'div', label: 'No instances of file usage found.' });
} else {
apiobj.params.form.append({ type: 'header', label: 'File usage' });
namespaces = [];
$.each(Twinkle.getPref('unlinkNamespaces'), function(k, v) {
namespaces.push(v === '0' ? '(Article)' : mw.config.get('wgFormattedNamespaces')[v]);
});
apiobj.params.form.append({
type: 'div',
label: 'Selected namespaces: ' + namespaces.join(', '),
tooltip: 'You can change this with your Twinkle preferences, at [[TSW:TWPREFS]]'
});
if ($(xmlDoc).find('query-continue').length) {
apiobj.params.form.append({
type: 'div',
label: 'First ' + list.length.toString() + ' file usages shown.'
});
}
apiobj.params.form.append({
type: 'button',
label: 'Select All',
event: function(e) {
$(Morebits.quickForm.getElements(e.target.form, 'imageusage')).prop('checked', true);
}
});
apiobj.params.form.append({
type: 'button',
label: 'Deselect All',
event: function(e) {
$(Morebits.quickForm.getElements(e.target.form, 'imageusage')).prop('checked', false);
}
});
apiobj.params.form.append({
type: 'checkbox',
name: 'imageusage',
list: list
});
havecontent = true;
}
}
var backlinks = $(xmlDoc).find('query backlinks bl');
if (backlinks.length > 0) {
list = [];
for (i = 0; i < backlinks.length; ++i) {
var title = backlinks[i].getAttribute('title');
list.push({ label: title, value: title, checked: true });
}
apiobj.params.form.append({ type: 'header', label: 'Backlinks' });
namespaces = [];
$.each(Twinkle.getPref('unlinkNamespaces'), function(k, v) {
namespaces.push(v === '0' ? '(Article)' : mw.config.get('wgFormattedNamespaces')[v]);
});
apiobj.params.form.append({
type: 'div',
label: 'Selected namespaces: ' + namespaces.join(', '),
tooltip: 'You can change this with your Twinkle preferences, at [[TSW:TWPREFS]]'
});
if ($(xmlDoc).find('query-continue').length) {
apiobj.params.form.append({
type: 'div',
label: 'First ' + list.length.toString() + ' backlinks shown.'
});
}
apiobj.params.form.append({
type: 'button',
label: 'Select All',
event: function(e) {
$(Morebits.quickForm.getElements(e.target.form, 'backlinks')).prop('checked', true);
}
});
apiobj.params.form.append({
type: 'button',
label: 'Deselect All',
event: function(e) {
$(Morebits.quickForm.getElements(e.target.form, 'backlinks')).prop('checked', false);
}
});
apiobj.params.form.append({
type: 'checkbox',
name: 'backlinks',
list: list
});
havecontent = true;
} else {
apiobj.params.form.append({ type: 'div', label: 'No backlinks found.' });
}
if (havecontent) {
apiobj.params.form.append({ type: 'submit' });
}
var result = apiobj.params.form.render();
apiobj.params.Window.setContent(result);
Morebits.checkboxShiftClickSupport($("input[name='imageusage']", result));
Morebits.checkboxShiftClickSupport($("input[name='backlinks']", result));
}
},
unlinkBacklinks: function twinkleunlinkCallbackUnlinkBacklinks(pageobj) {
var oldtext = pageobj.getPageText();
var params = pageobj.getCallbackParameters();
var wikiPage = new Morebits.wikitext.page(oldtext);
var summaryText = '', warningString = false;
var text;
// remove image usages
if (params.doImageusage) {
wikiPage.commentOutImage(mw.config.get('wgTitle'), 'Commented out');
text = wikiPage.getText();
// did we actually make any changes?
if (text === oldtext) {
warningString = 'file usages';
} else {
summaryText = 'Commenting out use(s) of file';
oldtext = text;
}
}
// remove backlinks
if (params.doBacklinks) {
wikiPage.removeLink(Morebits.pageNameNorm);
text = wikiPage.getText();
// did we actually make any changes?
if (text === oldtext) {
warningString = warningString ? 'backlinks or file usages' : 'backlinks';
} else {
summaryText = (summaryText ? summaryText + ' / ' : '') + 'Removing link(s) to';
oldtext = text;
}
}
if (warningString) {
// nothing to do!
pageobj.getStatusElement().error("Didn't find any " + warningString + ' on the page.');
params.unlinker.workerFailure(pageobj);
return;
}
pageobj.setPageText(text);
pageobj.setEditSummary(summaryText + ' "' + Morebits.pageNameNorm + '": ' + params.reason + '.' + Twinkle.getPref('summaryAd'));
pageobj.setCreateOption('nocreate');
pageobj.save(params.unlinker.workerSuccess, params.unlinker.workerFailure);
}
};
})(jQuery);
// </nowiki>