Wikipedia:WikiProject User scripts/Scripts/Sort Image Links

The script sorts File Links (list of pages using the image) on Image pages. Articles are shown first, all other pages are sorted by namespace.

Description

The script sorts File Links (list of pages using the image) on Image pages. Articles are shown first, all other pages are sorted by namespace.

Limitation: for English projects only (namespaces are hardcoded).

You can test the script for example here: Image:Crypto_key.svg.

Questions or suggestions are welcome either on this talk page or on the author talk page.


Installation

All the code below should go to your monobook.js

Step 1

Main function:

//Sort Image Links
function sortImageFileLinks(){
 var rg = /^(Talk|User|Wikipedia|Image|MediaWiki|Template|Help|Category|Portal)( talk)?:/
 var li, i, removed = [], ul = document.getElementById('filelinks')
 if (!ul) return
 while ((ul=ul.nextSibling) && ul.nodeName != 'UL')
 if (!ul) return
 li = ul.getElementsByTagName('LI')
 for (i=0; i<li.length; i++)
   if (li[i].firstChild.title.match(rg))
     removed.push(li[i])
 removed.sort(function(a,b){ return (a.firstChild.title > b.firstChild.title)?1:-1})
 ul.appendChild(document.createElement('hr'))
 for (i=0; i<removed.length; i++)
   ul.appendChild(removed[i])
}

Step 2

Depends on how you want the script to work.

  • immediately on page load
if (mw.config.get('wgNamespaceNumber') == 6) 
 addOnloadHook(sortImageFileLinks);


  • when you click new sort links tab on top
if (mw.config.get('wgNamespaceNumber') == 6) 
 addOnloadHook(function(){
  addPortletLink('p-cactions', 'javascript:sortImageFileLinks()', 'sort links')
 })


  • when you click new [sort] link next to "File links" heading
if (mw.config.get('wgNamespaceNumber') == 6) 
 addOnloadHook(function(){
   var fl = document.getElementById('filelinks')
   if (fl) fl.innerHTML += ' <small>[<a href="https://profilbaru.com/en/javascript:sortImageFileLinks()">sort</a>]</small>'
})

Content Disclaimer

Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.

  1. The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
  2. There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
  3. It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
  4. Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.