From 83707028e54ac5d61e981967ae240535f0ce98b2 Mon Sep 17 00:00:00 2001 From: Kunal Mehta Date: Wed, 13 Aug 2014 11:39:38 -0700 Subject: [PATCH] Use SkinFactory to register skin, and Config instead of globals Change-Id: Ic90969e5d71458c880f2b59e160ffedd7a5ac9be --- SkinVector.php | 19 ++++++++++++++++--- Vector.php | 40 +++++++++++++++++++++++----------------- VectorTemplate.php | 8 ++------ 3 files changed, 41 insertions(+), 26 deletions(-) diff --git a/SkinVector.php b/SkinVector.php index 237a2419b..6ad919dd1 100644 --- a/SkinVector.php +++ b/SkinVector.php @@ -30,6 +30,14 @@ class SkinVector extends SkinTemplate { public $skinname = 'vector'; public $stylename = 'Vector'; public $template = 'VectorTemplate'; + /** + * @var Config + */ + private $config; + + public function __construct( Config $config ) { + $this->config = $config; + } protected static $bodyClasses = array( 'vector-animateLayout' ); @@ -38,8 +46,6 @@ class SkinVector extends SkinTemplate { * @param OutputPage $out Object to initialize */ public function initPage( OutputPage $out ) { - global $wgLocalStylePath; - parent::initPage( $out ); // Append CSS which includes IE only behavior fixes for hover support - @@ -48,7 +54,7 @@ class SkinVector extends SkinTemplate { $min = $this->getRequest()->getFuzzyBool( 'debug' ) ? '' : '.min'; $out->addHeadItem( 'csshover', '" ); @@ -67,6 +73,13 @@ class SkinVector extends SkinTemplate { $out->addModuleStyles( $styles ); } + /** + * Override to pass our Config instance to it + */ + public function setupTemplate( $classname, $repository = false, $cache_dir = false ) { + return new $classname( $this->config ); + } + /** * Adds classes to the body element. * diff --git a/Vector.php b/Vector.php index d16e8bbf1..c736b8d92 100644 --- a/Vector.php +++ b/Vector.php @@ -38,7 +38,29 @@ $wgAutoloadClasses['VectorTemplate'] = __DIR__ . '/VectorTemplate.php'; $wgMessagesDirs['Vector'] = __DIR__ . '/i18n'; // Register skin -$wgValidSkinNames['vector'] = 'Vector'; +SkinFactory::getDefaultInstance()->register( 'vector', 'Vector', function(){ + $config = ConfigFactory::getDefaultInstance()->makeConfig( 'vector' ); + return new SkinVector( $config ); +} ); + +// Register config +$wgConfigRegistry['vector'] = 'GlobalVarConfig::newInstance'; + +// Configuration options +/** + * Search form look. + * - true = use an icon search button + * - false = use Go & Search buttons + */ +$wgVectorUseSimpleSearch = true; + +/** + * Watch and unwatch as an icon rather than a link. + * - true = use an icon watch/unwatch button + * - false = use watch/unwatch text link + */ +$wgVectorUseIconWatch = true; + // Register modules $wgResourceModules['skins.vector.styles'] = array( @@ -86,19 +108,3 @@ $wgResourceModuleSkinStyles['vector'] = array( 'remoteSkinPath' => 'Vector', 'localBasePath' => __DIR__, ); - -// Configuration options - -/** - * Search form look. - * - true = use an icon search button - * - false = use Go & Search buttons - */ -$wgVectorUseSimpleSearch = true; - -/** - * Watch and unwatch as an icon rather than a link. - * - true = use an icon watch/unwatch button - * - false = use watch/unwatch text link - */ -$wgVectorUseIconWatch = true; diff --git a/VectorTemplate.php b/VectorTemplate.php index 291b761c4..7d673f4ab 100644 --- a/VectorTemplate.php +++ b/VectorTemplate.php @@ -33,12 +33,10 @@ class VectorTemplate extends BaseTemplate { * Outputs the entire contents of the (X)HTML page */ public function execute() { - global $wgVectorUseIconWatch; - // Build additional attributes for navigation urls $nav = $this->data['content_navigation']; - if ( $wgVectorUseIconWatch ) { + if ( $this->config->get( 'VectorUseIconWatch' ) ) { $mode = $this->getSkin()->getUser()->isWatched( $this->getSkin()->getRelevantTitle() ) ? 'unwatch' : 'watch'; @@ -362,8 +360,6 @@ class VectorTemplate extends BaseTemplate { * @param array $elements */ protected function renderNavigation( $elements ) { - global $wgVectorUseSimpleSearch; - // If only one element was given, wrap it in an array, allowing more // flexible arguments if ( !is_array( $elements ) ) { @@ -546,7 +542,7 @@ class VectorTemplate extends BaseTemplate {
config->get( 'VectorUseSimpleSearch' ) ) { ?>