// ReplyButtons.js - Adds custom buttons to the reply widget
// License: CC-BY-SA-4.0
(function() {
console.log('ReplyButtons.js loading...'); // Debug log
mw.hook('wikipage.content').add(function () {
if (mw.config.get('wgDiscussionToolsFeaturesEnabled')) {
console.log('Discussion tools enabled, attempting to load...'); // Debug log
mw.loader.using(['ext.discussionTools.ReplyWidget'], () => {
console.log('Reply widget loaded, creating buttons...'); // Debug log
// Helper function to create tools from config
function createToolFromConfig(config) {
// Create command
const CommandClass = function() {
ve.ui.Command.call(this, config.name);
};
OO.inheritClass(CommandClass, ve.ui.Command);
CommandClass.prototype.execute = function() {
const target = ve.init.target;
if (target) {
const surface = target.getSurface();
const surfaceModel = surface.getModel();
const content = typeof config.insertContent === 'function'
? config.insertContent()
: config.insertText;
surfaceModel.getFragment()
.collapseToEnd()
.insertContent(content)
.collapseToEnd()
.select();
}
return true;
};
ve.ui.commandRegistry.register(new CommandClass());
// Create tool
const ToolClass = function() {
ve.ui.Tool.apply(this, arguments);
};
OO.inheritClass(ToolClass, ve.ui.Tool);
ToolClass.static.name = config.name;
ToolClass.static.icon = config.icon;
ToolClass.static.title = config.title;
ToolClass.static.commandName = config.name;
ve.ui.toolFactory.register(ToolClass);
// Try different toolbar groups
try {
const toolbarGroups = mw.loader.moduleRegistry['ext.discussionTools.ReplyWidget']
.packageExports['dt-ve/CommentTarget.js'].static.toolbarGroups;
// Add to format group (usually group 1)
if (toolbarGroups[1] && toolbarGroups[1].include) {
toolbarGroups[1].include.push(config.name);
}
console.log(`Added tool ${config.name} to toolbar`); // Debug log
} catch (e) {
console.error('Error adding tool to toolbar:', e);
}
}
// Define your custom buttons here
const tools = [
{
name: 'welcomeTool', // Changed names to be more unique
icon: 'userAdd',
title: 'Welcome',
insertText: 'Hi {{BASEPAGENAME}}! I would like to welcome you to the Wikipedia community.
As you get started, you may find this short tutorial helpful:
{{Clickable button 2|Help:Introduction|Learn more about editing|class=mw-ui-progressive|style=margin-left: 1.6em;}}
Alternatively, the [[Wikipedia:Contributing to Wikipedia|contributing to Wikipedia]] page covers the same topics.
If you have any questions, we have a friendly space where experienced editors can help you here:
{{Clickable button 2|Wikipedia:Teahouse|Get help at the Teahouse|style=margin-left: 1.6em;}}
If you are not sure where to help out, you can find a task here:
{{Clickable button 2|Wikipedia:Task Center|Volunteer at the Task Center|style=margin-left: 1.6em;}}
Happy editing! <!-- Template:Welcome--> [[User:Polygnotus|Polygnotus]] ([[User talk:Polygnotus|talk]]) 21:44, 17 February 2025 (UTC)'
},
{
name: 'externalLinkTool',
icon: 'linkExternal',
title: 'External Link Warning',
insertText: '[[File:Information.svg|25px|alt=Information icon]] Hello, I'm [[User:Polygnotus|Polygnotus]]. I wanted to let you know that I removed one or more external links you added to the main body of an article. Generally, any relevant external links should be listed in an "External links" section at the end of the article and meet the [[Wikipedia:External links|external links guidelines]]. Links within the body of an article should be [[Wikipedia:Manual of Style/Linking|internal wikilinks]]. Normally, [[WP:ELMIN|only one official link is included]]. If you think I made a mistake, or if you have any questions, you can leave me a message on [[User_talk:Polygnotus|my talk page]]. Thank you. <!-- Template:Uw-elinbody --> [[User:Polygnotus|Polygnotus]] ([[User talk:Polygnotus|talk]]) 06:30, 10 October 2024 (UTC) [[User:Polygnotus|Polygnotus]] ([[User talk:Polygnotus|talk]]) 21:44, 17 February 2025 (UTC)'
},
{
name: 'spamTool',
icon: 'block',
title: 'Spam Warning',
insertText: '[[File:Information.svg|25px|alt=Information icon]] Hello, I'm [[User:Polygnotus|Polygnotus]]. I wanted to let you know that one or more external links you added have been removed because they seemed to be inappropriate for an encyclopedia. Take a look at our [[Wikipedia:External links|guidelines about external links]]. If you think I made a mistake, or if you have any questions, you can leave me a message on [[User_talk:Polygnotus|my talk page]]. Thank you. [[Category:User talk pages with Uw-spam1 notices|{{PAGENAME}}]]<!-- Template:uw-spam1 --> [[User:Polygnotus|Polygnotus]] ([[User talk:Polygnotus|talk]]) 21:44, 17 February 2025 (UTC)'
},
{
name: 'teahouseTool',
icon: 'help',
title: 'Teahouse Invitation',
insertText: 'If you have any questions, the [[WP:TEAHOUSE]] is a great place to get answers.'
},
{
name: 'vand1Tool',
icon: 'alert',
title: 'Vandalism Warning Level 1',
insertText: '[[File:Information.svg|25px|alt=Information icon]] Hello, I'm [[User:Polygnotus|Polygnotus]]. I wanted to let you know that one or more of [[Special:Contributions/Polygnotus/Scripts|your recent contributions]] have been undone because they did not appear constructive. If you would like to experiment, please use the [[Wikipedia:Sandbox|sandbox]]. If you have any questions, you can ask for assistance at the [[Wikipedia:Teahouse|Teahouse]] or the [[Wikipedia:Help desk|Help desk]]. Thanks.<!-- Template:uw-vandalism1 --> [[User:Polygnotus|Polygnotus]] ([[User talk:Polygnotus|talk]]) 21:44, 17 February 2025 (UTC)'
},
{
name: 'vand2Tool',
icon: 'alertWarning',
title: 'Vandalism Warning Level 2',
insertText: '[[File:Information orange.svg|25px|alt=Information icon]] Please refrain from making unconstructive edits to Wikipedia. Your edits appear to constitute [[Wikipedia:Vandalism|vandalism]] and have been [[Help:Reverting|reverted]]. If you would like to experiment, please use the [[Wikipedia:Sandbox|sandbox]]. Repeated vandalism may result in the [[Wikipedia:Blocking policy|loss of editing privileges]]. Thank you.<!-- Template:uw-vandalism2 --> [[User:Polygnotus|Polygnotus]] ([[User talk:Polygnotus|talk]]) 21:44, 17 February 2025 (UTC)'
},
{
name: 'vand3Tool',
icon: 'alertError',
title: 'Vandalism Warning Level 3',
insertText: '[[File:Nuvola apps important.svg|25px|alt=Warning icon]] Please stop. If you continue to [[Wikipedia:Vandalism|vandalize]] Wikipedia, you may be [[Wikipedia:Blocking policy|blocked from editing]]. <!-- Template:uw-vandalism3 --> [[User:Polygnotus|Polygnotus]] ([[User talk:Polygnotus|talk]]) 21:44, 17 February 2025 (UTC)'
},
{
name: 'vand4Tool',
icon: 'block',
title: 'Vandalism Warning Level 4',
insertText: '[[File:Stop hand nuvola.svg|30px|alt=Stop icon]] You may be '''[[Wikipedia:Blocking policy|blocked from editing]] without further warning''' the next time you [[Wikipedia:Vandalism|vandalize]] Wikipedia. <!-- Template:uw-vandalism4 --> [[User:Polygnotus|Polygnotus]] ([[User talk:Polygnotus|talk]]) 21:44, 17 February 2025 (UTC)'
}
];
// Create all tools
tools.forEach(createToolFromConfig);
console.log('All tools created'); // Debug log
});
}
});
})();