پرش به محتوا

مدیاویکی:Gadget-decodesummary.js: تفاوت میان نسخه‌ها

از دانشنامه علوم انسانی
imported>Dalba
جز diff before oldid
imported>Ebrahim
ساده‌سازی و رفع اشکال کد استثنای ابزار
 
(۳۵ نسخهٔ میانی ویرایش شده توسط ۶ کاربر نشان داده نشد)
خط ۱: خط ۱:
$(function () {
// <nowiki>
 
(function ($, mw) {
'use strict';
'use strict';
mw.loader.using('jquery.byteLimit', function () {
$('#wpSummary, #wpReason, #mwProtect-reason, #mw-input-wpReason-other').byteLimit(Infinity);
var nonLinkChars = / \\^`#<>\[\]"\t\n{\|}/.source;
});
var linkComponent = '[^' + nonLinkChars + ']*';
$('#wpSummary, #wpReason, #mwProtect-reason, #mw-input-wpReason-other').on('paste keyup change',
var linkEnd = '(?=$|[' +  nonLinkChars + '])';
function (e) {
var siteCode = mw.config.get('wgServer').match(/\w+\./)[0].slice(0,-1);
var that, val, bytes;
var selfSiteIntLinkStart = '[[' + siteCode + ':';
that = $(this);
var mwLinkStart = /(?:https?:)?\/\/([a-z\-]+)\.(?:wikipedia|wikimedia)(?:\.beta\.wmflabs)?\.org\//.source;
val = that.val();
var simpleTitleLink = RegExp(
// from https://stackoverflow.com/questions/2219526/
mwLinkStart
bytes = encodeURI(val).split(/%(?:u[0-9A-F]{2})?[0-9A-F]{2}|./).length - 1;
+  /(?:wiki\/|w\/index\.php\?title=)([^&]*)/.source
that.css('background-color', bytes > 255 ? '#FFEBEB' : 'white');
+ linkEnd
val = val.replace( // place diff before oldid
);
/(oldid=(?:\d+|next|prev|cur|))&(diff=(?:\d+|next|prev|cur|))/gi,
var diffRegex = RegExp(
'$2&$1'
'(?:' + mwLinkStart + linkComponent
).replace( // Special:Diff
+ ')?&?diff=(\\d+|next|prev|cur)(?:&oldid=(\\d+|next|prev|cur)?)?(#'
/(?:(^|[ \\^`#<>\[\]\"\t\n{|}])|https?:\/\/([a-z\-]+)\.(?:wikipedia|wikimedia)\.org\/[^ \\^`#<>\[\]\"\t\n{|}]*)&?diff=(\d+|next|prev|cur)(?:&oldid=(\d+|next|prev|cur|))?(#[^ \\^`#<>\[\]\"\t\n{|}]*)?(?=$|[ \\^`#<>\[\]\"\t\n{|}])/gi,
+ linkComponent + ')?' + linkEnd,
'$1[[$2:Special:Diff/$4/$3$5]]'
'gi'
).replace( // Special:Permalink
);
/(?:(^|[ \\^`#<>\[\]\"\t\n{|}])|https?:\/\/([a-z\-]+)\.(?:wikipedia|wikimedia)\.org\/[^ \\^`#<>\[\]\"\t\n{|}]*)&?oldid=(\d+|next|prev|cur)(#[^ \\^`#<>\[\]\"\t\n{|}]*)?(?=$|[ \\^`#<>\[\]\"\t\n{|}])/gi,
var oldidRegex = RegExp(
'$1[[$2:Special:Permalink/$3$4]]'
'(?:' + mwLinkStart + linkComponent + ')?&?oldid=(\\d+|next|prev|cur)(#'
).replace( // [[Special:Diff/12345678/prev]] is equal to [[Special:Diff/12345678]]
+ linkComponent + ')?' + linkEnd,
/\[\[([a-z\-]+:)Special:Diff\/(\d+|next|prev|cur)\/prev\]\]/gi,
'gi'
'[[$1Special:Diff/$2]]'
);
).replace( // no oldid
'Special:Diff//',
function decodeSummary(e) {
'Special:Diff/'
var target, val, originalVal;
).replace(
target = $(e.currentTarget);
'[[fa:',  
val = originalVal = target.val();
'[['
try {
).replace(
val = decodeURI(val.replace(/%20/g, '\uFFFF')).replace(/\uFFFF/g, '%20'); // uFFFF is a noncharacter
'[[:',  
    val = decodeSummarySpecial(val);
'[['
    if (val !== originalVal) {
);
    target.val(val);
try {
    }
val = decodeURI(val.replace(/%20/g, '‍‍‍')).replace(/‍‍‍/g, '%20'); // three zwnj
} catch (ignore) {}
} catch(ignore) {}
}
if (val !== that.val()) {
that.val(val);
function decodeSummarySpecial(val) {
}
return val
});
// Put diff before oldid.
});
.replace(/(oldid=(?:\d+|next|prev|cur)?)&(diff=(?:\d+|next|prev|cur)?)/gi, '$2&$1')
// Special:Diff
.replace(diffRegex, '[[$1:Special:Diff/$3/$2$4]]')
// Special:Permalink
.replace(oldidRegex, '[[$1:Special:Permalink/$2$3]]')
// [[Special:Diff/12345678/prev]] is equal to [[Special:Diff/12345678]]
.replace(/\[\[([a-z\-]+:)Special:Diff\/(\d+|next|prev|cur)\/prev\]\]/gi, '[[$1Special:Diff/$2]]')
// no oldid
.replace('Special:Diff//', 'Special:Diff/')
.replace(simpleTitleLink, '[[$1:$2]]')
.replace(selfSiteIntLinkStart, '[[')
.replace('[[:', '[[');
}
if(['Emailuser', 'UrlShortener'].indexOf(mw.config.get('wgCanonicalSpecialPageName')) === -1) {
$(
'#wpSummary, #wpReason, [name=wpReason], #mwProtect-reason,' +
'#mw-input-wpReason-other, #wpComment,' +
' .mw-ui-input.summary, .oo-ui-inputWidget-input'
).on('paste keyup change', decodeSummary);
}
 
window.decodeSummarySpecial = decodeSummarySpecial;
 
})(jQuery, mediaWiki);
 
// </nowiki>

نسخهٔ کنونی تا ۱ اکتبر ۲۰۲۱، ساعت ۱۳:۳۱

// <nowiki>

(function ($, mw) {
	'use strict';
	
	var nonLinkChars = / \\^`#<>\[\]"\t\n{\|}/.source;
	var linkComponent = '[^' + nonLinkChars + ']*';
	var linkEnd = '(?=$|[' +  nonLinkChars + '])';
	var siteCode = mw.config.get('wgServer').match(/\w+\./)[0].slice(0,-1);
	var selfSiteIntLinkStart = '[[' + siteCode + ':';
	var mwLinkStart = /(?:https?:)?\/\/([a-z\-]+)\.(?:wikipedia|wikimedia)(?:\.beta\.wmflabs)?\.org\//.source;
	var simpleTitleLink = RegExp(
		mwLinkStart
		+  /(?:wiki\/|w\/index\.php\?title=)([^&]*)/.source
		+ linkEnd
	);
	var diffRegex = RegExp(
		'(?:' + mwLinkStart + linkComponent
		+ ')?&?diff=(\\d+|next|prev|cur)(?:&oldid=(\\d+|next|prev|cur)?)?(#'
		+ linkComponent + ')?' + linkEnd,
		'gi'
	);
	var oldidRegex = RegExp(
		'(?:' + mwLinkStart + linkComponent + ')?&?oldid=(\\d+|next|prev|cur)(#' 
		+ linkComponent + ')?' + linkEnd,
		'gi'
	);
	
	function decodeSummary(e) {
		var target, val, originalVal;
		target = $(e.currentTarget);
		val = originalVal = target.val();
		try {
			val = decodeURI(val.replace(/%20/g, '\uFFFF')).replace(/\uFFFF/g, '%20'); // uFFFF is a noncharacter
		    val = decodeSummarySpecial(val);
		    if (val !== originalVal) {
		  	  target.val(val);
		    }
		} catch (ignore) {}
	}
	
	function decodeSummarySpecial(val) {
		return val
			// Put diff before oldid.
			.replace(/(oldid=(?:\d+|next|prev|cur)?)&(diff=(?:\d+|next|prev|cur)?)/gi, '$2&$1')
			// Special:Diff
			.replace(diffRegex, '[[$1:Special:Diff/$3/$2$4]]')
			// Special:Permalink
			.replace(oldidRegex, '[[$1:Special:Permalink/$2$3]]')
			// [[Special:Diff/12345678/prev]] is equal to [[Special:Diff/12345678]]
			.replace(/\[\[([a-z\-]+:)Special:Diff\/(\d+|next|prev|cur)\/prev\]\]/gi, '[[$1Special:Diff/$2]]')
			// no oldid
			.replace('Special:Diff//', 'Special:Diff/')
			.replace(simpleTitleLink, '[[$1:$2]]')
			.replace(selfSiteIntLinkStart, '[[')
			.replace('[[:', '[[');
	}
	
	if(['Emailuser', 'UrlShortener'].indexOf(mw.config.get('wgCanonicalSpecialPageName')) === -1) {
		$(
			'#wpSummary, #wpReason, [name=wpReason], #mwProtect-reason,' + 
			'#mw-input-wpReason-other, #wpComment,' +
			' .mw-ui-input.summary, .oo-ui-inputWidget-input'
		).on('paste keyup change', decodeSummary);
	}

	window.decodeSummarySpecial = decodeSummarySpecial;

})(jQuery, mediaWiki);

// </nowiki>