Extract Portal mustache component from VectorTemplate.php

A Portal (or portlet) in the Vector context is a section of the
sidebar menu (e.g. Tools, Languges etc.).

The hook that places content between the portals (or portlets?)
such as `SkinTemplateToolboxEnd` and `otherlanguages` has been
enclosed inside of an output buffer so that any content it
produces can be passed to a template.

Bug: T239248, T240062
Change-Id: I882db161e5462cf88aa48c9cfd91448eb97a4a77
This commit is contained in:
Jan Drewniak 2020-01-10 16:00:54 +01:00
parent 093cc20ee0
commit 361e0d6f71
2 changed files with 51 additions and 38 deletions

View file

@ -228,45 +228,39 @@ class VectorTemplate extends BaseTemplate {
if ( $msg === null ) {
$msg = $name;
}
$msgObj = $this->getMsg( $msg );
$labelId = Sanitizer::escapeIdForAttribute( "p-$name-label" );
?>
<div class="portal" role="navigation" id="<?php
echo htmlspecialchars( Sanitizer::escapeIdForAttribute( "p-$name" ) )
?>"<?php
echo Linker::tooltip( 'p-' . $name )
?> aria-labelledby="<?php echo htmlspecialchars( $labelId ) ?>">
<h3<?php $this->html( 'userlangattributes' ) ?> id="<?php echo htmlspecialchars( $labelId )
?>"><?php
echo htmlspecialchars( $msgObj->exists() ? $msgObj->text() : $msg );
?></h3>
<div class="body">
<?php
if ( is_array( $content ) ) {
?>
<ul>
<?php
foreach ( $content as $key => $val ) {
echo $this->makeListItem( $key, $val );
}
if ( $hook !== null ) {
// Avoid PHP 7.1 warning
$skin = $this;
Hooks::run( $hook, [ &$skin, true ] );
}
?>
</ul>
<?php
} else {
// Allow raw HTML block to be defined by extensions
echo $content;
}
$this->renderAfterPortlet( $name );
?>
</div>
</div>
<?php
$msgObj = $this->getMsg( $msg );
$props = [
'portal-id' => "p-$name",
'html-tooltip' => Linker::tooltip( 'p-' . $name ),
'msg-label' => $msgObj->exists() ? $msgObj->text() : $msg,
'msg-label-id' => "p-$name-label",
'html-userlangattributes' => $this->data['userlangattributes'] ?? '',
'html-portal-content' => '',
'html-after-portal' => $this->getAfterPortlet( $name ),
];
if ( is_array( $content ) ) {
$props['html-portal-content'] .= '<ul>';
foreach ( $content as $key => $val ) {
$props['html-portal-content'] .= $this->makeListItem( $key, $val );
}
if ( $hook !== null ) {
// Avoid PHP 7.1 warning
$skin = $this;
ob_start();
Hooks::run( $hook, [ &$skin, true ] );
$params['html-portal-content'] .= ob_get_contents();
ob_end_clean();
}
$props['html-portal-content'] .= '</ul>';
} else {
// Allow raw HTML block to be defined by extensions
$props['html-portal-content'] = $content;
}
echo $this->templateParser->processTemplate( 'Portal', $props );
}
/**

View file

@ -0,0 +1,19 @@
{{!
string portal-id
string html-tooltip
string msg-label-id
string|null html-userlangattributes
string msg-label}
string html-portal-content
string|null html-after-portal
}}
<div class="portal" role="navigation" id="{{portal-id}}" {{{html-tooltip}}} aria-labelledby="{{msg-label-id}}">
<h3 {{{html-userlangattributes}}} id="{{msg-label-id}}">
{{msg-label}}
</h3>
<div class="body">
{{{html-portal-content}}}
{{{html-after-portal}}}
</div>
</div>