14,061
edits
m (1 revision imported) |
(Localise) |
||
(4 intermediate revisions by 2 users not shown) | |||
Line 10: | Line 10: | ||
**************************************** | **************************************** | ||
* Mode of invocation: Tab ("Unlink") | * Mode of invocation: Tab ("Unlink") | ||
* Active on: Non-special pages, except | * Active on: Non-special pages, except Sarkarverse:Sandbox | ||
* Config directives in: TwinkleConfig | * Config directives in: TwinkleConfig | ||
*/ | */ | ||
Twinkle.unlink = function twinkleunlink() { | Twinkle.unlink = function twinkleunlink() { | ||
if( mw.config.get('wgNamespaceNumber') < 0 || mw.config.get('wgPageName') === ' | if( mw.config.get('wgNamespaceNumber') < 0 || mw.config.get('wgPageName') === 'Sarkarverse:Sandbox' ) { | ||
return; | return; | ||
} | } | ||
Twinkle.addPortletLink( Twinkle.unlink.callback, "Unlink", "tw-unlink", "Unlink backlinks" ); | // Restrict to extended confirmed users. This is done here instead of above to avoid an unnecessary API call. | ||
mw.user.getRights().then(function (rights) { | |||
if( rights.indexOf('extendedconfirmed') !== -1 ) { | |||
Twinkle.addPortletLink( Twinkle.unlink.callback, "Unlink", "tw-unlink", "Unlink backlinks" ); | |||
} | |||
}); | |||
}; | }; | ||
Line 39: | Line 44: | ||
Window.setTitle( "Unlink backlinks" + (mw.config.get('wgNamespaceNumber') === 6 ? " and file usages" : "") ); | Window.setTitle( "Unlink backlinks" + (mw.config.get('wgNamespaceNumber') === 6 ? " and file usages" : "") ); | ||
Window.setScriptName( "Twinkle" ); | Window.setScriptName( "Twinkle" ); | ||
Window.addFooterLink( "Twinkle help", " | Window.addFooterLink( "Twinkle help", "SV:TW/DOC#unlink" ); | ||
var form = new Morebits.quickForm( Twinkle.unlink.callback.evaluate ); | var form = new Morebits.quickForm( Twinkle.unlink.callback.evaluate ); | ||
// prepend some basic documentation | // prepend some basic documentation | ||
var node1 = Morebits.htmlNode("code", "[[" + Morebits.pageNameNorm + "|link text]]") | var node1 = Morebits.htmlNode("code", "[[" + Morebits.pageNameNorm + "|link text]]"); | ||
var node2 = Morebits.htmlNode("code", "link text"); | var node2 = Morebits.htmlNode("code", "link text"); | ||
node1.style.fontFamily = node2.style.fontFamily = "monospace"; | node1.style.fontFamily = node2.style.fontFamily = "monospace"; | ||
Line 51: | Line 56: | ||
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 ? ", and/or hide all inclusions of this file by wrapping them in <!-- --> comment markup" : "") + | (mw.config.get('wgNamespaceNumber') === 6 ? ", and/or hide all inclusions of this file by wrapping them in <!-- --> comment markup" : "") + | ||
". For instance, ", | ". For instance, ", | ||
node1, | node1, | ||
Line 80: | Line 85: | ||
'iulimit': Morebits.userIsInGroup( 'sysop' ) ? 5000 : 500, // 500 is max for normal users, 5000 for bots and sysops | 'iulimit': Morebits.userIsInGroup( 'sysop' ) ? 5000 : 500, // 500 is max for normal users, 5000 for bots and sysops | ||
'blnamespace': Twinkle.getPref('unlinkNamespaces'), | 'blnamespace': Twinkle.getPref('unlinkNamespaces'), | ||
'iunamespace': Twinkle.getPref('unlinkNamespaces') | 'iunamespace': Twinkle.getPref('unlinkNamespaces'), | ||
'rawcontinue': true | |||
}; | }; | ||
} else { | } else { | ||
Line 89: | Line 95: | ||
'blfilterredir': 'nonredirects', | 'blfilterredir': 'nonredirects', | ||
'bllimit': Morebits.userIsInGroup( 'sysop' ) ? 5000 : 500, // 500 is max for normal users, 5000 for bots and sysops | 'bllimit': Morebits.userIsInGroup( 'sysop' ) ? 5000 : 500, // 500 is max for normal users, 5000 for bots and sysops | ||
'blnamespace': Twinkle.getPref('unlinkNamespaces') | 'blnamespace': Twinkle.getPref('unlinkNamespaces'), | ||
'rawcontinue': true | |||
}; | }; | ||
} | } | ||
Line 105: | Line 112: | ||
Twinkle.unlink.callback.evaluate = function twinkleunlinkCallbackEvaluate(event) { | Twinkle.unlink.callback.evaluate = function twinkleunlinkCallbackEvaluate(event) { | ||
var reason = event.target.reason.value; | var reason = event.target.reason.value; | ||
if (!reason) { | if (!reason) { | ||
Line 138: | Line 118: | ||
} | } | ||
var backlinks, imageusage; | var backlinks = [], imageusage = []; | ||
if( event.target.backlinks ) { | if( event.target.backlinks ) { | ||
backlinks = Twinkle.unlink.getChecked2(event.target.backlinks); | backlinks = Twinkle.unlink.getChecked2(event.target.backlinks); | ||
Line 148: | Line 128: | ||
Morebits.simpleWindow.setButtonsEnabled( false ); | Morebits.simpleWindow.setButtonsEnabled( false ); | ||
Morebits.status.init( event.target ); | Morebits.status.init( event.target ); | ||
Morebits. | |||
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 = { | Twinkle.unlink.callbacks = { | ||
Line 189: | Line 174: | ||
type: 'div', | type: 'div', | ||
label: "Selected namespaces: " + namespaces.join(', '), | label: "Selected namespaces: " + namespaces.join(', '), | ||
tooltip: "You can change this with your Twinkle preferences, at [[ | tooltip: "You can change this with your Twinkle preferences, at [[SV:TWPREFS]]" | ||
}); | }); | ||
if ($(xmlDoc).find('query-continue').length) { | if ($(xmlDoc).find('query-continue').length) { | ||
Line 235: | Line 220: | ||
type: 'div', | type: 'div', | ||
label: "Selected namespaces: " + namespaces.join(', '), | label: "Selected namespaces: " + namespaces.join(', '), | ||
tooltip: "You can change this with your Twinkle preferences, at [[ | tooltip: "You can change this with your Twinkle preferences, at [[SV:TWPREFS]]" | ||
}); | }); | ||
if ($(xmlDoc).find('query-continue').length) { | if ($(xmlDoc).find('query-continue').length) { | ||
Line 282: | Line 267: | ||
}, | }, | ||
unlinkBacklinks: function twinkleunlinkCallbackUnlinkBacklinks(pageobj) { | unlinkBacklinks: function twinkleunlinkCallbackUnlinkBacklinks(pageobj) { | ||
var | var oldtext = pageobj.getPageText(); | ||
var params = pageobj.getCallbackParameters(); | 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."); | |||
if ( | params.unlinker.workerFailure(pageobj); | ||
// | |||
return; | return; | ||
} | } | ||
pageobj.setPageText(text); | pageobj.setPageText(text); | ||
pageobj.setEditSummary(" | pageobj.setEditSummary(summaryText + " \"" + Morebits.pageNameNorm + "\": " + params.reason + "." + Twinkle.getPref('summaryAd')); | ||
pageobj.setCreateOption('nocreate'); | pageobj.setCreateOption('nocreate'); | ||
pageobj.save( | pageobj.save(params.unlinker.workerSuccess, params.unlinker.workerFailure); | ||
} | } | ||
}; | }; |