summaryrefslogtreecommitdiff
blob: 3960231debf0fe7993b52a8fc35fa38972344e25 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
declare( strict_types = 1 );

namespace MediaWiki\Extension\Translate\Statistics;

use MessageGroups;

/**
 * Provides some hand default implementations for TranslationStatsInterface.
 * @ingroup Stats
 * @license GPL-2.0-or-later
 * @since 2010.07
 */
abstract class TranslationStatsBase implements TranslationStatsInterface {
	/** @var TranslationStatsGraphOptions */
	protected $opts;

	public function __construct( TranslationStatsGraphOptions $opts ) {
		$this->opts = $opts;
	}

	public function indexOf( $row ) {
		return [ 'all' ];
	}

	public function labels() {
		return [ 'all' ];
	}

	public function getDateFormat() {
		$dateFormat = 'Y-m-d';
		$scale = $this->opts->getValue( 'scale' );
		if ( $scale === 'months' ) {
			$dateFormat = 'Y-m';
		} elseif ( $scale === 'weeks' ) {
			$dateFormat = 'Y-\WW';
		} elseif ( $scale === 'hours' ) {
			$dateFormat .= ';H';
		}

		return $dateFormat;
	}

	protected static function makeTimeCondition( $field, $start, $end ) {
		$db = wfGetDB( DB_REPLICA );

		$conds = [];
		if ( $start !== null ) {
			$conds[] = "$field >= '{$db->timestamp( $start )}'";
		}
		if ( $end !== null ) {
			$conds[] = "$field <= '{$db->timestamp( $end )}'";
		}

		return $conds;
	}

	/**
	 * @since 2012-03-05
	 * @param array $groupIds
	 * @return array
	 */
	protected static function namespacesFromGroups( $groupIds ) {
		$namespaces = [];
		foreach ( $groupIds as $id ) {
			$group = MessageGroups::getGroup( $id );
			if ( $group ) {
				$namespace = $group->getNamespace();
				$namespaces[$namespace] = true;
			}
		}

		return array_keys( $namespaces );
	}
}

class_alias( TranslationStatsBase::class, '\MediaWiki\Extensions\Translate\TranslationStatsBase' );