MediaWiki  master
SkinMustache.php
Go to the documentation of this file.
1 <?php
20 use Wikimedia\WrappedStringList;
21 
26 class SkinMustache extends SkinTemplate {
30  private $templateParser = null;
31 
39  protected function getTemplateParser() {
40  if ( $this->templateParser === null ) {
41  $this->templateParser = new TemplateParser( $this->options['templateDirectory'] );
42  }
43  return $this->templateParser;
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 
87  public function getTemplateData() {
88  $out = $this->getOutput();
89  $printSource = Html::rawElement( 'div', [ 'class' => 'printfooter' ], $this->printSource() );
90  $bodyContent = $out->getHTML() . "\n" . $printSource;
91 
92  $data = [
93  // Array objects
94  'array-indicators' => $this->getIndicatorsData( $out->getIndicators() ),
95  // Data objects
96  'data-search-box' => $this->buildSearchProps(),
97  // HTML strings
98  'html-site-notice' => $this->getSiteNotice(),
99  'html-title' => $out->getPageTitle(),
100  'html-subtitle' => $this->prepareSubtitle(),
101  'html-body-content' => $this->wrapHTML( $out->getTitle(), $bodyContent ),
102  'html-categories' => $this->getCategories(),
103  'html-after-content' => $this->afterContentHook(),
104  'html-undelete-link' => $this->prepareUndeleteLink(),
105  'html-user-language-attributes' => $this->prepareUserLanguageAttributes(),
106  ];
107 
108  foreach ( $this->options['messages'] ?? [] as $message ) {
109  $data["msg-{$message}"] = $this->msg( $message )->text();
110  }
111 
112  return $data;
113  }
114 
118  private function buildSearchProps() : array {
119  $config = $this->getConfig();
120 
121  $props = [
122  'form-action' => $config->get( 'Script' ),
123  'html-button-search-fallback' => $this->makeSearchButton(
124  'fulltext',
125  [ 'id' => 'mw-searchButton', 'class' => 'searchButton mw-fallbackSearchButton' ]
126  ),
127  'html-button-search' => $this->makeSearchButton(
128  'go',
129  [ 'id' => 'searchButton', 'class' => 'searchButton' ]
130  ),
131  'html-input' => $this->makeSearchInput( [ 'id' => 'searchInput' ] ),
132  'msg-search' => $this->msg( 'search' )->text(),
133  'page-title' => SpecialPage::getTitleFor( 'Search' )->getPrefixedDBkey(),
134  ];
135 
136  return $props;
137  }
138 
146  private function tailElement( $out ) {
147  $tail = [
148  MWDebug::getDebugHTML( $this ),
149  $this->bottomScripts(),
150  wfReportTime( $out->getCSP()->getNonce() ),
152  . Html::closeElement( 'body' )
153  . Html::closeElement( 'html' )
154  ];
155 
156  return WrappedStringList::join( "\n", $tail );
157  }
158 }
SkinMustache\buildSearchProps
buildSearchProps()
Definition: SkinMustache.php:118
ContextSource\getConfig
getConfig()
Definition: ContextSource.php:67
Skin\getSiteNotice
getSiteNotice()
Get the site notice.
Definition: Skin.php:1945
MWDebug\getDebugHTML
static getDebugHTML(IContextSource $context)
Returns the HTML to add to the page for the toolbar.
Definition: MWDebug.php:563
SkinMustache\generateHTML
generateHTML()
Subclasses not wishing to use the QuickTemplate render method can rewrite this method,...
Definition: SkinMustache.php:52
MWDebug\getHTMLDebugLog
static getHTMLDebugLog()
Generate debug log in HTML for displaying at the bottom of the main content area.
Definition: MWDebug.php:597
SpecialPage\getTitleFor
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,...
Definition: SpecialPage.php:92
SkinTemplate\wrapHTML
wrapHTML( $title, $html)
Wrap the body text with language information and identifiable element.
Definition: SkinTemplate.php:165
Skin\bottomScripts
bottomScripts()
This gets called shortly before the "</body>" tag.
Definition: Skin.php:690
Skin\afterContentHook
afterContentHook()
This runs a hook to allow extensions placing their stuff after content and article metadata (e....
Definition: Skin.php:652
Html\closeElement
static closeElement( $element)
Returns "</$element>".
Definition: Html.php:315
wfReportTime
wfReportTime( $nonce=null)
Returns a script tag that stores the amount of time it took MediaWiki to handle the request in millis...
Definition: GlobalFunctions.php:1302
SkinMustache\tailElement
tailElement( $out)
The final bits that go to the bottom of a page HTML document including the closing tags.
Definition: SkinMustache.php:146
Skin\getIndicatorsData
getIndicatorsData( $indicators)
Return an array of indicator data.
Definition: Skin.php:2125
Skin\getCategories
getCategories()
Definition: Skin.php:619
ContextSource\getOutput
getOutput()
Definition: ContextSource.php:121
ContextSource\msg
msg( $key,... $params)
Get a Message object with context set Parameters are the same as wfMessage()
Definition: ContextSource.php:184
SkinTemplate\setupTemplateContext
setupTemplateContext()
Setup class properties that are necessary prior to calling setupTemplateForOutput.
Definition: SkinTemplate.php:90
Skin\makeSearchInput
makeSearchInput( $attrs=[])
Definition: Skin.php:2400
SkinMustache\$templateParser
TemplateParser null $templateParser
Definition: SkinMustache.php:30
SkinTemplate\$template
string $template
For QuickTemplate, the name of the subclass which will actually fill the template.
Definition: SkinTemplate.php:50
Skin\printSource
printSource()
Text with the permalink to the source page, usually shown on the footer of a printed page.
Definition: Skin.php:713
SkinTemplate\prepareUserLanguageAttributes
prepareUserLanguageAttributes()
Prepare user language attribute links.
Definition: SkinTemplate.php:204
Html\rawElement
static rawElement( $element, $attribs=[], $contents='')
Returns an HTML element in a string.
Definition: Html.php:209
SkinTemplate\prepareUndeleteLink
prepareUndeleteLink()
Prepare undelete link for output in page.
Definition: SkinTemplate.php:306
SkinMustache
Generic template for use with Mustache templates.
Definition: SkinMustache.php:26
SkinMustache\getTemplateData
getTemplateData()
Subclasses may extend this method to add additional template data.
Definition: SkinMustache.php:87
Skin\makeSearchButton
makeSearchButton( $mode, $attrs=[])
Definition: Skin.php:2417
TemplateParser
Definition: TemplateParser.php:27
SkinTemplate\prepareSubtitle
prepareSubtitle()
Prepare the subtitle of the page for output in the skin if one has been set.
Definition: SkinTemplate.php:190
SkinTemplate
Base class for template-based skins.
Definition: SkinTemplate.php:39
SkinMustache\getTemplateParser
getTemplateParser()
Get the template parser, it will be lazily created if not already set.
Definition: SkinMustache.php:39