Content deleted Content added
Polygnotus (talk | contribs) No edit summary |
Polygnotus (talk | contribs) No edit summary |
||
(2 intermediate revisions by the same user not shown) | |||
Line 1:
//https://en.wikipedia.org/wiki/Wikipedia_talk:Twinkle#Twinkle_feature_request_--_look_for_previous_XfDs
// Add AfD search functionality to Wikipedia
$(document).ready(function() {
Line 50 ⟶ 52:
aplimit: 50,
format: 'json'
}).
var exactMatches = data.query.allpages || [];
Line 61 ⟶ 63:
srlimit: 50,
format: 'json'
}).
var searchMatches = searchData.query.search || [];
Line 90 ⟶ 92:
displayAfDResults(allMatches, articleTitle);
}
}).
// If search fails, just show exact matches
displayAfDResults(exactMatches, articleTitle);
});
}).
$('#afd-search-btn').text('Search AfD').css('color', '#0645ad');
mw.notify('Error searching for AfD discussions', { type: 'error' });
Line 102 ⟶ 104:
function getAfDDates(pages, articleTitle) {
var api = new mw.Api();
var pagesWithDates = [];
var mostRecentDate = null;
var mostRecentTimestamp = 0;
var completedRequests = 0;
// If no pages, just display empty results
if (pages.length === 0) {
displayAfDResults(pages, articleTitle);
}
// Fetch date for each page individually
prop: 'revisions',
rvlimit: 1,
rvprop: 'timestamp'
}).then(function(data) {
if (data.query && data.query.pages) {
var pageId = Object.keys(data.query.pages)[0];
pageData = data.query.pages[pageId];
if (pageData && !pageData.missing && pageData.revisions && pageData.revisions.length > 0) {
var timestamp = pageData.revisions[0].timestamp;
var date = new Date(timestamp);
var timestampMs = date.getTime();
console.log('Page:', pageData.title, 'Date:', date.toDateString());
pagesWithDates.push({
title: pageData.title,
date: date,
timestamp: timestampMs
});
// Track most recent
if (timestampMs > mostRecentTimestamp) {
mostRecentTimestamp = timestampMs;
mostRecentDate = date;
}
hasDate = true;
}
}
// If no date found, add page without date
if (!hasDate) {
console.log('No date found for:', page.title);
pagesWithDates.push({
title:
date:
timestamp:
});
}
completedRequests++;
// When all requests are complete, display results
if (completedRequests === pages.length) {
// Sort by date (most recent first, pages without dates last)
pagesWithDates.sort(function(a, b) {
if (!a.timestamp && !b.timestamp) return 0;
if (!a.timestamp) return 1;
if (!b.timestamp) return -1;
return b.timestamp - a.timestamp;
});
//
threeMonthsAgo.setMonth(threeMonthsAgo.getMonth() - 3);
var isRecent = mostRecentDate && mostRecentDate
console.log('Most recent date:', mostRecentDate ? mostRecentDate.toDateString() : 'none', 'Is recent:', isRecent);
displayAfDResults(pagesWithDates, articleTitle, mostRecentDate, isRecent);
}
}).catch(function(error) {
console.log('API error for', page.title, ':', error);
// Add page without date on error
pagesWithDates.push({
title: page.title,
date: null,
timestamp: 0
});
completedRequests++;
// When all requests are complete (including errors), display results
if (completedRequests === pages.length) {
displayAfDResults(pagesWithDates, articleTitle, mostRecentDate, false);
}
});
});
}
|