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->newSelectQueryBuilder()
100 wfDebug( __METHOD__ .
"-queryend\n" );
103 $dateFormat = $so->getDateFormat();
104 $increment = self::getIncrement( $opts->getValue(
'scale' ) );
106 $labels = $so->labels();
107 $keys = array_keys( $labels );
108 $values = array_pad( [], count( $labels ), 0 );
109 $defaults = array_combine( $keys, $values );
113 $lastValue = $end ?? $now + 10;
114 while ( $cutoff <= $lastValue ) {
115 $date = $language->sprintfDate( $dateFormat, wfTimestamp( TS_MW, $cutoff ) );
116 $cutoff += $increment;
117 $data[$date] = $defaults;
120 $data[$language->sprintfDate( $dateFormat, wfTimestamp( TS_MW, $lastValue ) )] = $defaults;
123 $labelToIndex = array_flip( $labels );
125 foreach ( $res as $row ) {
126 $indexLabels = $so->indexOf( $row );
127 if ( $indexLabels ===
false ) {
131 foreach ( $indexLabels as $i ) {
132 if ( !isset( $labelToIndex[$i] ) ) {
135 $date = $language->sprintfDate( $dateFormat, $so->getTimestamp( $row ) );
137 if ( !isset( $data[$date] ) ) {
141 $data[$date][$labelToIndex[$i]]++;
146 if ( count( $labels ) === 1 && $labels[0] ===
'all' ) {
150 foreach ( $labels as &$label ) {
151 if ( !str_contains( $label,
'@' ) ) {
154 [ $groupId, $code ] = explode(
'@', $label, 2 );
155 if ( $code && $groupId ) {
156 $code = Utilities::getLanguageName( $code, $language->getCode() ) .
" ($code)";
157 $group = MessageGroups::getGroup( $groupId );
158 $group = $group ? $group->getLabel() : $groupId;
159 $label =
"$group @ $code";
161 $label = Utilities::getLanguageName( $code, $language->getCode() ) .
" ($code)";
162 } elseif ( $groupId ) {
163 $group = MessageGroups::getGroup( $groupId );
164 $label = $group ? $group->getLabel() : $groupId;
169 if ( $end ===
null ) {
171 $last = end( $data );
173 unset( $data[$key] );
174 $data[
"$key*" ] = $last;
177 return [ $labels, $data ];