2declare( strict_types = 1 );
4namespace MediaWiki\Extension\Translate\Statistics;
6use MediaWiki\MediaWikiServices;
21 parent::__construct( $opts );
23 $opts->boundValue(
'days', 1, 400 );
26 public function preQuery( &$tables, &$fields, &$conds, &$type, &$options, &$joins, $start, $end ) {
27 global $wgTranslateMessageNamespaces;
29 $db = wfGetDB( DB_REPLICA );
31 $tables = [
'recentchanges' ];
32 $fields = [
'rc_timestamp' ];
36 'rc_namespace' => $wgTranslateMessageNamespaces,
38 'rc_type != ' . RC_LOG,
41 $timeConds = self::makeTimeCondition(
'rc_timestamp', $start, $end );
42 $conds = array_merge( $conds, $timeConds );
44 $options = [
'ORDER BY' =>
'rc_timestamp' ];
46 $this->groups = array_map(
'MessageGroups::normalizeId', $this->opts->getGroups() );
49 if ( count( $namespaces ) ) {
50 $conds[
'rc_namespace'] = $namespaces;
54 foreach ( $this->opts->getLanguages() as $code ) {
55 $languages[] =
'rc_title ' . $db->buildLike( $db->anyString(),
"/$code" );
57 if ( count( $languages ) ) {
58 $conds[] = $db->makeList( $languages, LIST_OR );
61 $fields[] =
'rc_title';
63 if ( $this->groups ) {
64 $fields[] =
'rc_namespace';
67 if ( $this->opts->getValue(
'count' ) ===
'users' ) {
68 $fields[] =
'rc_actor';
75 if ( $this->opts->getValue(
'count' ) ===
'users' ) {
78 if ( isset( $this->seenUsers[$date][$row->rc_actor] ) ) {
82 $this->seenUsers[$date][$row->rc_actor] =
true;
86 if ( strpos( $row->rc_title,
'/' ) ===
false ) {
91 if ( !$this->groups && !$this->opts->getLanguages() ) {
96 [ $key, $code ] = TranslateUtils::figureMessage( $row->rc_title );
101 if ( $this->groups ) {
106 $groups = TranslateUtils::messageKeyToGroups( $row->rc_namespace, $key );
107 $groups = array_intersect( $this->groups, $groups );
110 if ( $this->opts->getLanguages() ) {
118 return $this->
combineTwoArrays( $this->groups, $this->opts->getLanguages() );
122 return $row->rc_timestamp;
133 if ( $group || $code ) {
134 return "$group@$code";
148 if ( !count( $groups ) ) {
152 if ( !count( $codes ) ) {
157 foreach ( $groups as $group ) {
158 foreach ( $codes as $code ) {
159 $items[] = $this->
makeLabel( $group, $code );
173 switch ( $this->opts->getValue(
'scale' ) ) {
187 return MediaWikiServices::getInstance()->getContentLanguage()
191 return substr( $timestamp, 0, -$cut );
Essentially random collection of helper functions, similar to GlobalFunctions.php.