Template talk:If in category

Alternative methods?
@Sdkb, do you think some alternative methods of checking if the page contains a category would be worth trying? For example, Find page text doesn't require a hacky article transclusion, and as I recently found out, modules can be used to recursively expand templates, which might help with indirect categorisation (see ExpandTemplates). Qwerfjkl talk  10:29, 29 May 2022 (UTC)
 * PINGFIX @. &#8213;  Qwerfjkl talk  10:31, 29 May 2022 (UTC)
 * Would searching for the page in the, instead of looking for the category in the page text, be one such alternative (which, as a bonus, can include subcategories, might work with pages added through templates, and not be as expensive)? I tried that here, but didn't quite get it there yet. — Guarapiranga ☎ 01:51, 30 May 2022 (UTC)
 * I'd definitely be open to alternative methods if you can get them to work; have at it! &#123;{u&#124; Sdkb  }&#125;  talk 05:12, 30 May 2022 (UTC)
 * OTOH, Galobtter reckons this template would probably be cheaper if done purely as a module... [and it] only search[ed] the last section of the article. — Guarapiranga ☎ 06:10, 30 May 2022 (UTC)
 * Probably just using Find page text would help a lot since it's a module that pretty much does what is needed here. Galobtter (pingó mió) 06:17, 30 May 2022 (UTC)
 * Here's a Find page text example: Producing '' &#8213;  Qwerfjkl  talk  06:59, 30 May 2022 (UTC)
 * Like, Qwerfjkl? — Guarapiranga ☎ 08:59, 30 May 2022 (UTC)
 * And here's a Module:String example: Producing '' &#8213;  Qwerfjkl  talk  08:00, 30 May 2022 (UTC)
 * module:string vs module:string2: is there a difference in performance? — Guarapiranga ☎ 09:03, 30 May 2022 (UTC)
 * @Guarapiranga, and  respectively, in terms of real-time usage (seconds) as an average over 5 tests. &#8213;  Qwerfjkl  talk  11:56, 31 May 2022 (UTC)
 * 25x faster?? That's huge! Sure about that, Qwerfjkl? To me this indicates module:string has some serious implementation issues (it seems string2 has really pulled some strings on string 😅). What about the version? Works? — Guarapiranga ☎ 12:06, 31 May 2022 (UTC)
 * ┌─────────────────────┘ @Guarapiranga, I think it's because String recursively substitutes the text it's given, whereas String2 fetches the current content t on a page title. Theoretically, String could detect indirect categorisation; I haven't tested it though. I'll test the sandbox later. &#8213;  Qwerfjkl talk  12:21, 31 May 2022 (UTC)
 * The sandbox isn't really comparable because it's a template taking parameters, not simply wikitext, but it took about 0.7-8 s, and 0.002 s when substituted. &#8213;  Qwerfjkl talk  10:17, 1 June 2022 (UTC)
 * I think if you want this different version to work, you are gonna need to put the entire thing in lua. In it's current state, its forced to transclude the entire article. This leads to a lovely little "Warning: Post-expand include size is too large" should a somewhat large article be checked (Like if Earth is checked twice), and the other stats in the Parser profiling data aren't looking to pretty. A lua implementation would probably dodge a lot of the current issues with the existing implementation. Note that modules like Module:Transcluder already exist that can help with something like this. Could this be a potential thing worth working on? Aidan9382 (talk) 05:08, 6 June 2022 (UTC)
 * @Aidan9382, as I mentioned above, the sandbox is way less expensive. &#8213;  Qwerfjkl talk  07:11, 6 June 2022 (UTC)
 * Oh god. It seems im extremely unlucky. I happened to pick a rare edge case in category detection which made me assume Find page text wouldnt work without full transclusion (It was a category that went ). I've gone ahead and fixed that, though for some reason LUA regex is acting funny with me today, so I'd like it if you double checked that. Note though that, now that it seems fine, why hasnt this version been put into use? Aidan9382 (talk) 07:28, 6 June 2022 (UTC)
 * Given that If in category is used in exactly mainspace articles, I don't see why not, Aidan. — Guarapiranga ☎ 09:50, 6 June 2022 (UTC)
 * If you're done giving it some final changes, could you move everything to the live version? This new version also helps solve a new problem with Featured picture, and I'd like to get that patched up. Thanks! Aidan9382 (talk) 10:20, 6 June 2022 (UTC)
 * OOjs UI icon check-constructive.svg Done &#8213;  Qwerfjkl talk  10:30, 6 June 2022 (UTC)
 * How about to accommodate redirects? — Guarapiranga ☎ 01:40, 7 June 2022 (UTC)
 * ┌─────────────────────┘ Well, I (stress) tested it here, with no problems, so went ahead and committed it (since it wasn't yet used in mainspace anyhow--and now it is!) — Guarapiranga ☎ 03:40, 7 June 2022 (UTC)