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 Approved.

Operator: Cyberpower678 (talk · contribs · SUL · edit count · logs · page moves · block log · rights log · ANI search)

Time filed: 15:21, Monday January 14, 2013 (UTC)

Automatic, Supervised, or Manual: Automatic

Programming language(s): PHP

Source code available: Per request

Function overview: Add and remove PC protection templates from protected and non-protected pages respectively.

Links to relevant discussions (where appropriate): Uncontroversial task

Edit period(s): Continuous

Estimated number of pages affected: About 1-10 pages a day. Initial run may be higher.

Exclusion compliant (Yes/No): Yes, but unnecessary.

Already has a bot flag (Yes/No): No

Function details: The bot obtains a list of pages that have pending changes protected on it and applies the appropriate level protection template. It then looks at all the pages with a protection template and checks if they have that respective protection on it. If not, it will remove it.

Task switch: Click to enable

Discussion[edit]

Sounds like a good task. I'm guessing PC protection isnt covered by the other bots which check for the templates on article pages? ·Add§hore· Talk To Me! 18:51, 14 January 2013 (UTC)Reply[reply]
I think Sigma was working on integrating this into his bot (discussion), however I don't know if he ever finished it. Legoktm (talk) 18:57, 14 January 2013 (UTC)Reply[reply]
Even if, multiple jobs doing such tasks don't hurt the ecosystem of Wikipedia. ;-) mabdul 19:17, 14 January 2013 (UTC)Reply[reply]
A simple check against original page size should fix this. ·Add§hore· Talk To Me! 21:50, 16 January 2013 (UTC)Reply[reply]
There was a temporary API failure from what I gather from the logs. The get page call gave the bot an empty string so it returned an empty string plus a tag. As to why the other tag was removed, I believe I see the issue in the code and the bug is set off if the tag is placed right after another protection tag.—cyberpower ChatOffline 22:17, 16 January 2013 (UTC)Reply[reply]

Would you mind making the source code public for review? --Chris 14:33, 17 January 2013 (UTC)Reply[reply]

Sure. As soon as my computer is available I will post it.—cyberpower ChatOffline 15:14, 17 January 2013 (UTC)Reply[reply]
User:Cyberbot II/Run/PC/sourcecyberpower ChatOffline 16:52, 17 January 2013 (UTC)Reply[reply]
Note: I have updated the code to check to make sure the buffer matches the actual source. This will also convieniently reduce edit conflicts as well. This will allow for another bot to run this task simultaneously.—cyberpower ChatOffline 16:57, 17 January 2013 (UTC)Reply[reply]
I'd have some suggested changes there, for stability and resource usage.
  1. Most fundamentally, you are currently querying the page content of every flagged page (multiple times even). I'm not familiar with that bot framework, but I assume it's using the API, not the toolserver database, so that's very wasteful. Instead, I would recommend to restructure the code to test all pages like you already do when removing tags:
    • Get all transclusions of pp-pc1 and pp-pc2
    • Get the list of all flagged pages with their protection levels
    • Iterate through all flagged pages, test whether the required template is already on the page by checking the respective transclusion list. If it's missing, add it.
      Bonus is that you can avoid parsing the page for existence of the template, the current regex isn't quite right, and it's impossible to get it completely right without duplicating the entire MediaWiki parser
  2. The edits don't guard against edit conflicts. I am, again, not familiar with the framework, but I assume the page object you get back from init_page alrady contains everything you need to do that, it may be sufficient to simply reuse the same page object. So only init a given page once, if you separate the get_text from the edit, you risk that another editor's changes are completely overwritten without warning or edit conflict recognition.
    If this is X!'s framework then you could ask him about it.
  3. It seems like there should be a way to get the list of flagged pages from the API, but at a glance I don't see a (sane) way. Screen-scraping is a pain though, makes it much more likely that the bot breaks with updates
  4. The regex to remove the transclusion could be revised to be more exact. E.g., it currently incorrectly misses (( pp-pc1)), and incorrectly matches ((P-PC1/sandbox)). Like I said before it's not practical to get it completely right, but it can be made a bit more precise.
  5. For adding the template, I would advise to use the prependtext feature from the editing API. That way, you don't need to get and resubmit the existing page content at all.
  6. For maintainability, avoid code duplications. Both when adding and removing texts, there are significant chunks of code copy/pasted. That works, but is harder to maintain and comprehend. It would be appropriate to turn those blocks into functions, just pass the few bits that are different as parameters
Amalthea 19:48, 17 January 2013 (UTC)Reply[reply]
Thank you Amalthea. I give you a more detailed reply later.—cyberpower ChatOnline 23:17, 17 January 2013 (UTC)Reply[reply]
I will take up your suggestions and be more careful coding new scripts next for my next tasks and requests. I looked through the API to see if I can query it to obtian PC protected pages, but I couldn't find one. I am more than willing to constantly update page scratching code to acheive the desired goal as long as the API doesn't yet support it. Once it does, I will write a new subcommand into the framework to allow for this. The framework is called Peachy, and it's written by X!, although, he admits he no longer knows how it works. I learned the Peachy Framework by reading it. I'm still exploring its capabilities and update the minor bugs I find when going through it.—cyberpower ChatOnline 01:50, 18 January 2013 (UTC)Reply[reply]

Trial complete. Given the issues raised. The bot shouldn't be approved yet. Though most of edits are good, per Amalthea, the code needs some more love. I'll post the new code once I have it updated.—cyberpower ChatOnline 01:01, 22 January 2013 (UTC)Reply[reply]

Try for a Wikipedia:Labs account? ·Add§hore· Talk To Me! 23:15, 28 January 2013 (UTC)Reply[reply]
Why are you using peachy? :P ·Add§hore· Talk To Me! 22:59, 14 February 2013 (UTC)Reply[reply]
Why not. I like it.—cyberpower OnlineBe my Valentine 23:29, 14 February 2013 (UTC)Reply[reply]
I just think there are more up to date frameworks:). Any further updates? ·Add§hore· Talk To Me! 22:59, 22 February 2013 (UTC)Reply[reply]
My entire bot runs on Peachy. I don't really feel like rewriting it. Especially since I don't have the time to. Besides, I have plans for Peachy 2 and am considering to release it into public domain for everyone to use as well.—cyberpower ChatOnline 23:12, 22 February 2013 (UTC)Reply[reply]
Re-write complete, performing final tests.—cyberpower ChatOnline 00:45, 27 February 2013 (UTC)Reply[reply]
Approved for trial (5 days). Please provide a link to the relevant contributions and/or diffs when the trial is complete. ·Add§hore· Talk To Me! 03:22, 27 February 2013 (UTC)Reply[reply]
Task running. Found and fixed this bug, where the bot was repeatedly edit warring with itself. Turns out I forgot to shut off the follow redirect function, and it was following a redirect of Chris Lee (referee) which is PC1 and fully protected for some reason.
Trial complete. Edits look good. No blanking issues present.—cyberpower ChatAbsent 20:18, 4 March 2013 (UTC)Reply[reply]
 Approved. ·Add§hore· Talk To Me! 14:27, 6 March 2013 (UTC)Reply[reply]
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.