From 0c8caebfc6e62feae08604c013b99423a81ddcec Mon Sep 17 00:00:00 2001 From: Jon Robson Date: Fri, 20 Oct 2023 12:56:45 -0700 Subject: [PATCH] Generate section edit links via SkinMustache Bug: T346944 Depends-On: Ief6a6ee03ada8207fc5c60ea438412fa2d529022 Change-Id: I9f768706c0a0f14f14ee4b3812288218bef36018 --- includes/Skins/IconButtonLink.mustache | 5 ++ includes/Skins/SectionLinks.mustache | 4 ++ includes/Skins/SkinMinerva.php | 51 ++++----------------- resources/skins.minerva.base.styles/ui.less | 4 +- skin.json | 1 + 5 files changed, 22 insertions(+), 43 deletions(-) create mode 100644 includes/Skins/IconButtonLink.mustache create mode 100644 includes/Skins/SectionLinks.mustache diff --git a/includes/Skins/IconButtonLink.mustache b/includes/Skins/IconButtonLink.mustache new file mode 100644 index 000000000..ef078b621 --- /dev/null +++ b/includes/Skins/IconButtonLink.mustache @@ -0,0 +1,5 @@ + + {{#data-icon}}{{>Icon}}{{/data-icon}}{{ text }} + diff --git a/includes/Skins/SectionLinks.mustache b/includes/Skins/SectionLinks.mustache new file mode 100644 index 000000000..e0cdeb304 --- /dev/null +++ b/includes/Skins/SectionLinks.mustache @@ -0,0 +1,4 @@ + +{{#array-links}}{{>IconButtonLink}}{{/array-links}} + + diff --git a/includes/Skins/SkinMinerva.php b/includes/Skins/SkinMinerva.php index 31d66729b..1de64a3cc 100644 --- a/includes/Skins/SkinMinerva.php +++ b/includes/Skins/SkinMinerva.php @@ -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 ); } /** diff --git a/resources/skins.minerva.base.styles/ui.less b/resources/skins.minerva.base.styles/ui.less index fc5dbfbb0..2836849b2 100644 --- a/resources/skins.minerva.base.styles/ui.less +++ b/resources/skins.minerva.base.styles/ui.less @@ -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 } } diff --git a/skin.json b/skin.json index 55f9666c1..e0933fc74 100644 --- a/skin.json +++ b/skin.json @@ -103,6 +103,7 @@ "args": [ { "name": "minerva", "templateDirectory": "includes/Skins", + "templateSectionLinks": "SectionLinks", "tempUserBanner": true, "messages": [ "variants",