MediaWiki:Chat.js

/** * This file loads for every user the wiki chat. * For skin specific variants see MediaWiki:Chat.css * for oasis respectively * * Please test any changes made to this file. * Jshint  can catch syntax errors to help testing. * Alternatively, Wikia's code editor has jshint embedded to make life extra simple. * * To see which scripts this has loaded, see `smwiki.loaded` (from your js console) */

/* global mw, importArticles, ChatView, EmoticonMapping */

/* jshint bitwise:true, browser:true, camelcase:true, curly:true, devel:true, eqeqeq:true, es5:true, forin:true, immed:true, jquery:true, latedef:true, newcap:true, noarg:true, noempty:true, nonew:true, onevar:false, plusplus:false, quotmark:single, undef:true, unused:true, strict:true, trailing:true

window.chatags = { images: true, videos: true };

window.chatAnnouncementsAll = true;

importArticles({   type: 'script',    articles: [        // ...        'u:dev:MediaWiki:ChatAnnouncements/code.js',        'u:dev:MediaWiki:ChatOptions/code.js',        'MediaWiki:Chat.js/multiPM.js',        'MediaWiki:Chat.js/multiKick.js',        'u:shining-armor:MediaWiki:ChatTags/code.js',        'MediaWiki:Chat.js/inline.js',        // ...    ] });

/*	auto refresh emoticons and css all credit goes to Penguin-Pal $(function {	var gap = 30,		css = $('');	$(css).appendTo('head');	function request {		$.getJSON('/api.php?action=query&format=json&prop=revisions&titles=MediaWiki:Emoticons|MediaWiki:ChatResizeEmoticons.css&rvprop=content&cb=' + new Date.getTime, function(data) { var a = data.query.pages; for (var pageid in a) { if (a[pageid].title === 'MediaWiki:ChatResizeEmoticons.css') { $(css).text(a[pageid].revisions[0]['*']); } else if (a[pageid].title === 'MediaWiki:Emoticons') { updateEmoticons(a[pageid].revisions[0]['*']); }			}		});	}	function updateEmoticons(newEmoticons) {		mw.config.set('wgChatEmoticons', newEmoticons);		ChatView.prototype.emoticonMapping = new EmoticonMapping;		ChatView.prototype.emoticonMapping.loadFromWikiText(newEmoticons);	}	// make first request when joining the room	request;	// request again every every 'gap' seconds	setInterval(request, gap * 1000); });

/*    block some !say commands all credit goes to the Club Penguin Wiki for the code base

/* $(function {	var restrictedPhrases = [           // '!say !kick',			// '!say !ban',			// '!say !say', // prevent flooding with !say			// '!say !fail',			// '#ShutUpSM',			// '#ShutUpSM2k16',			// '#ShutUpSM2016',			// 'SHUT UP SM',			// '#shutupsm',			// '#shutupSM',			// 'Shut up, SM.',			// 'shut up sm',			// 'shut up SM',			// '#SHUTUPSM'		],		regexString = [];	for (var i in restrictedPhrases) {		regexString.push('^' + restrictedPhrases[i].replace(/[\\\/\.\,\?\!\(\|\)\:\{\}\[\]\+\*\=\^\$]/g, '\\$&'));	}	var regex = new RegExp(regexString.join('|'));	NodeChatDiscussion.prototype.getTextInput.keydown(function(e) { if (e.keyCode === 13 && !e.shiftKey) { if (this.value.search(regex) === 0) { e.preventDefault; }		}	}); });

/*	the following script blocks certain words in certain conditions regex reduction suggested by Callofduty4 http://community.wikia.com/wiki/Thread:628738#7 /*

$(function {	var count = 0,		limit = 3,		filter = {};	// simple phrases	filter.plain = [       'shut up'    ];	// phrases as regular expressions	filter.regex = [		"touch(?:es|ing)? (?:(?:him|her|it)self|themselves|(?:his|her|it'?s|their) parts?)",		'smoke weed',		'go to hell',		'kill yourself',		'screw you',		'how old (?:are|r) (?:yo)?u',		// 'pingu(?: the man|theman)?',		'special:userlogout'	];	// the evaluated phrases	filter.evaluated = [];	for (var i in filter.plain) {		filter.evaluated.push(filter.plain[i].replace(/[\\\/\{\}\,\[\-\]\(\|\)\.\,\?\!\=\*\+\^\$]/g, '\\$&'));	}	for (var i in filter.regex) {		filter.evaluated.push(filter.regex[i]);	}	// regex object	var regex = new RegExp( '(?:^| |\\.|\\,|\\\\|\\/|\\[|\\]|_|\\-|\\(|\\)|\\{|\\}|\'|\"|\\|?\\!)(?:' +		filter.evaluated.join('|') +		')(?: |\\.|\\,|\\\\|\\/|\\[|\\]|_|\\-|\\(|\\)|\\{|\\}|\'|\"|\\?|\\!|$)', 'i' // case insensitive );	// add digit suffix (e.g. "9001" -> "9001st" function parseTime(n) { var s = String(n), lastD = s.match(/[1-3]$/), suffixes = { '1': 'st', '2': 'nd', '3': 'rd' };		return s + (lastD ? suffixes[lastD[0]] : 'th'); }	$('textarea[name="message"]').keydown(function(e) {		if (e.keyCode === 13) {			if ($(this).val.match(regex)) {				$(this).val('');				count++;				if (count < limit) {					alert('Warning! You have been caught using a restricted phrase and your message has been blocked.\nThis is the ' + parseTime(count) + ' time you have been caught doing so. If this number reaches ' + limit + ', you will be kicked.');				} else {					location.href = '/';					window.close;				}			}		}	}); });