MediaWiki master
SkinMustache.php
Go to the documentation of this file.
1<?php
7namespace MediaWiki\Skin;
8
15
24 private $templateParser = null;
25
33 protected function getTemplateParser() {
34 if ( $this->templateParser === null ) {
35 $this->templateParser = new TemplateParser( $this->options['templateDirectory'] );
36 // For table of contents rendering.
37 $this->templateParser->enableRecursivePartials( true );
38 }
39 return $this->templateParser;
40 }
41
48 private function createTempUserBannerHTML() {
49 $isSupportedSkin = $this->getOptions()['tempUserBanner'];
50 $isTempUser = $this->getUser()->isTemp();
51
52 if ( !$isSupportedSkin || !$isTempUser ) {
53 return '';
54 }
55
56 $returntoParam = SkinComponentUtils::getReturnToParam(
57 $this->getTitle(),
58 $this->getRequest(),
59 $this->getAuthority()
60 );
61
62 $tempUserBanner = new SkinComponentTempUserBanner(
63 $returntoParam,
64 $this->getContext(),
65 $this->getUser(),
66 );
67 return $tempUserBanner->getTemplateData()['html'];
68 }
69
76 public function generateHTML() {
77 $this->setupTemplateContext();
78 $out = $this->getOutput();
79 $tp = $this->getTemplateParser();
80 $template = $this->options['template'] ?? 'skin';
81 $data = $this->getTemplateData();
82 $html = $this->createTempUserBannerHTML();
83 $html .= $tp->processTemplate( $template, $data );
84 return $html;
85 }
86
90 protected function doEditSectionLinksHTML( array $links, Language $lang ) {
91 $template = $this->getOptions()['templateSectionLinks'] ?? null;
92 if ( !$template ) {
93 return parent::doEditSectionLinksHTML( $links, $lang );
94 }
95 return $this->getTemplateParser()->processTemplate( $template, [
96 'class' => 'mw-editsection',
97 'array-links' => $links
98 ] );
99 }
100
105 public function getTemplateData() {
106 $out = $this->getOutput();
107 $printSource = Html::rawElement(
108 'div',
109 [
110 'class' => 'printfooter',
111 'data-nosnippet' => ''
112 ] + $this->getUserLanguageAttributes(),
113 $this->printSource()
114 );
115 $bodyContent = $out->getHTML() . "\n" . $printSource;
116
117 $newTalksHtml = $this->getNewtalks() ?: null;
118
119 $data = parent::getTemplateData() + [
120 // Array objects
121 'array-indicators' => $this->getIndicatorsData( $out->getIndicators() ),
122 // HTML strings
123 'html-site-notice' => $this->getSiteNotice() ?: null,
124 'html-user-message' => $newTalksHtml ?
125 Html::rawElement( 'div', [ 'class' => 'usermessage' ], $newTalksHtml ) : null,
126 'html-subtitle' => $this->prepareSubtitle(),
127 'html-body-content' => $this->wrapHTML( $out->getTitle(), $bodyContent ),
128 'html-categories' => $this->getCategories(),
129 'html-after-content' => $this->afterContentHook(),
130 'html-undelete-link' => $this->prepareUndeleteLink(),
131 'html-user-language-attributes' => $this->prepareUserLanguageAttributes(),
132
133 // links
134 'link-mainpage' => Title::newMainPage()->getLocalURL(),
135 ];
136
137 foreach ( $this->options['messages'] ?? [] as $message ) {
138 $data["msg-{$message}"] = $this->msg( $message )->text();
139 }
140 return $data;
141 }
142}
143
145class_alias( SkinMustache::class, 'SkinMustache' );
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:43
Handles compiling Mustache templates into PHP rendering functions.
Base class for language-specific code.
Definition Language.php:69
Generic template for use with Mustache templates.
doEditSectionLinksHTML(array $links, Language $lang)
to override by skinsstring
generateHTML()
Subclasses not wishing to use the QuickTemplate render method can rewrite this method,...
getTemplateData()
to extend. Subclasses may extend this method to add additional template data. this method should neve...
getTemplateParser()
Get the template parser, it will be lazily created if not already set.
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.
prepareUndeleteLink()
Prepare undelete link for output in page.
Definition Skin.php:2420
afterContentHook()
This runs a hook to allow extensions placing their stuff after content and article metadata (e....
Definition Skin.php:856
prepareUserLanguageAttributes()
Prepare user language attribute links.
Definition Skin.php:2409
getOptions()
Get current skin's options.
Definition Skin.php:2452
wrapHTML( $title, $html)
Wrap the body text with language information and identifiable element.
Definition Skin.php:2433
getUserLanguageAttributes()
Get user language attribute links array.
Definition Skin.php:2387
printSource()
Text with the permalink to the source page, usually shown on the footer of a printed page.
Definition Skin.php:900
prepareSubtitle(bool $withContainer=true)
Prepare the subtitle of the page for output in the skin if one has been set.
Definition Skin.php:2359
getIndicatorsData(array $indicators)
Return an array of indicator data.
Definition Skin.php:2147
getNewtalks()
Gets new talk page messages for the current user and returns an appropriate alert message (or an empt...
Definition Skin.php:1797
Represents a title within MediaWiki.
Definition Title.php:69