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