mirror of
https://gerrit.wikimedia.org/r/mediawiki/skins/Vector.git
synced 2024-11-24 15:53:46 +00:00
Overriding getPortletData will soon be deprecated
See Ib8fc4cd183df3ed059a2d7000c56ab0a11d34f47 Bug: T299456 Change-Id: I743088e2665f8b304fb6273e912f9a6e5ff92e66
This commit is contained in:
parent
c59a3b756f
commit
9b8d1b64cb
|
@ -587,9 +587,10 @@ class SkinVector extends SkinMustache {
|
||||||
$skin = $this;
|
$skin = $this;
|
||||||
$out = $skin->getOutput();
|
$out = $skin->getOutput();
|
||||||
$title = $out->getTitle();
|
$title = $out->getTitle();
|
||||||
$parentData = parent::getTemplateData();
|
$parentData = $this->decoratePortletsData( parent::getTemplateData() );
|
||||||
$featureManager = VectorServices::getFeatureManager();
|
$featureManager = VectorServices::getFeatureManager();
|
||||||
|
|
||||||
|
//
|
||||||
// Naming conventions for Mustache parameters.
|
// Naming conventions for Mustache parameters.
|
||||||
//
|
//
|
||||||
// Value type (first segment):
|
// Value type (first segment):
|
||||||
|
@ -927,29 +928,62 @@ class SkinVector extends SkinMustache {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* Performs updates to all portlets.
|
||||||
|
*
|
||||||
|
* @param array $data
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
protected function getPortletData(
|
private function decoratePortletsData( array $data ) {
|
||||||
$label,
|
foreach ( $data['data-portlets'] as $key => $pData ) {
|
||||||
array $urls = []
|
$data['data-portlets'][$key] = $this->decoratePortletData(
|
||||||
|
$key,
|
||||||
|
$pData
|
||||||
|
);
|
||||||
|
}
|
||||||
|
$sidebar = $data['data-portlets-sidebar'];
|
||||||
|
$sidebar['data-portlets-first'] = $this->decoratePortletData(
|
||||||
|
'navigation', $sidebar['data-portlets-first']
|
||||||
|
);
|
||||||
|
$rest = $sidebar['array-portlets-rest'];
|
||||||
|
foreach ( $rest as $key => $pData ) {
|
||||||
|
$rest[$key] = $this->decoratePortletData(
|
||||||
|
$pData['id'], $pData
|
||||||
|
);
|
||||||
|
}
|
||||||
|
$sidebar['array-portlets-rest'] = $rest;
|
||||||
|
$data['data-portlets-sidebar'] = $sidebar;
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Performs the following updates to portlet data:
|
||||||
|
* - Adds concept of menu types
|
||||||
|
* - Marks the selected variant in the variant portlet
|
||||||
|
* - modifies tooltips of personal and user-menu portlets
|
||||||
|
* @param string $key
|
||||||
|
* @param array $portletData
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
private function decoratePortletData(
|
||||||
|
string $key,
|
||||||
|
array $portletData
|
||||||
): array {
|
): array {
|
||||||
switch ( $label ) {
|
switch ( $key ) {
|
||||||
case 'user-menu':
|
case 'data-user-menu':
|
||||||
case 'actions':
|
case 'data-actions':
|
||||||
case 'variants':
|
case 'data-variants':
|
||||||
$type = self::MENU_TYPE_DROPDOWN;
|
$type = self::MENU_TYPE_DROPDOWN;
|
||||||
break;
|
break;
|
||||||
case 'views':
|
case 'data-views':
|
||||||
case 'namespaces':
|
case 'data-namespaces':
|
||||||
$type = self::MENU_TYPE_TABS;
|
$type = self::MENU_TYPE_TABS;
|
||||||
break;
|
break;
|
||||||
case 'notifications':
|
case 'data-notifications':
|
||||||
case 'personal':
|
case 'data-personal':
|
||||||
case 'user-page':
|
case 'data-user-page':
|
||||||
$type = self::MENU_TYPE_DEFAULT;
|
$type = self::MENU_TYPE_DEFAULT;
|
||||||
break;
|
break;
|
||||||
case 'lang':
|
case 'data-languages':
|
||||||
$type = $this->isLanguagesInContent() ?
|
$type = $this->isLanguagesInContent() ?
|
||||||
self::MENU_TYPE_DROPDOWN : self::MENU_TYPE_PORTAL;
|
self::MENU_TYPE_DROPDOWN : self::MENU_TYPE_PORTAL;
|
||||||
break;
|
break;
|
||||||
|
@ -959,20 +993,19 @@ class SkinVector extends SkinMustache {
|
||||||
}
|
}
|
||||||
|
|
||||||
$portletData = $this->decoratePortletClass(
|
$portletData = $this->decoratePortletClass(
|
||||||
parent::getPortletData( $label, $urls ),
|
$portletData,
|
||||||
$type
|
$type
|
||||||
);
|
);
|
||||||
|
|
||||||
// Special casing for Variant to change label to selected.
|
// Special casing for Variant to change label to selected.
|
||||||
// Hopefully we can revisit and possibly remove this code when the language switcher is moved.
|
// Hopefully we can revisit and possibly remove this code when the language switcher is moved.
|
||||||
if ( $label === 'variants' ) {
|
if ( $key === 'data-variants' ) {
|
||||||
foreach ( $urls as $key => $item ) {
|
$languageConverterFactory = MediaWikiServices::getInstance()->getLanguageConverterFactory();
|
||||||
// Check the class of the item for a `selected` class and if so, propagate the items
|
$pageLang = $this->getTitle()->getPageLanguage();
|
||||||
// label to the main label.
|
$converter = $languageConverterFactory->getLanguageConverter( $pageLang );
|
||||||
if ( isset( $item['class'] ) && stripos( $item['class'], 'selected' ) !== false ) {
|
$portletData['label'] = $pageLang->getVariantname(
|
||||||
$portletData['label'] = $item['text'];
|
$converter->getPreferredVariant()
|
||||||
}
|
);
|
||||||
}
|
|
||||||
// T289523 Add aria-label data to the language variant switcher.
|
// T289523 Add aria-label data to the language variant switcher.
|
||||||
$portletData['aria-label'] = $this->msg( 'vector-language-variant-switcher-label' );
|
$portletData['aria-label'] = $this->msg( 'vector-language-variant-switcher-label' );
|
||||||
}
|
}
|
||||||
|
@ -981,13 +1014,13 @@ class SkinVector extends SkinMustache {
|
||||||
// Vector, the "tooltip-p-personal" key is set to "User menu" which is appropriate for the user icon (dropdown
|
// Vector, the "tooltip-p-personal" key is set to "User menu" which is appropriate for the user icon (dropdown
|
||||||
// indicator for user links menu) for logged-in users. This overrides the tooltip for the user links menu icon
|
// indicator for user links menu) for logged-in users. This overrides the tooltip for the user links menu icon
|
||||||
// which is an ellipsis for anonymous users.
|
// which is an ellipsis for anonymous users.
|
||||||
if ( $label === 'user-menu' && !$this->isLegacy() && !$this->loggedin ) {
|
if ( $key === 'data-user-menu' && !$this->isLegacy() && !$this->loggedin ) {
|
||||||
$portletData['html-tooltip'] = Linker::tooltip( 'vector-anon-user-menu-title' );
|
$portletData['html-tooltip'] = Linker::tooltip( 'vector-anon-user-menu-title' );
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set tooltip to empty string for the personal menu for both logged-in and logged-out users to avoid showing
|
// Set tooltip to empty string for the personal menu for both logged-in and logged-out users to avoid showing
|
||||||
// the tooltip for legacy version.
|
// the tooltip for legacy version.
|
||||||
if ( $label === 'personal' && $this->isLegacy() ) {
|
if ( $key === 'data-personal' && $this->isLegacy() ) {
|
||||||
$portletData['html-tooltip'] = '';
|
$portletData['html-tooltip'] = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue