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

✓ Done Awesome! Thank you! —‍Mdaniels5757 (talk • contribs) 17:07, 29 October 2022 (UTC)Reply[reply]
Forgot to ping: @RZuo. —‍Mdaniels5757 (talk • contribs) 17:07, 29 October 2022 (UTC)Reply[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[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[reply]
@RZuo ✓ Done —‍Mdaniels5757 (talk • contribs) 15:33, 30 October 2022 (UTC)Reply[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[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[reply]

add support for searching by filetype, etc., e.g. filetype:video deepcat:"Tom Hanks".--RZuo (talk) 10:53, 20 October 2022 (UTC)Reply[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[reply]

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

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