Generate section edit links via SkinMustache

Bug: T346944
Depends-On: Ief6a6ee03ada8207fc5c60ea438412fa2d529022
Change-Id: I9f768706c0a0f14f14ee4b3812288218bef36018
This commit is contained in:
Jon Robson 2023-10-20 12:56:45 -07:00 committed by Bartosz Dziewoński
parent 7d59aa1843
commit 0c8caebfc6
5 changed files with 22 additions and 43 deletions

View file

@ -0,0 +1,5 @@
<a role="button"
{{#array-attributes}}{{key}}="{{value}}"{{/array-attributes}}
class="cdx-button cdx-button--size-large cdx-button--fake-button cdx-button--fake-button--enabled{{#data-icon}} cdx-button--icon-only cdx-button--weight-quiet{{/data-icon}}{{#class}} {{.}}{{/class}}">
{{#data-icon}}{{>Icon}}{{/data-icon}}<span>{{ text }}</span>
</a>

View file

@ -0,0 +1,4 @@
<span class="{{class}}">
{{#array-links}}{{>IconButtonLink}}{{/array-links}}
</span>

View file

@ -549,51 +549,20 @@ class SkinMinerva extends SkinMustache {
}
/**
* Overrides Skin::doEditSectionLink
* @param Title $nt The title being linked to (may not be the same as
* the current page, if the section is included from a template)
* @param string $section
* @param string|null $tooltip
* @param Language $lang
* @return string
* Modifies the template data before parsing in SkinMustache.
*
* @inheritDoc
*/
public function doEditSectionLink( Title $nt, $section, $tooltip, Language $lang ) {
if ( $this->getPermissions()->isAllowed( IMinervaPagePermissions::EDIT_OR_CREATE ) &&
!$nt->isMainPage() ) {
$message = $this->msg( 'mobile-frontend-editor-edit' )->inLanguage( $lang )->text();
$html = Html::openElement( 'span', [ 'class' => 'mw-editsection' ] );
if ( !$this->templateParser ) {
$this->templateParser = new TemplateParser( __DIR__ );
}
$templateParser = $this->templateParser;
$html .= $templateParser->processTemplate( 'Button', [
'tag-name' => 'a',
final protected function doEditSectionLinksHTML( array $links, Language $lang ) {
$transformedLinks = [];
foreach ( $links as $key => $link ) {
$transformedLinks[] = $link + [
'data-icon' => [
'icon' => 'edit-base20'
'icon' => $link['icon'],
],
'array-attributes' => [
[
'key' => 'href',
'value' => $nt->getLocalURL( [ 'action' => 'edit', 'section' => $section ] ),
],
[
'key' => 'title',
'value' => $this->msg( 'editsectionhint', $tooltip )->inLanguage( $lang )->text(),
],
[
'key' => 'data-section',
'value' => $section,
],
],
'label' => $message,
// Note visibility of the edit section link button is controlled by .edit-page in ui.less so
// we default to enabled even though this may not be true.
'classes' => 'edit-page',
] );
$html .= Html::closeElement( 'span' );
return $html;
];
}
return '';
return parent::doEditSectionLinksHTML( $transformedLinks, $lang );
}
/**

View file

@ -176,9 +176,9 @@ main {
// Negative margins to prevent the edit icon from affecting the height of the heading
margin-top: -1em;
margin-bottom: -1em;
.cdx-mixin-button-layout-flush( 'end', true, 'large' );
.cdx-button:last-child {
.cdx-mixin-button-layout-flush( 'end', true, 'large' );
.cdx-button {
font-size: 1rem; // stylelint-disable-line unit-disallowed-list
}
}

View file

@ -103,6 +103,7 @@
"args": [ {
"name": "minerva",
"templateDirectory": "includes/Skins",
"templateSectionLinks": "SectionLinks",
"tempUserBanner": true,
"messages": [
"variants",