User:Bosco-bot/common.js: Difference between revisions
Jump to navigation
Jump to search
Content deleted Content added
mNo edit summary Tag: Reverted |
mNo edit summary Tag: Reverted |
||
| Line 21: | Line 21: | ||
// |
// |
||
/** |
/** |
||
* MediaWiki JS helper: |
* MediaWiki JS helper: Request deletion |
||
* Adds a "Request deletion" tab to the page toolbar |
* Adds a "Request deletion" tab to the page toolbar. |
||
* and |
* When clicked, prompts for a reason and prepends {{delete|reason}}. |
||
*/ |
*/ |
||
mw.loader.using('mediawiki.util', function () { |
mw.loader.using(['mediawiki.util', 'mediawiki.api'], function () { |
||
// Add |
// Add the "Request deletion" tab in the actions menu |
||
mw.util.addPortletLink( |
var link = mw.util.addPortletLink( |
||
'p-cactions', // actions menu |
'p-cactions', // portlet: actions menu |
||
'#', // href |
'#', // href |
||
'Request deletion', // link text |
'Request deletion', // link text |
||
'ca- |
'ca-requestdeletion', // id |
||
'Requesting deletion' // tooltip |
'Requesting deletion' // tooltip |
||
); |
); |
||
// Attach click handler |
// Attach click handler to the new link |
||
$( |
$(link).on('click', function (e) { |
||
e.preventDefault(); |
e.preventDefault(); |
||
// Prompt user for reason |
// Prompt user for reason |
||
var reason = prompt('Enter reason for deletion:'); |
var reason = prompt('Enter reason for deletion:'); |
||
if (!reason) |
if (!reason) return; |
||
| ⚫ | |||
} |
|||
var pageName = mw.config.get('wgPageName'); |
|||
// Fetch current page content |
|||
new mw.Api().get({ |
new mw.Api().get({ |
||
action: 'query', |
action: 'query', |
||
prop: 'revisions', |
prop: 'revisions', |
||
rvprop: 'content', |
rvprop: 'content', |
||
rvslots: 'main', |
|||
| ⚫ | |||
}).done(function (data) { |
}).done(function (data) { |
||
var pages = data.query.pages; |
var pages = data.query.pages; |
||
var pageId = Object.keys(pages)[0]; |
var pageId = Object.keys(pages)[0]; |
||
var content = pages[pageId].revisions[0]['*']; |
var content = pages[pageId].revisions[0].slots.main['*']; |
||
// Prepend |
// Prepend delete template |
||
var newContent = '{{delete|' + reason + '}}\n' + content; |
var newContent = '{{delete|' + reason + '}}\n' + content; |
||
// Save |
// Save with fixed summary |
||
new mw.Api().postWithToken('csrf', { |
new mw.Api().postWithToken('csrf', { |
||
action: 'edit', |
action: 'edit', |
||
title: |
title: pageName, |
||
text: newContent, |
text: newContent, |
||
summary: 'Requesting deletion' |
summary: 'Requesting deletion' |
||
| Line 68: | Line 69: | ||
location.reload(); // reload to show template |
location.reload(); // reload to show template |
||
}).fail(function (err) { |
}).fail(function (err) { |
||
alert('Error saving page: ' + err); |
alert('Error saving page: ' + JSON.stringify(err)); |
||
}); |
}); |
||
}); |
}); |
||
Revision as of 03:58, 12 January 2026
// JWB
mw.loader.load('//en.wikipedia.org/w/index.php?title=User:Joeytje50/JWB.js&action=raw&ctype=text/javascript');
// MarkRights-zh
importScript('User:Bosco/MediaWiki:Gadget-MarkRights.js'); // Backlink: [[User:Bosco/MediaWiki:Gadget-MarkRights.js]]
// Mass block
mw.loader.load('//en.wikipedia.org/w/index.php?title=User:Timotheus_Canens/massblock.js&action=raw&ctype=text/javascript');
// AdvancedRollback
mw.loader.load('//dev.miraheze.org/w/index.php?title=User:PB2008/AdvancedRollback/auto.js&action=raw&ctype=text/javascript');
// Diffedit
mw.loader.load( '//meta.wikimedia.org/w/index.php?title=User:Jon_Harald_Søby/diffedit.js&action=raw&ctype=text/javascript' );
// Edit count
(function(editCount) {
if (editCount !== null) mw.loader.addStyleTag('#pt-mycontris>a::after, .menu__item--userContributions>span>span::after, #mw-mf-page-left .menu__item--userContributions>span::after {content: " (' + editCount + ')"}')
})(mw.config.get('wgUserEditCount'));
//
/**
* MediaWiki JS helper: Request deletion
* Adds a "Request deletion" tab to the page toolbar.
* When clicked, prompts for a reason and prepends {{delete|reason}}.
*/
mw.loader.using(['mediawiki.util', 'mediawiki.api'], function () {
// Add the "Request deletion" tab in the actions menu
var link = mw.util.addPortletLink(
'p-cactions', // portlet: actions menu
'#', // href
'Request deletion', // link text
'ca-requestdeletion', // id
'Requesting deletion' // tooltip
);
// Attach click handler to the new link
$(link).on('click', function (e) {
e.preventDefault();
// Prompt user for reason
var reason = prompt('Enter reason for deletion:');
if (!reason) return;
var pageName = mw.config.get('wgPageName');
// Fetch current page content
new mw.Api().get({
action: 'query',
prop: 'revisions',
rvprop: 'content',
rvslots: 'main',
titles: pageName
}).done(function (data) {
var pages = data.query.pages;
var pageId = Object.keys(pages)[0];
var content = pages[pageId].revisions[0].slots.main['*'];
// Prepend delete template
var newContent = '{{delete|' + reason + '}}\n' + content;
// Save with fixed summary
new mw.Api().postWithToken('csrf', {
action: 'edit',
title: pageName,
text: newContent,
summary: 'Requesting deletion'
}).done(function () {
location.reload(); // reload to show template
}).fail(function (err) {
alert('Error saving page: ' + JSON.stringify(err));
});
});
});
});