3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
21 use MediaWiki\Html\Html
;
22 use MediaWiki\Html\TemplateParser
;
23 use MediaWiki\Language\Language
;
24 use MediaWiki\Skin\SkinComponentTempUserBanner
;
25 use MediaWiki\Skin\SkinComponentUtils
;
26 use MediaWiki\Title\Title
;
29 * Generic template for use with Mustache templates.
32 class SkinMustache
extends SkinTemplate
{
34 * @var TemplateParser|null
36 private $templateParser = null;
39 * Get the template parser, it will be lazily created if not already set.
40 * The template directory is defined in the skin options passed to
41 * the class constructor.
43 * @return TemplateParser
45 protected function getTemplateParser() {
46 if ( $this->templateParser
=== null ) {
47 $this->templateParser
= new TemplateParser( $this->options
['templateDirectory'] );
48 // For table of contents rendering.
49 $this->templateParser
->enableRecursivePartials( true );
51 return $this->templateParser
;
55 * Creates a banner notifying IP masked users (temporary accounts)
56 * That they are editing via a temporary account.
60 private function createTempUserBannerHTML() {
61 $isSupportedSkin = $this->getOptions()['tempUserBanner'];
62 $isTempUser = $this->getUser()->isTemp();
64 if ( !$isSupportedSkin ||
!$isTempUser ) {
68 $returntoParam = SkinComponentUtils
::getReturnToParam(
74 $tempUserBanner = new SkinComponentTempUserBanner(
79 return $tempUserBanner->getTemplateData()['html'];
84 * Render the associated template. The master template is assumed
85 * to be 'skin' unless `template` has been passed in the skin options
88 public function generateHTML() {
89 $this->setupTemplateContext();
90 $out = $this->getOutput();
91 $tp = $this->getTemplateParser();
92 $template = $this->options
['template'] ??
'skin';
93 $data = $this->getTemplateData();
94 $html = $this->createTempUserBannerHTML();
95 $html .= $tp->processTemplate( $template, $data );
102 protected function doEditSectionLinksHTML( array $links, Language
$lang ) {
103 $template = $this->getOptions()['templateSectionLinks'] ??
null;
105 return parent
::doEditSectionLinksHTML( $links, $lang );
107 return $this->getTemplateParser()->processTemplate( $template, [
108 'class' => 'mw-editsection',
109 'array-links' => $links
115 * @return array Data specific for a mustache template. See parent function for common data.
117 public function getTemplateData() {
118 $out = $this->getOutput();
119 $printSource = Html
::rawElement(
122 'class' => 'printfooter',
123 'data-nosnippet' => ''
124 ] +
$this->getUserLanguageAttributes(),
127 $bodyContent = $out->getHTML() . "\n" . $printSource;
129 $newTalksHtml = $this->getNewtalks() ?
: null;
131 $data = parent
::getTemplateData() +
[
133 'array-indicators' => $this->getIndicatorsData( $out->getIndicators() ),
135 'html-site-notice' => $this->getSiteNotice() ?
: null,
136 'html-user-message' => $newTalksHtml ?
137 Html
::rawElement( 'div', [ 'class' => 'usermessage' ], $newTalksHtml ) : null,
138 'html-subtitle' => $this->prepareSubtitle(),
139 'html-body-content' => $this->wrapHTML( $out->getTitle(), $bodyContent ),
140 'html-categories' => $this->getCategories(),
141 'html-after-content' => $this->afterContentHook(),
142 'html-undelete-link' => $this->prepareUndeleteLink(),
143 'html-user-language-attributes' => $this->prepareUserLanguageAttributes(),
146 'link-mainpage' => Title
::newMainPage()->getLocalURL(),
149 foreach ( $this->options
['messages'] ??
[] as $message ) {
150 $data["msg-{$message}"] = $this->msg( $message )->text();