User:AnomieBOT/source/show-task-status.pl

if(window.mw){ mw.loader.load(["mediawiki.page.ready"],null,true); } EOHTML }

sub max { return $_[0] > $_[1] ? $_[0] : $_[1]; }
 * 1) Utility function to find the max of two numbers

sub ftime { my $t = shift; return '-' unless $t; return POSIX::strftime( '%F %T', gmtime $t ); }
 * 1) Utility function to format a timestamp

sub tasksorter { my ($a,$b) = @_; my $na = $a->{'botnum'}; my $nb = $b->{'botnum'};
 * 1) Sorting function for the bot tasks table

return $a->{'task'} cmp $b->{'task'} if $na eq $nb; return $na <=> $nb if $na =~ /^\d+/ && $nb =~ /^\d+/; return -1 if $na =~ /^\d+/; return 1 if $nb =~ /^\d+/; return $na cmp $nb; }

sub esc { my $s = shift; $s=~s/&/&amp;/g; $s=~s//&gt;/g; $s=~s/"/&quot;/g;	return $s; }
 * 1) Simple HTML encoding

sub print_data { my @rows = @_;
 * 1) Print the table rows

%l = ; for my $row (@rows) { for my $k (@fields) { $l{$k} = max( $l{$k} // length($labels{$k}), length( $row->{$k} ) ); }	}

my ($make, $pre, $mid, $post); if ( grep $_ eq '--html', @ARGV ) { $make = sub { my ($obj, $k) = @_; my $v = esc( $obj->{$k} ); my $sv = esc( $obj->{"sort $k"} // $obj->{$k} );

my $td = '{"isold $k"} // 0; $td .= qq( data-value="$sv") if $sv ne $v; $td .= ">$v "; return $td; };		($pre, $mid, $post) = (' ', '', ' '); print " "; for my $k (@fields) { printf ' %s ', esc( $labels{$k} ); }		print " \n"; print " \n"; } else { $make = sub { my ($obj, $k) = @_; return sprintf( "%$align{$k}$l{$k}s", $obj->{$k} ); };		($pre, $mid, $post) = (, ' ', ); my @line1 = ; my @line2 = ; for my $k (@fields) { push @line1, $labels{$k}. (" " x ($l{$k} - length($labels{$k}))); push @line2, "-" x $l{$k}; }		print join(" ", @line1). "\n"; print join(" ", @line2). "\n"; }

for my $row (@rows) { print $pre. join( $mid, map { $make->($row, $_) } @fields). $post. "\n"; }

if ( grep $_ eq '--html', @ARGV ) { print " \n"; } }