From ff49d0c9be825135b3b10d5aa21dddbece928587 Mon Sep 17 00:00:00 2001 From: Hannes Date: Thu, 28 Jan 2021 20:34:46 +0100 Subject: [PATCH] refactor: Create base partial class --- includes/Partials/Drawer.php | 20 +++--------- includes/Partials/Header.php | 28 +--------------- includes/Partials/Metadata.php | 19 +---------- includes/Partials/Partial.php | 59 ++++++++++++++++++++++++++++++++++ includes/Partials/Theme.php | 19 +---------- 5 files changed, 66 insertions(+), 79 deletions(-) create mode 100644 includes/Partials/Partial.php diff --git a/includes/Partials/Drawer.php b/includes/Partials/Drawer.php index d5e243d6..beb67926 100644 --- a/includes/Partials/Drawer.php +++ b/includes/Partials/Drawer.php @@ -28,7 +28,6 @@ namespace Citizen\Partials; use Exception; use ResourceLoaderSkinModule; use Skin; -use SkinCitizen; /** * Drawer partial of Skin Citizen @@ -38,21 +37,7 @@ use SkinCitizen; * + Special Pages Link * + Upload Link */ -class Drawer { - - /** - * @var Skin - */ - private $skin; - - /** - * Drawer constructor. - * @param SkinCitizen $skin - */ - public function __construct( SkinCitizen $skin ) { - $this->skin = $skin; - } - +final class Drawer extends Partial { /** * Get and pick the correct logo based on types and variants * Based on getLogoData() in MW 1.36 @@ -61,8 +46,10 @@ class Drawer { */ public function getLogoData() : array { $logoData = ResourceLoaderSkinModule::getAvailableLogos( $this->skin->getConfig() ); + // check if the logo supports variants $variantsLogos = $logoData['variants'] ?? null; + if ( $variantsLogos ) { $preferred = $this->skin->getOutput()->getTitle() ->getPageViewLanguage()->getCode(); @@ -74,6 +61,7 @@ class Drawer { } } } + return $logoData; } diff --git a/includes/Partials/Header.php b/includes/Partials/Header.php index dead208e..d194666c 100644 --- a/includes/Partials/Header.php +++ b/includes/Partials/Header.php @@ -25,13 +25,10 @@ declare( strict_types=1 ); namespace Citizen\Partials; -use Citizen\GetConfigTrait; use Linker; use MediaWiki\MediaWikiServices; use MWException; -use OutputPage; use Skin; -use SkinCitizen; use SpecialPage; use Title; @@ -43,30 +40,7 @@ use Title; * - Search * - Theme Toggle */ -class Header { - - use GetConfigTrait; - - /** - * @var Skin - */ - private $skin; - - /** - * Needed for trait - * - * @var OutputPage - */ - private $out; - - /** - * Header constructor. - * @param SkinCitizen $skin - */ - public function __construct( SkinCitizen $skin ) { - $this->skin = $skin; - $this->out = $skin->getOutput(); - } +final class Header extends Partial { /** * Build Personal Tools menu diff --git a/includes/Partials/Metadata.php b/includes/Partials/Metadata.php index cfb9f9c8..bbeae97f 100644 --- a/includes/Partials/Metadata.php +++ b/includes/Partials/Metadata.php @@ -25,26 +25,9 @@ declare( strict_types=1 ); namespace Citizen\Partials; -use Citizen\GetConfigTrait; use Exception; -use OutputPage; -class Metadata { - - use GetConfigTrait; - - /** - * @var OutputPage - */ - private $out; - - /** - * Metadata constructor. - * @param OutputPage $out - */ - public function __construct( OutputPage $out ) { - $this->out = $out; - } +final class Metadata extends Partial { /** * Adds metadata to the output page diff --git a/includes/Partials/Partial.php b/includes/Partials/Partial.php new file mode 100644 index 00000000..707edcdd --- /dev/null +++ b/includes/Partials/Partial.php @@ -0,0 +1,59 @@ +. + * + * @file + * @ingroup Skins + */ + +declare( strict_types=1 ); + +namespace Citizen\Partials; + +use Citizen\GetConfigTrait; +use OutputPage; +use SkinCitizen; + +/** + * The base class for all skin partials + */ +abstract class Partial { + + use GetConfigTrait; + + /** + * @var SkinCitizen + */ + protected $skin; + + /** + * Needed for trait + * + * @var OutputPage + */ + protected $out; + + /** + * Drawer constructor. + * @param SkinCitizen $skin + */ + public function __construct( SkinCitizen $skin ) { + $this->skin = $skin; + $this->out = $skin->getOutput(); + } +} diff --git a/includes/Partials/Theme.php b/includes/Partials/Theme.php index d0941144..40a0c5d5 100644 --- a/includes/Partials/Theme.php +++ b/includes/Partials/Theme.php @@ -25,29 +25,12 @@ declare( strict_types=1 ); namespace Citizen\Partials; -use Citizen\GetConfigTrait; use MediaWiki\MediaWikiServices; -use OutputPage; /** * Theme switcher partial of Skin Citizen */ -class Theme { - - use GetConfigTrait; - - /** - * @var OutputPage - */ - private $out; - - /** - * Theme constructor. - * @param OutputPage $out - */ - public function __construct( OutputPage $out ) { - $this->out = $out; - } +final class Theme extends Partial { /** * Sets the corresponding theme class on the element