Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 27
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
SkinComponentLastModified
0.00% covered (danger)
0.00%
0 / 27
0.00% covered (danger)
0.00%
0 / 2
20
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
2
 getTemplateData
0.00% covered (danger)
0.00%
0 / 23
0.00% covered (danger)
0.00%
0 / 1
12
1<?php
2
3namespace MediaWiki\Skin;
4
5use MediaWiki\Language\Language;
6use MediaWiki\MediaWikiServices;
7use MediaWiki\User\User;
8use MessageLocalizer;
9
10class SkinComponentLastModified implements SkinComponent {
11    /** @var Language */
12    private $language;
13    /** @var MessageLocalizer */
14    private $localizer;
15    /** @var string|null|false */
16    private $revisionTimestamp;
17    /** @var User */
18    private $user;
19
20    /**
21     * @param SkinComponentRegistryContext $skinContext
22     * @param string|null|false $revisionTimestamp
23     */
24    public function __construct( SkinComponentRegistryContext $skinContext, $revisionTimestamp = null ) {
25        $this->revisionTimestamp = $revisionTimestamp;
26        $this->localizer = $skinContext->getMessageLocalizer();
27        $this->user = $skinContext->getUser();
28        $this->language = $skinContext->getLanguage();
29    }
30
31    /**
32     * Get the timestamp of the latest revision, formatted in user language
33     *
34     * @inheritDoc
35     */
36    public function getTemplateData(): array {
37        $localizer = $this->localizer;
38        $user = $this->user;
39        $language = $this->language;
40        $timestamp = $this->revisionTimestamp;
41
42        if ( $timestamp ) {
43            $d = $language->userDate( $timestamp, $user );
44            $t = $language->userTime( $timestamp, $user );
45            $s = ' ' . $localizer->msg( 'lastmodifiedat', $d, $t )->parse();
46        } else {
47            $s = '';
48            $d = null;
49            $t = null;
50        }
51
52        $isLagged = MediaWikiServices::getInstance()->getDBLoadBalancerFactory()->laggedReplicaUsed();
53        if ( $isLagged ) {
54            $s .= ' <strong>' .
55                $localizer->msg( 'laggedreplicamode' )->parse() .
56                '</strong>';
57        }
58
59        return [
60            'is-replica' => $isLagged,
61            'text' => $s,
62            'date' => $d,
63            'time' => $t,
64            'timestamp' => $timestamp,
65        ];
66    }
67}