Content deleted Content added
DreamRimmer (talk | contribs) move arbcom section |
DreamRimmer (talk | contribs) batches, simple caching |
||
Line 7:
*/
$(document).ready(function() {
// Simple cache for API results
var apiCache = {};
var CACHE_DURATION = 10 * 60 * 1000; // 10 minutes
function getCacheKey(api, params) {
return JSON.stringify({api: api.toString(), params: params});
}
function getCachedResult(key) {
var cached = apiCache[key];
if (cached && (Date.now() - cached.timestamp < CACHE_DURATION)) {
return cached.data;
}
return null;
}
function setCachedResult(key, data) {
apiCache[key] = {
data: data,
timestamp: Date.now()
};
}
function initializeAdminNewsTools() {
$('#mw-content-text > p').remove();
Line 364 ⟶ 387:
}
function
var cached =
var currentParams = {...params, lelimit: Math.min(batchSize, params.lelimit || 500)};
function fetchBatch() {
return new Promise((resolve, reject) => {
var timeout = setTimeout(() => {
reject(new Error('API request timeout'));
}, 15000);
api.get(currentParams).then(response => {
clearTimeout(timeout);
var newResults = response.query.logevents || [];
results.push(...newResults);
if (response.continue && results.length < (params.lelimit || 500)) {
currentParams = {...currentParams, ...response.continue};
setTimeout(() => {
fetchBatch().then(resolve).catch(reject);
}, delay);
} else {
setCachedResult(cacheKey, results);
resolve(results);
}
}).catch(error => {
clearTimeout(timeout);
reject(error);
});
});
}
return fetchBatch();
}
function
var
if
return
var currentParams = {...params, rvlimit: Math.min(batchSize, params.rvlimit || 500)};
function fetchBatch() {
return new Promise((resolve, reject) => {
var timeout = setTimeout(() => {
reject(new Error('API request timeout'));
}, 15000);
api.get(currentParams).then(response => {
clearTimeout(timeout);
const pages = response.query.pages || {};
Object.values(pages).forEach(page => {
if (page.revisions) {
results.push(...page.revisions);
}
});
if (response.continue && results.length < (params.rvlimit || 500)) {
currentParams = {...currentParams, ...response.continue};
setTimeout(() => {
fetchBatch().then(resolve).catch(reject);
}, delay);
} else {
setCachedResult(cacheKey, results);
resolve(results);
}
}).catch(error => {
clearTimeout(timeout);
reject(error);
});
});
return
}
Line 395 ⟶ 475:
return Promise.all([
action: 'query',
list: 'logevents',
Line 401 ⟶ 481:
lestart: endTs,
leend: startTs,
lelimit:
leprop: 'timestamp|title|user|userid|details|params|type|comment|ids',
format: 'json'
}),
action: 'query',
list: 'logevents',
Line 411 ⟶ 491:
lestart: endTs,
leend: startTs,
lelimit:
leprop: 'timestamp|title|user|userid|details|params|type|comment|ids',
format: 'json'
Line 435 ⟶ 515:
}
function
const weeks = getWeeksInMonth(year, month);
var cacheKey = `tech_news_${year}_${month}`;
var cached = getCachedResult(cacheKey);
if (cached) {
return Promise.resolve(cached);
}
return
if (response.parse &&
const html = response.parse.text['*'];
const match = html.match(/(\d{4}), week (\d+) \(([^)]+)\)/);
if (match) {
const weekDate = match[3];
const parsedDate = new Date(weekDate);
if (parsedDate.getMonth() === month - 1) {
resolve({ week, date: weekDate, url: `https://meta.wikimedia.org/wiki/Tech/News/${year}/${week}` });
return;
}
}
}
}).catch(() => {
});
});
}));
}
const batches = [];
for (let i = 0; i < weeks.length; i += batchSize) {
batches.push(weeks.slice(i, i + batchSize));
}
return batches.reduce((promise, batch) => {
return promise.then(results => {
return fetchWeekBatch(batch).then(batchResults => {
return results.concat(batchResults);
});
});
}, Promise.resolve([])).then(results => {
const validWeeks = results.filter(r => r !== null);
let html;
if (!validWeeks.length) {
} else {
html = '<h4>Tech News Links</h4><ul>';
validWeeks.forEach(({ week, date, url }) => {
html += `<li><a href="${url}" target="_blank">Tech/News/${year}/${week}</a> (${date})</li>`;
});
html += '</ul>';
}
setCachedResult(cacheKey, html);
return html;
});
Line 477 ⟶ 589:
function fetchCentralizedDiscussion(startTs, endTs) {
return
action: 'query',
titles: 'Template:Centralized discussion',
Line 483 ⟶ 595:
rvstart: endTs,
rvend: startTs,
rvlimit:
rvprop: 'timestamp|user|comment|ids',
format: 'json'
Line 493 ⟶ 605:
function fetchArbComNotices(startTs, endTs) {
return
action: 'query',
titles: 'Wikipedia:Arbitration Committee/Noticeboard',
Line 499 ⟶ 611:
rvstart: endTs,
rvend: startTs,
rvlimit:
rvprop: 'timestamp|user|comment|tags|ids',
format: 'json'
Line 509 ⟶ 621:
function fetchArbComCases() {
var cacheKey = 'arbcom_cases';
var cached = getCachedResult(cacheKey);
if (cached) {
return Promise.resolve(cached);
}
return Promise.all([
resolve({ parse: null });
});
}),
new Promise((resolve) => {
var timeout = setTimeout(() => resolve({ parse: null }), 10000);
localApi.get({
action: 'parse',
page: 'Template:ArbComOpenTasks/ClosedCases',
format: 'json',
prop: 'text'
}).then(response => {
clearTimeout(timeout);
resolve(response);
}).catch(() => {
clearTimeout(timeout);
resolve({ parse: null });
});
})
]).then(([openResponse, closedResponse]) => {
let html = '';
Line 542 ⟶ 678:
html += '<p><a href="https://en.wikipedia.org/wiki/Template:ArbComOpenTasks" target="_blank">See detailed statistics</a></p>';
setCachedResult(cacheKey, html);
return html;
});
Line 615 ⟶ 751:
return html;
}
function fetchRecentRfCsBatched() {
var cacheKey = 'recent_rfcs';
var cached = getCachedResult(cacheKey);
if (cached) {
return Promise.resolve(cached);
}
const rfcPages = [
{ name: 'Biographies', url: 'Wikipedia:Requests_for_comment/Biographies' },
Line 635 ⟶ 778:
];
return
localApi.get({
}).then(response => {
clearTimeout(timeout);
if (response.parse && response.parse.wikitext) {
const wikitext = response.parse.wikitext['*'];
const rfcs = parseRfCs(wikitext, page.name);
resolve(rfcs);
} else {
resolve([]);
}
}).catch(() => {
clearTimeout(timeout);
resolve([]);
});
});
}));
}
const batchSize = 3;
const batches = [];
for (let i = 0; i < rfcPages.length; i += batchSize) {
batches.push(rfcPages.slice(i, i + batchSize));
}
return batches.reduce((promise, batch, index) => {
return promise.then(results => {
return fetchPageBatch(batch).then(batchResults => {
// Add delay between batches except for the last one
if (index < batches.length - 1) {
return new Promise(resolve => {
setTimeout(() => {
resolve(results.concat(batchResults.flat()));
}, 300);
});
} else {
return results.concat(batchResults.flat());
}
});
});
}, Promise.resolve([])).then(allRfcs => {
const result = createRfCDisplay(allRfcs);
setCachedResult(cacheKey, result);
return result;
});
}
Line 782 ⟶ 958:
function checkPageExists(title) {
var cached =
if (cached !== null)
}
return new Promise((resolve) => {
setCachedResult(cacheKey, false);
resolve(false);
}, 10000);
localApi.get({
action: 'query',
titles: title,
format: 'json'
}).then(response => {
clearTimeout(timeout);
const pages = response.query.pages || {};
const exists = !Object.values(pages).some(page => page.hasOwnProperty('missing'));
setCachedResult(cacheKey, exists);
resolve(exists);
}).catch(() => {
clearTimeout(timeout);
setCachedResult(cacheKey, false);
resolve(false);
});
});
}
Line 837 ⟶ 1,033:
if (section === 'all' || section === 'tech') {
promises.push(
sections.push('tech');
}
Line 852 ⟶ 1,048:
if ((section === 'all' || section === 'rfc') && isCurrentOrLastMonth) {
promises.push(
sections.push('rfc');
}
|