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 $dbr = $this->getDB( DB_REPLICA );
28
29 $users = $dbr->newSelectQueryBuilder()
30 ->select( [
31 'user_name',
32 'user_registration',
33 'user_editcount',
34 'ug_group',
35 ] )
36 ->from( 'user' )
37 ->leftJoin( 'user_groups', null, [
38 'user_id=ug_user',
39 'ug_group' => 'translator',
40 'ug_expiry IS NULL OR ug_expiry >= ' . $dbr->addQuotes( $dbr->timestamp() ),
41 ] )
42 ->where( [
43 'user_registration is not null'
44 ] )
45 ->orderBy( 'user_id' )
46 ->caller( __METHOD__ )
47 ->fetchResultSet();
48
49 echo "username\tregistration ts\tedit count\tis translator?\tpromoted ts\tmethod\n";
50
51 $rejected = $dbr->newSelectQueryBuilder()
52 ->select( [
53 'log_title',
54 'log_timestamp',
55 ] )
56 ->from( 'logging' )
57 ->where( [
58 'log_type' => 'translatorsandbox',
59 'log_action' => 'rejected',
60 ] )
61 ->caller( __METHOD__ )
62 ->fetchResultSet();
63
64 foreach ( $rejected as $r ) {
65 echo "{$r->log_title}\t{$r->log_timestamp}\t0\t\t\tsandbox\n";
66 }
67
68 foreach ( $users as $u ) {
69 $logs = $dbr->newSelectQueryBuilder()
70 ->select( [
71 'log_type',
72 'log_action',
73 'log_timestamp',
74 'log_params',
75 ] )
76 ->from( 'logging' )
77 ->where( [
78 'log_title' => $u->user_name,
79 'log_type' => [ 'rights', 'translatorsandbox' ],
80 ] )
81 ->orderBy( 'log_id' )
82 ->caller( __METHOD__ )
83 ->fetchResultSet();
84
85 $promoted = null;
86 $method = 'normal';
87 foreach ( $logs as $log ) {
88 if ( $log->log_action === 'promoted' ) {
89 $promoted = $log->log_timestamp;
90 $method = 'sandbox';
91 break;
92 } elseif ( $log->log_action === 'rights' ) {
93 // phpcs:disable Generic.PHP.NoSilencedErrors.Discouraged
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;
99 break;
100 }
101 } elseif (
102 isset( $data['5::newgroups'] ) &&
103 in_array( 'translator', $data['5::newgroups'] )
104 ) {
105 $promoted = $log->log_timestamp;
106 break;
107 }
108 }
109 }
110
111 echo "{$u->user_name}\t{$u->user_registration}\t{$u->user_editcount}" .
112 "\t{$u->ug_group}\t{$promoted}\t{$method}\n";
113 }
114 }
115}
116
117$maintClass = TS::class;
118require_once RUN_MAINTENANCE_IF_MAIN;