MediaWiki  master
SkinMustache.php
Go to the documentation of this file.
1 <?php
25 class SkinMustache extends SkinTemplate {
29  private $templateParser = null;
30 
38  protected function getTemplateParser() {
39  if ( $this->templateParser === null ) {
40  $this->templateParser = new TemplateParser( $this->options['templateDirectory'] );
41  // For table of contents rendering.
42  $this->templateParser->enableRecursivePartials( true );
43  }
44  return $this->templateParser;
45  }
46 
53  public function generateHTML() {
54  $this->setupTemplateContext();
55  $out = $this->getOutput();
56  $tp = $this->getTemplateParser();
57  $template = $this->options['template'] ?? 'skin';
58  $data = $this->getTemplateData();
59 
60  // T259955: OutputPage::headElement must be called last (after getTemplateData)
61  // as it calls OutputPage::getRlClient, which freezes the ResourceLoader
62  // modules queue for the current page load.
63  $html = $out->headElement( $this );
64 
65  $html .= $tp->processTemplate( $template, $data );
66  $html .= $out->tailElement( $this );
67  return $html;
68  }
69 
74  public function getTemplateData() {
75  $out = $this->getOutput();
76  $printSource = Html::rawElement( 'div', [ 'class' => 'printfooter' ], $this->printSource() );
77  $bodyContent = $out->getHTML() . "\n" . $printSource;
78 
79  $newTalksHtml = $this->getNewtalks() ?: null;
80 
81  $data = parent::getTemplateData() + [
82  // Array objects
83  'array-indicators' => $this->getIndicatorsData( $out->getIndicators() ),
84  // HTML strings
85  'html-site-notice' => $this->getSiteNotice() ?: null,
86  'html-user-message' => $newTalksHtml ?
87  Html::rawElement( 'div', [ 'class' => 'usermessage' ], $newTalksHtml ) : null,
88  'html-subtitle' => $this->prepareSubtitle(),
89  'html-body-content' => $this->wrapHTML( $out->getTitle(), $bodyContent ),
90  'html-categories' => $this->getCategories(),
91  'html-after-content' => $this->afterContentHook(),
92  'html-undelete-link' => $this->prepareUndeleteLink(),
93  'html-user-language-attributes' => $this->prepareUserLanguageAttributes(),
94 
95  // links
96  'link-mainpage' => Title::newMainPage()->getLocalUrl(),
97  ];
98 
99  foreach ( $this->options['messages'] ?? [] as $message ) {
100  $data["msg-{$message}"] = $this->msg( $message )->text();
101  }
102  return $data;
103  }
104 }
msg( $key,... $params)
Get a Message object with context set Parameters are the same as wfMessage()
static rawElement( $element, $attribs=[], $contents='')
Returns an HTML element in a string.
Definition: Html.php:214
Generic template for use with Mustache templates.
getTemplateData()
@inheritDoc
TemplateParser null $templateParser
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 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:709
prepareUndeleteLink()
Prepare undelete link for output in page.
Definition: Skin.php:2518
getNewtalks()
Gets new talk page messages for the current user and returns an appropriate alert message (or an empt...
Definition: Skin.php:1689
getSiteNotice()
Definition: Skin.php:1844
getIndicatorsData( $indicators)
Return an array of indicator data.
Definition: Skin.php:2000
prepareSubtitle()
Prepare the subtitle of the page for output in the skin if one has been set.
Definition: Skin.php:2411
printSource()
Text with the permalink to the source page, usually shown on the footer of a printed page.
Definition: Skin.php:750
prepareUserLanguageAttributes()
Prepare user language attribute links.
Definition: Skin.php:2507
wrapHTML( $title, $html)
Wrap the body text with language information and identifiable element.
Definition: Skin.php:2540
getCategories()
Definition: Skin.php:674
static newMainPage(MessageLocalizer $localizer=null)
Create a new Title for the Main Page.
Definition: Title.php:700