MediaWiki master
SkinMustache.php
Go to the documentation of this file.
1<?php
26
35 private $templateParser = null;
36
44 protected function getTemplateParser() {
45 if ( $this->templateParser === null ) {
46 $this->templateParser = new TemplateParser( $this->options['templateDirectory'] );
47 // For table of contents rendering.
48 $this->templateParser->enableRecursivePartials( true );
49 }
50 return $this->templateParser;
51 }
52
59 private function createTempUserBannerHTML() {
60 $isSupportedSkin = $this->getOptions()['tempUserBanner'];
61 $isTempUser = $this->getUser()->isTemp();
62
63 if ( !$isSupportedSkin || !$isTempUser ) {
64 return '';
65 }
66
67 $returntoParam = SkinComponentUtils::getReturnToParam(
68 $this->getTitle(),
69 $this->getRequest(),
70 $this->getAuthority()
71 );
72
73 $tempUserBanner = new SkinComponentTempUserBanner(
74 $returntoParam,
75 $this->getContext(),
76 $this->getUser(),
77 );
78 return $tempUserBanner->getTemplateData()['html'];
79 }
80
87 public function generateHTML() {
88 $this->setupTemplateContext();
89 $out = $this->getOutput();
90 $tp = $this->getTemplateParser();
91 $template = $this->options['template'] ?? 'skin';
92 $data = $this->getTemplateData();
93 $tempUserBannerHTML = $this->createTempUserBannerHTML();
94
95 // T259955: OutputPage::headElement must be called last (after getTemplateData)
96 // as it calls OutputPage::getRlClient, which freezes the ResourceLoader
97 // modules queue for the current page load.
98 $html = $out->headElement( $this );
99
100 $html .= $tempUserBannerHTML;
101
102 $html .= $tp->processTemplate( $template, $data );
103 $html .= $out->tailElement( $this );
104 return $html;
105 }
106
110 protected function doEditSectionLinksHTML( array $links, Language $lang ) {
111 $template = $this->getOptions()['templateSectionLinks'] ?? null;
112 if ( !$template ) {
113 return parent::doEditSectionLinksHTML( $links, $lang );
114 }
115 return $this->getTemplateParser()->processTemplate( $template, [
116 'class' => 'mw-editsection',
117 'array-links' => $links
118 ] );
119 }
120
125 public function getTemplateData() {
126 $out = $this->getOutput();
127 $printSource = Html::rawElement(
128 'div',
129 [
130 'class' => 'printfooter',
131 'data-nosnippet' => ''
132 ] + $this->getUserLanguageAttributes(),
133 $this->printSource()
134 );
135 $bodyContent = $out->getHTML() . "\n" . $printSource;
136
137 $newTalksHtml = $this->getNewtalks() ?: null;
138
139 $data = parent::getTemplateData() + [
140 // Array objects
141 'array-indicators' => $this->getIndicatorsData( $out->getIndicators() ),
142 // HTML strings
143 'html-site-notice' => $this->getSiteNotice() ?: null,
144 'html-user-message' => $newTalksHtml ?
145 Html::rawElement( 'div', [ 'class' => 'usermessage' ], $newTalksHtml ) : null,
146 'html-subtitle' => $this->prepareSubtitle(),
147 'html-body-content' => $this->wrapHTML( $out->getTitle(), $bodyContent ),
148 'html-categories' => $this->getCategories(),
149 'html-after-content' => $this->afterContentHook(),
150 'html-undelete-link' => $this->prepareUndeleteLink(),
151 'html-user-language-attributes' => $this->prepareUserLanguageAttributes(),
152
153 // links
154 'link-mainpage' => Title::newMainPage()->getLocalURL(),
155 ];
156
157 foreach ( $this->options['messages'] ?? [] as $message ) {
158 $data["msg-{$message}"] = $this->msg( $message )->text();
159 }
160 return $data;
161 }
162}
Base class for language-specific code.
Definition Language.php:63
msg( $key,... $params)
Get a Message object with context set Parameters are the same as wfMessage()
getContext()
Get the base IContextSource object.
This class is a collection of static functions that serve two purposes:
Definition Html.php:56
Represents a title within MediaWiki.
Definition Title.php:78
Generic template for use with Mustache templates.
getTemplateData()
to extend. Subclasses may extend this method to add additional template data. this method should neve...
generateHTML()
Subclasses not wishing to use the QuickTemplate render method can rewrite this method,...
getTemplateParser()
Get the template parser, it will be lazily created if not already set.
doEditSectionLinksHTML(array $links, Language $lang)
to override by skinsstring
Base class for QuickTemplate-based skins.
string $template
For QuickTemplate, the name of the subclass which will actually fill the template.
setupTemplateContext()
Setup class properties that are necessary prior to calling setupTemplateForOutput.
afterContentHook()
This runs a hook to allow extensions placing their stuff after content and article metadata (e....
Definition Skin.php:797
prepareUndeleteLink()
Prepare undelete link for output in page.
Definition Skin.php:2391
getNewtalks()
Gets new talk page messages for the current user and returns an appropriate alert message (or an empt...
Definition Skin.php:1729
getUserLanguageAttributes()
Get user language attribute links array.
Definition Skin.php:2358
getSiteNotice()
Definition Skin.php:1891
getIndicatorsData( $indicators)
Return an array of indicator data.
Definition Skin.php:2075
getOptions()
Get current skin's options.
Definition Skin.php:2432
printSource()
Text with the permalink to the source page, usually shown on the footer of a printed page.
Definition Skin.php:841
prepareSubtitle(bool $withContainer=true)
Prepare the subtitle of the page for output in the skin if one has been set.
Definition Skin.php:2330
prepareUserLanguageAttributes()
Prepare user language attribute links.
Definition Skin.php:2380
wrapHTML( $title, $html)
Wrap the body text with language information and identifiable element.
Definition Skin.php:2413
getCategories()
Definition Skin.php:762