MediaWiki:FastCreate.js

/** * @Name           FastCreate * @Version        v1.0 * @Author         KockaAdmiralac * @Author         TheGoldenPatrik1 * @Description    Adds fully customizable buttons to quickly create pages. */

(function(window, $, mw, undefined) {   "use strict";        var self = {            init: function {                if (!window.QCButtons) {                    return;                 }                new mw.Api.get({ action: 'query', titles: window.QCButtons.map(function(b) {                       return b.target;                    }).join('|') }).done(function(d) { var exists = {}, pages = d.query.pages; for (var p in pages) { exists[pages[p].title] = Number(p) > 0; }                   window.QCButtons.forEach(function(b) {                        if (exists[b.target] && !b.alwaysDisplay) {                            return;                        }                        $(b.placement || '#WikiaBar .toolbar .tools')[b.prepend ? 'prepend' : 'append']( $('').append(                               $('', { title: 'one-click create', 'data-summary': b.summary, 'data-target': b.target, 'data-content': b.content, 'data-id': 'quickcreate', text: b.label, click: self.click })                           )                        );                    });                    mw.hook('quickcreate.init').fire(QCButtons); });           },            click: function {                var data = $(this).data;                console.log(data);                self.createPage(data.target, data.summary, data.content);            },            createPage: function(target, summary, content) {                new mw.Api.post({ action: 'edit', title: target, summary: summary, text: content, token: mw.user.tokens.get('editToken') }).done(function(res) { window.location.href = mw.util.getUrl(target); });           }        };    mw.loader.using(['mediawiki.util', 'mediawiki.api']).then(self.init); }(window, jQuery, mediaWiki));