مدیاویکی:Gadget-decodesummary.js: تفاوت میان نسخهها
ظاهر
imported>Jon (WMF) maintenance: more info TypeError: null is not an object (evaluating 'val.replace') |
imported>Huji exclusions |
||
| خط ۷۰: | خط ۷۰: | ||
} | } | ||
if( | if(mw.config.get("wgCanonicalSpecialPageName") != "Emailuser" & | ||
mw.config.get("wgCanonicalSpecialPageName") != "UrlShortener") { | |||
$( | $( | ||
'#wpSummary, #wpReason, [name=wpReason], #mwProtect-reason, #mw-input-wpReason-other, #wpComment, .mw-ui-input.summary, .oo-ui-inputWidget-input' | '#wpSummary, #wpReason, [name=wpReason], #mwProtect-reason, #mw-input-wpReason-other, #wpComment, .mw-ui-input.summary, .oo-ui-inputWidget-input' | ||
).on('paste keyup change', decodeSummary); | ).on('paste keyup change', decodeSummary); | ||
} | } | ||
نسخهٔ ۲۹ سپتامبر ۲۰۲۱، ساعت ۲۲:۴۹
decodeSummarySettings = {
server: mw.config.get('wgServer')
};
decodeSummarySettings.nonLinkChars = / \\^`#<>\[\]"\t\n{\|}/.source;
decodeSummarySettings.linkComponent = '[^' + decodeSummarySettings.nonLinkChars + ']*';
decodeSummarySettings.linkEnd = '(?=$|[' + decodeSummarySettings.nonLinkChars + '])';
decodeSummarySettings.siteCode = decodeSummarySettings.server.match(/\w+\./)[0].slice(0,-1);
decodeSummarySettings.selfSiteIntLinkStart = '[[' + decodeSummarySettings.siteCode + ':';
decodeSummarySettings.mwLinkStart = /(?:https?:)?\/\/([a-z\-]+)\.(?:wikipedia|wikimedia)(?:\.beta\.wmflabs)?\.org\//.source;
decodeSummarySettings.simpleTitleLink = RegExp(
decodeSummarySettings.mwLinkStart
+ /(?:wiki\/|w\/index\.php\?title=)([^&]*)/.source
+ decodeSummarySettings.linkEnd
);
decodeSummarySettings.diffRegex = RegExp(
'(?:'
+ decodeSummarySettings.mwLinkStart
+ decodeSummarySettings.linkComponent
+ ')?&?diff=(\\d+|next|prev|cur)(?:&oldid=(\\d+|next|prev|cur)?)?(#'
+ decodeSummarySettings.linkComponent
+ ')?'
+ decodeSummarySettings.linkEnd,
'gi'
);
decodeSummarySettings.oldidRegex = RegExp(
'(?:'
+ decodeSummarySettings.mwLinkStart
+ decodeSummarySettings.linkComponent
+ ')?&?oldid=(\\d+|next|prev|cur)(#'
+ decodeSummarySettings.linkComponent
+ ')?'
+ decodeSummarySettings.linkEnd,
'gi'
);
function decodeSummary (e) {
'use strict';
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) {
'use strict';
return val.replace( // Put diff before oldid.
/(oldid=(?:\d+|next|prev|cur)?)&(diff=(?:\d+|next|prev|cur)?)/gi, '$2&$1'
).replace( // Special:Diff
decodeSummarySettings.diffRegex, '[[$1:Special:Diff/$3/$2$4]]'
).replace( // Special:Permalink
decodeSummarySettings.oldidRegex, '[[$1:Special:Permalink/$2$3]]'
).replace( // [[Special:Diff/12345678/prev]] is equal to [[Special:Diff/12345678]]
/\[\[([a-z\-]+:)Special:Diff\/(\d+|next|prev|cur)\/prev\]\]/gi, '[[$1Special:Diff/$2]]'
).replace( // no oldid
'Special:Diff//', 'Special:Diff/'
).replace(
decodeSummarySettings.simpleTitleLink, '[[$1:$2]]'
).replace(
decodeSummarySettings.selfSiteIntLinkStart, '[['
).replace(
'[[:', '[['
);
}
if(mw.config.get("wgCanonicalSpecialPageName") != "Emailuser" &
mw.config.get("wgCanonicalSpecialPageName") != "UrlShortener") {
$(
'#wpSummary, #wpReason, [name=wpReason], #mwProtect-reason, #mw-input-wpReason-other, #wpComment, .mw-ui-input.summary, .oo-ui-inputWidget-input'
).on('paste keyup change', decodeSummary);
}