Completed
Push — bootstrap4 ( dc7ca1...d74498 )
by Simon
06:19
created

TemplateOutput::setUpSmarty()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 34

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 34
rs 9.376
c 0
b 0
f 0
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('loggedIn', false);
49
        $this->assign('baseurl', $this->getSiteConfiguration()->getBaseUrl());
50
        $this->assign('mediawikiScriptPath', $this->getSiteConfiguration()->getMediawikiScriptPath());
51
52
        $this->assign('siteNoticeText', '');
53
        $this->assign('toolversion', Environment::getToolVersion());
54
55
        // default these
56
        $this->assign('onlineusers', array());
57
        $this->assign('typeAheadBlock', '');
58
        $this->assign('extraJs', array());
59
        $this->assign('extraCss', array());
60
61
        // nav menu access control
62
        $this->assign('nav__canRequests', false);
63
        $this->assign('nav__canLogs', false);
64
        $this->assign('nav__canUsers', false);
65
        $this->assign('nav__canSearch', false);
66
        $this->assign('nav__canStats', false);
67
        $this->assign('nav__canBan', false);
68
        $this->assign('nav__canEmailMgmt', false);
69
        $this->assign('nav__canWelcomeMgmt', false);
70
        $this->assign('nav__canSiteNoticeMgmt', false);
71
        $this->assign('nav__canUserMgmt', false);
72
        $this->assign('nav__canViewRequest', false);
73
74
        $this->assign('page', $this);
75
    }
76
77
    /**
78
     * Fetches a rendered Smarty template
79
     *
80
     * @param $template string Template file path, relative to /templates/
81
     *
82
     * @return string Templated HTML
83
     */
84
    final protected function fetchTemplate($template)
85
    {
86
        return $this->smarty->fetch($template);
87
    }
88
}
89