Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 16
0.00% covered (danger)
0.00%
0 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
SetupHandler
0.00% covered (danger)
0.00%
0 / 16
0.00% covered (danger)
0.00%
0 / 4
90
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 onCanonicalNamespaces
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
6
 onSpecialPage_initList
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
6
 onTitleQuickPermissions
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
20
1<?php
2
3namespace MediaWiki\Extension\SecurePoll\HookHandler;
4
5use MediaWiki\Config\Config;
6use MediaWiki\Extension\SecurePoll\SpecialSecurePollLog;
7use MediaWiki\Hook\CanonicalNamespacesHook;
8use MediaWiki\Permissions\Hook\TitleQuickPermissionsHook;
9use MediaWiki\SpecialPage\Hook\SpecialPage_initListHook;
10
11class SetupHandler implements
12    CanonicalNamespacesHook,
13    SpecialPage_initListHook,
14    TitleQuickPermissionsHook
15{
16    /** @var Config */
17    private $config;
18
19    /**
20     * @param Config $config
21     */
22    public function __construct( Config $config ) {
23        $this->config = $config;
24    }
25
26    /**
27     * @inheritDoc
28     */
29    public function onCanonicalNamespaces( &$namespaces ) {
30        if ( $this->config->get( 'SecurePollUseNamespace' ) ) {
31            $namespaces[NS_SECUREPOLL] = 'SecurePoll';
32            $namespaces[NS_SECUREPOLL_TALK] = 'SecurePoll_talk';
33        }
34    }
35
36    // phpcs:disable MediaWiki.NamingConventions.LowerCamelFunctionsName.FunctionName
37
38    /**
39     * @inheritDoc
40     */
41    public function onSpecialPage_initList( &$list ) {
42        if ( $this->config->get( 'SecurePollUseLogging' ) ) {
43            $list['SecurePollLog'] = [
44                'class' => SpecialSecurePollLog::class,
45                'services' => [
46                    'UserFactory',
47                ]
48            ];
49        }
50    }
51
52    /**
53     * @inheritDoc
54     */
55    public function onTitleQuickPermissions(
56        $title, $user, $action, &$errors, $doExpensiveQueries, $short
57    ) {
58        if ( $this->config->get( 'SecurePollUseNamespace' ) && $title->getNamespace() === NS_SECUREPOLL &&
59            $action !== 'read'
60        ) {
61            $errors[] = [ 'securepoll-ns-readonly' ];
62
63            return false;
64        }
65
66        return true;
67    }
68}