MediaWiki master
SkinMustache.php
Go to the documentation of this file.
1<?php
27
36 private $templateParser = null;
37
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 );
50 }
51 return $this->templateParser;
52 }
53
60 private function createTempUserBannerHTML() {
61 $isSupportedSkin = $this->getOptions()['tempUserBanner'];
62 $isTempUser = $this->getUser()->isTemp();
63
64 if ( !$isSupportedSkin || !$isTempUser ) {
65 return '';
66 }
67
68 $returntoParam = SkinComponentUtils::getReturnToParam(
69 $this->getTitle(),
70 $this->getRequest(),
71 $this->getAuthority()
72 );
73
74 $tempUserBanner = new SkinComponentTempUserBanner(
75 $returntoParam,
76 $this->getContext(),
77 $this->getUser(),
78 );
79 return $tempUserBanner->getTemplateData()['html'];
80 }
81
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 );
96 return $html;
97 }
98
102 protected function doEditSectionLinksHTML( array $links, Language $lang ) {
103 $template = $this->getOptions()['templateSectionLinks'] ?? null;
104 if ( !$template ) {
105 return parent::doEditSectionLinksHTML( $links, $lang );
106 }
107 return $this->getTemplateParser()->processTemplate( $template, [
108 'class' => 'mw-editsection',
109 'array-links' => $links
110 ] );
111 }
112
117 public function getTemplateData() {
118 $out = $this->getOutput();
119 $printSource = Html::rawElement(
120 'div',
121 [
122 'class' => 'printfooter',
123 'data-nosnippet' => ''
124 ] + $this->getUserLanguageAttributes(),
125 $this->printSource()
126 );
127 $bodyContent = $out->getHTML() . "\n" . $printSource;
128
129 $newTalksHtml = $this->getNewtalks() ?: null;
130
131 $data = parent::getTemplateData() + [
132 // Array objects
133 'array-indicators' => $this->getIndicatorsData( $out->getIndicators() ),
134 // HTML strings
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(),
144
145 // links
146 'link-mainpage' => Title::newMainPage()->getLocalURL(),
147 ];
148
149 foreach ( $this->options['messages'] ?? [] as $message ) {
150 $data["msg-{$message}"] = $this->msg( $message )->text();
151 }
152 return $data;
153 }
154}
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
Base class for language-specific code.
Definition Language.php:80
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:874
prepareUndeleteLink()
Prepare undelete link for output in page.
Definition Skin.php:2405
getNewtalks()
Gets new talk page messages for the current user and returns an appropriate alert message (or an empt...
Definition Skin.php:1786
getUserLanguageAttributes()
Get user language attribute links array.
Definition Skin.php:2372
getSiteNotice()
Definition Skin.php:1948
getIndicatorsData( $indicators)
Return an array of indicator data.
Definition Skin.php:2135
getOptions()
Get current skin's options.
Definition Skin.php:2437
printSource()
Text with the permalink to the source page, usually shown on the footer of a printed page.
Definition Skin.php:918
prepareSubtitle(bool $withContainer=true)
Prepare the subtitle of the page for output in the skin if one has been set.
Definition Skin.php:2344
prepareUserLanguageAttributes()
Prepare user language attribute links.
Definition Skin.php:2394
wrapHTML( $title, $html)
Wrap the body text with language information and identifiable element.
Definition Skin.php:2418
getCategories()
Definition Skin.php:839