2024-05-15 05:24:43 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare( strict_types=1 );
|
|
|
|
|
|
|
|
namespace MediaWiki\Skins\Citizen\Components;
|
|
|
|
|
2024-10-03 20:46:28 +00:00
|
|
|
use ExtensionRegistry;
|
2024-09-26 21:47:19 +00:00
|
|
|
use MessageLocalizer;
|
2024-05-15 05:24:43 +00:00
|
|
|
use Skin;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* CitizenComponentSearchBox component
|
|
|
|
*/
|
|
|
|
class CitizenComponentSearchBox implements CitizenComponent {
|
2024-09-26 21:47:19 +00:00
|
|
|
/** @var MessageLocalizer */
|
|
|
|
private $localizer;
|
|
|
|
|
2024-05-15 05:24:43 +00:00
|
|
|
/** @var array */
|
|
|
|
private $searchBoxData;
|
|
|
|
|
|
|
|
/** @var Skin */
|
|
|
|
private $skin;
|
|
|
|
|
|
|
|
/**
|
2024-09-26 21:47:19 +00:00
|
|
|
* @param MessageLocalizer $localizer
|
2024-05-15 05:24:43 +00:00
|
|
|
* @param array $searchBoxData
|
|
|
|
*/
|
|
|
|
public function __construct(
|
2024-09-26 21:47:19 +00:00
|
|
|
MessageLocalizer $localizer,
|
2024-05-15 05:24:43 +00:00
|
|
|
array $searchBoxData,
|
|
|
|
Skin $skin
|
|
|
|
) {
|
2024-09-26 21:47:19 +00:00
|
|
|
$this->localizer = $localizer;
|
2024-05-15 05:24:43 +00:00
|
|
|
$this->searchBoxData = $searchBoxData;
|
|
|
|
$this->skin = $skin;
|
|
|
|
}
|
|
|
|
|
2024-09-26 21:47:19 +00:00
|
|
|
/**
|
|
|
|
* Get the keyboard hint data
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
private function getKeyboardHintData() {
|
|
|
|
$data = [];
|
|
|
|
// There is probably a cleaner way to handle this
|
|
|
|
$map = [
|
|
|
|
'↑ ↓' => $this->localizer->msg( "citizen-search-keyhint-select" )->text(),
|
|
|
|
'/' => $this->localizer->msg( "citizen-search-keyhint-open" )->text(),
|
|
|
|
'Esc' => $this->localizer->msg( "citizen-search-keyhint-exit" )->text()
|
|
|
|
];
|
|
|
|
|
|
|
|
foreach ( $map as $key => $label ) {
|
|
|
|
$keyhint = new CitizenComponentKeyboardHint( $label, $key );
|
|
|
|
$data[] = $keyhint->getTemplateData();
|
|
|
|
}
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
2024-10-03 20:46:28 +00:00
|
|
|
/**
|
|
|
|
* Get the footer message
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
private function getFooterMessage(): string {
|
|
|
|
$isCirrusSearchExtensionEnabled = ExtensionRegistry::getInstance()->isLoaded( 'CirrusSearch' );
|
|
|
|
$searchBackend = $isCirrusSearchExtensionEnabled ? 'cirrussearch' : 'mediawiki';
|
|
|
|
return $this->localizer->msg(
|
|
|
|
'citizen-search-poweredby',
|
|
|
|
$this->localizer->msg( "citizen-search-poweredby-$searchBackend" )
|
|
|
|
)->text();
|
|
|
|
}
|
|
|
|
|
2024-05-15 05:24:43 +00:00
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
|
|
|
public function getTemplateData(): array {
|
|
|
|
$searchBoxData = $this->searchBoxData;
|
|
|
|
|
|
|
|
return $searchBoxData += [
|
2024-09-26 21:47:19 +00:00
|
|
|
'array-keyboard-hint' => $this->getKeyboardHintData(),
|
2024-10-03 20:46:28 +00:00
|
|
|
'msg-citizen-search-footer' => $this->getFooterMessage(),
|
2024-05-15 05:24:43 +00:00
|
|
|
'msg-citizen-search-toggle-shortcut' => '[/]',
|
|
|
|
'html-random-href' => $this->skin->makeSpecialUrl( 'Randompage' ),
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|