| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
use MediaWiki\Html\Html; |
| 22 |
use MediaWiki\Html\TemplateParser; |
| 23 |
use MediaWiki\Language\Language; |
| 24 |
use MediaWiki\Skin\SkinComponentTempUserBanner; |
| 25 |
use MediaWiki\Skin\SkinComponentUtils; |
| 26 |
use MediaWiki\Title\Title; |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
class SkinMustache extends SkinTemplate { |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
private $templateParser = null; |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
protected function getTemplateParser() { |
| 46 |
if ( $this->templateParser === null ) { |
| 47 |
$this->templateParser = new TemplateParser( $this->options['templateDirectory'] ); |
| 48 |
|
| 49 |
$this->templateParser->enableRecursivePartials( true ); |
| 50 |
} |
| 51 |
return $this->templateParser; |
| 52 |
} |
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
private function createTempUserBannerHTML() { |
| 61 |
$isSupportedSkin = $this->getOptions()['tempUserBanner']; |
| 62 |
$isTempUser = $this->getUser()->isTemp(); |
| 63 |
|
| 64 |
if ( !$isSupportedSkin || !$isTempUser ) { |
| 65 |
return ''; |
| 66 |
} |
| 67 |
|
| 68 |
$returntoParam = SkinComponentUtils::getReturnToParam( |
| 69 |
$this->getTitle(), |
| 70 |
$this->getRequest(), |
| 71 |
$this->getAuthority() |
| 72 |
); |
| 73 |
|
| 74 |
$tempUserBanner = new SkinComponentTempUserBanner( |
| 75 |
$returntoParam, |
| 76 |
$this->getContext(), |
| 77 |
$this->getUser(), |
| 78 |
); |
| 79 |
return $tempUserBanner->getTemplateData()['html']; |
| 80 |
} |
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
public function generateHTML() { |
| 89 |
$this->setupTemplateContext(); |
| 90 |
$out = $this->getOutput(); |
| 91 |
$tp = $this->getTemplateParser(); |
| 92 |
$template = $this->options['template'] ?? 'skin'; |
| 93 |
$data = $this->getTemplateData(); |
| 94 |
$html = $this->createTempUserBannerHTML(); |
| 95 |
$html .= $tp->processTemplate( $template, $data ); |
| 96 |
return $html; |
| 97 |
} |
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
protected function doEditSectionLinksHTML( array $links, Language $lang ) { |
| 103 |
$template = $this->getOptions()['templateSectionLinks'] ?? null; |
| 104 |
if ( !$template ) { |
| 105 |
return parent::doEditSectionLinksHTML( $links, $lang ); |
| 106 |
} |
| 107 |
return $this->getTemplateParser()->processTemplate( $template, [ |
| 108 |
'class' => 'mw-editsection', |
| 109 |
'array-links' => $links |
| 110 |
] ); |
| 111 |
} |
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
public function getTemplateData() { |
| 118 |
$out = $this->getOutput(); |
| 119 |
$printSource = Html::rawElement( |
| 120 |
'div', |
| 121 |
[ |
| 122 |
'class' => 'printfooter', |
| 123 |
'data-nosnippet' => '' |
| 124 |
] + $this->getUserLanguageAttributes(), |
| 125 |
$this->printSource() |
| 126 |
); |
| 127 |
$bodyContent = $out->getHTML() . "\n" . $printSource; |
| 128 |
|
| 129 |
$newTalksHtml = $this->getNewtalks() ?: null; |
| 130 |
|
| 131 |
$data = parent::getTemplateData() + [ |
| 132 |
|
| 133 |
'array-indicators' => $this->getIndicatorsData( $out->getIndicators() ), |
| 134 |
|
| 135 |
'html-site-notice' => $this->getSiteNotice() ?: null, |
| 136 |
'html-user-message' => $newTalksHtml ? |
| 137 |
Html::rawElement( 'div', [ 'class' => 'usermessage' ], $newTalksHtml ) : null, |
| 138 |
'html-subtitle' => $this->prepareSubtitle(), |
| 139 |
'html-body-content' => $this->wrapHTML( $out->getTitle(), $bodyContent ), |
| 140 |
'html-categories' => $this->getCategories(), |
| 141 |
'html-after-content' => $this->afterContentHook(), |
| 142 |
'html-undelete-link' => $this->prepareUndeleteLink(), |
| 143 |
'html-user-language-attributes' => $this->prepareUserLanguageAttributes(), |
| 144 |
|
| 145 |
|
| 146 |
'link-mainpage' => Title::newMainPage()->getLocalURL(), |
| 147 |
]; |
| 148 |
|
| 149 |
foreach ( $this->options['messages'] ?? [] as $message ) { |
| 150 |
$data["msg-{$message}"] = $this->msg( $message )->text(); |
| 151 |
} |
| 152 |
return $data; |
| 153 |
} |
| 154 |
} |