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 {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var MessageLocalizer
|
|
|
|
*/
|
|
|
|
private $messageLocalizer;
|
|
|
|
/**
|
|
|
|
* @var Title
|
|
|
|
*/
|
|
|
|
private $title;
|
|
|
|
/**
|
|
|
|
* @var bool
|
|
|
|
*/
|
|
|
|
private $doesPageHaveLanguages;
|
2019-06-24 17:59:11 +00:00
|
|
|
/**
|
2021-09-09 15:56:42 +00:00
|
|
|
* @var string Associated icon name
|
2019-06-24 17:59:11 +00:00
|
|
|
*/
|
2021-09-09 15:56:42 +00:00
|
|
|
private $icon;
|
2019-06-24 17:59:11 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string A translatable label used as text and title
|
|
|
|
*/
|
|
|
|
private $label;
|
|
|
|
|
2021-09-09 15:56:42 +00:00
|
|
|
/**
|
|
|
|
* @var string additional classes
|
|
|
|
*/
|
|
|
|
private $classes;
|
|
|
|
|
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;
|
2023-09-05 17:07:13 +00:00
|
|
|
$this->icon = 'language-base20';
|
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
|
|
|
|
*/
|
|
|
|
public function getName() {
|
|
|
|
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
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|