3 namespace MediaWiki\Skin
;
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
;
16 class SkinComponentCopyright
implements SkinComponent
{
17 use ProtectedHookAccessorTrait
;
21 /** @var MessageLocalizer */
23 /** @var SkinComponentRegistryContext */
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();
38 public function getTemplateData(): array {
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
);
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() ) {
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() ) {
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() ) {
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();