Talk:Community Wishlist/W393
Add topicWish received: Tool to show category path for files
[edit]Thanks again for another solid and well-researched submission. We’ve noted your request about showing the category path for files, and we’re starting to look into where it might best fit.
Appreciate your continued dedication to improving Commons — it really shows.
--ARamadan-WMF (talk) 17:24, 17 June 2025 (UTC)
Clarification
[edit]It's not 100% clear to me what you're asking for here ...
"Somebody please enable showing a category path beneath each item in the thumbnail view (and a button per item in the normal table view). It would be best as a native functionality but a gadget would help a lot too and maybe could later be turned into a native feature"
So I think what you mean is - if I do a deepcat search on Commons, then I want to see the category path from the searched-for category to the category-the-file-is-in for each image on the search results page. Is that correct?
CParle (WMF) (talk) 11:14, 18 June 2025 (UTC)
- That paragraph is indeed pretty unclear and confusing. I'll see if I can make the wish clearer. The other text explains it better than that paragraph.
- Yes, partly correct. This is first of all / mainly about a tool to see the category path from a given file to a given category – this tool/method/API-call could then be integrated in various ways.
- So when searching with deepcategory, it could preselect the category of the first deepcategory in the search query. In that deepcategory view there would be a button next to underneath each file (could also be in the image preview) to see the category-path (again, FastCCI basically already does this).
- Ideally if it's not too much serverload and feasible or via some 'load all' button, it could show the cat-path for why the file is included in the results as hoverable text underneath each file (that is why it's included in any of the deepcategory categories of the search query [which for the envisioned wall-of-images 'viewmode' would be just one category and just one cat is the most common case])
- And when viewing a file page, there would also be a button that when clicked shows an input box into which to enter the category to which it should show the path (from the file one is viewing to the entered category).
- So when searching with deepcategory, it could preselect the category of the first deepcategory in the search query. In that deepcategory view there would be a button next to underneath each file (could also be in the image preview) to see the category-path (again, FastCCI basically already does this).
- Prototyperspective (talk) 23:48, 18 June 2025 (UTC)
This already exists
[edit]https://categorypath.toolforge.org * Pppery * it has begun 15:48, 10 October 2025 (UTC)
- No, it doesn't. Thanks a lot for the link though! Maybe this could be developed further to also work for files on Commons or its code be used for this (probably rather FastCCI's code would be used since it can already be used for it if it wasn't down all the time despite being a default gadget for years until just very recently). Prototyperspective (talk) 16:43, 10 October 2025 (UTC)
- @Prototyperspective there's also this instrument: https://mbh.toolforge.org/cpf Well very well (talk) 23:43, 19 May 2026 (UTC)
- Yes, it works for any type of pages on any wiki, but uses depth-first search (not breadth-first search), and because of extremely deep Commons category tree, works bad on Commons (works better on wikis with less deep category tree). MBH (talk) 04:34, 20 May 2026 (UTC)
- @Prototyperspective there's also this instrument: https://mbh.toolforge.org/cpf Well very well (talk) 23:43, 19 May 2026 (UTC)
An attempt
[edit]@Prototyperspective I made an attempt at this. So far only works on media search for audio files (E.g. The dark wave search you had in your example). Try adding mw.loader.load( 'https://commons.wikimedia.org/wiki/User:Bawolff/catpath.js?action=raw&ctype=text/javascript') to commons:Special:MyPage/common.js. See also https://commons-cat-path.toolforge.org/ Bawolff (talk) 19:39, 18 April 2026 (UTC)
- I think it should now work for images on Special:MediaSearch as well. Bawolff (talk) 06:07, 19 April 2026 (UTC)
- Amazing! Thank you very much. This is super useful. I think the wish can be set to in progress now @MikeZ-WMF:.
- I noticed that for some images it does not display the path. (eg this here). Moreover, it would be great if there was a way to see the paths directly on the results page without having to open the QuickView. Could you add a button like 'load paths for results on this page' which if clicked loads the paths directly if the search query is just one deepcategory or opens an input box where one enters the category it should show the relation to? This would make it very useful to correct cases where there are lots of offtopic files (there's many of these). Prototyperspective (talk) 11:40, 19 April 2026 (UTC)
- Do you mean for like the audio page only? I'm not sure where exactly we would put the paths on the image page of media search where there is just images and no associated text. Bawolff (talk) 16:23, 19 April 2026 (UTC)
- I also added a button in the tools sidebar on image pages. Bawolff (talk) 18:48, 20 April 2026 (UTC)
- Great, thanks! Already found and fixed a few miscategorizations with it
- Some images still do not display the path – eg see the offtopic rocket start etc here
- The images on that page themselves also don't load in the QuickView and I think that wasn't happening before so probably the gadget is causing it
- Any ideas/way on how to make the link to check for the path to a cat quicker and easier to open? There's quite a few links in the Tools dropdown and every time one first needs to locate it. I'd prefer if the button was directly on the file page, eg next to "Open in MediaViewer" or in the form of a small button in the categories panel.
- Yes, just files in the open tab (eg Images or Audio) so when going to another tab one would have to click the button again to load the paths.
- The path would be added to .sdms-search-results__list -> after .sdms-image-result – specifically beneath it. It would be great if there was also a button that if clicked (default on depending on a preference) showed (trimmed) file titles beneath image thumbnails but that's another subject. Maybe roughly like so:
- Great, thanks! Already found and fixed a few miscategorizations with it
// select the target anchor elements (adjust selector as needed)
const anchors = document.querySelectorAll('a.sdms-image-result');
anchors.forEach(a => {
// choose the text you want under each link.
// Here we use the anchor's outerHTML (change to any string per-link)
const text = a.outerHTML; // or a.getAttribute('title') or any custom string
// create a block element to appear underneath
const wrapper = document.createElement('div');
wrapper.style.marginTop = '4px'; // spacing
wrapper.textContent = text; // for plain text; use innerHTML if you want HTML
// insert after the anchor
a.after(wrapper);
});
Prototyperspective (talk) 23:05, 20 April 2026 (UTC)
- If you mean file:First NASA ISINGLASS rocket launch.jpg, it shows the category path for me. Potentially if a lot of category paths are requested at once it might delay loading the path or cause it to fail (maybe). Bawolff (talk) 23:43, 20 April 2026 (UTC)
- Now I can see it too when I click on that image first. I clicked on a few other images first last time. However, that image doesn't load in the QuickView – there's just these three loading-dots. I've clicked around and the paths now kept on displaying so maybe #1 above is solved. Prototyperspective (talk) 11:00, 21 April 2026 (UTC)
- It happened again at the link Diagrams query and on the file pages of this and this. It worked for lots of other files but not these. Also I think the gadget once bugs like this are fixed would best be a default-enabled gadget and if not at least easily-enabable. Prototyperspective (talk) 11:35, 21 April 2026 (UTC)
- Hi @Prototyperspective
- Just checking in here as this is still marked in progress, but the proof of concept user script by @Bawolff may satisfy most needs? If merging into deepcat gadget is a hard requirement that solve other problems, then I think it makes sense to build consensus and support to prioritize this in the long-term. MikeZ-WMF (talk) 20:11, 30 June 2026 (UTC)