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 global $wgDisableUserGroupExpiry;
29 $dbr = wfGetDB( DB_REPLICA );
30 $users = $dbr->select(
31 [
'user',
'user_groups' ],
39 'user_registration is not null'
43 'ORDER BY' =>
'user_id ASC',
50 'ug_group' =>
'translator',
51 ( isset( $wgDisableUserGroupExpiry ) && !$wgDisableUserGroupExpiry ) ?
52 'ug_expiry IS NULL OR ug_expiry >= ' . $dbr->addQuotes( $dbr->timestamp() ) :
59 echo
"username\tregistration ts\tedit count\tis translator?\tpromoted ts\tmethod\n";
61 $rejected = $dbr->select(
68 'log_type' =>
'translatorsandbox',
69 'log_action' =>
'rejected',
74 foreach ( $rejected as $r ) {
75 echo
"{$r->log_title}\t{$r->log_timestamp}\t0\t\t\tsandbox\n";
78 foreach ( $users as $u ) {
88 'log_title' => $u->user_name,
89 'log_type' => [
'rights',
'translatorsandbox' ],
93 'ORDER BY' =>
'log_id ASC',
99 foreach ( $logs as $log ) {
100 if ( $log->log_action ===
'promoted' ) {
101 $promoted = $log->log_timestamp;
104 } elseif ( $log->log_action ===
'rights' ) {
106 $data = @unserialize( $log->log_params );
107 if ( $data ===
false ) {
108 $lines = explode(
"\n", $log->log_params, 3 );
109 if ( strpos( $lines[1],
'translator' ) !==
false ) {
110 $promoted = $log->log_timestamp;
114 isset( $data[
'5::newgroups'] ) &&
115 in_array(
'translator', $data[
'5::newgroups'] )
117 $promoted = $log->log_timestamp;
123 echo
"{$u->user_name}\t{$u->user_registration}\t{$u->user_editcount}" .
124 "\t{$u->ug_group}\t{$promoted}\t{$method}\n";