Translate extension for MediaWiki
 
Loading...
Searching...
No Matches
ReviewPerLanguageStats.php
1<?php
2declare( strict_types = 1 );
3
4namespace MediaWiki\Extension\Translate\Statistics;
5
7use Wikimedia\Rdbms\IDatabase;
8
16 public function preQuery(
17 IDatabase $database,
18 &$tables,
19 &$fields,
20 &$conds,
21 &$type,
22 &$options,
23 &$joins,
24 $start,
25 $end
26 ) {
27 global $wgTranslateMessageNamespaces;
28
29 $tables = [ 'logging' ];
30 $fields = [ 'log_timestamp' ];
31 $joins = [];
32
33 $conds = [
34 'log_namespace' => $wgTranslateMessageNamespaces,
35 'log_action' => 'message',
36 ];
37
38 $timeConds = self::makeTimeCondition( $database, 'log_timestamp', $start, $end );
39 $conds = array_merge( $conds, $timeConds );
40
41 $options = [ 'ORDER BY' => 'log_timestamp' ];
42
43 $this->groups = $this->opts->getGroups();
44
45 $namespaces = self::namespacesFromGroups( $this->groups );
46 if ( count( $namespaces ) ) {
47 $conds['log_namespace'] = $namespaces;
48 }
49
50 $languages = [];
51 foreach ( $this->opts->getLanguages() as $code ) {
52 $languages[] = 'log_title ' . $database->buildLike( $database->anyString(), "/$code" );
53 }
54 if ( count( $languages ) ) {
55 $conds[] = $database->makeList( $languages, LIST_OR );
56 }
57
58 $fields[] = 'log_title';
59
60 if ( $this->groups ) {
61 $fields[] = 'log_namespace';
62 }
63
64 if ( $this->opts->getValue( 'count' ) === 'reviewers' ) {
65 $fields[] = 'log_actor';
66 }
67
68 $type .= '-reviews';
69 }
70
71 public function indexOf( $row ) {
72 if ( $this->opts->getValue( 'count' ) === 'reviewers' ) {
73 $date = $this->formatTimestamp( $row->log_timestamp );
74
75 if ( isset( $this->seenUsers[$date][$row->log_actor] ) ) {
76 return false;
77 }
78
79 $this->seenUsers[$date][$row->log_actor] = 1;
80 }
81
82 // Do not consider language-less pages.
83 if ( !str_contains( $row->log_title, '/' ) ) {
84 return false;
85 }
86
87 // No filters, just one key to track.
88 if ( !$this->groups && !$this->opts->getLanguages() ) {
89 return [ 'all' ];
90 }
91
92 // The key-building needs to be in sync with ::labels().
93 [ $key, $code ] = Utilities::figureMessage( $row->log_title );
94
95 $groups = [];
96 $codes = [];
97
98 if ( $this->groups ) {
99 /* Get list of keys that the message belongs to, and filter
100 * out those which are not requested. */
101 $groups = Utilities::messageKeyToGroups( (int)$row->log_namespace, $key );
102 $groups = array_intersect( $this->groups, $groups );
103 }
104
105 if ( $this->opts->getLanguages() ) {
106 $codes = [ $code ];
107 }
108
109 return $this->combineTwoArrays( $groups, $codes );
110 }
111
112 public function labels() {
113 return $this->combineTwoArrays( $this->groups, $this->opts->getLanguages() );
114 }
115
116 public function getTimestamp( $row ) {
117 return $row->log_timestamp;
118 }
119}
Graph which provides statistics on number of reviews and reviewers.
labels()
Return the names of the variables being measured.
preQuery(IDatabase $database, &$tables, &$fields, &$conds, &$type, &$options, &$joins, $start, $end)
Query details that the graph must fill.
getTimestamp( $row)
Return the timestamp associated with this result row.
indexOf( $row)
Return the indexes which this result contributes to.
Graph which provides statistics on active users and number of translations.
combineTwoArrays( $groups, $codes)
Cross-product of two lists with string results, where either list can be empty.
formatTimestamp( $timestamp)
Returns unique index for given item in the scale being used.
Essentially random collection of helper functions, similar to GlobalFunctions.php.
Definition Utilities.php:31