enwikipedia-acc /
waca
| 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
Loading history...
|
|||
| 48 | $this->registerPlugin('modifier', 'implode', 'implode'); |
||
| 49 | |||
| 50 | $this->assign('currentUser', User::getCommunity()); |
||
| 51 | $this->assign('skin', 'auto'); |
||
| 52 | $this->assign('currentDomain', null); |
||
| 53 | $this->assign('loggedIn', false); |
||
| 54 | $this->assign('baseurl', $this->getSiteConfiguration()->getBaseUrl()); |
||
| 55 | $this->assign('resourceCacheEpoch', $this->getSiteConfiguration()->getResourceCacheEpoch()); |
||
| 56 | |||
| 57 | $this->assign('siteNoticeText', ''); |
||
| 58 | $this->assign('siteNoticeVersion', 0); |
||
| 59 | $this->assign('siteNoticeState', 'd-none'); |
||
| 60 | $this->assign('toolversion', Environment::getToolVersion()); |
||
| 61 | |||
| 62 | // default these |
||
| 63 | $this->assign('onlineusers', array()); |
||
| 64 | $this->assign('typeAheadBlock', ''); |
||
| 65 | $this->assign('extraJs', array()); |
||
| 66 | |||
| 67 | // nav menu access control |
||
| 68 | $this->assign('nav__canRequests', false); |
||
| 69 | $this->assign('nav__canLogs', false); |
||
| 70 | $this->assign('nav__canUsers', false); |
||
| 71 | $this->assign('nav__canSearch', false); |
||
| 72 | $this->assign('nav__canStats', false); |
||
| 73 | $this->assign('nav__canBan', false); |
||
| 74 | $this->assign('nav__canEmailMgmt', false); |
||
| 75 | $this->assign('nav__canWelcomeMgmt', false); |
||
| 76 | $this->assign('nav__canSiteNoticeMgmt', false); |
||
| 77 | $this->assign('nav__canUserMgmt', false); |
||
| 78 | $this->assign('nav__canViewRequest', false); |
||
| 79 | $this->assign('nav__canJobQueue', false); |
||
| 80 | $this->assign('nav__canFlaggedComments', false); |
||
| 81 | $this->assign('nav__canDomainMgmt', false); |
||
| 82 | $this->assign('nav__canQueueMgmt', false); |
||
| 83 | $this->assign('nav__canFormMgmt', false); |
||
| 84 | $this->assign('nav__canErrorLog', false); |
||
| 85 | |||
| 86 | // Navigation badges for concern areas. |
||
| 87 | $this->assign("nav__numAdmin", 0); |
||
| 88 | $this->assign("nav__numFlaggedComments", 0); |
||
| 89 | $this->assign("nav__numJobQueueFailed", 0); |
||
| 90 | |||
| 91 | // debug helpers |
||
| 92 | $this->assign('showDebugCssBreakpoints', $this->getSiteConfiguration()->getDebuggingCssBreakpointsEnabled()); |
||
| 93 | |||
| 94 | $this->assign('page', $this); |
||
| 95 | } |
||
| 96 | |||
| 97 | /** |
||
| 98 | * Fetches a rendered Smarty template |
||
| 99 | * |
||
| 100 | * @param $template string Template file path, relative to /templates/ |
||
| 101 | * |
||
| 102 | * @return string Templated HTML |
||
| 103 | */ |
||
| 104 | final protected function fetchTemplate($template) |
||
| 105 | { |
||
| 106 | return $this->smarty->fetch($template); |
||
| 107 | } |
||
| 108 | } |
||
| 109 |