User:PleaseStand/PsBot

PsBot will be a bot to automatically place the talkback template on users' talk pages, on behalf of editors who add corresponding, special-purpose templates to the talk pages to be linked to.

Changelog
22:02, 29 March 2010 (UTC): Since originally posting this at the Village Pump, I have thought that perhaps it would be good to repurpose the template name re to produce the text "@Example ", imitating Twitter. This is reflected below along with other changes.

22:22, 30 March 2010 (UTC): The template name to is probably more intuitive, and has the advantage that it does not even exist at all.
 * 17:59, 31 March 2010 (UTC): Method below updated to reflect this.
 * 20:28, 31 March 2010 (UTC): Talkback is not that much bigger than talkbackiny, and has the advantage that it says how to remove it.

21:18, 31 March 2010 (UTC): Changed how the talkbacks subpage works.

Method
Every five minutes, a queue is filled from Category:User notification pending, added by to when bot=Y. Once the queue is filled, if the below process is not already running, then it will be started.

The process to handle each page in this category is as follows:
 * 1) Set a flag, indicating that the queue is being emptied.
 * 2) Remove the page from the front of the queue.
 * 3) Check the page for a bot-exclusion tag. Skip the page if the tag excludes this bot (or all).
 * 4) Locate all transclusions of the above-named templates. For each transclusion in which bot=Y:
 * 5) Check if the username exists on Wikipedia. If not, skip.
 * 6) Check the user's talk page for a bot-exclusion tag. Skip the page if the tag excludes this bot (or all).
 * 7) * A redirect at that page would cause the bot to go to the target username instead (e.g. if the account is an alternative account of its operator).
 * 8) Find the section that the transclusion is in. Build a wikilink to that section.
 * 9) Check the emergency shutoff page. To avoid disruption, the page should probably be ".js protected" so that only the bot operator or an administrator can edit it.
 * 10) Post a talkback template on the user's talk page, referring back to the section, but not if there is already an identical one there.
 * 11) * If there are ten of these already, the sixth will link to the user talk subpage /Talkbacks, on which further talkback notices will be posted. Of course the bot will check for a bot exclusion template on that page also. Likewise with redirection.
 * 12) * The user can override the default, controlling how many talkbacks appear on his main talk page, using a template code. For example, he can set it to zero to avoid being bothered by the "New messages" banner but still receive bot-generated talkbacks.
 * 13) Replace the transclusion with "", which will remove the page from the category. Don't actually save the page though until all transclusions have been processed.
 * 14) If this was the last page in the queue, clear the flag.

Any questions, comments, or concerns?
Post them on the talk page.