Wikipedia:Bots/Requests for approval/MusikBot II 3


 * The following discussion is an archived debate. Please do not modify it. To request review of this BRFA, please start a new section at WT:BRFA. The result of the discussion was

MusikBot II 3
Operator:

Time filed: 03:02, Saturday, February 2, 2019 (UTC)

Function overview: Automatically protect high-risk templates and modules

Automatic, Supervised, or Manual: Automatic

Programming language(s): Ruby

Source code available: GitHub

Links to relevant discussions (where appropriate): Special:Permalink/881367182

Edit period(s): Daily

Estimated number of pages affected: ~500 on the first run. Variable for future runs, perhaps 0 to 5 pages daily.

Namespace(s): Template, Module, Wikipedia, User

Exclusion compliant (Yes/No): Yes, going by the  hash in the bot configuration.

Adminbot (Yes/No): Yes

Function details: Every day, a query is ran to identify templates and modules that have N number of transclusions, and it will protect them accordingly based on the bot configuration. Here is an explanation of each option and the initial values (per the WP:AN discussion):
 * The  option specifies what protection level should be applied for what transclusion count. For now this will be set to 500 transclusions for semi-protection, and 5000 for template protection.   and   are available as options but for now will be left   (unused).
 * The  (and   for regular expressions) option is a list of pages that the bot will ignore entirely. The keys are the full page titles (including namespace), and the values are an optional space to leave a comment summarizing why the page was excluded.
 * The  option specifies the number of days the bot should wait after a previous protection change (by another admin) before taking further action. The initial value for now will be 7 days.
 * Which namespaces to process. For now this includes Template, Module, Wikipedia, and User.

For now, the bot will not lower the protection level to conform to the settings. Move protection is applied using the same level as the edit protection, but again it will never lower the existing protection. The bot will also ignore any page specified at MediaWiki:Titleblacklist which includes the  flag, and the protection level is the same as the one the bot wants to apply.

Discussion

 * If you're running a query like  to find the templates to protect, I note that'll be a pretty expensive query and I wonder whether it can be run less often than daily. Anomie⚔ 03:26, 2 February 2019 (UTC)
 * , I imagine (as you have suggested to me in the past) that this could be batched, like:
 * The above takes under 2s to complete, and the size of the batches could in theory be adjusted on the fly. I know there isn't a tl_id field, which would be ideal, but this would make the overall query much less expensive. SQL Query me!  05:37, 2 February 2019 (UTC)
 * I've been doing something similar to:
 * Which usually takes around 30 seconds, and only a few seconds for the Module namespace. If you've any suggestions to improve it, please enlighten :) I don't think it's crazy long for a task of this nature. Do I need to check other namespaces, too?
 * Another thing I should bring up: There are subpages of Template:POTD for each individual day, and the current day always has a lot of transclusions. The following day it's removed from whichever template and the count goes back down again. Should I exclude these templates? Or add some special code to protect/unprotect accordingly, every day? &mdash; MusikAnimal  talk  07:43, 2 February 2019 (UTC)
 * POTD only has ~600 transclusions on low-visibility and low-vandalism-target userpages, so I think those templates should be excluded. Galobtter (pingó mió) 07:58, 2 February 2019 (UTC)
 * Per Administrator's noticeboard/Incidents, Could the bot run the query on Wikipedia space/other namespaces? (perhaps only weekly if the query is too slow?)
 * And I note that Database reports/Unprotected templates with many transclusions appears to run a very similar query. Galobtter (pingó mió) 10:00, 2 February 2019 (UTC)
 * Sure, we can include the Wikipedia namespace. It after all seems like the only other namespace that would contain highly-transcluded pages. &mdash; MusikAnimal  talk  10:04, 2 February 2019 (UTC)
 * I can see some userboxes and user templates having high transclusions - e.g there's User:Resoru/UBX/VG/ with 1700 transclusions etc. Galobtter (pingó mió) 10:17, 2 February 2019 (UTC)
 * Userboxes... of course. Sure, we can check the userspace too. &mdash; MusikAnimal  talk  19:10, 2 February 2019 (UTC)
 * Wow, that's surprisingly fast. Looks like it touches about 1e7 rows, finding the possible titles first then diving into the templatelinks tl_namespace index for each one. ... The ~4% of templates that are already protected account for ~98% of all template transclusions, so the query only has to look through the remaining ~2% of transclusions. I withdraw my concern, but you might have it give you some sort of warning if that query starts taking significantly more time. Anomie⚔ 13:42, 2 February 2019 (UTC)
 * Sure, we can include the Wikipedia namespace. It after all seems like the only other namespace that would contain highly-transcluded pages. &mdash; MusikAnimal  talk  10:04, 2 February 2019 (UTC)
 * I can see some userboxes and user templates having high transclusions - e.g there's User:Resoru/UBX/VG/ with 1700 transclusions etc. Galobtter (pingó mió) 10:17, 2 February 2019 (UTC)
 * Userboxes... of course. Sure, we can check the userspace too. &mdash; MusikAnimal  talk  19:10, 2 February 2019 (UTC)
 * Wow, that's surprisingly fast. Looks like it touches about 1e7 rows, finding the possible titles first then diving into the templatelinks tl_namespace index for each one. ... The ~4% of templates that are already protected account for ~98% of all template transclusions, so the query only has to look through the remaining ~2% of transclusions. I withdraw my concern, but you might have it give you some sort of warning if that query starts taking significantly more time. Anomie⚔ 13:42, 2 February 2019 (UTC)

Now that you've posted the source code, I've given it a quick review. Note I don't actually know python Ruby, so I mainly looked at the general logic. HTH. Anomie⚔ 14:06, 4 February 2019 (UTC)
 * L70-L81: The query you have here seems significantly slower than the one you posted earlier. Among other things, there should be no need for "DISTINCT(page_title)" nor for ordering the results.
 * L77, L80, L93: I don't see anything obvious that prevents SQL injection if,  , or   are set to unexpected values. Yes, MediaWiki's restriction of editing .json pages helps, but it doesn't hurt to double check it. Simply casting them to integers before interpolating would be good.
 * L88-L93: Seems like you could add  to the query to avoid fetching extra rows when all you care about is whether any rows exist.
 * L99: Does the  parameter to action=titleblacklist not work here?
 * Ha, it is clear that you don't actually know python, because the code is in Ruby :) Galobtter (pingó mió) 14:30, 4 February 2019 (UTC)
 * And I don't know Ruby either! ;) Anomie⚔ 13:01, 5 February 2019 (UTC)
 * Thanks for the code review! I have made some changes based on your feedback. I am using prepared statements now, but am not doing any type casting. I think it's better for it to fail entirely in this case (and logged to User:MusikBot II/TemplateProtector/Error log). You were right that the main query is a little slower, apparently due to the COUNT in the SELECT clause? It still maxes out at around 1 to 2 minutes run time, which I don't think is terrible. The whole task takes about 5 minutes to complete. Does the parameter to action=titleblacklist not work here? -- it does not appear to. I always get "ok" when logged in as the bot. Regards, &mdash;  MusikAnimal  talk  20:34, 4 February 2019 (UTC)
 * The selecting of COUNT(*) isn't the problem, the problems were the ORDER BY (which you fixed) and GROUPing BY tl_title instead of page_title (which you didn't fix yet). Sometimes MySQL can figure out things are equivalent based on join or where clauses and sometimes it can't, and this seems to be one where it can't.
 * Switching to a parameterized query for  should be sufficient, as it should result in an SQL error being thrown on bad input rather than an SQL injection.
 * What's the exact query you're trying with ? It works when I try something like this, both with this account and with AnomieBOT's account. Anomie⚔ 13:15, 5 February 2019 (UTC)
 * An example would be for Template:Taxonomy/Doridina, e.g. . I get "ok" while logged in and "blacklisted" while logged out. I guess it's just an issue for titles restricted to ? &mdash;  MusikAnimal  talk  17:25, 5 February 2019 (UTC)
 * Yeah, it looks like there's no way to override the "autoconfirmed" restriction. Anomie⚔ 21:58, 5 February 2019 (UTC)


 * Another issue I've encountered: Sometimes there is a highly visible Wikipedia page that is managed by a bot, for instance Good article nominations/Topic lists/Video games. If MusikBot were to template-protect, the bot can no longer edit it. In my opinion, we should just add template editor rights to such bots. If the transclusion count is really that high, I don't think it's safe to leave it under mere semi-protection. Another option is to check the revision history and try to deduce if it is bot-maintained. That seems error-prone and would be rather expensive, so I'm going to advise against this strategy. Finally, we could just ignore the Wikipedia namespace altogether. I have not encountered a bot-maintained Template or Module, and I suspect such bots would be handed template editor rights anyway. Thoughts? &mdash; MusikAnimal  talk  01:09, 6 February 2019 (UTC)
 * Ugh, there's also WikiProject to-do templates, e.g. WikiProject Bangladesh/to do. Many include constructive edits from unconfirmed users. I can exclude these using the  option, since all seem to end in "to do", "ToDo", or "to-do", etc. But again... some have an awfully high transclusion count. What to do? &mdash;  MusikAnimal  talk  01:18, 6 February 2019 (UTC)
 * IANA BAG member or BOTP expert, but if you were to generate a one-time list of guesses for such bots, I'd be more than comfortable granting template-editor to such bots assuming their operators having the equivalent. As you say, high risk transclusions should be protected, and bots should be made to work within that system not the other way around. (As an aside, this would be/have been a good argument for allowing ECP in this task.) ~  Amory  (u • t • c) 01:23, 6 February 2019 (UTC)
 * There's for Good article nominations/Topic lists/Video games and  for Good article nominations/backlog/items. That's the only two I've encountered thus far. &mdash;  MusikAnimal  talk  01:34, 6 February 2019 (UTC)
 * Sweet! WP:GAN/backlog/items has only ~700, so safely far from the TE level, and I think we can trust   ~  Amory  (u • t • c) 01:40, 6 February 2019 (UTC)
 * It might make more sense to just put such pages on your exclude list than to give random bots templateeditor. Anomie⚔ 01:57, 6 February 2019 (UTC)
 * I've already semi'd both. But Good article nominations/Topic lists/Video games has nearly 80,000 transclusions. That's a lot! At some point we have to draw the line... or use extended-confirmed protection? &mdash; MusikAnimal  talk  02:03, 6 February 2019 (UTC)
 * Given the circumstances (Legobot isn't a template editor), I went ahead and broke the rules by adding ECP to Good article nominations/Topic lists/Video games. The issue of what MusikBot should do in this scenario still stands. I guess we'll just handle it on a case by case basis. &mdash; MusikAnimal  talk  04:16, 6 February 2019 (UTC)
 * I think the easiest thing would be to, after the initial run, wait ~week for the next run, so that people can point out these edge cases to be added to the exclusion. Another thing you'd want to do is prepopulate the exclusion list with templates that have been ECP protected, because they will almost all be ones where people like have lowered the protection after (batch) template-protecting templates, and the bot shouldn't annoy people by again template-protecting the templates.
 * You'd also definitely want to exclude WikiProject banner templates from template-protection - Primefac batch protected all templates with ~2000+ transclusions nearly a year ago but reduced to semiprotection WikiProject templates, as they don't really need TPE. Galobtter (pingó mió) 06:31, 6 February 2019 (UTC)
 * Would it be better to just flat-out exclude all WikiProject banner templates, since they're likely all semi'd by now? I assume new WikiProjects aren't created that often. I'd prefer to leave this special handling to humans. Otherwise we'd need to further complicate the configuration by allowing you to specify protection levels for each of the  and.
 * Right now the bot only targets unprotected templates/modules, so we wouldn't be template-protecting anything that Primefac had lowered to ECP. Again if we want options like "exclude this page from template-protection, but do include it for semi-protection", it will complicate the configuration, which I'm hoping to avoid. &mdash; MusikAnimal  talk  18:14, 6 February 2019 (UTC)
 * My general thoughts is that counting transclusions isn't a very good metric for "highly visible template/module". I think page views is a significantly better metric. Legoktm (talk) 05:32, 6 February 2019 (UTC)
 * Page views would be extremely slow to query, but I suppose the bot could set the threshold for template-protection as: either 2000+ article space transclusions - which are very disproportionately viewed - or 10000+ non-article space transclusions, because vandalism or disruption on templates transcluded on talk pages is lower, and semi-protection would stop most of it. Though I think the blanket 5000 threshold works fine enough and not sure if it should be complicated. Galobtter (pingó mió) 06:31, 6 February 2019 (UTC)
 * I thought about going by pageviews. It would be interesting to see the results, to say the least! Though I question how feasible it is to go through every Template/Module/User/Wikipedia page and get the pageviews of all the transclusions :( Depending on the circumstances, it could take days to finish and be error-prone. Pageviews anomalies happen a lot too: e.g. false traffic from an undeclared bot, or recent deaths/incidents that can overnight send a generally unpopular page to the top of the charts. Defining the conditions for pageviews and working out all the edge cases is going to be a nightmare, let alone how slow it would be and challenging to implement. I'd love to rope in some pageviews logic, but hopefully we can save that for version 2 :)
 * But I do like 's compromise of going by the namespaces of the transclusions. That is a simple tweak to the query, and might even make the task as a whole faster (or slower... ;). It will complicate the configuration, though. I guess it would look something like:
 * a little ugly :/ I'm a bit hesitant to change the thresholds at this time. Shouldn't we go back to WP:AN for further input? I'd argue we should go with the current consensus, and see how people react after the first round of protections. I really like how simple the system is right now. &mdash; MusikAnimal  talk  17:54, 6 February 2019 (UTC)
 * Regarding The bot will also ignore any page specified at MediaWiki:Titleblacklist which includes the flag., the bot should still template-protect taxonomy templates like Template:Taxonomy/Embryophytes, being used on 10000+ articles and regularly getting disruption from people not getting a consensus for their changes (and as autotaxobox gets more widely used over manual taxobox, the transclusions of these templates are rising pretty quickly). Galobtter (pingó mió) 06:31, 6 February 2019 (UTC)
 * That seems reasonable. Maybe we should compare against the Titleblacklist protection level. So for taxonomy templates, if there are less than 5000 transclusions, we don't protect at all since it is already done by the Titleblacklist (as specified with ). If the template has >= 5000 transclusions, we template-protect as we would any template. That keeps it simple; basically checking the Titleblacklist is only done to avoid redundant protections. I think this is what  was going for when they commented on the WP:AN discussion. &mdash;  MusikAnimal  talk  18:04, 6 February 2019 (UTC)
 * a little ugly :/ I'm a bit hesitant to change the thresholds at this time. Shouldn't we go back to WP:AN for further input? I'd argue we should go with the current consensus, and see how people react after the first round of protections. I really like how simple the system is right now. &mdash; MusikAnimal  talk  17:54, 6 February 2019 (UTC)
 * Regarding The bot will also ignore any page specified at MediaWiki:Titleblacklist which includes the flag., the bot should still template-protect taxonomy templates like Template:Taxonomy/Embryophytes, being used on 10000+ articles and regularly getting disruption from people not getting a consensus for their changes (and as autotaxobox gets more widely used over manual taxobox, the transclusions of these templates are rising pretty quickly). Galobtter (pingó mió) 06:31, 6 February 2019 (UTC)
 * That seems reasonable. Maybe we should compare against the Titleblacklist protection level. So for taxonomy templates, if there are less than 5000 transclusions, we don't protect at all since it is already done by the Titleblacklist (as specified with ). If the template has >= 5000 transclusions, we template-protect as we would any template. That keeps it simple; basically checking the Titleblacklist is only done to avoid redundant protections. I think this is what  was going for when they commented on the WP:AN discussion. &mdash;  MusikAnimal  talk  18:04, 6 February 2019 (UTC)


 * Regarding multiple protection types - how will you handle these pages? (e.g. if the page has different move protections and edit protections) — xaosflux  Talk 15:44, 7 February 2019 (UTC)
 * Only edit protection is applied, though we could do move as well if you think it makes sense to do so? Note also we're only looking for templates/modules that are completely unprotected (for editing, not moving). &mdash; MusikAnimal  talk  17:05, 8 February 2019 (UTC)
 * Redirect handling? How are you going to handle redirects? (e.g. CLEAR vs Clear) ? — xaosflux  Talk 15:44, 7 February 2019 (UTC)
 * Redirects are not followed. &mdash; MusikAnimal  talk  17:06, 8 February 2019 (UTC)
 * When a redirect is transcluded, MediaWiki includes both the redirect and the target page in the templatelinks table. So if 700 pages transclude CLEAR and 900 transclude Clear directly (and no pages transclude any other redirect), the bot would see 700 for Template:CLEAR and 1600 for Template:Clear. And, I presume, it would protect each page accordingly? Anomie⚔ 21:12, 8 February 2019 (UTC)
 * Yep! The bot goes by whatever the count is in templatelinks, regardless if the page is a redirect. That is the intended behaviour, I hope? &mdash; MusikAnimal  talk  21:22, 8 February 2019 (UTC)
 * Sounds like good behavior to me. Anomie⚔ 12:31, 9 February 2019 (UTC)
 * Are you implmeneting downgrade prevention? Under what circumstances would you downgrade protection? —  xaosflux  Talk 15:50, 7 February 2019 (UTC)
 * Nope. Protection levels are never lowered by the bot. Future iterations of the bot may do this, pending discussion. For now, I'd like to get a simple solution deployed and see how the community reacts. &mdash; MusikAnimal  talk  17:13, 8 February 2019 (UTC)


 * OK to trial, 25 SPP's, 25 TEP's. — xaosflux  Talk 00:46, 18 February 2019 (UTC)
 * Also, MOVE protection should also be applied along with EDIT protections (never lowering any existing still even if they are of different levels) - reasoning is that this is the 'default' behavior for human admins. — xaosflux  Talk 00:48, 18 February 2019 (UTC)

Trial results
See. There were only 23 pages that qualified for template protection. Hopefully that's sufficient for the trial. As is always the case with my bot trials, the edits were semi-automated, hence the gaps between timestamps. I carefully reviewed each template before it applied protection, and as far as I can tell the bot performed as it should. &mdash; MusikAnimal  talk  00:15, 19 February 2019 (UTC)
 * This shouldn't hang things up, but would it be too much extra effort to skip adding move protection if the bot is semiprotecting? (auto)confirmed is required to move pages anyway, so it's extraneous. ~  Amory  (u • t • c) 01:40, 19 February 2019 (UTC)
 * Can do &mdash; MusikAnimal  talk  01:44, 19 February 2019 (UTC)
 * Though, I was sort of designing this to be wiki-agnostic. Not sure if this default move protection exists on other wikis &mdash; MusikAnimal  talk  01:45, 19 February 2019 (UTC)
 * There may be some local exceptions, but it has been since 2008: phab and meta. ~ Amory  (u • t • c) 11:09, 19 February 2019 (UTC)
 * I might prefer it to say "at-risk" for the autoconfirmed templates/modules, but probably not worth it. To my non-BAG eyes, these protections all look good — got a couple of redirects in there, which is nice.  The TWA badges are a great example of why this is a great idea, and the GAC criteria are another example of why extended confirmed would be good. ~  Amory  (u • t • c) 11:21, 19 February 2019 (UTC)

Primefac (talk) 20:44, 24 February 2019 (UTC)
 * The above discussion is preserved as an archive of the debate. Please do not modify it. To request review of this BRFA, please start a new section at WT:BRFA.