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-title' => $out->getPageTitle(),
87  'html-subtitle' => $this->prepareSubtitle(),
88  'html-body-content' => $this->wrapHTML( $out->getTitle(), $bodyContent ),
89  'html-categories' => $this->getCategories(),
90  'html-after-content' => $this->afterContentHook(),
91  'html-undelete-link' => $this->prepareUndeleteLink(),
92  'html-user-language-attributes' => $this->prepareUserLanguageAttributes(),
93 
94  // links
95  'link-mainpage' => Title::newMainPage()->getLocalUrl(),
96  ];
97 
98  foreach ( $this->options['messages'] ?? [] as $message ) {
99  $data["msg-{$message}"] = $this->msg( $message )->text();
100  }
101  return $data;
102  }
103 }
Skin\prepareSubtitle
prepareSubtitle()
Prepare the subtitle of the page for output in the skin if one has been set.
Definition: Skin.php:2381
Skin\getSiteNotice
getSiteNotice()
Definition: Skin.php:1818
SkinMustache\generateHTML
generateHTML()
Subclasses not wishing to use the QuickTemplate render method can rewrite this method,...
Definition: SkinMustache.php:51
Title\newMainPage
static newMainPage(MessageLocalizer $localizer=null)
Create a new Title for the Main Page.
Definition: Title.php:712
SkinTemplate\wrapHTML
wrapHTML( $title, $html)
Wrap the body text with language information and identifiable element.
Definition: SkinTemplate.php:165
Skin\afterContentHook
afterContentHook()
This runs a hook to allow extensions placing their stuff after content and article metadata (e....
Definition: Skin.php:636
Skin\getIndicatorsData
getIndicatorsData( $indicators)
Return an array of indicator data.
Definition: Skin.php:1966
Skin\getCategories
getCategories()
Definition: Skin.php:601
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:88
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:685
Skin\getNewtalks
getNewtalks()
Gets new talk page messages for the current user and returns an appropriate alert message (or an empt...
Definition: Skin.php:1664
SkinTemplate\prepareUserLanguageAttributes
prepareUserLanguageAttributes()
Prepare user language attribute links.
Definition: SkinTemplate.php:195
Html\rawElement
static rawElement( $element, $attribs=[], $contents='')
Returns an HTML element in a string.
Definition: Html.php:210
SkinTemplate\prepareUndeleteLink
prepareUndeleteLink()
Prepare undelete link for output in page.
Definition: SkinTemplate.php:260
SkinMustache
Generic template for use with Mustache templates.
Definition: SkinMustache.php:25
SkinMustache\getTemplateData
getTemplateData()
Subclasses may extend this method to add additional template data.The data keys should be valid Engli...
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