Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 36
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
SkinComponentCopyright
0.00% covered (danger)
0.00%
0 / 36
0.00% covered (danger)
0.00%
0 / 3
110
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
2
 getTemplateData
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
 getCopyrightHTML
0.00% covered (danger)
0.00%
0 / 29
0.00% covered (danger)
0.00%
0 / 1
72
1<?php
2
3namespace MediaWiki\Skin;
4
5use HtmlArmor;
6use MediaWiki\Config\Config;
7use MediaWiki\MainConfigNames;
8use MediaWiki\MediaWikiServices;
9use MediaWiki\SpecialPage\SpecialPage;
10use MediaWiki\Title\Title;
11use MediaWiki\User\User;
12use MessageLocalizer;
13
14class 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 = $linkRenderer->makeExternalLink(
76                $config->get( MainConfigNames::RightsUrl ),
77                $config->get( MainConfigNames::RightsText ),
78                $title ?? SpecialPage::getTitleFor( 'Badtitle' )
79            );
80        } elseif ( $config->get( MainConfigNames::RightsText ) ) {
81            $link = $config->get( MainConfigNames::RightsText );
82        } else {
83            # Give up now
84            return '';
85        }
86
87        // Allow for site and per-namespace customization of copyright notice.
88        $this->skinContext->runHook( 'onSkinCopyrightFooter', [ $title, $type, &$msg, &$link ] );
89        return $localizer->msg( $msg )->rawParams( $link )->text();
90    }
91}