MediaWiki:VSTFReport.js

/** * Name:       VSTFReport * Author:     KockaAdmiralac <1405223@gmail.com> * Description: *     Used for easier reporting vandalism to VSTF. *     Adds a "Report to VSTF" link to user's contributions *     The link automatically opens the VSTF vandalism report page *     and auto-fills the window with information about the user that is reported *     The whole process isn't automatical, as description for vandalism still needs to *      be filled in and the form isn't auto-submitted. * Version:    v1.3 */ (function {   'use strict';    var config = mw.config.get([ 'wgCanonicalSpecialPageName', 'wgCityId', 'wgPageName', 'wgServer', 'wgSiteName' ]), data = $.getUrlVars,       onVSTF = config.wgCityId === '65099' &&                 data.report &&                 data.cb !== $.storage.get('VSTFReported') &&                 $('.gran-bn.boton-solicitud').exists,        onContribs = config.wgCanonicalSpecialPageName === 'Contributions';    if (!onVSTF && !onContribs || window.VSTFReportLoaded) {        return;    }    window.VSTFReportLoaded = true;    var VSTFReport = {        baseURL: '//vstf.wikia.com/wiki/Report:',        pages: {            vandalism: 'Vandalism',            spam: 'Spam',            profile: 'User profile headers'        },        preload: function(i18n) {            i18n.loadMessages('u:vstf:MediaWiki:Custom-Reports/i18n.json')                .then($.proxy(this.init, this));        },        init: function(i18n) {            this.i18n = i18n;            if (onVSTF) {                this.initVSTF;            } else if (onContribs) { this.initContribs; }       },        initVSTF: function { this.interval = setInterval($.proxy(this.waitForButton, this), 100); },       waitForButton: function { var $button = $(Object.keys(this.pages).map(function(k) { return '#vstf-report-' + k;           }).join(', ')); if ($button.exists) { $button.click; $('#requestWindow #submit').click($.proxy(this.setCachebuster, this)); $('#wikiname').val(decodeURIComponent(decodeURIComponent(data.name))); $('#wikiurl').val(data.url); $('#user').val(decodeURIComponent(decodeURIComponent(data.user))); clearInterval(this.interval); }       },        setCachebuster: function { $.storage.set('VSTFReported', data.cb); },       initContribs: function { var server = config.wgServer; $(' ', {               id: 'VSTFReportButtons',                html: $.map(this.pages, $.proxy(function(v, k) {                    return $('', { 'class': 'wds-button wds-is-squished VSTFReportButton', href: new mw.Uri(this.baseURL + v).extend({                           report: '1',                            name: encodeURIComponent(config.wgSiteName),                            url: server.substring(7, server.length - 10),                            user: encodeURIComponent(data.target ? data.target.replace(/\+/g, ' ') : config.wgPageName.split('/')[1]),                           cb: Date.now                        }).toString, text: this.i18n.msg(                           'button' + k.charAt(0).toUpperCase + k.substring(1)                        ).plain });               }, this))            }).insertAfter('#contentSub'); }   };    if (!window.dev || !window.dev.i18n) { importArticle({           type: 'script',            article: 'u:dev:MediaWiki:I18n-js/code.js'        }); }   importArticle({        type: 'style',        article: 'u:dev:MediaWiki:VSTFReport.css'    }); mw.hook('dev.i18n').add($.proxy(VSTFReport.preload, VSTFReport)); });