Content deleted Content added
DreamRimmer (talk | contribs) specific to ArbCom topics only |
DreamRimmer (talk | contribs) recent rfcs, user-agent |
||
Line 389:
}
const metaApi = new mw.ForeignApi('https://meta.wikimedia.org/w/api.php', { headers: { 'Api-User-Agent': 'User:DreamRimmer/adminnewslettertools.js; https://en.wikipedia.org/wiki/User:DreamRimmer' } });
const localApi = new mw.Api({ headers: { 'Api-User-Agent': 'User:DreamRimmer/adminnewslettertools.js; https://en.wikipedia.org/wiki/User:DreamRimmer' } });
function fetchRightsChanges(startTs, endTs, startLabel, endLabel) {
Line 506:
return createEditTable('ArbCom topics', filtered, true);
});
}
function fetchRecentRfCs() {
const rfcPages = [
{ name: 'Biographies', url: 'Wikipedia:Requests_for_comment/Biographies' },
{ name: 'Economy, trade, and companies', url: 'Wikipedia:Requests_for_comment/Economy,_trade,_and_companies' },
{ name: 'History and geography', url: 'Wikipedia:Requests_for_comment/History_and_geography' },
{ name: 'Language and linguistics', url: 'Wikipedia:Requests_for_comment/Language_and_linguistics' },
{ name: 'Maths, science, and technology', url: 'Wikipedia:Requests_for_comment/Maths,_science,_and_technology' },
{ name: 'Art, architecture, literature, and media', url: 'Wikipedia:Requests_for_comment/Art,_architecture,_literature,_and_media' },
{ name: 'Politics, government, and law', url: 'Wikipedia:Requests_for_comment/Politics,_government,_and_law' },
{ name: 'Religion and philosophy', url: 'Wikipedia:Requests_for_comment/Religion_and_philosophy' },
{ name: 'Society, sports, and culture', url: 'Wikipedia:Requests_for_comment/Society,_sports,_and_culture' },
{ name: 'Wikipedia style and naming', url: 'Wikipedia:Requests_for_comment/Wikipedia_style_and_naming' },
{ name: 'Wikipedia policies and guidelines', url: 'Wikipedia:Requests_for_comment/Wikipedia_policies_and_guidelines' },
{ name: 'WikiProjects and collaborations', url: 'Wikipedia:Requests_for_comment/WikiProjects_and_collaborations' },
{ name: 'Wikipedia technical issues and templates', url: 'Wikipedia:Requests_for_comment/Wikipedia_technical_issues_and_templates' },
{ name: 'Wikipedia proposals', url: 'Wikipedia:Requests_for_comment/Wikipedia_proposals' },
{ name: 'Unsorted', url: 'Wikipedia:Requests_for_comment/Unsorted' },
{ name: 'User names', url: 'Wikipedia:Requests_for_comment/User_names' }
];
const promises = rfcPages.map(page => {
return localApi.get({
action: 'parse',
page: page.url,
format: 'json',
prop: 'wikitext'
}).then(response => {
if (response.parse && response.parse.wikitext) {
const wikitext = response.parse.wikitext['*'];
const rfcs = parseRfCs(wikitext, page.name);
return rfcs;
}
return [];
}).catch(() => []);
});
return Promise.all(promises).then(results => {
const allRfcs = results.flat();
return createRfCDisplay(allRfcs);
});
}
function parseRfCs(wikitext, topicName) {
const rfcs = [];
const rfcPattern = /'''\[\[([^\]]+)\]\]'''/g;
let match;
while ((match = rfcPattern.exec(wikitext)) !== null) {
const linkText = match[1];
let pageName, anchor;
if (linkText.includes('#')) {
[pageName, anchor] = linkText.split('#');
} else {
pageName = linkText;
anchor = '';
}
const afterMatch = wikitext.substring(match.index + match[0].length);
const rfcquoteMatch = afterMatch.match(/\{\{rfcquote\|text=([^}]+)\}\}/);
if (rfcquoteMatch) {
const rfcquoteText = rfcquoteMatch[1];
const timestampMatch = rfcquoteText.match(/(\d{2}:\d{2}, \d{1,2} \w+ \d{4} \(UTC\))/);
if (timestampMatch) {
const timestampStr = timestampMatch[1];
const rfcDate = new Date(timestampStr.replace(' (UTC)', ' UTC'));
const now = new Date();
const daysDiff = Math.floor((now - rfcDate) / (1000 * 60 * 60 * 24));
const url = anchor ?
`https://en.wikipedia.org/wiki/${encodeURIComponent(pageName)}#${encodeURIComponent(anchor)}` :
`https://en.wikipedia.org/wiki/${encodeURIComponent(pageName)}`;
rfcs.push({
topic: topicName,
title: pageName,
url: url,
daysOld: daysDiff,
timestamp: timestampStr
});
}
}
}
return rfcs;
}
function createRfCDisplay(rfcs) {
const currentDate = new Date().toLocaleDateString('en-GB', {
day: 'numeric',
month: 'long',
year: 'numeric',
timeZone: 'UTC'
}) + ' UTC';
const ageOptions = [3, 7, 10, 15, 20, 25, 30];
const topicNames = [
'Biographies', 'Economy, trade, and companies', 'History and geography',
'Language and linguistics', 'Maths, science, and technology',
'Art, architecture, literature, and media', 'Politics, government, and law',
'Religion and philosophy', 'Society, sports, and culture',
'Wikipedia style and naming', 'Wikipedia policies and guidelines',
'WikiProjects and collaborations', 'Wikipedia technical issues and templates',
'Wikipedia proposals', 'Unsorted', 'User names'
];
let html = `<p><small>Current date: ${currentDate}</small></p>`;
html += `<p>Age filter: <select id="rfc-age-filter" onchange="filterRfCs()">`;
ageOptions.forEach(age => {
const selected = age === 7 ? ' selected' : '';
html += `<option value="${age}"${selected}>${age} days old</option>`;
});
html += `</select></p>`;
html += '<div id="rfc-summary-table"><h4>RfC Count Summary</h4><table class="wikitable"><thead><tr><th>Topic</th>';
ageOptions.forEach(age => {
html += `<th>${age}d</th>`;
});
html += '</tr></thead><tbody>';
topicNames.forEach(topic => {
html += `<tr><td>${topic}</td>`;
ageOptions.forEach(age => {
const count = rfcs.filter(rfc => rfc.topic === topic && rfc.daysOld <= age).length;
html += `<td>${count}</td>`;
});
html += '</tr>';
});
html += '</tbody></table></div>';
ageOptions.forEach(age => {
const filteredRfcs = rfcs.filter(rfc => rfc.daysOld <= age);
const displayStyle = age === 7 ? 'block' : 'none';
html += `<div class="rfc-age-group" data-age="${age}" style="display: ${displayStyle};">`;
if (filteredRfcs.length === 0) {
html += `<p>No RfCs found that are ${age} days old or newer.</p>`;
} else {
topicNames.forEach(topic => {
const topicRfcs = filteredRfcs.filter(rfc => rfc.topic === topic);
if (topicRfcs.length > 0) {
html += `<h4>${topic} (${topicRfcs.length})</h4><ul>`;
topicRfcs.forEach(rfc => {
html += `<li><a href="${rfc.url}" target="_blank">${rfc.title}</a> (${rfc.daysOld} days old)</li>`;
});
html += '</ul>';
}
});
}
html += '</div>';
});
html += '<p><a href="https://en.wikipedia.org/wiki/Wikipedia:Requests_for_comment/All" target="_blank">All open RfCs</a></p>';
html += `<script>
function filterRfCs() {
const selectedAge = document.getElementById('rfc-age-filter').value;
const groups = document.querySelectorAll('.rfc-age-group');
groups.forEach(group => {
group.style.display = group.dataset.age == selectedAge ? 'block' : 'none';
});
}
</script>`;
return html;
}
Line 621 ⟶ 792:
resultIndex++;
}
if (sections.includes('rfc')) {
const rfcHtml = createCollapsibleSection('Recent RfCs', results[resultIndex]);
resultsContainer.append(rfcHtml);
resultIndex++;
}
if ((section === 'all' || section === 'arbcom') && isCurrentOrLastMonth) {
Line 628 ⟶ 804:
if ((section === 'all' || section === 'rfc') && isCurrentOrLastMonth) {
promises.push(fetchRecentRfCs());
}
if (section === 'all' || section === 'misc') {
|