MediaWiki REL1_35
SkinMustache.php
Go to the documentation of this file.
1<?php
20use Wikimedia\WrappedStringList;
21
30 private $templateParser = null;
31
39 protected function getTemplateParser() {
40 if ( $this->templateParser === null ) {
41 $this->templateParser = new TemplateParser( $this->options['templateDirectory'] );
42 }
44 }
45
52 public function generateHTML() {
53 $this->setupTemplateContext();
54 $out = $this->getOutput();
55 $tp = $this->getTemplateParser();
56 $template = $this->options['template'] ?? 'skin';
57 $data = $this->getTemplateData();
58
59 // T259955: OutputPage::headElement must be called last (after getTemplateData)
60 // as it calls OutputPage::getRlClient, which freezes the ResourceLoader
61 // modules queue for the current page load.
62 $html = $out->headElement( $this );
63
64 $html .= $tp->processTemplate( $template, $data );
65 $html .= $this->tailElement( $out );
66 return $html;
67 }
68
84 public function getTemplateData() {
85 $out = $this->getOutput();
86 $printSource = Html::rawElement( 'div', [ 'class' => 'printfooter' ], $this->printSource() );
87 $bodyContent = $out->getHTML() . "\n" . $printSource;
88
89 $data = [
90 // Array objects
91 'array-indicators' => $this->getIndicatorsData( $out->getIndicators() ),
92 // Data objects
93 'data-search-box' => $this->buildSearchProps(),
94 // HTML strings
95 'html-site-notice' => $this->getSiteNotice(),
96 'html-title' => $out->getPageTitle(),
97 'html-subtitle' => $this->prepareSubtitle(),
98 'html-body-content' => $this->wrapHTML( $out->getTitle(), $bodyContent ),
99 'html-categories' => $this->getCategories(),
100 'html-after-content' => $this->afterContentHook(),
101 'html-undelete-link' => $this->prepareUndeleteLink(),
102 'html-user-language-attributes' => $this->prepareUserLanguageAttributes(),
103 ];
104
105 return $data;
106 }
107
111 private function buildSearchProps() : array {
112 $config = $this->getConfig();
113
114 $props = [
115 'form-action' => $config->get( 'Script' ),
116 'html-button-search-fallback' => $this->makeSearchButton(
117 'fulltext',
118 [ 'id' => 'mw-searchButton', 'class' => 'searchButton mw-fallbackSearchButton' ]
119 ),
120 'html-button-search' => $this->makeSearchButton(
121 'go',
122 [ 'id' => 'searchButton', 'class' => 'searchButton' ]
123 ),
124 'html-input' => $this->makeSearchInput( [ 'id' => 'searchInput' ] ),
125 'msg-search' => $this->msg( 'search' )->text(),
126 'page-title' => SpecialPage::getTitleFor( 'Search' )->getPrefixedDBkey(),
127 ];
128
129 return $props;
130 }
131
139 private function tailElement( $out ) {
140 $tail = [
141 MWDebug::getDebugHTML( $this ),
142 $this->bottomScripts(),
143 wfReportTime( $out->getCSP()->getNonce() ),
144 Html::rawElement(
145 'div',
146 [ 'id' => 'mw-html-debug-log' ],
147 MWDebug::getHTMLDebugLog()
148 )
149 . Html::closeElement( 'body' )
150 . Html::closeElement( 'html' )
151 ];
152
153 return WrappedStringList::join( "\n", $tail );
154 }
155}
wfReportTime( $nonce=null)
Returns a script tag that stores the amount of time it took MediaWiki to handle the request in millis...
msg( $key,... $params)
Get a Message object with context set Parameters are the same as wfMessage()
Generic template for use with Mustache templates.
getTemplateData()
Subclasses may extend this method to add additional template data.
TemplateParser null $templateParser
tailElement( $out)
The final bits that go to the bottom of a page HTML document including the closing tags.
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.
Base class for template-based skins.
string $template
For QuickTemplate, the name of the subclass which will actually fill the template.
prepareUserLanguageAttributes()
Prepare user language attribute links.
wrapHTML( $title, $html)
Wrap the body text with language information and identifiable element.
setupTemplateContext()
Setup class properties that are necessary prior to calling setupTemplateForOutput.
prepareSubtitle()
Prepare the subtitle of the page for output in the skin if one has been set.
prepareUndeleteLink()
Prepare undelete link for output in page.
afterContentHook()
This runs a hook to allow extensions placing their stuff after content and article metadata (e....
Definition Skin.php:639
getSiteNotice()
Get the site notice.
Definition Skin.php:1953
getIndicatorsData( $indicators)
Return an array of indicator data.
Definition Skin.php:2130
printSource()
Text with the permalink to the source page, usually shown on the footer of a printed page.
Definition Skin.php:700
makeSearchInput( $attrs=[])
Definition Skin.php:2406
makeSearchButton( $mode, $attrs=[])
Definition Skin.php:2423
getCategories()
Definition Skin.php:606
static getTitleFor( $name, $subpage=false, $fragment='')
Get a localised Title object for a specified special page name If you don't need a full Title object,...