1 | <?php |
||
2 | /****************************************************************************** |
||
3 | * Wikipedia Account Creation Assistance tool * |
||
4 | * ACC Development Team. Please see team.json for a list of contributors. * |
||
5 | * * |
||
6 | * This is free and unencumbered software released into the public domain. * |
||
7 | * Please see LICENSE.md for the full licencing statement. * |
||
8 | ******************************************************************************/ |
||
9 | |||
10 | namespace Waca\Fragments; |
||
11 | |||
12 | use Smarty; |
||
13 | use Waca\DataObjects\User; |
||
14 | use Waca\Environment; |
||
15 | use Waca\SiteConfiguration; |
||
16 | |||
17 | trait TemplateOutput |
||
18 | { |
||
19 | /** @var Smarty */ |
||
20 | private $smarty; |
||
21 | |||
22 | /** |
||
23 | * @return SiteConfiguration |
||
24 | */ |
||
25 | protected abstract function getSiteConfiguration(); |
||
26 | |||
27 | /** |
||
28 | * Assigns a Smarty variable |
||
29 | * |
||
30 | * @param array|string $name the template variable name(s) |
||
31 | * @param mixed $value the value to assign |
||
32 | */ |
||
33 | final protected function assign($name, $value) |
||
34 | { |
||
35 | $this->smarty->assign($name, $value); |
||
36 | } |
||
37 | |||
38 | /** |
||
39 | * Sets up the variables used by the main Smarty base template. |
||
40 | * |
||
41 | * This list is getting kinda long. |
||
42 | */ |
||
43 | final protected function setUpSmarty() |
||
44 | { |
||
45 | $this->smarty = new Smarty(); |
||
46 | $this->smarty->addPluginsDir($this->getSiteConfiguration()->getFilePath() . '/smarty-plugins'); |
||
47 | $this->registerPlugin('modifier', 'count', 'count'); |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
48 | |||
49 | $this->assign('currentUser', User::getCommunity()); |
||
50 | $this->assign('skin', 'auto'); |
||
51 | $this->assign('currentDomain', null); |
||
52 | $this->assign('loggedIn', false); |
||
53 | $this->assign('baseurl', $this->getSiteConfiguration()->getBaseUrl()); |
||
54 | $this->assign('resourceCacheEpoch', $this->getSiteConfiguration()->getResourceCacheEpoch()); |
||
55 | |||
56 | $this->assign('siteNoticeText', ''); |
||
57 | $this->assign('siteNoticeVersion', 0); |
||
58 | $this->assign('siteNoticeState', 'd-none'); |
||
59 | $this->assign('toolversion', Environment::getToolVersion()); |
||
60 | |||
61 | // default these |
||
62 | $this->assign('onlineusers', array()); |
||
63 | $this->assign('typeAheadBlock', ''); |
||
64 | $this->assign('extraJs', array()); |
||
65 | |||
66 | // nav menu access control |
||
67 | $this->assign('nav__canRequests', false); |
||
68 | $this->assign('nav__canLogs', false); |
||
69 | $this->assign('nav__canUsers', false); |
||
70 | $this->assign('nav__canSearch', false); |
||
71 | $this->assign('nav__canStats', false); |
||
72 | $this->assign('nav__canBan', false); |
||
73 | $this->assign('nav__canEmailMgmt', false); |
||
74 | $this->assign('nav__canWelcomeMgmt', false); |
||
75 | $this->assign('nav__canSiteNoticeMgmt', false); |
||
76 | $this->assign('nav__canUserMgmt', false); |
||
77 | $this->assign('nav__canViewRequest', false); |
||
78 | $this->assign('nav__canJobQueue', false); |
||
79 | $this->assign('nav__canFlaggedComments', false); |
||
80 | $this->assign('nav__canDomainMgmt', false); |
||
81 | $this->assign('nav__canQueueMgmt', false); |
||
82 | $this->assign('nav__canFormMgmt', false); |
||
83 | $this->assign('nav__canErrorLog', false); |
||
84 | |||
85 | // Navigation badges for concern areas. |
||
86 | $this->assign("nav__numAdmin", 0); |
||
87 | $this->assign("nav__numFlaggedComments", 0); |
||
88 | $this->assign("nav__numJobQueueFailed", 0); |
||
89 | |||
90 | // debug helpers |
||
91 | $this->assign('showDebugCssBreakpoints', $this->getSiteConfiguration()->getDebuggingCssBreakpointsEnabled()); |
||
92 | |||
93 | $this->assign('page', $this); |
||
94 | } |
||
95 | |||
96 | /** |
||
97 | * Fetches a rendered Smarty template |
||
98 | * |
||
99 | * @param $template string Template file path, relative to /templates/ |
||
100 | * |
||
101 | * @return string Templated HTML |
||
102 | */ |
||
103 | final protected function fetchTemplate($template) |
||
104 | { |
||
105 | return $this->smarty->fetch($template); |
||
106 | } |
||
107 | } |
||
108 |