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