MediaWiki:Common.js: Difference between revisions

From Citypedia Online
Tag: Replaced
mNo edit summary
 
Line 1: Line 1:
/* Any JavaScript here will be loaded for all users on every page load. */
/* 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)
                    }
                }
            }
        }
    });
});

Latest revision as of 04:29, 28 January 2026

/* 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)
                    }
                }
            }
        }
    });
});