From d4befe8c397c0b8cb6fdc82daaab78c92a476b6c Mon Sep 17 00:00:00 2001 From: jdlrobson Date: Mon, 20 Sep 2021 19:12:48 -0700 Subject: [PATCH] Do not use User session in the constructor This is going to be forbidden going forward. The legacy lookup and overrides are deferred until they are actually needed to keep the constructor cheap Bug: T289163 Change-Id: Ib23360e3439abc828404c1de8e0906915ee7d8b6 --- includes/SkinVector.php | 52 ++++++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 22 deletions(-) diff --git a/includes/SkinVector.php b/includes/SkinVector.php index f097a50..2839d99 100644 --- a/includes/SkinVector.php +++ b/includes/SkinVector.php @@ -92,28 +92,6 @@ class SkinVector extends SkinMustache { return !$isLatestSkinFeatureEnabled; } - /** - * Overrides template, styles and scripts module when skin operates - * in legacy mode. - * - * @inheritDoc - * @param array|null $options Note; this param is only optional for internal purpose. - * Do not instantiate Vector, use SkinFactory to create the object instead. - * If you absolutely must to, this paramater is required; you have to provide the - * skinname with the `name` key. That's do it with `new SkinVector( ['name' => 'vector'] )`. - * Failure to do that, will lead to fatal exception. - */ - public function __construct( $options = [] ) { - if ( $this->isLegacy() ) { - $options['scripts'] = [ 'skins.vector.legacy.js' ]; - $options['styles'] = [ 'skins.vector.styles.legacy' ]; - $options['template'] = 'skin-legacy'; - unset( $options['link'] ); - } - - parent::__construct( $options ); - } - /** * Calls getLanguages with caching. * @return array @@ -318,6 +296,36 @@ class SkinVector extends SkinMustache { Hooks::onSkinTemplateNavigation( $skin, $content_navigation ); } + /** + * Updates modules for use in legacy Vector skin. + * Do not repeat this pattern. Will be addressed in T291098. + * @inheritDoc + */ + public function getDefaultModules() { + // FIXME: Do not repeat this pattern. Will be addressed in T291098. + if ( $this->isLegacy() ) { + $this->options['scripts'] = [ 'skins.vector.legacy.js' ]; + $this->options['styles'] = [ 'skins.vector.styles.legacy' ]; + } + return parent::getDefaultModules(); + } + + /** + * Updates HTML generation for use in legacy Vector skin. + * Do not repeat this pattern. Will be addressed in T291098. + * + * @inheritDoc + */ + public function generateHTML() { + if ( $this->isLegacy() ) { + $this->options['template'] = 'skin-legacy'; + // Does not apply to gadgets adding menu items via addPortletLink. Should be + // removed when Ib23360e3439abc828404c1de8e0906915ee7d8b6 is merged. + unset( $this->options['link'] ); + } + return parent::generateHTML(); + } + /** * Generate data needed to generate the sticky header. * Lack of i18n is intentional and will be done as part of follow up work.