MediaWiki:Gadget-find-archived-section.js: Difference between revisions
Content deleted Content added
update: add tilde (~) in search string to correctly handle section names where an article/redirect of the same name exists; remove hashColonFix as no longer necessary; also correctly handles section names beginning with a word then a colon (like "User:") |
Version 2: shows a link pointing directly to the archived discussion if it can be found |
||
Line 1:
var addsection = document.getElementById('ca-addsection');
var correctNs = mw.config.get('wgNamespaceNumber') % 2 === 1 || mw.config.get('wgNamespaceNumber') === 4;
// Show only on discussion pages (pages with "add section" button)
// On minerva skin (which doesn't use have add section button) show on all talk & project space pages
▲ if (!correctNs && mw.user.options.get('skin') === 'minerva') return;
if (!addsection && (!correctNs || !minerva)) {
return;
}
var
if (
return;
}
$('<div>').html('Looks like the discussion "' + sectionName + '" has been archived. Finding archived discussion...').addClass('archived-section-prompt').css({
'font-size': '90%',
'padding-left': '20px'
})
);
var prefix = mw.config.get('wgPageName').replace(/_/g, ' ');
// For admin noticeboards, archive pages titles are unusual
if (prefix === "Wikipedia:Administrators' noticeboard/Incidents") {
prefix = "Wikipedia:Administrators' noticeboard/IncidentArchive";
Line 20 ⟶ 33:
prefix = "Wikipedia:Administrators' noticeboard/Archive";
}
var
var searchLink = mw.config.get('wgScript')
+ '?title=Special:Search'
+ '&search=' +
+ '&prefix=' + encodeURIComponent(prefix);
// Fetch and parse search results page
$.ajax(searchLink).then(function(html) {
if ($(html).find('.mw-search-nonefound').length) {
var divHtml = 'No search results found for archived discussion "' + sectionName + '"';
} else {
var discussionLink = $(html).find('ul.mw-search-results .searchalttitle a').attr('href');
if (discussionLink) {
divHtml += '<b><a href="' + encodeURI(discussionLink) + '">Click to see archived discussion</a></b> ';
} else {
divHtml += '<a href="' + searchLink + '">Click to search in archives</a>. ';
}
}
$('.archived-section-prompt').html(divHtml);
▲ div.innerHTML = 'Looks like the discussion "' + hash.replace(/_/g, ' ') +
▲ '" has been archived. <a href="' + searchLink + '">Click to search in archives</a>.';
}).fail(function(err) {
▲ $('#mw-content-text').before(div);
console.error('[find-archived-section]: ', JSON.stringify(err));
});
});
|