User:PrimeHunter/Category source.js

This is an old revision of this page, as edited by PrimeHunter (talk | contribs) at 14:21, 14 May 2023 (This script adds "Source-added" and "Template-added" links under "Tools" in the sidebar on category pages). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)
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.
/*
   This script adds "Source-added" and "Template-added" links under "Tools" in the sidebar on category pages.
   "Source-added" searches category members which were added with category code in the source.
   "Template-added" shows all category members not found by "Source-added".
   To use the script, add the following line to Special:MyPage/common.js:
 
importScript('User:PrimeHunter/Category source.js'); // Linkback: [[User:PrimeHunter/Category source.js]]

*/
 
mw.loader.using(['mediawiki.util'], function () {
  if ( mw.config.get( 'wgNamespaceNumber' ) === 14 ) {
    mw.util.addPortletLink(
      'p-tb',
      'https://en.wikipedia.org/w/index.php?title=Special:Search&profile=advanced'
      + '&search=incategory%3A%22' + encodeURIComponent(mw.config.get( 'wgTitle' )) + '%22'
      + '+-insource%3A%2F\\[\\[Category:' + encodeURIComponent(mw.config.get( 'wgTitle' )) + '[\\|\\]]%2Fi'
      + '&ns0=1&ns1=1&ns2=1&ns3=1&ns4=1&ns5=1&ns6=1&ns7=1&ns8=1&ns9=1&ns10=1&ns11=1&ns12=1&ns13=1'
      + '&ns14=1&ns15=1&ns100=1&ns101=1&ns108=1&ns109=1&ns118=1&ns119=1&ns446=1&ns447=1'
      + '&ns710=1&ns711=1&ns828=1&ns829=1&ns2300=1&ns2301=1&ns2302=1&ns2303=1',
      'Template-added',
      'pt-templateadded',
      'Category members which were NOT added with category code in the source',
      null,
      '#t-info'
    );

    mw.util.addPortletLink(
      'p-tb',
      'https://en.wikipedia.org/w/index.php?title=Special:Search&profile=advanced'
      + '&search=incategory%3A%22' + encodeURIComponent(mw.config.get( 'wgTitle' )) + '%22'
      + '+insource%3A%2F\\[\\[Category:' + encodeURIComponent(mw.config.get( 'wgTitle' )) + '[\\|\\]]%2Fi'
      + '&ns0=1&ns1=1&ns2=1&ns3=1&ns4=1&ns5=1&ns6=1&ns7=1&ns8=1&ns9=1&ns10=1&ns11=1&ns12=1&ns13=1'
      + '&ns14=1&ns15=1&ns100=1&ns101=1&ns108=1&ns109=1&ns118=1&ns119=1&ns446=1&ns447=1'
      + '&ns710=1&ns711=1&ns828=1&ns829=1&ns2300=1&ns2301=1&ns2302=1&ns2303=1',
      'Source-added',
      'pt-sourceadded',
      'Category members which were added with category code in the source',
      null,
      '#pt-templateadded'
    );
  }
});