Merge "Special:BlockList: Update remove/change block links"
[mediawiki.git] / includes / skins / components / SkinComponentCopyright.php
blob97bd86dde2ef3178094176b60d781855d63c7569
1 <?php
3 namespace MediaWiki\Skin;
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;
16 class SkinComponentCopyright implements SkinComponent {
17 use ProtectedHookAccessorTrait;
19 /** @var Config */
20 private $config;
21 /** @var MessageLocalizer */
22 private $localizer;
23 /** @var SkinComponentRegistryContext */
24 private $skinContext;
25 /** @var User */
26 private $user;
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();
35 /**
36 * @inheritDoc
38 public function getTemplateData(): array {
39 return [
40 'html' => $this->getCopyrightHTML(),
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();
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() )
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' )
63 } elseif ( $config->get( MainConfigNames::RightsText ) ) {
64 $link = $config->get( MainConfigNames::RightsText );
65 } else {
66 # Give up now
67 return '';
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.
74 if ( !$isRevisionCurrent && !$localizer->msg( 'history_copyright' )->isDisabled() ) {
75 $type = 'history';
76 } else {
77 $type = 'normal';
80 $msgKey = $type === 'history' ? 'history_copyright' : 'copyright';
82 // Allow for site and per-namespace customization of copyright notice.
83 $this->getHookRunner()->onSkinCopyrightFooter( $title, $type, $msgKey, $link );
85 $msg = $localizer->msg( $msgKey )->rawParams( $link );
86 if ( !$msg->isDisabled() ) {
87 return $msg->text();
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';
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 );
104 // Allow for site and per-namespace customization of copyright notice.
105 $this->getHookRunner()->onSkinCopyrightFooterMessage( $title, $type, $msgSpec );
107 $msg = $localizer->msg( $msgSpec );
108 if ( !$msg->isDisabled() ) {
109 return $msg->parse();
112 return '';