User:ImplSearchBot/Code: Difference between revisions

Content added Content deleted
m (ImplSearchBot:0)
m (ImplSearchBot:0)
Line 117: Line 117:
}
}


foreach my $language (keys %impldiff)
&processimplediff(\%impldiff);
{
my $pagename = "Tasks not implemented in $language";
&out("Preparing data for:$pagename\n", 4);
my $hashref = $impldiff{$language}->{'impl'};
my %implemented = %$hashref;
$hashref = $impldiff{$language}->{'omit'};
my %omitted = %$hashref;
my $omitcount = scalar keys %omitted;




# To add here: Post stats on activities:
# Language metadata
# 2. Time last run started
my $taskcount = scalar @$alltasks;
my $unimpcount = $taskcount - scalar keys %implemented;
my $targetcount = ($taskcount - $omitcount);


my $runtime = time() - $starttime;
# Language-specific page data.
my $statsdata = "Pages edited last run: $pagesedited<br/>Time to post all per-language updates: $runtime seconds<br/>Category pulls: $categorypulls<br/>Cache hits: $cachehits<br/>";
my $unimplisting = "";
&out("Updating stats page. Runtime ($runtime), Pages edited ($pagesedited)\n", 2);
my $omitlisting = "";
my $pagedata; # Not assembled until the end.


&postpage("User:ImplSearchBot/Stats", $statsdata, "Updating stats data", 0);


&out("Updating bot code page\n", 4);

open my $sourcefile, '<', $0
or die "Finished without updating bot source page";

my $botsource;
$botsource .= $_ while <$sourcefile>;

close $sourcefile;

my $tag = "lang";

&postpage("User:ImplSearchBot/Code", "<$tag perl>$botsource</$tag>", 0);

&out("Updating cache\n", 4);
&commitcache();

&out("Done\n", 3);

exit(0);

sub build_posting
{
my $name = shift;
my $body = shift;

return {$name => $body};
}

sub prep_unimp_posting
{
my $impldiff = shift;
my $language = shift;
my $unimplisting = "";
foreach my $taskname (@$alltasks)
foreach my $taskname (@$alltasks)
{
{
Line 146: Line 173:
# Add the task to the unimplemented list, if it's unimplemented, and if it's not in the omit list.
# Add the task to the unimplemented list, if it's unimplemented, and if it's not in the omit list.
$unimplisting .= "* [[$baretaskname]]\n"
$unimplisting .= "* [[$baretaskname]]\n"
unless(exists $implemented{$taskname} or exists $omitted{$taskname});
unless(exists $impldiff->{$language}->{$taskname} or exists $impldiff->{$language}->{'omit'}->{$taskname});


}

return &build_posting("Template:" . &get_unimpl_template_name($language), $unimplisting);
}

sub prep_omit_posting
{
my $implediff = shift;
my $language = shift;
my $omitlisting = "";
my $omittemplatename = &get_omit_template_name($language);

foreach my $taskname (@$alltasks)
{
# We want the task name, not the fully-qualified wiki name.
my $baretaskname = $taskname;
$baretaskname =~ s/^Category://;
# Add the task to the omission list, if it's omitted.
# Add the task to the omission list, if it's omitted.
$omitlisting .= "* [[$baretaskname]]\n"
$omitlisting .= "* [[$baretaskname]]\n"
if(exists $omitted{$taskname})
if(exists $impldiff{$language}->{'omit'}->{$taskname})
}
}

# Note that there's no data in the template.
$implediff->{$language}->{'omit'} = 0
if( "" eq $omitlisting );

return &build_posting("Template:$omittemplatename", $omitlisting);
}

sub prep_listing_posting
{
my $impldiff = shift;
my $language = shift;

my $targetcount = $impldiff->{$language}->{'target_count'};
my $unimpcount = $impldiff->{$language}->{'unimp_count'};


# Prepare template fields
# Prepare template fields
Line 163: Line 223:


my $imppercfield = sprintf "|%u", $impperccalc;
my $imppercfield = sprintf "|%u", $impperccalc;

my $unimpltemplatename = "unimp_body_$language";
my $omittemplatename = "unimp_omit_body_$language";

# Prepare the listing page format.
# Prepare the listing page format.
$pagedata = '{{unimpl_header' . $langfield . $unimpfield . $tcfield . $imppercfield . '}}';
my $pagedata = '{{unimpl_header' . $langfield . $unimpfield . $tcfield . $imppercfield . '}}';
$pagedata .= "{{$unimpltemplatename" . "$unimpfield}}";
$pagedata .= "{{" . &get_unimpl_template_name($language) . "$unimpfield}}";


if ("" ne $omitlisting)
if (0 != $impldiff->{$language}->{'omit'})
{
{
$pagedata .= "{{omit_header" . "$langfield}}";
$pagedata .= "{{omit_header" . "$langfield}}";
$pagedata .= "{{$omittemplatename}}";
$pagedata .= "{{" . &get_omit_template_name($language) ."}}";
}
}


$pagedata .= "{{unimpl_footer$langfield}}";
$pagedata .= "{{unimpl_footer$langfield}}";


return &build_posting(&get_listing_name($language), $pagedata);
# Post the template containing the listing of unimplemented tasks.
}
&postpage("Template:$unimpltemplatename", "$unimplisting", "ImplSearchBot:Updating list body of unimplemented tasks.", 1);


sub prep_omit_cat_posting
# Post the template containing the listing of omitted tasks.
{
&postpage("Template:$omittemplatename", "$omitlisting", "ImplSearchBot:Updating list body of unimplemented tasks.", 1);
my $implediff = shift;
my $language = shift;
return &build_posting(&get_omit_cat_name, "{{omit_cat|$language}}");
}


sub get_listing_name
# Update the layout of the listing page, as it's now dynamic.
{
# Once we're communicating whether or not the omit listing chaged,
my $language = shift;
# this can become optional.
return "Tasks not implemented in $language";
&postpage($pagename, $pagedata, "ImplSearchBot:Updating layout of listing page.",1);
}


sub get_omit_template_name
my $omitcategoryname = "Category:$language/Omit";
{
my $omitcatpagedata = "{{omit_cat|$language}}";
my $language = shift;
&postpage($omitcategoryname, $omitcatpagedata, "ImplSearchBot:Updating Omit category body", 0)
return "unimp_omit_body_$language";
unless ( exists $createdomitcategories{$omitcategoryname} );
}


sub get_unimpl_template_name
{
my $language = shift;
return "unimp_body_$language";
}
}


sub get_omit_cat_name
# To add here: Post stats on activities:
{
# 2. Time last run started
my $language = shift;
return "Category:$language/Omit";
}


sub process_language
my $runtime = time() - $starttime;
{
my $statsdata = "Pages edited last run: $pagesedited<br/>Time to post all per-language updates: $runtime seconds<br/>Category pulls: $categorypulls<br/>Cache hits: $cachehits<br/>";
my $implediff = shift;
&out("Updating stats page. Runtime ($runtime), Pages edited ($pagesedited)\n", 2);
my $language = shift;


&postpage("User:ImplSearchBot/Stats", $statsdata, "Updating stats data", 0);


my $unimpl = &prep_unimp_posting($implediff, $language);
my $omit = &prep_omit_posting($implediff, $language);
my $listing = &prep_listing_posting($implediff, $language);


my %langpostings = ( %$unimpl, %$omit, %$listing );
&out("Updating bot code page\n", 4);


open my $sourcefile, '<', $0
or die "Finished without updating bot source page";


unless ( exists $createdomitcategories{&get_omit_cat_name($language)} )
my $botsource;
{
$botsource .= $_ while <$sourcefile>;
my $omit_cat = &prep_omit_cat_posting($implediff, $language);
%langpostings = ( %langpostings, %$omit_cat );
}


return \%langpostings;
close $sourcefile;
}


sub processimplediff
my $tag = "lang";
{
my $implediff = shift;
my %work;
foreach my $language (keys %impldiff)
{
&out("Preparing data for:$language\n", 4);
my $workitem = &process_language($implediff, $language);
%work = ( %work, %$workitem );
}


foreach my $pagename (keys %work)
&postpage("User:ImplSearchBot/Code", "<$tag perl>$botsource</$tag>", 0);
{

&out("Updating cache\n", 4);
&postpage($pagename, $work{$pagename}, "Updating $pagename", 0);
}
&commitcache();
}

&out("Done\n", 3);

exit(0);


sub geteditor
sub geteditor
Line 489: Line 570:
return undef
return undef
if( ( 0 == scalar keys %omit) && (0 == scalar keys %impl));
if( ( 0 == scalar keys %omit) && (0 == scalar keys %impl));
# Language metadata
my $unimpcount = scalar @$alltasks - scalar keys %impl;
my $targetcount = (scalar @$alltasks - scalar keys %omit);



# work to do.
# work to do.
return {'impl' => \%impl,
return {'impl' => \%impl,
'omit' => \%omit };
'omit' => \%omit,
'unimp_count' => $unimpcount,
'target_count' => $targetcount };
}
}