Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
Documentation for this user script can be added at User:Ilmari Karonen/longeditsummary. |
// LIMIT EDIT SUMMARIES TO EXACTLY 250 UTF-8 BYTES
// see EditPage::importFormData() in MediaWiki source for the source of the limit
// new, simpler and improved version, thanks to [[User:Remember the dot]] for the idea
$(function () {
var wpSummary = document.getElementById("wpSummary")
if (wpSummary)
{
var oldValue = wpSummary.value
var adjustMaxLength = function ()
{
// subtract the number of UTF-8 continuation bytes (0x80-0xBF) from the maxlength
var maxLength = 250 - encodeURI(wpSummary.value).split(/%[89AB]/i).length + 1
// the last character or group might've pushed us over; if so, revert it
if (wpSummary.value.length > maxLength && wpSummary.value != oldValue)
{
wpSummary.value = oldValue
}
else
{
oldValue = wpSummary.value
wpSummary.setAttribute("maxlength", maxLength)
}
}
var eventTypes = ["keyup", "keydown", "keypress", "mouseup", "mousedown", "click", "focus", "blur", "change"]
for (var i = 0; i < eventTypes.length; i++)
{
addHandler(wpSummary, eventTypes[i], adjustMaxLength)
}
adjustMaxLength()
}
})