21class TS extends Maintenance {
22 public function __construct() {
23 parent::__construct();
24 $this->addDescription(
'Script to gather translator stats in tsv format. ' .
25 'You can further process the output with translate-stats-process.php' );
28 public function execute() {
29 $dbr = $this->getDB( DB_REPLICA );
31 $users = $dbr->newSelectQueryBuilder()
39 ->leftJoin(
'user_groups',
null, [
41 'ug_group' =>
'translator',
42 'ug_expiry IS NULL OR ug_expiry >= ' . $dbr->addQuotes( $dbr->timestamp() ),
45 'user_registration is not null'
47 ->orderBy(
'user_id' )
48 ->caller( __METHOD__ )
51 echo
"username\tregistration ts\tedit count\tis translator?\tpromoted ts\tmethod\n";
53 $rejected = $dbr->newSelectQueryBuilder()
60 'log_type' =>
'translatorsandbox',
61 'log_action' =>
'rejected',
63 ->caller( __METHOD__ )
66 foreach ( $rejected as $r ) {
67 echo
"{$r->log_title}\t{$r->log_timestamp}\t0\t\t\tsandbox\n";
70 foreach ( $users as $u ) {
71 $logs = $dbr->newSelectQueryBuilder()
80 'log_title' => $u->user_name,
81 'log_type' => [
'rights',
'translatorsandbox' ],
84 ->caller( __METHOD__ )
89 foreach ( $logs as $log ) {
90 if ( $log->log_action ===
'promoted' ) {
91 $promoted = $log->log_timestamp;
94 } elseif ( $log->log_action ===
'rights' ) {
96 $data = @unserialize( $log->log_params );
97 if ( $data ===
false ) {
98 $lines = explode(
"\n", $log->log_params, 3 );
99 if ( str_contains( $lines[1],
'translator' ) ) {
100 $promoted = $log->log_timestamp;
104 isset( $data[
'5::newgroups'] ) &&
105 in_array(
'translator', $data[
'5::newgroups'] )
107 $promoted = $log->log_timestamp;
113 echo
"{$u->user_name}\t{$u->user_registration}\t{$u->user_editcount}" .
114 "\t{$u->ug_group}\t{$promoted}\t{$method}\n";