User:PrimeHunter/Parameter links.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
![]() | Documentation for this user script can be added at User:PrimeHunter/Parameter links. |
/* This script adds "Parameter links" below "What links here" in the sidebar.
"What links here" will include pages using a template with the link or
calling a template to produce the link.
"Parameter links" tries to search for pages which produce the link by calling a
link-making template with the page name as a parameter given in the source,
for example {{Cat|Stubs}} to produce a link to [[:Category:Stubs]].
It's an imperfect search and may not detect all wanted links correctly.
To use the script, add the following line to [[Special:MyPage/common.js]]:
importScript('User:PrimeHunter/Parameter links.js'); // Linkback: [[User:PrimeHunter/Parameter links.js]]
See [[PrimeHunter/Source links.js]] for a different script to search pages making a link with
full link syntax directly in the source, for example [[:Category:Stubs]].
*/
mw.loader.using(['mediawiki.util'], function () {
var name = mw.config.get( 'wgPageName' );
var title= mw.config.get( 'wgTitle' );
var url;
try {
url = mw.util.getUrl( 'Special:Search' ) + '?profile=all&search=' +
encodeURIComponent('linksto:"' + name + '" ' + 'insource:"' + title + '" ' +
'insource:/\\|[' + title[0] + title.charAt(0).toLowerCase() + ']' +
title.substring(1).replace(/[-[\]{}()*+!<=:?.\/\\^$|#\s,]/g, '\\$&') + '[\\}\\|#]/' ).replace(/_/g, " ");
} catch(e) {
url = '#error'; // EXAMPLE URL: https://en.wikipedia.org/w/index.php?title=%F0%9F%91%A9%F0%9F%8F%BF&action=history
}
mw.util.addPortletLink(
'p-tb',
url,
'Parameter links',
'pt-parameterlinks',
'What links here via a link-producing template call in the source with ' +
'the page name (without namespace) as a parameter',
null,
'#t-recentchangeslinked'
);
});