User:AnomieBOT/source/tasks/POTDPageCreator.pm: Difference between revisions

Content deleted Content added
AnomieBOT (talk | contribs)
Updating published sources: POTDPageCreator: * Supply {{para|date}} when creating subtemplates.
AnomieBOT (talk | contribs)
Updating published sources: POTDPageCreator: * Adjust regex, people have started not leaving a newline.
 
(2 intermediate revisions by the same user not shown)
Line 70:
return $res if $res;
 
if ( $outtxt=~s!^\s*\Q{{POTD/$date/{{#invoke:random|number|\E(\d+)\Q}}|{{{1|{{{style|default}}}}}}}}\E\s*\n!{{POTD protected/$date/{{#invoke:random|number|$1}}|{{{1|{{{style|default}}}}}}}}\n! ) {
my $n = $1;
for ( my $i = 1; $i <= $n; $i++ ) {
Line 85:
}
 
push @edits, [ $page2, $tok2, $outtxt2, "Creating protected version of a [[WP:POTD]] template by substing from {{[[$srcpage2|POTD/$date/$i]]|row}}" ];
}
 
push @edits, [ $page, $tok, $outtxt, "Creating protected version of a [[WP:POTD]] template by adjusting [[$srcpage]]" ];
} elsif ( $outtxt=~s/^\s*\Q{{POTD {{{1|{{{style|default}}}}}}\E\s*\n/{{subst:POTD row\n/ ) {
push @edits, [ $page, $tok, $outtxt, "Creating protected version of a [[WP:POTD]] template by substing from {{[[$srcpage|POTD/$date]]|row}}" ];
} else {
$api->warn( "$srcpage doesn't begin with expected wikitext\n$outtxt" );
Line 98:
 
foreach my $edit (@edits) {
my ($page, $tok, $outtxt, $summary) = @$edit;
my $res = $api->edit($tok, $outtxt, 'Creating protected version of a [[WP:POTD]] template'$summary, 0, 1);
if($res->{'code'} ne 'success'){
$api->warn("Write for $page failed: " . $res->{'error'});
Line 141:
prop => 'revisions',
rvprop => 'content',
rvslots => 'main',
rvlimit => 1,
formatversion => 2,
Line 150 ⟶ 151:
}
 
my $intxt = $res->{'query'}{'pages'}[0]{'revisions'}[0]{'slots'}{'main'}{'content'} // '';
# Act like preloading does
my ($outtxt,$nowiki) = $api->strip_nowiki($intxt);