MediaWiki master
SkinMustache.php
Go to the documentation of this file.
1<?php
7namespace MediaWiki\Skin;
8
13
22 private $templateParser = null;
23
31 protected function getTemplateParser() {
32 if ( $this->templateParser === null ) {
33 $this->templateParser = new TemplateParser( $this->options['templateDirectory'] );
34 // For table of contents rendering.
35 $this->templateParser->enableRecursivePartials( true );
36 }
37 return $this->templateParser;
38 }
39
46 public function generateHTML() {
47 $this->setupTemplateContext();
48 $out = $this->getOutput();
49 $tp = $this->getTemplateParser();
50 $template = $this->options['template'] ?? 'skin';
51 $data = $this->getTemplateData();
52 return $tp->processTemplate( $template, $data );
53 }
54
58 protected function doEditSectionLinksHTML( array $links, Language $lang ) {
59 $template = $this->getOptions()['templateSectionLinks'] ?? null;
60 if ( !$template ) {
61 return parent::doEditSectionLinksHTML( $links, $lang );
62 }
63 return $this->getTemplateParser()->processTemplate( $template, [
64 'class' => 'mw-editsection',
65 'array-links' => $links
66 ] );
67 }
68
73 public function getTemplateData() {
74 $out = $this->getOutput();
75 $printSource = Html::rawElement(
76 'div',
77 [
78 'class' => 'printfooter',
79 'data-nosnippet' => ''
80 ] + $this->getUserLanguageAttributes(),
81 $this->printSource()
82 );
83 $bodyContent = $out->getHTML() . "\n" . $printSource;
84
85 $newTalksHtml = $this->getNewtalks() ?: null;
86
87 $data = parent::getTemplateData() + [
88 // Array objects
89 'array-indicators' => $this->getIndicatorsData( $out->getIndicators() ),
90 // HTML strings
91 'html-site-notice' => $this->getSiteNotice() ?: null,
92 'html-user-message' => $newTalksHtml ?
93 Html::rawElement( 'div', [ 'class' => 'usermessage' ], $newTalksHtml ) : null,
94 'html-subtitle' => $this->prepareSubtitle(),
95 'html-body-content' => $this->wrapHTML( $out->getTitle(), $bodyContent ),
96 'html-categories' => $this->getCategories(),
97 'html-after-content' => $this->afterContentHook(),
98 'html-undelete-link' => $this->prepareUndeleteLink(),
99 'html-user-language-attributes' => $this->prepareUserLanguageAttributes(),
100
101 // links
102 'link-mainpage' => Title::newMainPage()->getLocalURL(),
103 ];
104
105 foreach ( $this->options['messages'] ?? [] as $message ) {
106 $data["msg-{$message}"] = $this->msg( $message )->text();
107 }
108 return $data;
109 }
110}
111
113class_alias( SkinMustache::class, 'SkinMustache' );
msg( $key,... $params)
Get a Message object with context set Parameters are the same as wfMessage()
This class is a collection of static functions that serve two purposes:
Definition Html.php:44
Handles compiling Mustache templates into PHP rendering functions.
Base class for language-specific code.
Definition Language.php:65
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:2447
afterContentHook()
This runs a hook to allow extensions placing their stuff after content and article metadata (e....
Definition Skin.php:852
prepareUserLanguageAttributes()
Prepare user language attribute links.
Definition Skin.php:2436
getOptions()
Get current skin's options.
Definition Skin.php:2479
wrapHTML( $title, $html)
Wrap the body text with language information and identifiable element.
Definition Skin.php:2460
getUserLanguageAttributes()
Get user language attribute links array.
Definition Skin.php:2414
printSource()
Text with the permalink to the source page, usually shown on the footer of a printed page.
Definition Skin.php:896
prepareSubtitle(bool $withContainer=true)
Prepare the subtitle of the page for output in the skin if one has been set.
Definition Skin.php:2386
getIndicatorsData(array $indicators)
Return an array of indicator data.
Definition Skin.php:2160
getNewtalks()
Gets new talk page messages for the current user and returns an appropriate alert message (or an empt...
Definition Skin.php:1795
Represents a title within MediaWiki.
Definition Title.php:69