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  }
42  return $this->templateParser;
43  }
44 
51  public function generateHTML() {
52  $this->setupTemplateContext();
53  $out = $this->getOutput();
54  $tp = $this->getTemplateParser();
55  $template = $this->options['template'] ?? 'skin';
56  $data = $this->getTemplateData();
57 
58  // T259955: OutputPage::headElement must be called last (after getTemplateData)
59  // as it calls OutputPage::getRlClient, which freezes the ResourceLoader
60  // modules queue for the current page load.
61  $html = $out->headElement( $this );
62 
63  $html .= $tp->processTemplate( $template, $data );
64  $html .= $out->tailElement( $this );
65  return $html;
66  }
67 
72  public function getTemplateData() {
73  $out = $this->getOutput();
74  $printSource = Html::rawElement( 'div', [ 'class' => 'printfooter' ], $this->printSource() );
75  $bodyContent = $out->getHTML() . "\n" . $printSource;
76 
77  $newTalksHtml = $this->getNewtalks() ?: null;
78 
79  $data = parent::getTemplateData() + [
80  // Array objects
81  'array-indicators' => $this->getIndicatorsData( $out->getIndicators() ),
82  // HTML strings
83  'html-site-notice' => $this->getSiteNotice() ?: null,
84  'html-user-message' => $newTalksHtml ?
85  Html::rawElement( 'div', [ 'class' => 'usermessage' ], $newTalksHtml ) : null,
86  'html-subtitle' => $this->prepareSubtitle(),
87  'html-body-content' => $this->wrapHTML( $out->getTitle(), $bodyContent ),
88  'html-categories' => $this->getCategories(),
89  'html-after-content' => $this->afterContentHook(),
90  'html-undelete-link' => $this->prepareUndeleteLink(),
91  'html-user-language-attributes' => $this->prepareUserLanguageAttributes(),
92 
93  // links
94  'link-mainpage' => Title::newMainPage()->getLocalUrl(),
95  ];
96 
97  foreach ( $this->options['messages'] ?? [] as $message ) {
98  $data["msg-{$message}"] = $this->msg( $message )->text();
99  }
100  return $data;
101  }
102 }
Skin\prepareSubtitle
prepareSubtitle()
Prepare the subtitle of the page for output in the skin if one has been set.
Definition: Skin.php:2461
Skin\getSiteNotice
getSiteNotice()
Definition: Skin.php:1898
SkinMustache\generateHTML
generateHTML()
Subclasses not wishing to use the QuickTemplate render method can rewrite this method,...
Definition: SkinMustache.php:51
Skin\wrapHTML
wrapHTML( $title, $html)
Wrap the body text with language information and identifiable element.
Definition: Skin.php:2595
Title\newMainPage
static newMainPage(MessageLocalizer $localizer=null)
Create a new Title for the Main Page.
Definition: Title.php:710
Skin\afterContentHook
afterContentHook()
This runs a hook to allow extensions placing their stuff after content and article metadata (e....
Definition: Skin.php:708
Skin\prepareUndeleteLink
prepareUndeleteLink()
Prepare undelete link for output in page.
Definition: Skin.php:2568
Skin\getIndicatorsData
getIndicatorsData( $indicators)
Return an array of indicator data.
Definition: Skin.php:2046
Skin\prepareUserLanguageAttributes
prepareUserLanguageAttributes()
Prepare user language attribute links.
Definition: Skin.php:2557
Skin\getCategories
getCategories()
Definition: Skin.php:673
ContextSource\getOutput
getOutput()
Definition: ContextSource.php:126
ContextSource\msg
msg( $key,... $params)
Get a Message object with context set Parameters are the same as wfMessage()
Definition: ContextSource.php:197
SkinTemplate\setupTemplateContext
setupTemplateContext()
Setup class properties that are necessary prior to calling setupTemplateForOutput.
Definition: SkinTemplate.php:87
SkinMustache\$templateParser
TemplateParser null $templateParser
Definition: SkinMustache.php:29
SkinTemplate\$template
string $template
For QuickTemplate, the name of the subclass which will actually fill the template.
Definition: SkinTemplate.php:39
Skin\printSource
printSource()
Text with the permalink to the source page, usually shown on the footer of a printed page.
Definition: Skin.php:757
Skin\getNewtalks
getNewtalks()
Gets new talk page messages for the current user and returns an appropriate alert message (or an empt...
Definition: Skin.php:1744
Html\rawElement
static rawElement( $element, $attribs=[], $contents='')
Returns an HTML element in a string.
Definition: Html.php:213
SkinMustache
Generic template for use with Mustache templates.
Definition: SkinMustache.php:25
SkinMustache\getTemplateData
getTemplateData()
@inheritDoc
Definition: SkinMustache.php:72
TemplateParser
Definition: TemplateParser.php:27
SkinTemplate
Base class for QuickTemplate-based skins.
Definition: SkinTemplate.php:34
SkinMustache\getTemplateParser
getTemplateParser()
Get the template parser, it will be lazily created if not already set.
Definition: SkinMustache.php:38