2019-06-20 15:18:20 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* This program 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 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
2019-07-01 18:06:01 +00:00
|
|
|
namespace MediaWiki\Minerva\Menu\Entries;
|
2019-06-20 15:18:20 +00:00
|
|
|
|
2023-08-19 04:23:00 +00:00
|
|
|
use MediaWiki\Title\Title;
|
2019-06-20 15:18:20 +00:00
|
|
|
use MessageLocalizer;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Model for a menu entry that represents a language selector for current title
|
|
|
|
*/
|
|
|
|
class LanguageSelectorEntry implements IMenuEntry {
|
|
|
|
|
2024-03-28 19:15:41 +00:00
|
|
|
private MessageLocalizer $messageLocalizer;
|
|
|
|
private Title $title;
|
|
|
|
private bool $doesPageHaveLanguages;
|
|
|
|
/** @var string Associated icon name */
|
|
|
|
private string $icon;
|
|
|
|
/** @var string A translatable label used as text and title */
|
|
|
|
private string $label;
|
|
|
|
/** @var string additional classes */
|
|
|
|
private string $classes;
|
2021-09-09 15:56:42 +00:00
|
|
|
|
2019-06-20 15:18:20 +00:00
|
|
|
/**
|
|
|
|
* LanguageSelectorEntry constructor.
|
|
|
|
* @param Title $title Current Title
|
|
|
|
* @param bool $doesPageHaveLanguages Whether the page is also available in other
|
|
|
|
* languages or variants
|
|
|
|
* @param MessageLocalizer $messageLocalizer Used for translation texts
|
2021-09-09 15:56:42 +00:00
|
|
|
* @param bool $isButton
|
|
|
|
* @param string $classes page classes
|
2019-06-24 17:59:11 +00:00
|
|
|
* @param string $label Menu entry label and title
|
2019-06-20 15:18:20 +00:00
|
|
|
*/
|
|
|
|
public function __construct(
|
|
|
|
Title $title,
|
|
|
|
$doesPageHaveLanguages,
|
2019-06-24 17:59:11 +00:00
|
|
|
MessageLocalizer $messageLocalizer,
|
2021-09-09 15:56:42 +00:00
|
|
|
$isButton = false,
|
|
|
|
$classes = '',
|
2019-06-24 17:59:11 +00:00
|
|
|
$label = 'mobile-frontend-language-article-heading'
|
2019-06-20 15:18:20 +00:00
|
|
|
) {
|
|
|
|
$this->title = $title;
|
|
|
|
$this->doesPageHaveLanguages = $doesPageHaveLanguages;
|
|
|
|
$this->messageLocalizer = $messageLocalizer;
|
2024-05-13 21:53:31 +00:00
|
|
|
$this->icon = $doesPageHaveLanguages ? 'language-base20' : 'language-disabled';
|
2019-06-24 17:59:11 +00:00
|
|
|
$this->label = $label;
|
2021-09-09 15:56:42 +00:00
|
|
|
$this->classes = $classes;
|
2019-06-20 15:18:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
2024-03-28 19:15:41 +00:00
|
|
|
public function getName(): string {
|
2019-06-20 15:18:20 +00:00
|
|
|
return 'language-selector';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
|
|
|
public function getCSSClasses(): array {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
|
|
|
public function getComponents(): array {
|
|
|
|
$switcherLink = false;
|
|
|
|
$switcherClasses = ' language-selector';
|
|
|
|
|
|
|
|
if ( $this->doesPageHaveLanguages ) {
|
2023-01-12 17:17:15 +00:00
|
|
|
$switcherLink = '#p-lang';
|
2019-06-20 15:18:20 +00:00
|
|
|
} else {
|
|
|
|
$switcherClasses .= ' disabled';
|
|
|
|
}
|
2019-06-24 17:59:11 +00:00
|
|
|
$msg = $this->messageLocalizer->msg( $this->label );
|
2019-06-20 15:18:20 +00:00
|
|
|
|
|
|
|
return [
|
|
|
|
[
|
2023-08-08 23:33:28 +00:00
|
|
|
'tag-name' => 'a',
|
|
|
|
'classes' => $this->classes . ' ' . $switcherClasses,
|
|
|
|
'label' => $msg,
|
|
|
|
'data-icon' => [
|
|
|
|
'icon' => $this->icon,
|
|
|
|
],
|
|
|
|
'array-attributes' => [
|
|
|
|
[
|
|
|
|
'key' => 'href',
|
|
|
|
'value' => $switcherLink,
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'key' => 'data-mw',
|
|
|
|
'value' => 'interface',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'key' => 'data-event-name',
|
|
|
|
'value' => 'menu.languages',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'key' => 'title',
|
|
|
|
'value' => $msg,
|
|
|
|
],
|
|
|
|
],
|
|
|
|
],
|
2019-06-20 15:18:20 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|