MediaWiki:Gadget-find-archived-section.js: Difference between revisions
Content deleted Content added
+function requested on talk |
sync in update, requested on talk |
||
Line 5:
* | Please discuss changes on the talk page or on [[WT:Gadget]] before editing. |
* |_____________________________________________________________________________|
*
* Gadget to navigate to an archived section after following its broken link.
*
* Author: SD0001
* Documentation: [[User:SD0001/find-archived-section]]
*
*/
Line 16:
// START EDITING HERE FOR LOCALISATION
// Messages: translate these strings if porting to a non-English language wiki
mw.messages.set({
"
"fas-exact-match": 'Looks like the discussion "$1" has been archived. <b><a href="$2">Click to see archived discussion</a></b> <small>(<a href="$3">or search in archives</a>)</small>',
"fas-inexact-match": 'Looks like the discussion "$1" has been archived. <a href="$2">Click to search in archives</a>.',
"fas-no
});▼
▲};
var config = {
// Function to introduce arbitrary changes to prefix.
Line 35 ⟶ 34:
case "Wikipedia:Administrators' noticeboard":
return "Wikipedia:Administrators' noticeboard/Archive";
default:
return prefix;
}
Line 56 ⟶ 55:
var sectionName = decodeURIComponent(
window.___location.hash.slice(1) // to remove the leading #
.replace(/_/g, ' ')
);
Line 66 ⟶ 65:
if (!sectionName || // no section name in URL
sectionName.indexOf('/media/') === 0 || // URLs used by MediaViewer
/^\d{12} /.test(sectionName) || // URLs used by convenientDiscussions
document.getElementById(sectionName.replace(/ /g, '_')) !== null) { // section exists on page
}
var escapeQuotes = function(str) {
Line 81 ⟶ 76:
$('#mw-content-text').before(
$('<div>')
.text(mw.msg
.addClass('archived-section-prompt')
.css({
Line 118 ⟶ 113:
}
var results = json.query.search;
if (results.length === 0) {
} else {
Line 134 ⟶ 128:
var result = results[i];
// sectiontitle in API output has spaces encoded as underscores
if (
result.sectiontitle pageTitle = result.title;
▲ break;
▲ }
}
}
Line 151 ⟶ 144:
});
if (pageTitle) { // if a section with the same name was found
var discussionLink = mw.util.getUrl(pageTitle) + '#' + mw.util.wikiUrlencode(sectionNameFound);
$('.archived-section-prompt').html(mw.msg('fas-exact-match', escapedSectionName, discussionLink, searchLink));
} else {
$('.archived-section-prompt').html(mw.msg('fas-inexact-match', escapedSectionName, searchLink));
}
}
}).catch(function(err) {
|