2022-12-16 18:03:07 +00:00
|
|
|
<?php
|
|
|
|
namespace MediaWiki\Skins\Vector\Components;
|
|
|
|
|
2022-12-19 15:57:48 +00:00
|
|
|
use Title;
|
|
|
|
|
2022-12-16 18:03:07 +00:00
|
|
|
/**
|
|
|
|
* VectorComponentLanguageButton component
|
|
|
|
*/
|
|
|
|
class VectorComponentLanguageDropdown implements VectorComponent {
|
|
|
|
private const CLASS_PROGRESSIVE = 'mw-ui-progressive';
|
|
|
|
/** @var string */
|
|
|
|
private $label;
|
|
|
|
/** @var string */
|
|
|
|
private $ariaLabel;
|
|
|
|
/** @var string */
|
|
|
|
private $class;
|
|
|
|
/** @var int */
|
|
|
|
private $numLanguages;
|
|
|
|
/** @var array */
|
|
|
|
private $menuContentsData;
|
2022-12-19 15:57:48 +00:00
|
|
|
/** @var Title|null */
|
|
|
|
private $title;
|
2022-12-16 18:03:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $label human readable
|
|
|
|
* @param string $ariaLabel label for accessibility
|
|
|
|
* @param string $class of the dropdown component
|
|
|
|
* @param int $numLanguages
|
|
|
|
* @param string $itemHTML the HTML of the list e.g. `<li>...</li>`
|
|
|
|
* @param string $beforePortlet no known usages. Perhaps can be removed in future
|
|
|
|
* @param string $afterPortlet used by Extension:ULS
|
2022-12-19 15:57:48 +00:00
|
|
|
* @param Title|null $title
|
2022-12-16 18:03:07 +00:00
|
|
|
*/
|
|
|
|
public function __construct(
|
|
|
|
string $label, string $ariaLabel, string $class, int $numLanguages,
|
|
|
|
// @todo: replace with >MenuContents class.
|
2022-12-19 15:57:48 +00:00
|
|
|
string $itemHTML, string $beforePortlet = '', string $afterPortlet = '', $title = null
|
2022-12-16 18:03:07 +00:00
|
|
|
) {
|
|
|
|
$this->label = $label;
|
|
|
|
$this->ariaLabel = $ariaLabel;
|
|
|
|
$this->class = $class;
|
|
|
|
$this->numLanguages = $numLanguages;
|
|
|
|
$this->menuContentsData = [
|
|
|
|
'html-items' => $itemHTML,
|
|
|
|
'html-before-portal' => $beforePortlet,
|
|
|
|
'html-after-portal' => $afterPortlet,
|
|
|
|
];
|
2022-12-19 15:57:48 +00:00
|
|
|
$this->title = $title;
|
2022-12-16 18:03:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
|
|
|
public function getTemplateData(): array {
|
2022-12-19 15:57:48 +00:00
|
|
|
$title = $this->title;
|
2023-01-13 06:31:55 +00:00
|
|
|
$isSubjectPage = $title && $title->exists() && !$title->isTalkPage();
|
|
|
|
// If page doesn't exist or if it's in a talk namespace, we should
|
2022-12-19 15:57:48 +00:00
|
|
|
// display a less prominent "language" button, without a label, and
|
|
|
|
// quiet instead of progressive. For this reason some default values
|
|
|
|
// should be updated for this case. (T316559)
|
2023-01-13 06:31:55 +00:00
|
|
|
if ( !$isSubjectPage ) {
|
2022-12-19 15:57:48 +00:00
|
|
|
$icon = '<span class="mw-ui-icon mw-ui-icon-wikimedia-language"></span>';
|
|
|
|
$label = '';
|
|
|
|
$headingClass = 'mw-ui-button mw-ui-quiet mw-portlet-lang-heading-empty';
|
|
|
|
$checkboxClass = 'mw-interlanguage-selector-empty';
|
|
|
|
} else {
|
|
|
|
$icon = '<span class="mw-ui-icon mw-ui-icon-wikimedia-language-progressive"></span>';
|
|
|
|
$label = $this->label;
|
|
|
|
$headingClass = 'mw-ui-button mw-ui-quiet '
|
|
|
|
. self::CLASS_PROGRESSIVE . ' mw-portlet-lang-heading-' . strval( $this->numLanguages );
|
|
|
|
$checkboxClass = 'mw-interlanguage-selector';
|
|
|
|
}
|
|
|
|
$dropdown = new VectorComponentDropdown( 'p-lang-btn', $label, $this->class );
|
|
|
|
|
2022-12-16 18:03:07 +00:00
|
|
|
$dropdownData = $dropdown->getTemplateData();
|
|
|
|
// override default heading class.
|
2022-12-19 15:57:48 +00:00
|
|
|
$dropdownData['heading-class'] = $headingClass;
|
2022-12-16 18:03:07 +00:00
|
|
|
// ext.uls.interface attaches click handler to this selector.
|
2022-12-19 15:57:48 +00:00
|
|
|
$dropdownData['checkbox-class'] = $checkboxClass;
|
2022-12-16 18:03:07 +00:00
|
|
|
// Override header icon (currently no way to do this using constructor)
|
2022-12-19 15:57:48 +00:00
|
|
|
$dropdownData['html-vector-heading-icon'] = $icon;
|
2022-12-16 18:03:07 +00:00
|
|
|
$dropdownData['aria-label'] = $this->ariaLabel;
|
2023-01-13 06:31:55 +00:00
|
|
|
$dropdownData['is-language-selector-empty'] = !$isSubjectPage;
|
2022-12-19 15:57:48 +00:00
|
|
|
|
2022-12-16 18:03:07 +00:00
|
|
|
return $dropdownData + $this->menuContentsData;
|
|
|
|
}
|
|
|
|
}
|