2declare( strict_types = 1 );
4namespace MediaWiki\Extension\Translate\Statistics;
8use MediaWiki\MediaWikiServices;
22 parent::__construct( $opts );
24 $opts->boundValue(
'days', 1, 400 );
27 public function preQuery( &$tables, &$fields, &$conds, &$type, &$options, &$joins, $start, $end ) {
28 global $wgTranslateMessageNamespaces;
30 $db = wfGetDB( DB_REPLICA );
32 $tables = [
'recentchanges' ];
33 $fields = [
'rc_timestamp' ];
37 'rc_namespace' => $wgTranslateMessageNamespaces,
39 'rc_type != ' . RC_LOG,
42 $timeConds = self::makeTimeCondition(
'rc_timestamp', $start, $end );
43 $conds = array_merge( $conds, $timeConds );
45 $options = [
'ORDER BY' =>
'rc_timestamp' ];
47 $this->groups = array_map( [ MessageGroups::class,
'normalizeId' ], $this->opts->getGroups() );
50 if ( count( $namespaces ) ) {
51 $conds[
'rc_namespace'] = $namespaces;
55 foreach ( $this->opts->getLanguages() as $code ) {
56 $languages[] =
'rc_title ' . $db->buildLike( $db->anyString(),
"/$code" );
58 if ( count( $languages ) ) {
59 $conds[] = $db->makeList( $languages, LIST_OR );
62 $fields[] =
'rc_title';
64 if ( $this->groups ) {
65 $fields[] =
'rc_namespace';
68 if ( $this->opts->getValue(
'count' ) ===
'users' ) {
69 $fields[] =
'rc_actor';
76 if ( $this->opts->getValue(
'count' ) ===
'users' ) {
79 if ( isset( $this->seenUsers[$date][$row->rc_actor] ) ) {
83 $this->seenUsers[$date][$row->rc_actor] =
true;
87 if ( strpos( $row->rc_title,
'/' ) ===
false ) {
92 if ( !$this->groups && !$this->opts->getLanguages() ) {
97 [ $key, $code ] = Utilities::figureMessage( $row->rc_title );
102 if ( $this->groups ) {
107 $groups = Utilities::messageKeyToGroups( (
int)$row->rc_namespace, $key );
108 $groups = array_intersect( $this->groups, $groups );
111 if ( $this->opts->getLanguages() ) {
119 return $this->
combineTwoArrays( $this->groups, $this->opts->getLanguages() );
123 return $row->rc_timestamp;
134 if ( $group || $code ) {
135 return "$group@$code";
149 if ( !count( $groups ) ) {
153 if ( !count( $codes ) ) {
158 foreach ( $groups as $group ) {
159 foreach ( $codes as $code ) {
160 $items[] = $this->
makeLabel( $group, $code );
174 switch ( $this->opts->getValue(
'scale' ) ) {
188 return MediaWikiServices::getInstance()->getContentLanguage()
192 return substr( $timestamp, 0, -$cut );