2022-05-21 20:24:35 +00:00
|
|
|
<?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 );
|
|
|
|
|
2022-05-26 20:54:52 +00:00
|
|
|
namespace MediaWiki\Skins\Citizen\Partials;
|
2022-05-21 20:24:35 +00:00
|
|
|
|
|
|
|
use Html;
|
2022-05-21 20:27:46 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
2022-05-21 20:24:35 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Title partial of Skin Citizen
|
|
|
|
*/
|
|
|
|
final class Title extends Partial {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Build the HTML for html-title-heading
|
2022-05-21 20:27:46 +00:00
|
|
|
* Backported from 1.39 to 1.35
|
|
|
|
* TODO: Deprecate this when we move to 1.39 and T306440 is resolved
|
2022-05-21 20:24:35 +00:00
|
|
|
*
|
2022-05-21 20:27:46 +00:00
|
|
|
* @param array $parentData
|
|
|
|
* @param Title $title
|
2022-05-21 20:24:35 +00:00
|
|
|
* @return string html
|
|
|
|
*/
|
|
|
|
public function buildTitle( $parentData, $title ) {
|
2022-05-22 19:12:05 +00:00
|
|
|
// @since 1.38
|
|
|
|
$blankedHeading = $parentData['is-title-blank'] ?? false;
|
2022-05-21 20:27:46 +00:00
|
|
|
$htmlTitle = $parentData['html-title'];
|
2022-05-21 20:24:35 +00:00
|
|
|
|
2022-05-21 20:27:46 +00:00
|
|
|
$data = Html::rawElement(
|
|
|
|
'h1',
|
|
|
|
[
|
|
|
|
'id' => 'firstHeading',
|
|
|
|
'class' => 'firstHeading mw-first-heading',
|
|
|
|
'style' => $blankedHeading ? 'display: none' : null
|
|
|
|
] + $this->getUserLanguageAttributes(),
|
|
|
|
$this->decorateTitle( $htmlTitle )
|
|
|
|
);
|
2022-05-21 20:24:35 +00:00
|
|
|
|
2022-05-21 20:27:46 +00:00
|
|
|
return $data;
|
2022-05-21 20:24:35 +00:00
|
|
|
}
|
|
|
|
|
2022-05-21 20:27:46 +00:00
|
|
|
/**
|
|
|
|
* Wrap text within parenthesis with a span tag
|
|
|
|
*
|
2022-05-22 19:12:05 +00:00
|
|
|
* @param string $html title of the page
|
2022-05-21 20:27:46 +00:00
|
|
|
* @return string html
|
|
|
|
*/
|
|
|
|
private function decorateTitle( $html ) {
|
|
|
|
$pattern = '/(\(.+\))/';
|
|
|
|
$replacement = '<span class="firstHeading-parenthesis">$1</span>';
|
|
|
|
$$html = preg_replace( $pattern, $replacement, $html );
|
2022-05-21 20:24:35 +00:00
|
|
|
|
2022-05-21 20:27:46 +00:00
|
|
|
return $html;
|
|
|
|
}
|
2022-05-21 20:24:35 +00:00
|
|
|
|
2022-05-21 20:27:46 +00:00
|
|
|
/**
|
|
|
|
* 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 [];
|
|
|
|
}
|
2022-05-21 20:24:35 +00:00
|
|
|
}
|