Translate extension for MediaWiki
 
Loading...
Searching...
No Matches
TranslationStatsBase.php
1<?php
2declare( strict_types = 1 );
3
4namespace MediaWiki\Extension\Translate\Statistics;
5
7use Wikimedia\Rdbms\IDatabase;
8
16 protected TranslationStatsGraphOptions $opts;
17
18 public function __construct( TranslationStatsGraphOptions $opts ) {
19 $this->opts = $opts;
20 }
21
22 public function indexOf( $row ) {
23 return [ 'all' ];
24 }
25
26 public function labels() {
27 return [ 'all' ];
28 }
29
30 public function getDateFormat() {
31 $dateFormat = 'Y-m-d';
32 $scale = $this->opts->getValue( 'scale' );
33 if ( $scale === 'years' ) {
34 $dateFormat = 'Y';
35 } elseif ( $scale === 'months' ) {
36 $dateFormat = 'Y-m';
37 } elseif ( $scale === 'weeks' ) {
38 $dateFormat = 'Y-\WW';
39 } elseif ( $scale === 'hours' ) {
40 $dateFormat .= ';H';
41 }
42
43 return $dateFormat;
44 }
45
46 protected static function makeTimeCondition( IDatabase $database, $field, $start, $end ) {
47 $conds = [];
48 if ( $start !== null ) {
49 $conds[] = "$field >= " . $database->addQuotes( $database->timestamp( $start ) );
50 }
51 if ( $end !== null ) {
52 $conds[] = "$field <= " . $database->addQuotes( $database->timestamp( $end ) );
53 }
54
55 return $conds;
56 }
57
63 protected static function namespacesFromGroups( $groupIds ) {
64 $namespaces = [];
65 foreach ( $groupIds as $id ) {
66 $group = MessageGroups::getGroup( $id );
67 if ( $group ) {
68 $namespace = $group->getNamespace();
69 $namespaces[$namespace] = true;
70 }
71 }
72
73 return array_keys( $namespaces );
74 }
75}
Factory class for accessing message groups individually by id or all of them as a list.
Provides some hand default implementations for TranslationStatsInterface.
labels()
Return the names of the variables being measured.
__construct(TranslationStatsGraphOptions $opts)
Constructor.
indexOf( $row)
Return the indexes which this result contributes to.