diff --git a/includes/Partials/FirstHeading.php b/includes/Partials/FirstHeading.php deleted file mode 100644 index a59f0740..00000000 --- a/includes/Partials/FirstHeading.php +++ /dev/null @@ -1,46 +0,0 @@ -. - * - * @file - * @ingroup Skins - */ - -declare( strict_types=1 ); - -namespace Citizen\Partials; - -/** - * FirstHeading partial of Skin Citizen - */ -final class FirstHeading extends Partial { - - /** - * Wrap parenthesis text in FirstHeading - * - * @param string $htmlTitle html-title in Mustache - * @return string html - */ - public function buildFirstHeading( $htmlTitle ) { - $pattern = '/(\(.+\))/'; - $replacement = '$1'; - $htmlTitle = preg_replace( $pattern, $replacement, $htmlTitle ); - - return $htmlTitle; - } -} diff --git a/includes/Partials/Title.php b/includes/Partials/Title.php new file mode 100644 index 00000000..1be1f7a4 --- /dev/null +++ b/includes/Partials/Title.php @@ -0,0 +1,96 @@ +. + * + * @file + * @ingroup Skins + */ + +declare( strict_types=1 ); + +namespace Citizen\Partials; + +use MediaWiki\MediaWikiServices; +use Html; + +/** + * Title partial of Skin Citizen + */ +final class Title extends Partial { + + /** + * Build the HTML for html-title-heading + * Backported from 1.39 to 1.35 + * TODO: Deprecate this when we move to 1.39 and T306440 is resolved + * + * @param array $parentData + * @param Title $title + * @return string html + */ + public function buildTitle( $parentData, $title ) { + $blankedHeading = $parentData['is-title-blank'] ?? false; // @since 1.38 + $htmlTitle = $parentData['html-title']; + + $data = Html::rawElement( + 'h1', + [ + 'id' => 'firstHeading', + 'class' => 'firstHeading mw-first-heading', + 'style' => $blankedHeading ? 'display: none' : null + ] + $this->getUserLanguageAttributes(), + $this->decorateTitle( $htmlTitle ) + ); + + return $data; + } + + /** + * Wrap text within parenthesis with a span tag + * + * @return string html + */ + private function decorateTitle( $html ) { + $pattern = '/(\(.+\))/'; + $replacement = '$1'; + $$html = preg_replace( $pattern, $replacement, $html ); + + return $html; + } + + /** + * From core because it is private + * + * @return array + */ + private function getUserLanguageAttributes() { + $userLang = $this->skin->getLanguage(); + $userLangCode = $userLang->getHtmlCode(); + $userLangDir = $userLang->getDir(); + $contLang = MediaWikiServices::getInstance()->getContentLanguage(); + if ( + $userLangCode !== $contLang->getHtmlCode() || + $userLangDir !== $contLang->getDir() + ) { + return [ + 'lang' => $userLangCode, + 'dir' => $userLangDir, + ]; + } + return []; + } +} diff --git a/includes/SkinCitizen.php b/includes/SkinCitizen.php index fad95203..6f879917 100644 --- a/includes/SkinCitizen.php +++ b/includes/SkinCitizen.php @@ -24,7 +24,6 @@ use Citizen\GetConfigTrait; use Citizen\Partials\BodyContent; use Citizen\Partials\Drawer; -use Citizen\Partials\FirstHeading; use Citizen\Partials\Footer; use Citizen\Partials\Header; use Citizen\Partials\Logos; @@ -32,6 +31,7 @@ use Citizen\Partials\Metadata; use Citizen\Partials\PageTools; use Citizen\Partials\Tagline; use Citizen\Partials\Theme; +use Citizen\Partials\Title; /** * Skin subclass for Citizen @@ -70,7 +70,7 @@ class SkinCitizen extends SkinMustache { $header = new Header( $this ); $logos = new Logos( $this ); $drawer = new Drawer( $this ); - $firstHeading = new FirstHeading( $this ); + $pageTitle = new Title( $this ); $tagline = new Tagline( $this ); $bodycontent = new BodyContent( $this ); $footer = new Footer( $this ); @@ -112,12 +112,11 @@ class SkinCitizen extends SkinMustache { 'msg-citizen-jumptotop' => $this->msg( 'citizen-jumptotop' )->text() . ' [home]', ], - 'html-title--formatted' => $firstHeading->buildFirstHeading( $parentData[ 'html-title' ] ), + 'html-title-heading--formatted' => $pageTitle->buildTitle( $parentData, $title ), 'data-pagetools' => $tools->buildPageTools( $parentData ), 'html-newtalk' => $newTalksHtml ? '
' . $newTalksHtml . '
' : '', - 'page-langcode' => $title->getPageViewLanguage()->getHtmlCode(), 'msg-tagline' => $tagline->getTagline( $out ), diff --git a/templates/ContentHeader.mustache b/templates/ContentHeader.mustache index ca03d9a4..bd166dc0 100644 --- a/templates/ContentHeader.mustache +++ b/templates/ContentHeader.mustache @@ -1,13 +1,11 @@ {{! - string page-langcode the content language of the article. Assumed to be escaped HTML. - string page-langcode the content language of the article. Assumed to be escaped HTML. - string html-title--formatted + string html-title-heading--formatted string msg-tagline }}
-

{{{html-title--formatted}}}

+ {{{html-title-heading--formatted}}} {{>Indicators}}
{{msg-tagline}}
diff --git a/templates/skin.mustache b/templates/skin.mustache index 637aa2c3..b08032da 100644 --- a/templates/skin.mustache +++ b/templates/skin.mustache @@ -3,9 +3,7 @@ Also used by CentralNotice to inject banners into Vector. Indicator[] array-indicators wiki-defined badges such as "good article", "featured article". An empty array if none are defined. - string page-langcode the content language of the article. Assumed to be escaped HTML. string html-newtalk - string page-langcode the content language of the article. Assumed to be escaped HTML. string html-title--formatted string msg-tagline string html-prebodyhtml