This is an old revision of this page, as edited by SD0001(talk | contribs) at 22:23, 13 November 2019(move all strings into an object for internationalization). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.Revision as of 22:23, 13 November 2019 by SD0001(talk | contribs)(move all strings into an object for internationalization)
This page is loaded as a part of the find-archived-section gadget, used by 5,637 users.
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
(function(){varaddsection=document.getElementById('ca-addsection');varcorrectNs=mw.config.get('wgNamespaceNumber')%2===1||mw.config.get('wgNamespaceNumber')===4;varminerva=mw.config.get('skin')==='minerva';// Show only on discussion pages (pages with "add section" button)// On minerva skin (which doesn't use add section button) show on all talk & project space pagesif(!addsection&&(!correctNs||!minerva)){return;}varsectionName=decodeURIComponent(window.___location.hash.slice(1)// .slice(1) to remove the leading #.replace(/_/g,' '));// Try to undo the anchor encoding (UTF-8 percent encoding but with % replaced by . )// For some strange reason, the . itself isn't encoded, this means the encoding process isn't// exactly reversiblevarsectionNameDotDecoded=decodeURIComponent(sectionName.replace(/\.([0-9A-F]{2})/g,'%$1'));if(!sectionName||// no section name in URLsectionName.indexOf('/media/')===0||// URLs used by MediaViewerdocument.getElementById(sectionName.replace(/ /g,'_'))!==null){// section exists on pagereturn;}varmsg={"starter-text":"Looks like the discussion \"$1\" has been archived. ","finding":"Finding archived discussion...","click-link":"Click to see archived discussion","no-search-results":"No search results found for archived discussion \"$1\"","search-link-found":"(or search in archives)","search-link-notfound":"Click to search in archives"};$('#mw-content-text').before($('<div>').text(msg['starter-text'].replace('$1',sectionName)+msg['finding']).addClass('archived-section-prompt').css({'font-size':'90%','padding':'0 0 10px 20px'}));varprefix=mw.config.get('wgPageName').replace(/_/g,' ');// For admin noticeboards, archive pages titles are unusualif(prefix==="Wikipedia:Administrators' noticeboard/Incidents"){prefix="Wikipedia:Administrators' noticeboard/IncidentArchive";}elseif(prefix==="Wikipedia:Administrators' noticeboard/Edit warring"){prefix="Wikipedia:Administrators' noticeboard/3RRArchive";}elseif(prefix==="Wikipedia:Administrators' noticeboard"){prefix="Wikipedia:Administrators' noticeboard/Archive";}varsearchQuery=sectionNameDotDecoded===sectionName?'"'+sectionName+'" prefix:"'+prefix+'"':'"'+sectionName+'" OR "'+sectionNameDotDecoded+'" prefix:"'+prefix+'"';mw.loader.using(['mediawiki.util','mediawiki.api']).then(function(){returnnewmw.Api({ajax:{headers:{'Api-User-Agent':'w:en:User:SD0001/find-archived-section.js'}}}).get({action:'query',list:'search',srsearch:searchQuery,srprop:'sectiontitle',srsort:'create_timestamp_desc',// list more recent archives firstsrlimit:'20'});}).then(function(json){if(!json||!json.query||!json.query.search){return;}vardivHtml;varresults=json.query.search;if(results.length===0){divHtml=msg['no-search-results'].replace('$1',mw.html.escape(sectionName));}else{varpageTitle,sectionNameFound;// will either be sectionName or sectionNameDotDecoded// obtain the the first exact section title match (which would be from the most recent archive)// this loop iterates over just one item in the vast majority of casesvarsectionName_=sectionName.replace(/ /g,'_');varsectionNameDotDecoded_=sectionNameDotDecoded.replace(/ /g,'_');for(variinresults){varresult=results[i];// sectiontitle in API output has spaces encoded as underscoresif(result.sectiontitle){if(result.sectiontitle===sectionName_||result.sectiontitle===sectionNameDotDecoded_){pageTitle=result.title;sectionNameFound=result.sectiontitle.replace(/_/g,' ');break;}}}varsearchLink=mw.util.getUrl('Special:Search',{search:'~'+searchQuery,// ~ in the beginning forces a search even if a page of the same name exists, see [[H:FORCE]]prefix:prefix,sort:'create_timestamp_desc'});divHtml=msg['starter-text'].replace('$1',mw.html.escape(sectionNameFound||sectionName));if(pageTitle){// if a section with the same name was foundvardiscussionLink=mw.util.getUrl(pageTitle)+'#'+mw.util.wikiUrlencode(sectionNameFound);divHtml+='<b><a href="'+discussionLink+'">'+msg['click-link']+'</a></b> ';divHtml+='<small><a href="'+searchLink+'">'+msg['search-link-found']+'</a></small>. ';}else{divHtml+='<a href="'+searchLink+'">'+msg['search-link-notfound']+'</a>. ';}}$('.archived-section-prompt').html(divHtml);}).fail(function(err){console.error('[find-archived-section]: ',JSON.stringify(err));});})();