From afebb45eb9449cf66d11f23c6c837855aacb7ce9 Mon Sep 17 00:00:00 2001 From: jdlrobson Date: Tue, 19 May 2020 17:19:00 -0700 Subject: [PATCH] SkinTemplateOutputPageBeforeExec is deprecated Instead use SkinAfterPortlet to force the language portal to always display. This will work with all Wikimedia deployed skins that use ULS (note the Minerva skin is not impacted but in future can benefit from this change) Depends-On: I438daa79d3d97e2518e6258c3213a805bd1f30e8 Bug: T253178 Change-Id: I2843edde1bb45c70911d5acf2f7dafdff3bac53e --- extension.json | 1 - includes/UniversalLanguageSelectorHooks.php | 49 ++++++++++++++++++--- 2 files changed, 42 insertions(+), 8 deletions(-) diff --git a/extension.json b/extension.json index c2ab3e55..fa5d9c6f 100644 --- a/extension.json +++ b/extension.json @@ -29,7 +29,6 @@ "PersonalUrls": "UniversalLanguageSelectorHooks::addPersonalBarTrigger", "ResourceLoaderGetConfigVars": "UniversalLanguageSelectorHooks::addConfig", "ResourceLoaderRegisterModules": "UniversalLanguageSelectorHooks::onResourceLoaderRegisterModules", - "SkinTemplateOutputPageBeforeExec": "UniversalLanguageSelectorHooks::onSkinTemplateOutputPageBeforeExec", "UserGetLanguageObject": "UniversalLanguageSelectorHooks::getLanguage" }, "APIModules": { diff --git a/includes/UniversalLanguageSelectorHooks.php b/includes/UniversalLanguageSelectorHooks.php index c3b5b32e..e7b2c4ad 100644 --- a/includes/UniversalLanguageSelectorHooks.php +++ b/includes/UniversalLanguageSelectorHooks.php @@ -26,7 +26,15 @@ class UniversalLanguageSelectorHooks { * Used when extension registration in use which skips the main php file */ public static function setVersionConstant() { + global $wgHooks; define( 'ULS_VERSION', '2018-10-26' ); + // The SkinAfterPortlet hook was introduced in version >= 1.35. + // It is the same as BaseTemplateAfterPortlet with the exception of its parameters. + if ( interface_exists( MediaWiki\Skins\Hook\SkinAfterPortletHook::class ) ) { + $wgHooks['SkinAfterPortlet'][] = "UniversalLanguageSelectorHooks::onSkinAfterPortlet"; + } else { + $wgHooks['BaseTemplateAfterPortlet'][] = "UniversalLanguageSelectorHooks::onBaseTemplateAfterPortlet"; + } } /** @@ -476,15 +484,34 @@ class UniversalLanguageSelectorHooks { } /** - * Hook: SkinTemplateOutputPageBeforeExec - * @param Skin $skin * @param QuickTemplate $template + * @param string $name + * @param string &$content */ - public static function onSkinTemplateOutputPageBeforeExec( Skin $skin, - QuickTemplate $template + public static function onBaseTemplateAfterPortlet( + QuickTemplate $template, + string $name, + string &$content + ) { + self::onSkinAfterPortlet( $template->getSkin(), $name, $content ); + } + + /** + * @param Skin $skin + * @param string $name + * @param string &$content + */ + public static function onSkinAfterPortlet( + Skin $skin, + string $name, + string &$content ) { global $wgULSPosition; + if ( $name !== 'lang' ) { + return; + } + if ( $wgULSPosition !== 'interlanguage' ) { return; } @@ -493,9 +520,17 @@ class UniversalLanguageSelectorHooks { return; } - // Set to an empty array, just to make sure that the section appears - if ( $template->get( 'language_urls' ) === false ) { - $template->set( 'language_urls', [] ); + // An empty span will force the language portal to always display in + // the skins that support it! e.g. Vector. + if ( count( $skin->getLanguages() ) === 0 ) { + // If no languages force it on. + $content .= Html::element( + 'span', + [ + 'class' => 'uls-after-portlet-link', + ], + '' + ); } }