MediaWiki:Spotlight.js

/* 	@ Created By Lil' Miss Rarity, customized by Joeytje50 (i18n compatibility upgrade and dropdown languages) @ Some functions added by Jr Mime (pop-up layout, variables) @ Adds a pop up modal form for spotlights @ License: CC-BY-NC-SA @ License Jurisdiction: International */	// Variables for later on	// Keep these in an object for organization var _kt = { 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, msg = messages = { get: function(name) { return (messages[_kt.language.toUpperCase]||messages['EN'])[name]; },			languages: { AR: 'ar - العربية', CS: 'cs - Česky', DA: 'da - Dansk', FA: 'fa - فارسی', HU: 'hu - Magyar', ID: 'id - Bahasa Indonesia', MS: 'ms - Malay', NN: 'nn - ‪Norsk (nynorsk)‬', NO: 'no - Norsk (bokmål)‬', SV: 'sv - Svenska', TR: 'tr - Türkçe', XX: 'Other' },		};	 importScriptPage("MediaWiki:ApiKey.js", "wlb"); // English / default messages['EN'] = { "button-open": "Click here to add a new request", "button-close": "Click here to close the request", "form-language-choose": "Choose language", }	function hideForm { $('#request-form').fadeOut; setTimeout(function {				$('#request-form').remove;				console.log("Form removed successfully");			}, 1000); }	// Add buttons depending on user language if(_kt.pagename === 'Kittens' || _kt.pagename === "Wikia_Translators:International_Spotlights") { $("head").append(" #spotlight input { margin-bottom: 15px; } ");

var buttonappend = '' + msg.get('button-open') + ''; document.getElementById("lang-EN").innerHTML = buttonappend; window.dropdown = ''; dropdown += '' + msg.get('form-language-choose') + ' '; for (var i in msg.languages) { dropdown += ''+msg.languages[i]+' '; }		dropdown += ' '; }	// This opens the form for the users to fill out function openFormSpotlight { $("#lang-EN").after(' Spotlight request Example spotlights    Wiki name    URL  http://  .wikia.com   Select your language (' + window.dropdown + ') These languages cannot be requested: en, ca/es, de</a>, fi</a>, fr</a>, it</a>, ja</a>, ko</a>, nl</a>, pl</a>, pt</a>, ru</a>, vi</a>, zh</a>. Caption (Your language) - maximum 40 characters. <input id="intcaption" type="text" placeholder="Caption in your language" maxlength="40" style="width:400px;"/> Caption (English)  <input id="englishcaption" type="text" placeholder="English translation of caption" style="width:400px"/>  Signature  <input id="signatureplace" type="text" value="' + _kt.signature + '"style="width:400px"/>  Image  Please add the image after you sent the request. Tell us why your wiki should be featured wikia-wide: <textarea style="width: 100%; min-height: 100px;" id="tell_us_why" name="tell_us_why" placeholder="Add your text here!">   <button onclick="submitformSpotlight2">Submit request ');		$('#spotlight-submit').text(msg.get('button-close'));		$('#spotlight-submit').removeAttr("onclick").attr("onclick", "hideForm");	}

function submitformSpotlight2 { console.log('Starting to submit...'); var $form = $('#spotlight'), wikiname = $form.find('#wikiname').val, url = $form.find('#wikiurl').val, intcaption = $form.find('#intcaption').val, lang = $form.find('#language').val, encaption = $form.find('#englishcaption').val, image = $form.find('#image').val, reason = $form.find('#tell_us_why').val, signatureplace = $form.find('#signatureplace').val, page = '\n\n\n* ' + wikiname + ' ( al &bull;  sp  &bull;  up )\n* Caption\n** '+ lang + ': ' + intcaption + '\n** EN: ' + encaption + '\n* ' + signatureplace + '\n' + reason; // If language or header is blank, return alerts if (!lang) { alert('Please select a language!'); }		if (!wikiname) { alert('Please fill in wikiname!'); }	console.log('Performed checks...'); // Ajax URL var url = _kt.server + '/api.php?action=edit&title=Spotlight_request:' + encodeURIComponent(lang) + '/' + encodeURIComponent(wikiname) + '&text=' + encodeURIComponent(page) + '&summary=New+spotlight+request+(' + encodeURIComponent(lang) + ')&token=' + encodeURIComponent(_kt.edittoken) + '&createonly=1'; console.log('Got the url: ',url); $.post(url, function {	console.log('Should be done now:');	window.location = _kt.server + '/wiki/' + 'Spotlight_request:' + encodeURIComponent(lang) + '/' + encodeURIComponent(wikiname);		}); console.log('Sent request...'); }

/* auto reply buttons */ staffUsers = [ "MehrBot", "MtaÄ", "Vuh", "Yatalu", "Hulothe" ];	if ((jQuery.inArray( wgUserName, staffUsers ) !== -1)) {

$(".notifbox.status").after(' ');

$(".notifbox.status").prepend(' '	+ '<select name="spotlight-action" id="spotlight-action" value="?">' 	+ '<option value="" selected disabled>Choose an action '	+ '<option value="Accept">Accept '	+ '<option value="Reject">Reject '	+ '<option value="MoreInfo">Request more info '	+ ' ');

spotlightAction = '';

var spotlightReplyForm = ' ' + ' ' + spotlightAction + ' this spotlight ' + ' Official reason for your chosen action ' + ' Enter a comment ' + '<button onclick="submitSpotlightReply">Submit ' + ' ';

$( "select[name='spotlight-action']" ).change(function {		if ($(this).val == 'Accept') {	//        alert("Hello accept");			spotlightAction = "Accept";			spotlightFinalAction = "Accept";			spotlightTemplate = "Accepted";			$("#reply-container").html(spotlightReplyForm);			$("#spotlight-action-heading").text(spotlightAction);			cssAdjustments;			$("#official-reason").remove;		} else if ($(this).val == 'Reject' ) {	//        alert("Hello reject");			spotlightAction = "Reject";			spotlightFinalAction = "Reject";			spotlightTemplate = "Rejected";			$("#reply-container").html(spotlightReplyForm);			$("#spotlight-action-heading").text(spotlightAction);			cssAdjustments;

} else if ($(this).val == 'MoreInfo' ) { //       alert("GIVE ME MOAR INFO"); spotlightAction = "Request more information about"; spotlightFinalAction = "MoreInfo"; spotlightTemplate = "Waiting"; $("#reply-container").html(spotlightReplyForm); $("#spotlight-action-heading").text(spotlightAction); cssAdjustments; $("#official-reason").remove; }	});

function cssAdjustments { $("#request-reply textarea").css("box-sizing", "border-box").css("width", "100%").css("height", "75px"); }

function submitSpotlightReply {

$(".request-reply-form").after(' '); $("#rawtext").load(wgServer + "/wiki/" + wgPageName + "?action=raw");

additionalComment = $("#spotlight-comment textarea").val;

setTimeout(function {		$("#rawtext").append("\n\n" + additionalComment);	}, 1000); setTimeout(function {

currentPage = $("#rawtext").html;

officialReason = $("#official-reason textarea").val; articleName = wgPageName;

setTimeout(function {			// determine state 			if (spotlightTemplate === "Accepted") {				spot_final_template = ;				page = currentPage.replace(, spot_final_template).replace(, spot_final_template).replace(, spot_final_template);			} else if (spotlightTemplate === "Rejected") {				spot_final_template = ;				page = currentPage.replace('✅', spot_final_template).replace(, spot_final_template).replace(, spot_final_template);			} else if (spotlightTemplate === "Waiting") {				spot_final_template = ;				page = currentPage.replace('✅', spot_final_template).replace(, spot_final_template).replace(, spot_final_template);			}

var url_editing = _api.server + '/api.php?action=edit&title=' + encodeURIComponent(articleName) + '&text=' + encodeURIComponent(page) + '&token=' + encodeURIComponent(_api.edittoken) + '&summary=Replied to request';

$.post(url_editing, function {			console.log('Should be done now:');			window.location.reload;		}); }, 2000);	}, 2000);

}

}