mirror of
https://github.com/StarCitizenTools/mediawiki-skins-Citizen.git
synced 2024-11-24 14:34:09 +00:00
feat(core): intergrate firstHeading changes from MW 1.39
* It is a temporary backport until we move to minimum 1.39 * Add support for blanking title introduced from 1.38
This commit is contained in:
parent
726a348369
commit
1df970eb41
|
@ -1,46 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Citizen - A responsive skin developed for the Star Citizen Wiki
|
||||
*
|
||||
* This file is part of Citizen.
|
||||
*
|
||||
* Citizen is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Citizen is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Citizen. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @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 = '<span class="firstHeading-parenthesis">$1</span>';
|
||||
$htmlTitle = preg_replace( $pattern, $replacement, $htmlTitle );
|
||||
|
||||
return $htmlTitle;
|
||||
}
|
||||
}
|
96
includes/Partials/Title.php
Normal file
96
includes/Partials/Title.php
Normal file
|
@ -0,0 +1,96 @@
|
|||
<?php
|
||||
/**
|
||||
* Citizen - A responsive skin developed for the Star Citizen Wiki
|
||||
*
|
||||
* This file is part of Citizen.
|
||||
*
|
||||
* Citizen is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Citizen is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Citizen. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @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 = '<span class="firstHeading-parenthesis">$1</span>';
|
||||
$$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 [];
|
||||
}
|
||||
}
|
|
@ -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 ? '<div class="usermessage">' . $newTalksHtml . '</div>' : '',
|
||||
'page-langcode' => $title->getPageViewLanguage()->getHtmlCode(),
|
||||
|
||||
'msg-tagline' => $tagline->getTagline( $out ),
|
||||
|
||||
|
|
|
@ -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
|
||||
}}
|
||||
<header class="mw-body-header">
|
||||
<div class="page-heading">
|
||||
<div class="firstHeading-container">
|
||||
<h1 id="firstHeading" class="firstHeading" lang="{{page-langcode}}">{{{html-title--formatted}}}</h1>
|
||||
{{{html-title-heading--formatted}}}
|
||||
{{>Indicators}}
|
||||
</div>
|
||||
<div id="siteSub">{{msg-tagline}}</div>
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue