MediaWiki:TranslateForm-i18n-js.js

/* @ Created By Lil' Miss Rarity, customized by Joeytje50 (i18n compatibility upgrade and dropdown languages) @ further customised by sactage for compatibility with i18n.js @ Some functions added by Jr Mime (pop-up layout, variables) @ Adds a pop up modal form for wlb.wikia.com @ License: CC-BY-NC-SA @ License Jurisdiction: International */

// Variables for later on // Keep these in an object for organization var _tr = { edittoken: mw.user.tokens.values.editToken, namespace: mw.config.get( 'wgNamespaceNumber' ), pagename: mw.config.get( 'wgPageName' ), server: mw.config.get( 'wgServer' ), signature:  + , language: mw.config.get( 'wgUserLanguage' ) };

var $ = this.jQuery, mw = this.mediaWiki, i;

if (_tr.pagename === 'Translate:FakeRequests') {

function initTranslateForm { // Add buttons depending on user language

var buttonappend = '' + mw.msg( 'i18n-button' ) + ''; try { document.getElementById("lang-" + _tr.language.toUpperCase).innerHTML = buttonappend; } catch (e) { document.getElementById("lang-EN").innerHTML = buttonappend; }       window.dropdown = ''; dropdown += '' + mw.msg( 'i18n-form-language-choose' ) + ' '; for (var i in i18n.languages) { dropdown += '' + i18n.languages[i] + ' '; }       dropdown += ' ';

// This opens the form for the users to fill out }

function openFormTranslate { $.showCustomModal(mw.msg( 'i18n-form-name' ), ' ' + mw.msg( 'i18n-form-header' ) + '  ' + mw.msg( 'i18n-form-information-header' ) + ' [?]   ', {            id: "requestWindow",            width: 650,            buttons: [                {                    id: "cancel",                    message: "Cancel",                    handler: function  {                        cancelformTranslate;                    }                },                {                    id: "submit",                    defaultButton: true,                    message: "Submit", handler: function { submitformTranslate; }               }            ]        });    }

// Closes the form

function cancelformTranslate { $("#requestWindow").closeModal; }

// Submits the form

function submitformTranslate { console.log('Starting to submit...'); var $form = $('#translationForm'), header = $form.find('#request-header').val, lang = $form.find('#language').val, lang2 = $form.find('#language2').val, wikiurl = $form.find('#wiki-url').val, items = $form.find('#items').val, extrainfo = $form.find('#extrainfo').val, signatureplace = $form.find('#signature-place').val, page = '\n\n\n\'\'\'\'\'\': w:c:' + wikiurl + '\n\n\'\'\'\'\'\': ' + items + '\n\n\'\'\'\'\'\': ' + extrainfo + '\n\n\'\'\'\'\'\': ' + signatureplace + '\n';

// Making sure the header isn't blank, and a language has been filled in       if (!header) { alert("Please title your request!"); return; }       if (!lang||!lang2) { alert('Please select a language!'); return; }       console.log('Performed checks...');

// Ajax URL var url = _tr.server + '/api.php?action=edit&title=Translate:FAKE ' + encodeURIComponent(header) + ' (' + encodeURIComponent(lang) + '+%E2%86%92+' + encodeURIComponent(lang2) + ')&text=' + encodeURIComponent(page) + '&summary=New+translate+request+(' + encodeURIComponent(lang) + '+%E2%86%92+' + encodeURIComponent(lang2) + ')&token=' + encodeURIComponent(_tr.edittoken); console.log('Got the url: ',url);

$.post(url, function (r) {           console.log('Should be done now:', r);            cancelformTranslate;            window.location.reload;        }); console.log('Sent request...'); }

$.when(       i18n.registerMessages('form-common', [               'i18n-button', 'i18n-form-name', 'i18n-form-header', 'i18n-form-header-placeholder', 'i18n-form-language-choose', 'i18n-form-url', 'i18n-form-information-header', 'i18n-form-information-request', 'i18n-form-items', 'i18n-form-extrainfo', 'i18n-form-extrainfo-placeholder', 'i18n-form-signature' ]       ),        i18n.registerMessages('translateform', [               'i18n-form-translate-language', 'i18n-form-translate-items-placeholder' ]       )    ).done(i18n.require('form-common').done(i18n.require('translateform').done(initTranslateForm))); }