mirror of
https://gerrit.wikimedia.org/r/mediawiki/skins/Vector.git
synced 2024-11-23 23:33:54 +00:00
Inject service LanguageConverterFactory into VectorComponentVariants
Change-Id: I0e1fa5a8f8f6705e2439bdbc914b9d80b0072c30
This commit is contained in:
parent
ed47ecfc46
commit
c9408c027e
|
@ -2,13 +2,14 @@
|
|||
namespace MediaWiki\Skins\Vector\Components;
|
||||
|
||||
use Language;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use MediaWiki\Languages\LanguageConverterFactory;
|
||||
use MediaWiki\StubObject\StubUserLang;
|
||||
|
||||
/**
|
||||
* VectorComponentVariants component
|
||||
*/
|
||||
class VectorComponentVariants implements VectorComponent {
|
||||
private LanguageConverterFactory $languageConverterFactory;
|
||||
/** @var array */
|
||||
private $menuData;
|
||||
/** @var Language|StubUserLang */
|
||||
|
@ -17,11 +18,18 @@ class VectorComponentVariants implements VectorComponent {
|
|||
private $ariaLabel;
|
||||
|
||||
/**
|
||||
* @param LanguageConverterFactory $languageConverterFactory
|
||||
* @param array $menuData
|
||||
* @param Language|StubUserLang $pageLang
|
||||
* @param string $ariaLabel
|
||||
*/
|
||||
public function __construct( array $menuData, $pageLang, string $ariaLabel ) {
|
||||
public function __construct(
|
||||
LanguageConverterFactory $languageConverterFactory,
|
||||
array $menuData,
|
||||
$pageLang,
|
||||
string $ariaLabel
|
||||
) {
|
||||
$this->languageConverterFactory = $languageConverterFactory;
|
||||
$this->menuData = $menuData;
|
||||
$this->pageLang = $pageLang;
|
||||
$this->ariaLabel = $ariaLabel;
|
||||
|
@ -32,8 +40,7 @@ class VectorComponentVariants implements VectorComponent {
|
|||
* @return string
|
||||
*/
|
||||
private function getDropdownLabel(): string {
|
||||
$languageConverterFactory = MediaWikiServices::getInstance()->getLanguageConverterFactory();
|
||||
$converter = $languageConverterFactory->getLanguageConverter( $this->pageLang );
|
||||
$converter = $this->languageConverterFactory->getLanguageConverter( $this->pageLang );
|
||||
return $this->pageLang->getVariantname(
|
||||
$converter->getPreferredVariant()
|
||||
);
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
namespace MediaWiki\Skins\Vector;
|
||||
|
||||
use ExtensionRegistry;
|
||||
use MediaWiki\Languages\LanguageConverterFactory;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use MediaWiki\Skins\Vector\Components\VectorComponentAppearance;
|
||||
use MediaWiki\Skins\Vector\Components\VectorComponentButton;
|
||||
|
@ -32,15 +33,17 @@ class SkinVector22 extends SkinMustache {
|
|||
/** @var null|array for caching purposes */
|
||||
private $languages;
|
||||
|
||||
private LanguageConverterFactory $languageConverterFactory;
|
||||
private FeatureManagerFactory $featureManagerFactory;
|
||||
private ?FeatureManager $featureManager = null;
|
||||
|
||||
public function __construct(
|
||||
LanguageConverterFactory $languageConverterFactory,
|
||||
FeatureManagerFactory $featureManagerFactory,
|
||||
array $options
|
||||
) {
|
||||
parent::__construct( $options );
|
||||
|
||||
$this->languageConverterFactory = $languageConverterFactory;
|
||||
// Cannot use the context in the constructor, setContext is called after construction
|
||||
$this->featureManagerFactory = $featureManagerFactory;
|
||||
}
|
||||
|
@ -413,6 +416,7 @@ class SkinVector22 extends SkinMustache {
|
|||
$title->getLocalURL( [ 'action' => 'edit', 'section' => 'new' ] )
|
||||
) : null,
|
||||
'data-variants' => new VectorComponentVariants(
|
||||
$this->languageConverterFactory,
|
||||
$portlets['data-variants'],
|
||||
$title->getPageLanguage(),
|
||||
$this->msg( 'vector-language-variant-switcher-label' )
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace MediaWiki\Skins\Vector;
|
||||
|
||||
use MediaWiki\Languages\LanguageConverterFactory;
|
||||
use MediaWiki\Skins\Vector\Components\VectorComponentSearchBox;
|
||||
use MediaWiki\Skins\Vector\Components\VectorComponentVariants;
|
||||
use SkinMustache;
|
||||
|
@ -21,6 +22,16 @@ class SkinVectorLegacy extends SkinMustache {
|
|||
private const MENU_TYPE_DROPDOWN = 2;
|
||||
private const MENU_TYPE_PORTAL = 3;
|
||||
|
||||
private LanguageConverterFactory $languageConverterFactory;
|
||||
|
||||
public function __construct(
|
||||
LanguageConverterFactory $languageConverterFactory,
|
||||
array $options
|
||||
) {
|
||||
parent::__construct( $options );
|
||||
$this->languageConverterFactory = $languageConverterFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
|
@ -108,6 +119,7 @@ class SkinVectorLegacy extends SkinMustache {
|
|||
// Hopefully we can revisit and possibly remove this code when the language switcher is moved.
|
||||
if ( $key === 'data-variants' ) {
|
||||
$variant = new VectorComponentVariants(
|
||||
$this->languageConverterFactory,
|
||||
$portletData,
|
||||
$this->getTitle()->getPageLanguage(),
|
||||
$this->msg( 'vector-language-variant-switcher-label' )
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
"vector-2022": {
|
||||
"class": "MediaWiki\\Skins\\Vector\\SkinVector22",
|
||||
"services": [
|
||||
"LanguageConverterFactory",
|
||||
"Vector.FeatureManagerFactory"
|
||||
],
|
||||
"args": [
|
||||
|
@ -108,6 +109,9 @@
|
|||
},
|
||||
"vector": {
|
||||
"class": "MediaWiki\\Skins\\Vector\\SkinVectorLegacy",
|
||||
"services": [
|
||||
"LanguageConverterFactory"
|
||||
],
|
||||
"args": [
|
||||
{
|
||||
"name": "vector",
|
||||
|
|
|
@ -416,6 +416,7 @@ class VectorHooksTest extends MediaWikiIntegrationTestCase {
|
|||
public function testOnSkinTemplateNavigation() {
|
||||
$this->overrideConfigValue( 'VectorUseIconWatch', true );
|
||||
$skin = new SkinVector22(
|
||||
$this->getServiceContainer()->getLanguageConverterFactory(),
|
||||
$this->getServiceContainer()->get( 'Vector.FeatureManagerFactory' ),
|
||||
[ 'name' => 'vector' ]
|
||||
);
|
||||
|
@ -458,6 +459,7 @@ class VectorHooksTest extends MediaWikiIntegrationTestCase {
|
|||
*/
|
||||
public function testUpdateUserLinksItems() {
|
||||
$vector2022Skin = new SkinVector22(
|
||||
$this->getServiceContainer()->getLanguageConverterFactory(),
|
||||
$this->getServiceContainer()->get( 'Vector.FeatureManagerFactory' ),
|
||||
[ 'name' => 'vector-2022' ]
|
||||
);
|
||||
|
@ -471,7 +473,10 @@ class VectorHooksTest extends MediaWikiIntegrationTestCase {
|
|||
'login' => [ 'class' => [], 'icon' => 'login' ],
|
||||
]
|
||||
];
|
||||
$vectorLegacySkin = new SkinVectorLegacy( [ 'name' => 'vector' ] );
|
||||
$vectorLegacySkin = new SkinVectorLegacy(
|
||||
$this->getServiceContainer()->getLanguageConverterFactory(),
|
||||
[ 'name' => 'vector' ]
|
||||
);
|
||||
$contentNavLegacy = [
|
||||
'associated-pages' => [],
|
||||
'views' => [],
|
||||
|
@ -502,6 +507,7 @@ class VectorHooksTest extends MediaWikiIntegrationTestCase {
|
|||
|
||||
// Anon users
|
||||
$skin = new SkinVector22(
|
||||
$this->getServiceContainer()->getLanguageConverterFactory(),
|
||||
$this->getServiceContainer()->get( 'Vector.FeatureManagerFactory' ),
|
||||
[ 'name' => 'vector-2022' ]
|
||||
);
|
||||
|
|
Loading…
Reference in a new issue