Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 33 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
SkinComponentCopyright | |
0.00% |
0 / 33 |
|
0.00% |
0 / 3 |
110 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
getTemplateData | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
getCopyrightHTML | |
0.00% |
0 / 26 |
|
0.00% |
0 / 1 |
72 |
1 | <?php |
2 | |
3 | namespace MediaWiki\Skin; |
4 | |
5 | use HtmlArmor; |
6 | use MediaWiki\Config\Config; |
7 | use MediaWiki\Linker\Linker; |
8 | use MediaWiki\MainConfigNames; |
9 | use MediaWiki\MediaWikiServices; |
10 | use MediaWiki\Title\Title; |
11 | use MediaWiki\User\User; |
12 | use MessageLocalizer; |
13 | |
14 | class SkinComponentCopyright implements SkinComponent { |
15 | /** @var Config */ |
16 | private $config; |
17 | /** @var MessageLocalizer */ |
18 | private $localizer; |
19 | /** @var SkinComponentRegistryContext */ |
20 | private $skinContext; |
21 | /** @var User */ |
22 | private $user; |
23 | |
24 | /** |
25 | * @param SkinComponentRegistryContext $skinContext |
26 | */ |
27 | public function __construct( SkinComponentRegistryContext $skinContext ) { |
28 | $this->skinContext = $skinContext; |
29 | $this->config = $skinContext->getConfig(); |
30 | $this->localizer = $skinContext->getMessageLocalizer(); |
31 | $this->user = $skinContext->getUser(); |
32 | } |
33 | |
34 | /** |
35 | * @inheritDoc |
36 | */ |
37 | public function getTemplateData(): array { |
38 | return [ |
39 | 'html' => $this->getCopyrightHTML(), |
40 | ]; |
41 | } |
42 | |
43 | /** |
44 | * Get the copyright. |
45 | * |
46 | * @return string |
47 | */ |
48 | public function getCopyrightHTML(): string { |
49 | $out = $this->skinContext->getOutput(); |
50 | $title = $out->getTitle(); |
51 | $isRevisionCurrent = $out->isRevisionCurrent(); |
52 | $config = $this->config; |
53 | $localizer = $this->localizer; |
54 | $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer(); |
55 | if ( !$isRevisionCurrent |
56 | && !$localizer->msg( 'history_copyright' )->inContentLanguage()->isDisabled() |
57 | ) { |
58 | $type = 'history'; |
59 | } else { |
60 | $type = 'normal'; |
61 | } |
62 | |
63 | if ( $type == 'history' ) { |
64 | $msg = 'history_copyright'; |
65 | } else { |
66 | $msg = 'copyright'; |
67 | } |
68 | |
69 | if ( $config->get( MainConfigNames::RightsPage ) ) { |
70 | $title = Title::newFromText( $config->get( MainConfigNames::RightsPage ) ); |
71 | $link = $linkRenderer->makeKnownLink( $title, |
72 | new HtmlArmor( $config->get( MainConfigNames::RightsText ) ?: $title->getText() ) |
73 | ); |
74 | } elseif ( $config->get( MainConfigNames::RightsUrl ) ) { |
75 | $link = Linker::makeExternalLink( $config->get( MainConfigNames::RightsUrl ), |
76 | $config->get( MainConfigNames::RightsText ) ); |
77 | } elseif ( $config->get( MainConfigNames::RightsText ) ) { |
78 | $link = $config->get( MainConfigNames::RightsText ); |
79 | } else { |
80 | # Give up now |
81 | return ''; |
82 | } |
83 | |
84 | // Allow for site and per-namespace customization of copyright notice. |
85 | $this->skinContext->runHook( 'onSkinCopyrightFooter', [ $title, $type, &$msg, &$link ] ); |
86 | return $localizer->msg( $msg )->rawParams( $link )->text(); |
87 | } |
88 | } |