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
This commit is contained in:
@@ -29,7 +29,6 @@
|
|||||||
"PersonalUrls": "UniversalLanguageSelectorHooks::addPersonalBarTrigger",
|
"PersonalUrls": "UniversalLanguageSelectorHooks::addPersonalBarTrigger",
|
||||||
"ResourceLoaderGetConfigVars": "UniversalLanguageSelectorHooks::addConfig",
|
"ResourceLoaderGetConfigVars": "UniversalLanguageSelectorHooks::addConfig",
|
||||||
"ResourceLoaderRegisterModules": "UniversalLanguageSelectorHooks::onResourceLoaderRegisterModules",
|
"ResourceLoaderRegisterModules": "UniversalLanguageSelectorHooks::onResourceLoaderRegisterModules",
|
||||||
"SkinTemplateOutputPageBeforeExec": "UniversalLanguageSelectorHooks::onSkinTemplateOutputPageBeforeExec",
|
|
||||||
"UserGetLanguageObject": "UniversalLanguageSelectorHooks::getLanguage"
|
"UserGetLanguageObject": "UniversalLanguageSelectorHooks::getLanguage"
|
||||||
},
|
},
|
||||||
"APIModules": {
|
"APIModules": {
|
||||||
|
|||||||
@@ -26,7 +26,15 @@ class UniversalLanguageSelectorHooks {
|
|||||||
* Used when extension registration in use which skips the main php file
|
* Used when extension registration in use which skips the main php file
|
||||||
*/
|
*/
|
||||||
public static function setVersionConstant() {
|
public static function setVersionConstant() {
|
||||||
|
global $wgHooks;
|
||||||
define( 'ULS_VERSION', '2018-10-26' );
|
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 QuickTemplate $template
|
||||||
|
* @param string $name
|
||||||
|
* @param string &$content
|
||||||
*/
|
*/
|
||||||
public static function onSkinTemplateOutputPageBeforeExec( Skin $skin,
|
public static function onBaseTemplateAfterPortlet(
|
||||||
QuickTemplate $template
|
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;
|
global $wgULSPosition;
|
||||||
|
|
||||||
|
if ( $name !== 'lang' ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if ( $wgULSPosition !== 'interlanguage' ) {
|
if ( $wgULSPosition !== 'interlanguage' ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -493,9 +520,17 @@ class UniversalLanguageSelectorHooks {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set to an empty array, just to make sure that the section appears
|
// An empty span will force the language portal to always display in
|
||||||
if ( $template->get( 'language_urls' ) === false ) {
|
// the skins that support it! e.g. Vector.
|
||||||
$template->set( 'language_urls', [] );
|
if ( count( $skin->getLanguages() ) === 0 ) {
|
||||||
|
// If no languages force it on.
|
||||||
|
$content .= Html::element(
|
||||||
|
'span',
|
||||||
|
[
|
||||||
|
'class' => 'uls-after-portlet-link',
|
||||||
|
],
|
||||||
|
''
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user