Translate extension for MediaWiki
 
Loading...
Searching...
No Matches
translator-stats.php
Go to the documentation of this file.
1<?php
10use MediaWiki\Maintenance\Maintenance;
11
12// Standard boilerplate to define $IP
13if ( getenv( 'MW_INSTALL_PATH' ) !== false ) {
14 $IP = getenv( 'MW_INSTALL_PATH' );
15} else {
16 $dir = __DIR__;
17 $IP = "$dir/../../..";
18}
19require_once "$IP/maintenance/Maintenance.php";
20
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' );
26 }
27
28 public function execute() {
29 $dbr = $this->getDB( DB_REPLICA );
30
31 $users = $dbr->newSelectQueryBuilder()
32 ->select( [
33 'user_name',
34 'user_registration',
35 'user_editcount',
36 'ug_group',
37 ] )
38 ->from( 'user' )
39 ->leftJoin( 'user_groups', null, [
40 'user_id=ug_user',
41 'ug_group' => 'translator',
42 'ug_expiry IS NULL OR ug_expiry >= ' . $dbr->addQuotes( $dbr->timestamp() ),
43 ] )
44 ->where( [
45 'user_registration is not null'
46 ] )
47 ->orderBy( 'user_id' )
48 ->caller( __METHOD__ )
49 ->fetchResultSet();
50
51 echo "username\tregistration ts\tedit count\tis translator?\tpromoted ts\tmethod\n";
52
53 $rejected = $dbr->newSelectQueryBuilder()
54 ->select( [
55 'log_title',
56 'log_timestamp',
57 ] )
58 ->from( 'logging' )
59 ->where( [
60 'log_type' => 'translatorsandbox',
61 'log_action' => 'rejected',
62 ] )
63 ->caller( __METHOD__ )
64 ->fetchResultSet();
65
66 foreach ( $rejected as $r ) {
67 echo "{$r->log_title}\t{$r->log_timestamp}\t0\t\t\tsandbox\n";
68 }
69
70 foreach ( $users as $u ) {
71 $logs = $dbr->newSelectQueryBuilder()
72 ->select( [
73 'log_type',
74 'log_action',
75 'log_timestamp',
76 'log_params',
77 ] )
78 ->from( 'logging' )
79 ->where( [
80 'log_title' => $u->user_name,
81 'log_type' => [ 'rights', 'translatorsandbox' ],
82 ] )
83 ->orderBy( 'log_id' )
84 ->caller( __METHOD__ )
85 ->fetchResultSet();
86
87 $promoted = null;
88 $method = 'normal';
89 foreach ( $logs as $log ) {
90 if ( $log->log_action === 'promoted' ) {
91 $promoted = $log->log_timestamp;
92 $method = 'sandbox';
93 break;
94 } elseif ( $log->log_action === 'rights' ) {
95 // phpcs:disable Generic.PHP.NoSilencedErrors.Discouraged
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;
101 break;
102 }
103 } elseif (
104 isset( $data['5::newgroups'] ) &&
105 in_array( 'translator', $data['5::newgroups'] )
106 ) {
107 $promoted = $log->log_timestamp;
108 break;
109 }
110 }
111 }
112
113 echo "{$u->user_name}\t{$u->user_registration}\t{$u->user_editcount}" .
114 "\t{$u->ug_group}\t{$promoted}\t{$method}\n";
115 }
116 }
117}
118
119$maintClass = TS::class;
120require_once RUN_MAINTENANCE_IF_MAIN;