Page MenuHomePhabricator

Automatic signature obsolete tag warning/patcher
Closed, DuplicatePublicFeature

Description

Feature summary (what you would like to be able to do and where):
When entering a signature with obsolete tags, patch it automatically (if possible) or warn the user that it's not gonna fly.

Use case(s):
User enters signature with obsolete tags. onblur() they are instantly warned and have an opportunity to fix it, if the signature couldn't be fixed automatically.

Benefits:
Less annoying than only being told after pressing save.

Enwiki currently has a proposal to disallow obsolete tags in signatures: https://en.wikipedia.org/wiki/Wikipedia%3AVillage_pump_(proposals)#RfC:_disallowing_new_signatures_obsolete_tags

I have no idea if/when I would set up an environment to file a patch myself (T111565#9362369), but I wrote this little snippet to aid users who try to enter obsolete tags. It should be adjusted to use OOUI properly (I took the styling from Special:CreateAccount when entering an invalid username) and i18n stuff should be done.

I already knew when writing it that it couldn't be implemented as a gadget as those don't load on Special:Preferences. It's quite likely I've once again wasted my time. C'est la vie and all that.

//Sigcheck is public domain, irrevocably released as WTFPL Version 2[www.wtfpl.net/about/] by its author, Alexis Jazz.
$('#mw-input-wpnickname input')[0].addEventListener('focus', function() {
	//mw.loader.load('sigcheck') or something, the rest of the code below can be loaded by this
});
var AJsigC = {};
AJsigC.msg = {bad:'You entered an obsolete tag in your signature. (<code>&lt;center&gt;</code>, <code>&lt;font&gt;</code>, <code>&lt;strike&gt;</code> or <code>&lt;tt&gt;</code>) Please remove it.',fixed:'You entered an obsolete tag in your signature. It has been automatically fixed for you.'};
mw.loader.addStyleTag('.AJsigC_err,.AJsigC_warn{color: #000000;box-sizing: border-box;margin-bottom: 16px;border: 1px solid;padding: 12px 24px;word-wrap: break-word;overflow-wrap: break-word;overflow: hidden;}.AJsigC_err{background-color: #fee7e6;border-color: #b32424:} .AJsigC_warn{background-color: #fef6e7;border-color: #ac6600;}');
AJsigC.heck = function(int) {
	if ( $('#mw-input-wpfancysig input')[0].checked ) {
		if ( $('#mw-input-wpnickname input')[0].value.match(/<(center|font|strike|tt)[^>]*>/) ) {
			AJsigC.fixed = $('#mw-input-wpnickname input')[0].value
			.replace(/<center>(([^<]|<(?!\/center))*)<\/center>/g,'<div style="text-align: center;">$1<\/div>') //could happen within an inline block or something?
			.replace(/<center style="([^"]*)">(([^<]|<(?!\/center))*)<\/center>/g,'<div style="text-align: center;$1">$2<\/div>')
			.replace(/<font>(([^<]|<(?!\/font))*)<\/font>/g,'$1')
			.replace(/<font([^>]*)color="([^ ])*"([^>]*)>(([^<]|<(?!\/font))*)<\/font>/g,'<font$1yBADFONTycolor:$2;yBADFONTy$3>$4</font>')
			.replace(/<font([^>]*)size="([0-9]*)(em|px|%)*"([^>]*)>(([^<]|<(?!\/font))*)<\/font>/g,'<font$1yBADFONTyfont-size:$2$3;yBADFONTy$4>$5</font>')
			.replace(/<font([^>]*)face="([^ ])*"([^>]*)>(([^<]|<(?!\/font))*)<\/font>/g,'<font$1yBADFONTyfont-family:$2;yBADFONTy$3>$4</font>')
			.replace(/<font[ ]?(yBADFONTy(([^y]|y(?!BADFONTy))*yBADFONTy[ ]?)*)>(([^<]|<(?!\/font))*)<\/font>/g,'<span style="$1">$4</span>')
			.replace(/yBADFONTy/g,'')
			.replace(/<strike>(([^<]|<(?!\/strike))*)<\/strike>/g,'<s>$1</s>')
			.replace(/<tt>(([^<]|<(?!\/tt))*)<\/tt>/g,'<code>$1</code>');
			AJsigC.warn = document.createElement('div');
			$('.AJsigC_warn,.AJsigC_err').remove();
			if ( ! AJsigC.fixed.match(/<(center|font|strike|tt)[^>]*>/) && AJsigC.fixed.length < 256 ) {
				$('#mw-input-wpnickname input')[0].value = AJsigC.fixed;
				AJsigC.warn.innerHTML = AJsigC.msg.fixed;
				AJsigC.warn.classList.add('AJsigC_warn');
				$('#mw-input-wpnickname input')[0].parentElement.append(AJsigC.warn);
			} else {
				AJsigC.warn.innerHTML = AJsigC.msg.bad;
				AJsigC.warn.classList.add('AJsigC_err');
				$('#mw-input-wpnickname input')[0].parentElement.append(AJsigC.warn);
			}
		}
	
	}
};
if ( $('#mw-input-wpnickname input:not(.AJsigC)') ) {
	$('#mw-input-wpnickname input').addClass('AJsigC');
	$('#mw-input-wpnickname input')[0].addEventListener('blur', AJsigC.heck);
	$('#mw-input-wpfancysig input')[0].addEventListener('change', AJsigC.heck);
}