MediaWiki:Common.js
From Citypedia Online
Note: After publishing, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
/* Any JavaScript here will be loaded for all users on every page load. */
/* Add a custom AI Stub Button to the toolbar */
mw.hook( 'wikiEditor.toolbarReady' ).add( function ( $textarea ) {
$textarea.wikiEditor( 'addToToolbar', {
section: 'main',
group: 'insert',
tools: {
"ai-stub": {
label: 'Generate AI Stub',
type: 'button',
icon: 'https://upload.wikimedia.org/wikipedia/commons/1/12/Magic_wand_icon.png',
action: {
type: 'callback',
execute: function() {
var topic = prompt("Enter the article topic:");
if (!topic) return;
// Show a loading message
$textarea.textSelection('encapsulateSelection', { pre: "Generating stub for: " + topic + "...\n" });
// Call your AI backend/API here
// For a live site, you'd use a secure proxy.
// For testing, you can call OpenAI directly (NOT RECOMMENDED FOR PUBLIC WIKIS)
}
}
}
}
});
});
