Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 46 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
ReviewPerLanguageStats | |
0.00% |
0 / 46 |
|
0.00% |
0 / 4 |
272 | |
0.00% |
0 / 1 |
preQuery | |
0.00% |
0 / 26 |
|
0.00% |
0 / 1 |
42 | |||
indexOf | |
0.00% |
0 / 18 |
|
0.00% |
0 / 1 |
72 | |||
labels | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getTimestamp | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | declare( strict_types = 1 ); |
3 | |
4 | namespace MediaWiki\Extension\Translate\Statistics; |
5 | |
6 | use MediaWiki\Extension\Translate\Utilities\Utilities; |
7 | use Wikimedia\Rdbms\IDatabase; |
8 | |
9 | /** |
10 | * Graph which provides statistics on number of reviews and reviewers. |
11 | * @ingroup Stats |
12 | * @license GPL-2.0-or-later |
13 | * @since 2012.03 |
14 | */ |
15 | class ReviewPerLanguageStats extends TranslatePerLanguageStats { |
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 | } |