Operator: [[Sam Korn]] (smoddy)
Automatic or Manually Assisted: Automatic
Programming Language(s): PHP
Function Overview: Per
request, migrate fields in {{
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:
{{
FilmsWikiProject}}
, {{
WikiProject Film}}
, {{
WPFILM}}
, {{
WP Film}}
and {{
FILM}}
with {{
WikiProject Films}}
.needs-synopsis
to needs-plot
|importance=
, |attention=
, |auto=
, |nested=
, |portal1-name=
, |portal2-name=
, |portal3-name=
|portal4-name=
, |portal5-name=
, |article=
, |start=
, |end=
).The bot will only edit if an action was taken in step 2.
The code uses the 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 {{
WikiProject Films}}
or to continue using {{
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.
[[Sam Korn]] (smoddy) 01:14, 7 March 2009 (UTC) reply
I see a few issues in the code:
$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 {{
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 {{A|foo={{B}}}} would result in {{A|foo=}}}}.Also, a few minor comments:
Anomie ⚔ 15:21, 7 March 2009 (UTC) reply
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 separatetemplate("{{foox|xx}} {{foo|yy}} !!","foo")
. There's also a second issue that you need a .* in "(\}.*)
", or else 'end' is wrong when the template has no parameters.{{foo|bar|baz|}}
). In both cases, it claims an extra parameter containing "}".{{foo|bar||baz}}
. When you reconstruct the template, suddenly {{{2}}} is baz and {{{3}}} is unset.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!
[[Sam Korn]]
(smoddy)
20:26, 7 March 2009 (UTC)
reply
$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
this.Approved. Anomie ⚔ 14:27, 9 March 2009 (UTC) reply
Operator: [[Sam Korn]] (smoddy)
Automatic or Manually Assisted: Automatic
Programming Language(s): PHP
Function Overview: Per
request, migrate fields in {{
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:
{{
FilmsWikiProject}}
, {{
WikiProject Film}}
, {{
WPFILM}}
, {{
WP Film}}
and {{
FILM}}
with {{
WikiProject Films}}
.needs-synopsis
to needs-plot
|importance=
, |attention=
, |auto=
, |nested=
, |portal1-name=
, |portal2-name=
, |portal3-name=
|portal4-name=
, |portal5-name=
, |article=
, |start=
, |end=
).The bot will only edit if an action was taken in step 2.
The code uses the 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 {{
WikiProject Films}}
or to continue using {{
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.
[[Sam Korn]] (smoddy) 01:14, 7 March 2009 (UTC) reply
I see a few issues in the code:
$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 {{
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 {{A|foo={{B}}}} would result in {{A|foo=}}}}.Also, a few minor comments:
Anomie ⚔ 15:21, 7 March 2009 (UTC) reply
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 separatetemplate("{{foox|xx}} {{foo|yy}} !!","foo")
. There's also a second issue that you need a .* in "(\}.*)
", or else 'end' is wrong when the template has no parameters.{{foo|bar|baz|}}
). In both cases, it claims an extra parameter containing "}".{{foo|bar||baz}}
. When you reconstruct the template, suddenly {{{2}}} is baz and {{{3}}} is unset.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!
[[Sam Korn]]
(smoddy)
20:26, 7 March 2009 (UTC)
reply
$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
this.Approved. Anomie ⚔ 14:27, 9 March 2009 (UTC) reply