MediaWiki talk:Gadget-DeepcatSearch.js

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search


New gadget

[edit]

{{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

--RZuo (talk) 16:24, 3 March 2021 (UTC)[reply]

✓ Done Awesome! Thank you! —‍Mdaniels5757 (talk • contribs) 17:07, 29 October 2022 (UTC)[reply]
Forgot to ping: @RZuo. —‍Mdaniels5757 (talk • contribs) 17:07, 29 October 2022 (UTC)[reply]

Resolved

[edit]

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.--RZuo (talk) 16:24, 3 March 2021 (UTC)[reply]

@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) ".--RZuo (talk) 14:18, 30 October 2022 (UTC)[reply]
@RZuo ✓ Done —‍Mdaniels5757 (talk • contribs) 15:33, 30 October 2022 (UTC)[reply]

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 .--RZuo (talk) 23:28, 2 December 2022 (UTC)[reply]

Feature requests

[edit]

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

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

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

enable customisation on search keywords, number of results per page, sorting order, etc. RZuo (talk) 12:36, 25 January 2023 (UTC)[reply]
incategory links.
link to mediasearch incategory sorted by recency. RZuo (talk) 10:57, 28 August 2023 (UTC)[reply]

Edit requests

[edit]

{{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. RZuo (talk) 17:28, 18 November 2022 (UTC)[reply]

✓ Done; ping User:Jmabel from the discussion --Lucas Werkmeister (talk) 19:04, 30 September 2023 (UTC)[reply]

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

[edit]

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)[reply]

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

{{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. RZuo (talk) 10:26, 9 January 2024 (UTC)[reply]
✓ Done --Lucas Werkmeister (talk) 18:32, 10 January 2024 (UTC)[reply]
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)[reply]
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)[reply]
too many subcats. use petscan mode. RZuo (talk) 17:26, 16 June 2024 (UTC)[reply]
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:RZuo/common.js#L-151 and DIY for yours. RZuo (talk) 17:29, 16 June 2024 (UTC)[reply]
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)[reply]

Deepcat PetScan 999

[edit]
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.

Prototyperspective

    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. RZuo (talk) 13:26, 23 January 2024 (UTC)[reply]

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? RZuo (talk) 13:28, 23 January 2024 (UTC)[reply]
the benefit is, petscan query is not restricted by the 256 cat search limit. RZuo (talk) 14:09, 23 January 2024 (UTC)[reply]
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)[reply]