Content deleted Content added
updated range blocks link |
improve IPv6 address compression, other minor changes |
||
Line 13:
const ip = extractIP(userName);
if (ip) {
addContributionsLinks(ip, userName.includes('/'));
if (ip.mask !== (ip.version === 6 ? 128 : 32)) {▼
mw.util.addPortletLink('p-tb', '/wiki/Special:BlankPage/RangeCalculator', 'Range calculator');▼
mw.util.addPortletLink('p-tb', '#', 'Range selector')▼
.addEventListener('click', event => {▼
event.preventDefault();▼
startRangeSelection();▼
});▼
}▼
}
} else if (specialPage === 'Blankpage') {
Line 42 ⟶ 34:
const ip = extractIP(match[1]);
if (ip) {
let rangeIP = maskedIP(ip, ip.mask, false).toUpperCase();
mw.util.addPortletLink('p-tb', `/wiki/Special:BlankPage/RangeBlocks/${ip.ip}`, "Find range blocks");▼
if (!pageParam.includes('/')) {
rangeIP = rangeIP.split('/')[0];
}
▲ mw.util.addPortletLink('p-tb', `/wiki/Special:BlankPage/RangeBlocks/${
}
}
Line 50 ⟶ 46:
// adds links to user tools
function addContributionsLinks(ip, isRange) {
const userToolsContainer = document.querySelector('.mw-contributions-user-tools .mw-changeslist-links');
if (!userToolsContainer) return;
Line 56 ⟶ 52:
if (blockLogLink) {
const rangeLogLink = document.createElement('a');
let rangeIP = maskedIP(ip, ip.mask, false).toUpperCase();
const rangeLogPage = `Special:BlankPage/RangeBlocks/${ip.ip}`;▼
if (!isRange) {
rangeIP = rangeIP.split('/')[0];
▲ }
rangeLogLink.href = `/wiki/${rangeLogPage}`;
rangeLogLink.textContent = '(ranges)';
Line 84:
for (let mask = floor; mask <= ceiling && mask < ip.mask; mask += steps) {
const contribsLink = document.createElement('a');
const contribsIP = maskedIP(ip, mask, false).toUpperCase();
contribsLink.href = `/wiki/Special:Contributions/${
contribsLink.textContent = `/${mask}`;
contribsLink.className = 'mw-contributions-link-range-suggestion';
Line 90 ⟶ 91:
span.appendChild(contribsLink);
userToolsContainer.insertBefore(span, insertBefore);
}
}
}
Line 209 ⟶ 218:
api = new mw.Api();
formatTimeAndDate = mw.loader.require('mediawiki.DateFormatter').formatTimeAndDate;
const rangeIP = maskedIP(ip, mask, false).toUpperCase();
document.title = `Range blocks for ${
const heading = document.querySelector('#firstHeading');
if (heading) {
heading.innerHTML = `Range blocks for ${
}
const contentContainer = document.querySelector('#mw-content-text');
Line 218 ⟶ 228:
contentContainer.innerHTML = '';
const statusMessage = document.createElement('p');
statusMessage.innerHTML = `Querying logs for IP blocks affecting <a href="/wiki/Special:Contributions/${
contentContainer.appendChild(statusMessage);
const resultsList = document.createElement('ul');
contentContainer.appendChild(resultsList);
const masks = ip.version === 6 ? sequence(19, 64) : sequence(16, 31);
if (!masks.includes(ip.mask)) {
masks.push(ip.mask);
}
const blocks = [];
const blockPromises = masks.map(mask => {
Line 245 ⟶ 258:
statusMessage.innerHTML = '<span style="color:red;">No blocks found.</span>';
} else {
statusMessage.innerHTML = `Range blocks for <a href="/wiki/Special:Contributions/${
}
mw.hook('wikipage.content').fire($(contentContainer));
Line 342 ⟶ 355:
// convert BigInt back to IPv6 string
function bigIntToIPv6(bigIntValue, prefixLength = 128, compress = true) {
function compressIPv6(ipv6) {
const zeroBlocks = ipv6.match(/\b0(?:\:0)+\b/g);
const longestZeroBlock = zeroBlocks.reduce((longest, current) => {
return current.length > longest.length ? current : longest;
}, "");
if (longestZeroBlock) {
return ipv6.replace(new RegExp(`\\b${longestZeroBlock}\\b`), '::');
}
return ipv6;
}
const segments = [];
for (let i = 0; i < 8; i++) {
Line 348 ⟶ 371:
segments.push(segment.toString(16));
}
if (compress) {
ipv6 = compressIPv6(ipv6);
}
return ipv6 + (prefixLength < 128 ? `/${prefixLength}` : '');
}
// generate masked IP range
function maskedIP(ip, prefixLength, compress = true) {
return ip.version === 6 ? maskedIPv6(ip.ip, prefixLength, compress) : maskedIPv4(ip.ip, prefixLength);
}
// generate masked IPv6 range
function maskedIPv6(ipv6, prefixLength, compress = true) {
const bigIntValue = ipv6ToBigInt(ipv6);
const shift = 128 - prefixLength;
const mask = (1n << BigInt(128 - shift)) - 1n;
const masked = bigIntValue & (mask << BigInt(shift));
return bigIntToIPv6(masked, prefixLength, compress);
}
|