19class TS extends Maintenance {
20 public function __construct() {
21 parent::__construct();
22 $this->addDescription(
'Script to gather translator stats in tsv format. ' .
23 'You can further process the output with translate-stats-process.php' );
26 public function execute() {
27 $dbr = $this->getDB( DB_REPLICA );
29 $users = $dbr->newSelectQueryBuilder()
37 ->leftJoin(
'user_groups',
null, [
39 'ug_group' =>
'translator',
40 'ug_expiry IS NULL OR ug_expiry >= ' . $dbr->addQuotes( $dbr->timestamp() ),
43 'user_registration is not null'
45 ->orderBy(
'user_id' )
46 ->caller( __METHOD__ )
49 echo
"username\tregistration ts\tedit count\tis translator?\tpromoted ts\tmethod\n";
51 $rejected = $dbr->newSelectQueryBuilder()
58 'log_type' =>
'translatorsandbox',
59 'log_action' =>
'rejected',
61 ->caller( __METHOD__ )
64 foreach ( $rejected as $r ) {
65 echo
"{$r->log_title}\t{$r->log_timestamp}\t0\t\t\tsandbox\n";
68 foreach ( $users as $u ) {
69 $logs = $dbr->newSelectQueryBuilder()
78 'log_title' => $u->user_name,
79 'log_type' => [
'rights',
'translatorsandbox' ],
82 ->caller( __METHOD__ )
87 foreach ( $logs as $log ) {
88 if ( $log->log_action ===
'promoted' ) {
89 $promoted = $log->log_timestamp;
92 } elseif ( $log->log_action ===
'rights' ) {
94 $data = @unserialize( $log->log_params );
95 if ( $data ===
false ) {
96 $lines = explode(
"\n", $log->log_params, 3 );
97 if ( str_contains( $lines[1],
'translator' ) ) {
98 $promoted = $log->log_timestamp;
102 isset( $data[
'5::newgroups'] ) &&
103 in_array(
'translator', $data[
'5::newgroups'] )
105 $promoted = $log->log_timestamp;
111 echo
"{$u->user_name}\t{$u->user_registration}\t{$u->user_editcount}" .
112 "\t{$u->ug_group}\t{$promoted}\t{$method}\n";