| 1 |
<?php |
| 2 |
namespace MediaWiki\Skins\Vector\Components; |
| 3 |
|
| 4 |
use MediaWiki\Title\Title; |
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
class VectorComponentLanguageDropdown implements VectorComponent { |
| 10 |
|
| 11 |
private $label; |
| 12 |
|
| 13 |
private $ariaLabel; |
| 14 |
|
| 15 |
private $class; |
| 16 |
|
| 17 |
private $numLanguages; |
| 18 |
|
| 19 |
private $menuContentsData; |
| 20 |
|
| 21 |
private $title; |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
public function __construct( |
| 34 |
string $label, string $ariaLabel, string $class, int $numLanguages, |
| 35 |
|
| 36 |
string $itemHTML, string $beforePortlet = '', string $afterPortlet = '', $title = null |
| 37 |
) { |
| 38 |
$this->label = $label; |
| 39 |
$this->ariaLabel = $ariaLabel; |
| 40 |
$this->class = $class; |
| 41 |
$this->numLanguages = $numLanguages; |
| 42 |
$this->menuContentsData = [ |
| 43 |
'html-items' => $itemHTML, |
| 44 |
'html-before-portal' => $beforePortlet, |
| 45 |
'html-after-portal' => $afterPortlet, |
| 46 |
]; |
| 47 |
$this->title = $title; |
| 48 |
} |
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
public function getTemplateData(): array { |
| 54 |
$title = $this->title; |
| 55 |
$isSubjectPage = $title && $title->exists() && !$title->isTalkPage(); |
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
$buttonClasses = 'cdx-button cdx-button--fake-button cdx-button--fake-button--enabled cdx-button--weight-quiet'; |
| 61 |
if ( !$isSubjectPage ) { |
| 62 |
$icon = 'language'; |
| 63 |
$this->class .= ' mw-portlet-lang-icon-only'; |
| 64 |
$labelClass = $buttonClasses . ' cdx-button--icon-only mw-portlet-lang-heading-empty'; |
| 65 |
$checkboxClass = 'mw-interlanguage-selector-empty'; |
| 66 |
} else { |
| 67 |
$icon = 'language-progressive'; |
| 68 |
$labelClass = $buttonClasses . ' cdx-button--action-progressive' |
| 69 |
. ' mw-portlet-lang-heading-' . strval( $this->numLanguages ); |
| 70 |
$checkboxClass = 'mw-interlanguage-selector'; |
| 71 |
} |
| 72 |
$dropdown = new VectorComponentDropdown( 'p-lang-btn', $this->label, $this->class ); |
| 73 |
$dropdownData = $dropdown->getTemplateData(); |
| 74 |
|
| 75 |
$dropdownData['label-class'] = $labelClass; |
| 76 |
|
| 77 |
$dropdownData['checkbox-class'] = $checkboxClass; |
| 78 |
$dropdownData['icon'] = $icon; |
| 79 |
$dropdownData['aria-label'] = $this->ariaLabel; |
| 80 |
$dropdownData['is-language-selector-empty'] = !$isSubjectPage; |
| 81 |
|
| 82 |
return $dropdownData + $this->menuContentsData; |
| 83 |
} |
| 84 |
} |