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 | /** |
29 | * @param SkinComponentRegistryContext $skinContext |
30 | */ |
31 | public function __construct( SkinComponentRegistryContext $skinContext ) { |
32 | $this->skinContext = $skinContext; |
33 | $this->config = $skinContext->getConfig(); |
34 | $this->localizer = $skinContext->getMessageLocalizer(); |
35 | $this->user = $skinContext->getUser(); |
36 | } |
37 | |
38 | /** |
39 | * @inheritDoc |
40 | */ |
41 | public function getTemplateData(): array { |
42 | return [ |
43 | 'html' => $this->getCopyrightHTML(), |
44 | ]; |
45 | } |
46 | |
47 | /** |
48 | * Get the copyright. |
49 | * |
50 | * @return string |
51 | */ |
52 | public function getCopyrightHTML(): string { |
53 | $out = $this->skinContext->getOutput(); |
54 | $title = $out->getTitle(); |
55 | $isRevisionCurrent = $out->isRevisionCurrent(); |
56 | $config = $this->config; |
57 | $localizer = $this->localizer; |
58 | $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer(); |
59 | |
60 | if ( $config->get( MainConfigNames::RightsPage ) ) { |
61 | $title = Title::newFromText( $config->get( MainConfigNames::RightsPage ) ); |
62 | $link = $linkRenderer->makeKnownLink( $title, |
63 | new HtmlArmor( $config->get( MainConfigNames::RightsText ) ?: $title->getText() ) |
64 | ); |
65 | } elseif ( $config->get( MainConfigNames::RightsUrl ) ) { |
66 | $link = $linkRenderer->makeExternalLink( |
67 | $config->get( MainConfigNames::RightsUrl ), |
68 | $config->get( MainConfigNames::RightsText ), |
69 | $title ?? SpecialPage::getTitleFor( 'Badtitle' ) |
70 | ); |
71 | } elseif ( $config->get( MainConfigNames::RightsText ) ) { |
72 | $link = $config->get( MainConfigNames::RightsText ); |
73 | } else { |
74 | # Give up now |
75 | return ''; |
76 | } |
77 | |
78 | if ( $config->get( MainConfigNames::AllowRawHtmlCopyrightMessages ) ) { |
79 | // First check whether the old, raw HTML messages exist (if not disallowed by wiki config), |
80 | // for compatibility with on-wiki message overrides. |
81 | |
82 | if ( !$isRevisionCurrent && !$localizer->msg( 'history_copyright' )->isDisabled() ) { |
83 | $type = 'history'; |
84 | } else { |
85 | $type = 'normal'; |
86 | } |
87 | |
88 | $msgKey = $type === 'history' ? 'history_copyright' : 'copyright'; |
89 | |
90 | // Allow for site and per-namespace customization of copyright notice. |
91 | $this->getHookRunner()->onSkinCopyrightFooter( $title, $type, $msgKey, $link ); |
92 | |
93 | $msg = $localizer->msg( $msgKey )->rawParams( $link ); |
94 | if ( !$msg->isDisabled() ) { |
95 | return $msg->text(); |
96 | } |
97 | } |
98 | |
99 | // TODO: The hook should probably be called with $type === 'history' even if this message |
100 | // is disabled, to allow customization, but then we'd probably have to call it again with |
101 | // $type === 'normal' if it turns out it's not customized? |
102 | if ( !$isRevisionCurrent && !$localizer->msg( 'copyright-footer-history' )->isDisabled() ) { |
103 | $type = 'history'; |
104 | } else { |
105 | $type = 'normal'; |
106 | } |
107 | |
108 | // If it does not exist or disabled, use the new, safer wikitext message. |
109 | $msgKey = $type === 'history' ? 'copyright-footer-history' : 'copyright-footer'; |
110 | $msgSpec = Message::newFromSpecifier( $msgKey )->rawParams( $link ); |
111 | |
112 | // Allow for site and per-namespace customization of copyright notice. |
113 | $this->getHookRunner()->onSkinCopyrightFooterMessage( $title, $type, $msgSpec ); |
114 | |
115 | $msg = $localizer->msg( $msgSpec ); |
116 | if ( !$msg->isDisabled() ) { |
117 | return $msg->parse(); |
118 | } |
119 | |
120 | return ''; |
121 | } |
122 | } |