50 $dbr = $this->loadBalancer->getConnection( DB_REPLICA );
52 $so = $this->getStatsProvider( $opts->getValue(
'count' ), $opts );
54 $fixedStart = $opts->getValue(
'start' ) !==
'';
57 $period = 3600 * 24 * $opts->getValue(
'days' );
60 $cutoff = (int)wfTimestamp( TS_UNIX, $opts->getValue(
'start' ) );
62 $cutoff = $now - $period;
64 $cutoff = self::roundTimestampToCutoff( $opts->getValue(
'scale' ), $cutoff,
'earlier' );
69 $end = self::roundTimestampToCutoff( $opts->getValue(
'scale' ), $start + $period,
'later' ) - 1;
89 wfTimestamp( TS_MW, $start ),
90 wfTimestampOrNull( TS_MW, $end )
92 $res = $dbr->select( $tables, $fields, $conds, $type, $options, $joins );
93 wfDebug( __METHOD__ .
"-queryend\n" );
96 $dateFormat = $so->getDateFormat();
97 $increment = self::getIncrement( $opts->getValue(
'scale' ) );
99 $labels = $so->labels();
100 $keys = array_keys( $labels );
101 $values = array_pad( [], count( $labels ), 0 );
102 $defaults = array_combine( $keys, $values );
106 $lastValue = $end ?? $now + 10;
107 while ( $cutoff <= $lastValue ) {
108 $date = $language->sprintfDate( $dateFormat, wfTimestamp( TS_MW, $cutoff ) );
109 $cutoff += $increment;
110 $data[$date] = $defaults;
113 $data[$language->sprintfDate( $dateFormat, wfTimestamp( TS_MW, $lastValue ) )] = $defaults;
116 $labelToIndex = array_flip( $labels );
118 foreach ( $res as $row ) {
119 $indexLabels = $so->indexOf( $row );
120 if ( $indexLabels ===
false ) {
124 foreach ( $indexLabels as $i ) {
125 if ( !isset( $labelToIndex[$i] ) ) {
128 $date = $language->sprintfDate( $dateFormat, $so->getTimestamp( $row ) );
130 if ( !isset( $data[$date] ) ) {
134 $data[$date][$labelToIndex[$i]]++;
139 if ( count( $labels ) === 1 && $labels[0] ===
'all' ) {
143 foreach ( $labels as &$label ) {
144 if ( !str_contains( $label,
'@' ) ) {
147 [ $groupId, $code ] = explode(
'@', $label, 2 );
148 if ( $code && $groupId ) {
149 $code = Utilities::getLanguageName( $code, $language->getCode() ) .
" ($code)";
150 $group = MessageGroups::getGroup( $groupId );
151 $group = $group ? $group->getLabel() : $groupId;
152 $label =
"$group @ $code";
154 $label = Utilities::getLanguageName( $code, $language->getCode() ) .
" ($code)";
155 } elseif ( $groupId ) {
156 $group = MessageGroups::getGroup( $groupId );
157 $label = $group ? $group->getLabel() : $groupId;
162 if ( $end ===
null ) {
164 $last = end( $data );
166 unset( $data[$key] );
167 $data[
"$key*" ] = $last;
170 return [ $labels, $data ];