Template talk:High-use

(Redirected from Template talk:High-use/sandbox)
Latest comment: 1 day ago by CalendulaAsteraceae in topic Edit request 27 August 2025: refactor

Use on taxonomy templates

edit

Taxonomy templates, i.e. templates like Template:Taxonomy/Otophysi, are part of the WP:Automated taxobox system. They function like database entries and are used by the system to construct automated taxoboxes. Neither sandboxes nor testcases make much sense for taxonomy templates, because the potential effects of a change to a taxonomy template can only be fully seen by looking at the resulting taxoboxes created by the automated taxobox system. Accordingly, I'm experimenting in this module's sandbox with constructing a different message when invoked from a taxonomy template.

If you have any comments, please leave them at Wikipedia talk:Automated taxobox system/Archive 7#High use notices on taxonomy templates to avoid duplicated discussions. Peter coxhead (talk) 18:22, 25 May 2025 (UTC)Reply

Include mainspace count

edit

Instead of just taking the number of transclusions and dividing by {{NUMBEROFPAGES}} (which is currently 63,227,481), I was thinking it might make for a more cautionary warning to also show how big the number is compared to {{NUMBEROFARTICLES}}. See [1] for the sandboxed change. Basically, this would cause the template to look like this:

Naturally, not all templates that use {{High-use}} are used in mainspace, so I can see how this change could be a little confusing, but I think it would still make the percent number more meaningfully cautionary. For example, Template:Short description says that the template is used on "10% of all pages", which honestly feels like not a big number—it would more clearly impress upon the layperson the gravity of the situation if it said "92% of all mainspace articles". Template:WikiProject banner shell would say: "This template is used on approximately 11,300,000 pages, which is roughly 161% of all mainspace articles or 18% of all pages." Mz7 (talk) 06:50, 29 May 2025 (UTC)Reply

@Mz7 I'm worried that would be a bit misleading, as it would result in things like {{WikiProject banner shell}} saying that it's being used on 163% of mainspace articles. If there's a strong desire to include this information I could look into having Ahechtbot tabulate mainspace transclusions in addition to all transclusions, but that would cause a significant increase in runtime and require breaking changes to the data pages. --Ahecht (TALK
PAGE
)
18:13, 29 August 2025 (UTC)Reply

TemplateStyles

edit

There are a few high-use template styles, e.g., Template:Sister project/styles.css, which have no such indication (as they do not have documentation subpages). In my own private wiki, I have provided an analogous notice via the top icon indicator as these are still processed within CSS comments. My Module:High-use has been changed as follows:

local function showIndicator()
	return mw.getCurrentFrame():preprocess([=[
{{#tag:indicator|<span class="plainlinks" style="background-color:pink;">[[WP:High-risk templates|High-use]]:[https://linkcount.toolforge.org/?project=en.wikipedia.org&page={{urlencode:{{FULLPAGENAME}}}}#transclusions {{#invoke:transclusion count|fetch}}]</span>|name=High-use}}]=])
end

function p._main(args, nocat)
	local contentModel = mw.title.getCurrentTitle().contentModel
	if contentModel == "css" or contentModel == "sanitized-css" then
		return showIndicator()
	end
-- remainder of function

If you think this is useful on Wikipedia, I can make the associated changes for all but non-admin protected pages. Dpleibovitz (talk) 17:14, 16 July 2025 (UTC)Reply

Edit request 27 August 2025: refactor

edit

Description of suggested change: I've refactored the module code to make it:

  • easier to understand (added comments)
  • easier to localize
  • have less repeated code
  • use |demo= as the title everywhere, including in the Toolforge link, if provided
  • use the base page for /testcases pages as well as /doc and /sandbox
  • use Lua for the system categorization code instead of preprocessing a string containing {{sandbox other}}, a switch statement, and a Module:Effective protection level invocation

My code is in Module:High-use/sandbox and the test cases are at Template:High-use/testcases. Please check my code and update the main module if it looks good!

Diff: sandbox diffCalendulaAsteraceae (talkcontribs) 08:28, 27 August 2025 (UTC)Reply

Answering your post at Wikipedia:Village pump (technical) § Code review for Module:High-use refactor here because this is a better venue.
Add require ('strict') which will help find globals that ought not be globals, etc.
For i18n, consider rewriting count_from_args() (lines 18–36 – permalink); mayhaps sommat like this:
require ('strict');

local lang_obj = mw.getContentLanguage()										-- this here because the language object is used multiple places in the module

local function count_from_args(args_t)
	if tonumber(args_t.count) then												-- check if function has already been used
		return count;															-- early exit if already used
	end

	local count;	

	if count == nil and yesno(args_t['fetch']) == true then						-- '== true' instead of '~= false'
		count = _fetch(args_t)													-- fetch transclusion count
	end
	
	if count == nil and args_t[1] ~= nil and args_t[1] ~= '' then				-- use explicitly-provided count when fetch fails
		count = math.floor (lang_obj:parseFormattedNumber (args_t[1]));			-- convert local language number string to a number understandable by lua
	end
	
	return count > 0 and count or nil;											-- incase someone writes a negative number
end
Trappist the monk (talk) 16:35, 29 August 2025 (UTC)Reply
Thank you, implemented! I think the current code does use _fetch if args['fetch'] is nil, so I've left that as-is. —CalendulaAsteraceae (talkcontribs) 21:25, 29 August 2025 (UTC)Reply
It looks like you've implemented hooks to show percentage of articles in addition to all pages. See the section above for my concerns there. We can tabulate mainspace usage separately with the bot, but it's not worth the effort unless there's actual consensus to include it. --Ahecht (TALK
PAGE
)
19:09, 29 August 2025 (UTC)Reply
TBH I just left that in because someone else had been working on it, no problem to take that out. —CalendulaAsteraceae (talkcontribs) 21:20, 29 August 2025 (UTC)Reply