Failed Conditions
Push — rbac ( 1ec5d5 )
by Simon
18:18 queued 05:15
created

TemplateOutput   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 87
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 87
ccs 0
cts 35
cp 0
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 3

5 Methods

Rating   Name   Duplication   Size   Complexity  
getSiteConfiguration() 0 1 ?
A setTailScript() 0 4 1
A assign() 0 4 1
B setUpSmarty() 0 34 1
A fetchTemplate() 0 6 1
1
<?php
2
/******************************************************************************
3
 * Wikipedia Account Creation Assistance tool                                 *
4
 *                                                                            *
5
 * All code in this file is released into the public domain by the ACC        *
6
 * Development Team. Please see team.json for a list of contributors.         *
7
 ******************************************************************************/
8
9
namespace Waca\Fragments;
10
11
use Smarty;
12
use Waca\DataObjects\User;
13
use Waca\Environment;
14
use Waca\SiteConfiguration;
15
16
trait TemplateOutput
17
{
18
    /** @var Smarty */
19
    private $smarty;
20
    /** @var string Extra JavaScript to include at the end of the page's execution */
21
    private $tailScript;
22
23
    /**
24
     * @return SiteConfiguration
25
     */
26
    protected abstract function getSiteConfiguration();
27
28
    /**
29
     * Include extra JavaScript at the end of the page's execution
30
     *
31
     * @param $script string JavaScript to include at the end of the page
32
     */
33
    final protected function setTailScript($script)
34
    {
35
        $this->tailScript = $script;
36
    }
37
38
    /**
39
     * Assigns a Smarty variable
40
     *
41
     * @param  array|string $name  the template variable name(s)
42
     * @param  mixed        $value the value to assign
43
     */
44
    final protected function assign($name, $value)
45
    {
46
        $this->smarty->assign($name, $value);
47
    }
48
49
    /**
50
     * Sets up the variables used by the main Smarty base template.
51
     *
52
     * This list is getting kinda long.
53
     */
54
    final protected function setUpSmarty()
55
    {
56
        $this->smarty = new Smarty();
57
        $this->smarty->addPluginsDir($this->getSiteConfiguration()->getFilePath() . '/smarty-plugins');
58
59
        $this->assign('currentUser', User::getCommunity());
60
        $this->assign('loggedIn', false);
61
        $this->assign('baseurl', $this->getSiteConfiguration()->getBaseUrl());
62
        $this->assign('mediawikiScriptPath', $this->getSiteConfiguration()->getMediawikiScriptPath());
63
64
        $this->assign('siteNoticeText', '');
65
        $this->assign('toolversion', Environment::getToolVersion());
66
67
        // default these
68
        $this->assign('onlineusers', array());
69
        $this->assign('typeAheadBlock', '');
70
        $this->assign('extraJs', array());
71
        $this->assign('extraCss', array());
72
73
        // nav menu access control
74
        $this->assign('nav__canRequests', false);
75
        $this->assign('nav__canLogs', false);
76
        $this->assign('nav__canUsers', false);
77
        $this->assign('nav__canSearch', false);
78
        $this->assign('nav__canStats', false);
79
        $this->assign('nav__canBan', false);
80
        $this->assign('nav__canEmailMgmt', false);
81
        $this->assign('nav__canWelcomeMgmt', false);
82
        $this->assign('nav__canSiteNoticeMgmt', false);
83
        $this->assign('nav__canUserMgmt', false);
84
        $this->assign('nav__canViewRequest', false);
85
86
        $this->assign('page', $this);
87
    }
88
89
    /**
90
     * Fetches a rendered Smarty template
91
     *
92
     * @param $template string Template file path, relative to /templates/
93
     *
94
     * @return string Templated HTML
95
     */
96
    final protected function fetchTemplate($template)
97
    {
98
        $this->assign("tailScript", $this->tailScript);
99
100
        return $this->smarty->fetch($template);
101
    }
102
}
103