Wikipedia:Bots/Requests for approval/Sambot 3
{{Newbot|Sambot|3}} Operator: Automatic or Manually Assisted: Automatic Programming Language(s): PHP Function Overview: Per request, migrate fields in {{tlx|WikiProject Films}}. Edit period(s): Once Already has a bot flag (Y/N): Yes Function Details: Get all the pages in :Category:Films that need a synopsis. For each one: The bot will only edit if an action was taken in step 2. The code uses the [http://pillar.googlecode.com Pillar] framework. The source is User:Sambot/Code/Templates.php. The templates.ini file that contains the settings for the run is: sourcetype=categorymembers sourcename=Category:Films that need a synopsis templatename=FilmsWikiProject:WikiProject Films,WikiProject Film:WikiProject Films,WPFILM:WikiProject Films,WP Film:WikiProject Films,FILM:WikiProject Films fieldsremove=importance,attention,auto,nested,portal1-name,portal21-name,portal3-name,portal4-name,portal5-name fieldsmigrate=needs-synopsis:needs-plot onlyif=fieldsmigrate N.B. that there is still discussion over whether to move to {{tlx|WikiProject Films}} or to continue using {{tlx|Films}}. I won't run the bot until it is clear which is the preferred option, but I'm making the request now because the change (to one line in the above config file) is incidental to the bot request. I see a few issues in the code: Also, a few minor comments: Anomie⚔ 15:21, 7 March 2009 (UTC) :All these issues, including the minor ones, are now fixed in a major refactoring of the code -- many thanks for your comments. :: There's a new bug or two: ::* ::* It'll screw up if none of the $namesmigratefrom entries match; $list will be empty, and it might just blank the page. ::* templatesplit screws up if the template has no parameters, or if the last parameter is empty (e.g. ::* templatesplit screws up if the template has an empty parameter, e.g. ::And a comment or two: ::* In the name migrator, if it's trying to migrate ::* In the field migrator, just do the preg_replace unconditionally. If there is no match, it'll work right. ::* It seems to work ok here, but there tends to be issues in PHP with ::Anomie⚔ 19:53, 7 March 2009 (UTC) :::All these really are fixed now! The solution to your third point is a little hackish, but it will always work. With your fourth point, I beg to differ -- the name migrator was already case insensitive for the first letter. With your sixth point, I have indeed changed it to a :::: I didn't notice earlier, but if you're going to stick a page name into a regular expressions, you have to make sure to properly escape any metacharacters: :::: Other than that, looks good. {{BotTrial|edits=30}} Anomie⚔ 22:00, 7 March 2009 (UTC) :::::{{BotTrialComplete}}. The only issue was that the bot needlessly changed the capitalisation of template calls like [https://secure.wikimedia.org/wikipedia/en/w/index.php?title=Talk:1_Night_in_China&diff=prev&oldid=276027154 this]. Issue is now corrected. {{BotApproved}} Anomie⚔ 14:27, 9 March 2009 (UTC) :The above discussion is preserved as an archive of the debate. Please do not modify it. Subsequent comments should be made in a new section.
Sambot 03[[User:Sambot|Sambot 3]]
needs-synopsis
to needs-plot
=Discussion=
$settings['sourcefrom']
seems to be used but never defined.separatetemplate
function will match any template beginning with the target; for example, when it is looking for {{tl|WikiProject Film}} it would find {{WikiProject Filmmaking}}./[\D\d]*/
the same as /.*/s
, or /(?s:.*)/
? It's fine either way, although the latter might be more clear to others.\s*
in your field migrator: "/(\|\s*)" . $fieldsmigratefrom[$i] . "(\s*=[^|}]*)/i"
. Also, as far as I can tell the part in grey is not necessary here, but shouldn't hurt anything either.\s*
in your field remover.foo
from
separatetemplate
is still b0rken. The major issue is that $from will not necessarily be the same as the start of the preg_match; try passing
. There's also a second issue that you need a .* in "(\}.*)
", or else 'end' is wrong when the template has no parameters.
). In both cases, it claims an extra parameter containing "}".
. When you reconstruct the template, suddenly foo
it won't match Foo
.foreach($x as &$v){ }
unless you unset($v)
after the end of the loop; in particular, if $v is assigned again before being unset it'll overwrite the last member of $x. It's up to you, but IMO better safe than sorry.for
loop. Thanks! $nameinsearch = "(?i:" . quotemeta(substr($namesmigratefrom[$i],0,1)) . ")" . quotemeta(substr($namesmigratefrom[$i],1));
Note also the use of the (?i:)
group, which basically applies the 'i' flag to just that bit of the regex. Also, you applied the "found" check to the wrong namesmigratefrom loop: try [http://en.wikipedia.org/w/index.php?diff=275676918&oldid=275676384 this].