49 $dbr = wfGetDB( DB_REPLICA );
51 $so = $this->getStatsProvider( $opts->getValue(
'count' ), $opts );
53 $fixedStart = $opts->getValue(
'start' ) !==
'';
56 $period = 3600 * 24 * $opts->getValue(
'days' );
59 $cutoff = (int)wfTimestamp( TS_UNIX, $opts->getValue(
'start' ) );
61 $cutoff = $now - $period;
63 $cutoff = self::roundTimestampToCutoff( $opts->getValue(
'scale' ), $cutoff,
'earlier' );
68 $end = self::roundTimestampToCutoff( $opts->getValue(
'scale' ), $start + $period,
'later' ) - 1;
80 $so->preQuery( $tables, $fields, $conds, $type, $options, $joins, $start, $end );
81 $res = $dbr->select( $tables, $fields, $conds, $type, $options, $joins );
82 wfDebug( __METHOD__ .
"-queryend\n" );
85 $dateFormat = $so->getDateFormat();
86 $increment = self::getIncrement( $opts->getValue(
'scale' ) );
88 $labels = $so->labels();
89 $keys = array_keys( $labels );
90 $values = array_pad( [], count( $labels ), 0 );
91 $defaults = array_combine( $keys, $values );
95 $lastValue = $end ?? $now + 10;
96 while ( $cutoff <= $lastValue ) {
97 $date = $language->sprintfDate( $dateFormat, wfTimestamp( TS_MW, $cutoff ) );
98 $cutoff += $increment;
99 $data[$date] = $defaults;
102 $data[$language->sprintfDate( $dateFormat, wfTimestamp( TS_MW, $lastValue ) )] = $defaults;
105 $labelToIndex = array_flip( $labels );
107 foreach ( $res as $row ) {
108 $indexLabels = $so->indexOf( $row );
109 if ( $indexLabels ===
false ) {
113 foreach ( $indexLabels as $i ) {
114 if ( !isset( $labelToIndex[$i] ) ) {
117 $date = $language->sprintfDate( $dateFormat, $so->getTimestamp( $row ) );
119 if ( !isset( $data[$date] ) ) {
123 $data[$date][$labelToIndex[$i]]++;
128 if ( count( $labels ) === 1 && $labels[0] ===
'all' ) {
132 foreach ( $labels as &$label ) {
133 if ( strpos( $label,
'@' ) ===
false ) {
136 [ $groupId, $code ] = explode(
'@', $label, 2 );
137 if ( $code && $groupId ) {
140 $group = $group ? $group->getLabel() : $groupId;
141 $label =
"$group @ $code";
144 } elseif ( $groupId ) {
146 $label = $group ? $group->getLabel() : $groupId;
151 if ( $end ===
null ) {
153 $last = end( $data );
155 unset( $data[$key] );
156 $data[
"$key*" ] = $last;
159 return [ $labels, $data ];