Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 46 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
SkinComponentCopyright | |
0.00% |
0 / 46 |
|
0.00% |
0 / 3 |
272 | |
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 / 39 |
|
0.00% |
0 / 1 |
210 |
1 | <?php |
2 | |
3 | namespace MediaWiki\Skin; |
4 | |
5 | use HtmlArmor; |
6 | use MediaWiki\Config\Config; |
7 | use MediaWiki\HookContainer\ProtectedHookAccessorTrait; |
8 | use MediaWiki\MainConfigNames; |
9 | use MediaWiki\MediaWikiServices; |
10 | use MediaWiki\Message\Message; |
11 | use MediaWiki\SpecialPage\SpecialPage; |
12 | use MediaWiki\Title\Title; |
13 | use MediaWiki\User\User; |
14 | use MessageLocalizer; |
15 | |
16 | class SkinComponentCopyright implements SkinComponent { |
17 | use ProtectedHookAccessorTrait; |
18 | |
19 | /** @var Config */ |
20 | private $config; |
21 | /** @var MessageLocalizer */ |
22 | private $localizer; |
23 | /** @var SkinComponentRegistryContext */ |
24 | private $skinContext; |
25 | /** @var User */ |
26 | private $user; |
27 | |
28 | public function __construct( SkinComponentRegistryContext $skinContext ) { |
29 | $this->skinContext = $skinContext; |
30 | $this->config = $skinContext->getConfig(); |
31 | $this->localizer = $skinContext->getMessageLocalizer(); |
32 | $this->user = $skinContext->getUser(); |
33 | } |
34 | |
35 | /** |
36 | * @inheritDoc |
37 | */ |
38 | public function getTemplateData(): array { |
39 | return [ |
40 | 'html' => $this->getCopyrightHTML(), |
41 | ]; |
42 | } |
43 | |
44 | public function getCopyrightHTML(): string { |
45 | $out = $this->skinContext->getOutput(); |
46 | $title = $out->getTitle(); |
47 | $isRevisionCurrent = $out->isRevisionCurrent(); |
48 | $config = $this->config; |
49 | $localizer = $this->localizer; |
50 | $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer(); |
51 | |
52 | if ( $config->get( MainConfigNames::RightsPage ) ) { |
53 | $title = Title::newFromText( $config->get( MainConfigNames::RightsPage ) ); |
54 | $link = $linkRenderer->makeKnownLink( $title, |
55 | new HtmlArmor( $config->get( MainConfigNames::RightsText ) ?: $title->getText() ) |
56 | ); |
57 | } elseif ( $config->get( MainConfigNames::RightsUrl ) ) { |
58 | $link = $linkRenderer->makeExternalLink( |
59 | $config->get( MainConfigNames::RightsUrl ), |
60 | $config->get( MainConfigNames::RightsText ), |
61 | $title ?? SpecialPage::getTitleFor( 'Badtitle' ) |
62 | ); |
63 | } elseif ( $config->get( MainConfigNames::RightsText ) ) { |
64 | $link = $config->get( MainConfigNames::RightsText ); |
65 | } else { |
66 | # Give up now |
67 | return ''; |
68 | } |
69 | |
70 | if ( $config->get( MainConfigNames::AllowRawHtmlCopyrightMessages ) ) { |
71 | // First check whether the old, raw HTML messages exist (if not disallowed by wiki config), |
72 | // for compatibility with on-wiki message overrides. |
73 | |
74 | if ( !$isRevisionCurrent && !$localizer->msg( 'history_copyright' )->isDisabled() ) { |
75 | $type = 'history'; |
76 | } else { |
77 | $type = 'normal'; |
78 | } |
79 | |
80 | $msgKey = $type === 'history' ? 'history_copyright' : 'copyright'; |
81 | |
82 | // Allow for site and per-namespace customization of copyright notice. |
83 | $this->getHookRunner()->onSkinCopyrightFooter( $title, $type, $msgKey, $link ); |
84 | |
85 | $msg = $localizer->msg( $msgKey )->rawParams( $link ); |
86 | if ( !$msg->isDisabled() ) { |
87 | return $msg->text(); |
88 | } |
89 | } |
90 | |
91 | // TODO: The hook should probably be called with $type === 'history' even if this message |
92 | // is disabled, to allow customization, but then we'd probably have to call it again with |
93 | // $type === 'normal' if it turns out it's not customized? |
94 | if ( !$isRevisionCurrent && !$localizer->msg( 'copyright-footer-history' )->isDisabled() ) { |
95 | $type = 'history'; |
96 | } else { |
97 | $type = 'normal'; |
98 | } |
99 | |
100 | // If it does not exist or disabled, use the new, safer wikitext message. |
101 | $msgKey = $type === 'history' ? 'copyright-footer-history' : 'copyright-footer'; |
102 | $msgSpec = Message::newFromSpecifier( $msgKey )->rawParams( $link ); |
103 | |
104 | // Allow for site and per-namespace customization of copyright notice. |
105 | $this->getHookRunner()->onSkinCopyrightFooterMessage( $title, $type, $msgSpec ); |
106 | |
107 | $msg = $localizer->msg( $msgSpec ); |
108 | if ( !$msg->isDisabled() ) { |
109 | return $msg->parse(); |
110 | } |
111 | |
112 | return ''; |
113 | } |
114 | } |