MediaWiki talk:Gadget-DeepcatSearch.js

Category:User scripts needing internationalisation Category:Gadget scripts#Deepcat%20Search

New gadget

{{Editprotect}}

/**
  * Builds a search-string like  Gadget-DeepcatSearch.js + deepcat:"Gadget-DeepcatSearch.js"
  * to ease finding images in a category and its sub-categories.
  * The links are added as new tabs (monobook) or to the tab-cycler (dropdown, vector).
  *
  * @rev 15:30, 3 March 2021 (UTC)
  * @author Gadget-Gmaps.js by Docu (2009)
  * @author Gadget-Geocodecattodo.js forked by Abigor (2009)
  * @author Gadget-Searchnotincat.js forked by Docu (2010)
  * @author rewritten by DieBuche (2010) and Rillke (2012)
  * @author Gadget-DeepcatSearch.js forked by RoyZuo (2021)
**/

/*global mw, jQuery*/
if (mw.config.get('wgNamespaceNumber') === 14) {
  jQuery(document).ready(function(){
    'use strict';
    mw.util.addPortletLink('p-cactions', 
      mw.config.get('wgScript') + "?title=Special:MediaSearch&search=" + 
      encodeURIComponent(mw.config.get('wgTitle')) + "+deepcat:%22" + 
      (mw.config.get('wgTitle').split(" ").join("_")) + "%22", 
    'Deepcat Search (MediaSearch)', 
    'ca-deepcatsearch', 
    "Find images in sub-categories");
    mw.util.addPortletLink('p-cactions', 
      mw.config.get('wgScript') + "?title=Special:Search&limit=100&search=" + 
      encodeURIComponent(mw.config.get('wgTitle')) + "+deepcat:%22" + 
      (mw.config.get('wgTitle').split(" ").join("_")) + "%22", 
    'Deepcat Search (classic)', 
    'ca-deepcatsearch',
    "Find images in sub-categories");
  });
}

i adapted MediaWiki:Gadget-Searchnotincat.js to create a new gadget, which lets users see all files under a category and some of its subcats on a single page, in response to Commons:Village_pump/Archive/2021/02#Certain_diffused_categories.

working principle

the new gadget makes two buttons on any cat pages. the button is a link to search example deepcat:"example" on cat:example. one uses mediasearch and the other uses classic search.

this is particularly useful for displaying files diffused into subcats whose titles contain the top cat's name. for example, if you use this on Category:Tsai Ing-wen, all the files will be found because all the files are sorted into at least one "cat:Tsai Ing-wen in YYYY", which perfectly hits the search keywords.

MediaWiki:Gadget-DeepcatSearch

{{gadget-desc|self=MediaWiki:Gadget-DeepcatSearch|name=Deepcat Search|On Category pages, add two new tabs to easily search for files in the category and its sub-categories.|talk=MediaWiki talk:Gadget-DeepcatSearch.js|doc=Help:DeepcatSearch.js}}

MediaWiki:Gadgets-definition

DeepcatSearch[ResourceLoader|dependencies=mediawiki.util]|DeepcatSearch.js

--RoyZuo (talk) 16:24, 3 March 2021 (UTC)

✓ Done Awesome! Thank you! —Mdaniels5757 (talk  contribs) 17:07, 29 October 2022 (UTC)
Forgot to ping: @RoyZuo. —Mdaniels5757 (talk  contribs) 17:07, 29 October 2022 (UTC)

Resolved

if the category title satisfies .+by .+ then the link produced should truncate the part starting with by. for example, links for Category:Tom Hanks by year should search Tom Hanks deepcat:"Tom Hanks by year" instead.--RoyZuo (talk) 16:24, 3 March 2021 (UTC)

@Mdaniels5757: thanks a lot for creating the gadget page after more than one year! 😭
i taught myself a bit of js just now and figured out this problem. can you please do the following edits?
  1. add var dckey = mw.config.get('wgTitle').replace(/\sby\s.+/g, ""); between line 14 and 15.
  2. replace all " encodeURIComponent(mw.config.get('wgTitle')) " with " encodeURIComponent(dckey) ".--RoyZuo (talk) 14:18, 30 October 2022 (UTC)
@RoyZuo ✓ DoneMdaniels5757 (talk  contribs) 15:33, 30 October 2022 (UTC)

add the following codes after line 32.

    mw.util.addPortletLink('p-cactions', 
      mw.config.get('wgScript') + "?sort=create_timestamp_desc&title=Special:Search&limit=100&search=%22" + 
      encodeURIComponent(dckey) + "%22+-deepcat:%22" + 
      (mw.config.get('wgTitle').split(" ").join("_")) + "%22", 
    'minusDeepcat', 
    'ca-deepcatsearch',
    "Find files outside sub-categories");

this enables finding files outside the cat tree, for potential categorisation into the tree. example: https://commons.wikimedia.org/w/index.php?sort=create_timestamp_desc&title=Special:Search&limit=100&search=%22Taylor%20Swift%22+-deepcat:%22Taylor_Swift%22 .--RoyZuo (talk) 23:28, 2 December 2022 (UTC)

Feature requests

the buttons should appear like MediaWiki:Gadget-fastcci.js buttons instead of tabs in the dropdown menu.--RoyZuo (talk) 16:24, 3 March 2021 (UTC)

add support for searching by filetype, etc., e.g. filetype:video deepcat:"Tom Hanks".--RoyZuo (talk) 10:53, 20 October 2022 (UTC)

it seems i dont actually need the complicated "dckey" manoeuvre. instead just use "insource:Category".--RoyZuo (talk) 10:01, 25 January 2023 (UTC) using only deepcat:".." is good enough.--RoyZuo (talk) 12:11, 11 February 2023 (UTC)

enable customisation on search keywords, number of results per page, sorting order, etc. RoyZuo (talk) 12:36, 25 January 2023 (UTC)
incategory links.
link to mediasearch incategory sorted by recency. RoyZuo (talk) 10:57, 28 August 2023 (UTC)
see also Commons:Village_pump/Technical#c-Pelikana-20241028142600-Can_category_content_be_viewed_by_date?.--RoyZuo (talk) 15:40, 28 October 2024 (UTC)

Edit requests

{{Ep}} line 25: replace Deepcat Search (MediaSearch) with Deepcat🖼️.

line 30: replace Deepcat Search (classic) with Deepcat🔍.

reason: feedback from Commons:Village_pump/Archive/2022/10#New_gadget:_Deepcat_Search.

please also edit MediaWiki:Gadget-DeepcatSearch: replace doc=Help:DeepcatSearch.js with doc=Help:Gadget-DeepcatSearch. RoyZuo (talk) 17:28, 18 November 2022 (UTC)

✓ Done; ping User:JmabelCategory:Commons User template with namespace from the discussion --Lucas Werkmeister (talk) 19:04, 30 September 2023 (UTC)

Doesn't work & why is there no wall of images view?

It doesn't show any images of subcategories, even on categories where there are only few images in subcategories.

I'd like to use this to have a wall of images for images in category and its subcategories (if possible sorted by number of uses & relevance). For this I go to a category page and click on More->Deepcat🖼️ but even in categories with few subcats such as this it only shows the images of the main category.

So the tool seems to be dysfunctional.

I think having a wall of images view on cat pages would be very useful for many (incl readers not logged in). So I proposed that here. Prototyperspective (talk) 13:16, 8 January 2024 (UTC)

@Prototyperspective it's due to an unnecessary bit of code i made.--RoyZuo (talk) 10:29, 9 January 2024 (UTC)

{{Editprotect}}

please change both lines 21 and 28.
replace
encodeURIComponent(dckey) + "+deepcat:
with
"deepcategory:
which means removing encodeURIComponent(dckey) from the generated url. also using the full word which is a bit more practical. RoyZuo (talk) 10:26, 9 January 2024 (UTC)
✓ Done --Lucas Werkmeister (talk) 18:32, 10 January 2024 (UTC)
Thank you both! Now it works and also shows some images of subcategories in cats with many subcats like this.
Remaining problems are that most users don't know how to have this wall of images view and have the gadget disabled, that unregistered users can't use it, and that it can't sort (cached data not resorted each time it's used) the shown files by relevance via how often they are used in Wikipedia articles etc, whether they are quality images and by how up-to-date they are. I hope that at some point this view is as at least as easily enabable and visible as the "Category Slideshow" view which I don't think is even remotely as useful in practice as this viewmode. Prototyperspective (talk) 18:51, 10 January 2024 (UTC)
Again it doesn't work: when running it (wall of images view) on Category:Microscopic images relating to biology it just shows "We didn't find any results Try more general terms or check your spelling". Could you fix that? Prototyperspective (talk) 10:46, 16 June 2024 (UTC)
too many subcats. use petscan mode. RoyZuo (talk) 17:26, 16 June 2024 (UTC)
oh sorry. petscan mode has not been enabled for the gadget. you can copy the code in the next section to your common.js. see User:RoyZuo/common.js#L-151 and DIY for yours. RoyZuo (talk) 17:29, 16 June 2024 (UTC)
If this makes it work could you please add this to the gadget itself? Maybe as a third item in the dropdown or calling things automatically if it returned there's too many subcats or no results. Prototyperspective (talk) 20:42, 17 June 2024 (UTC)

Deepcat PetScan 999

It is requested that an edit or modification be made to this protected page.
Administrators: Please apply <nowiki> or {{Tl}} to the tag after the request is fulfilled.

RoyZuo

Category:Commons protected edit requests for interface administrators#Gadget-DeepcatSearch.js
    mw.util.addPortletLink('p-cactions', 
    
        "https://petscan.wmflabs.org/?project=wikimedia&cb_labels_any_l=1&cb_labels_no_l=1&cb_labels_yes_l=1&language=commons&ns%5B6%5D=1&output_limit=999&depth=99&sortorder=descending&format=html&active_tab=tab_output&ext_image_data=on&doit=&categories=" +
    
      mw.config.get('wgTitle').split(" ").join("_"), 
    
    'Deepcat PetScan 999', 
    
    'ca-deepcatsearch',
    
    "PetScan images in sub-categories");

please add these lines after line 31.

they will add a new tab that links to a petscan query of 99 levels down the category. the query is autorun and returns max. 999 files.

then, delete the words "two new" from MediaWiki:Gadget-DeepcatSearch for conciseness. RoyZuo (talk) 13:26, 23 January 2024 (UTC)

also, change line 15 to
if (mw.config.get('wgNamespaceNumber') === 14 || mw.config.get('wgNamespaceNumber') === 15) {
so that it works on cat talk pages too. quite reasonable? RoyZuo (talk) 13:28, 23 January 2024 (UTC)
the benefit is, petscan query is not restricted by the 256 cat search limit. RoyZuo (talk) 14:09, 23 January 2024 (UTC)
Would this solve the problem that e.g. here only "We didn't find any results" is displayed?
Also @Mdaniels5757: Prototyperspective (talk) 23:02, 14 July 2024 (UTC)

Deepcategory has been improved

Seems like the deepcategory search operator has been improved so the gadget should work more often: phab:T369808.

See phab:T376440 for the issue that if solved would probably make this very useful gadget work in all cats. "Deepcategory search does not show any results on Commons instead of results up to the configured limits". Prototyperspective (talk) 00:05, 17 October 2024 (UTC)

Apparently now it even works for categories as large as Art. Could somebody explain what has changed? So far it seems like the linked issue may not need to be solved and things do work now which would be great.
Also see issues here for further ways to improve MediaSearch which is leveraged by this tool.
If this works as well as it seems, I think making this gadget available by default or adding a button for the view it creates to category pages could be considered now. In videos of categories the Videos tab should be selected in MediaSearch.
Prototyperspective (talk) 13:03, 17 October 2024 (UTC)
Okay it hasn't been fixed – it only changes to incategory so it displays some results if there are files directly in the category. I found out by searching deepcategory:"Science" which shows results for incategory:"Science". So the T376440 issue linked above still needs to be fixed so shows the deepcategory results up to some limit (and it could make use of caching). Prototyperspective (talk) 13:40, 18 October 2024 (UTC)
I'm wondering if that is an improvement. Maybe on special:search, we could edit the interface message to make it clear. On MediaSearch, it's a bit more confusing.
 ∞∞ Enhancing999 (talk) 16:06, 18 October 2024 (UTC)
I added an update request to MediaWiki talk:Cirrussearch-feature-deepcat-timeout.
 ∞∞ Enhancing999 (talk) 10:19, 19 October 2024 (UTC)
Category:Commons User template with namespace Category:Commons protected edit requests for interface administrators Category:Gadget scripts Category:User scripts needing internationalisation