Translate extension for MediaWiki
 
Loading...
Searching...
No Matches
TranslationStatsBase.php
1<?php
2declare( strict_types = 1 );
3
4namespace MediaWiki\Extension\Translate\Statistics;
5
7
16 protected $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( $field, $start, $end ) {
47 $db = wfGetDB( DB_REPLICA );
48
49 $conds = [];
50 if ( $start !== null ) {
51 $conds[] = "$field >= " . $db->addQuotes( $db->timestamp( $start ) );
52 }
53 if ( $end !== null ) {
54 $conds[] = "$field <= " . $db->addQuotes( $db->timestamp( $end ) );
55 }
56
57 return $conds;
58 }
59
65 protected static function namespacesFromGroups( $groupIds ) {
66 $namespaces = [];
67 foreach ( $groupIds as $id ) {
68 $group = MessageGroups::getGroup( $id );
69 if ( $group ) {
70 $namespace = $group->getNamespace();
71 $namespaces[$namespace] = true;
72 }
73 }
74
75 return array_keys( $namespaces );
76 }
77}
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.
Factory class for accessing message groups individually by id or all of them as an list.