Passed
Push — u2f-deprecation ( 289827 )
by Simon
28:23 queued 18:22
created

TemplateOutput::setTailScript()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
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
21
    /**
22
     * @return SiteConfiguration
23
     */
24
    protected abstract function getSiteConfiguration();
25
26
    /**
27
     * Assigns a Smarty variable
28
     *
29
     * @param  array|string $name  the template variable name(s)
30
     * @param  mixed        $value the value to assign
31
     */
32
    final protected function assign($name, $value)
33
    {
34
        $this->smarty->assign($name, $value);
35
    }
36
37
    /**
38
     * Sets up the variables used by the main Smarty base template.
39
     *
40
     * This list is getting kinda long.
41
     */
42
    final protected function setUpSmarty()
43
    {
44
        $this->smarty = new Smarty();
45
        $this->smarty->addPluginsDir($this->getSiteConfiguration()->getFilePath() . '/smarty-plugins');
46
47
        $this->assign('currentUser', User::getCommunity());
48
        $this->assign('currentDomain', null);
49
        $this->assign('loggedIn', false);
50
        $this->assign('baseurl', $this->getSiteConfiguration()->getBaseUrl());
51
        $this->assign('resourceCacheEpoch', $this->getSiteConfiguration()->getResourceCacheEpoch());
52
53
        $this->assign('siteNoticeText', '');
54
        $this->assign('siteNoticeVersion', 0);
55
        $this->assign('siteNoticeState', 'd-none');
56
        $this->assign('toolversion', Environment::getToolVersion());
57
58
        // default these
59
        $this->assign('onlineusers', array());
60
        $this->assign('typeAheadBlock', '');
61
        $this->assign('extraJs', array());
62
63
        // nav menu access control
64
        $this->assign('nav__canRequests', false);
65
        $this->assign('nav__canLogs', false);
66
        $this->assign('nav__canUsers', false);
67
        $this->assign('nav__canSearch', false);
68
        $this->assign('nav__canStats', false);
69
        $this->assign('nav__canBan', false);
70
        $this->assign('nav__canEmailMgmt', false);
71
        $this->assign('nav__canWelcomeMgmt', false);
72
        $this->assign('nav__canSiteNoticeMgmt', false);
73
        $this->assign('nav__canUserMgmt', false);
74
        $this->assign('nav__canViewRequest', false);
75
        $this->assign('nav__canJobQueue', false);
76
        $this->assign('nav__canFlaggedComments', false);
77
        $this->assign('nav__canDomainMgmt', false);
78
        $this->assign('nav__canQueueMgmt', false);
79
        $this->assign('nav__canFormMgmt', false);
80
        $this->assign('nav__canErrorLog', false);
81
82
        // Navigation badges for concern areas.
83
        $this->assign("nav__numAdmin", 0);
84
        $this->assign("nav__numFlaggedComments", 0);
85
        $this->assign("nav__numJobQueueFailed", 0);
86
87
        // debug helpers
88
        $this->assign('showDebugCssBreakpoints', $this->getSiteConfiguration()->getDebuggingCssBreakpointsEnabled());
89
90
        $this->assign('page', $this);
91
    }
92
93
    /**
94
     * Fetches a rendered Smarty template
95
     *
96
     * @param $template string Template file path, relative to /templates/
97
     *
98
     * @return string Templated HTML
99
     */
100
    final protected function fetchTemplate($template)
101
    {
102
        return $this->smarty->fetch($template);
103
    }
104
}
105