Use SkinFactory to register skin, and Config instead of globals

Change-Id: Ic90969e5d71458c880f2b59e160ffedd7a5ac9be
This commit is contained in:
Kunal Mehta 2014-08-13 11:39:38 -07:00
parent 2a1f5b0727
commit 83707028e5
3 changed files with 41 additions and 26 deletions

View file

@ -30,6 +30,14 @@ class SkinVector extends SkinTemplate {
public $skinname = 'vector'; public $skinname = 'vector';
public $stylename = 'Vector'; public $stylename = 'Vector';
public $template = 'VectorTemplate'; public $template = 'VectorTemplate';
/**
* @var Config
*/
private $config;
public function __construct( Config $config ) {
$this->config = $config;
}
protected static $bodyClasses = array( 'vector-animateLayout' ); protected static $bodyClasses = array( 'vector-animateLayout' );
@ -38,8 +46,6 @@ class SkinVector extends SkinTemplate {
* @param OutputPage $out Object to initialize * @param OutputPage $out Object to initialize
*/ */
public function initPage( OutputPage $out ) { public function initPage( OutputPage $out ) {
global $wgLocalStylePath;
parent::initPage( $out ); parent::initPage( $out );
// Append CSS which includes IE only behavior fixes for hover support - // 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'; $min = $this->getRequest()->getFuzzyBool( 'debug' ) ? '' : '.min';
$out->addHeadItem( 'csshover', $out->addHeadItem( 'csshover',
'<!--[if lt IE 7]><style type="text/css">body{behavior:url("' . '<!--[if lt IE 7]><style type="text/css">body{behavior:url("' .
htmlspecialchars( $wgLocalStylePath ) . htmlspecialchars( $this->getConfig()->get( 'LocalStylePath' ) ) .
"/{$this->stylename}/csshover{$min}.htc\")}</style><![endif]-->" "/{$this->stylename}/csshover{$min}.htc\")}</style><![endif]-->"
); );
@ -67,6 +73,13 @@ class SkinVector extends SkinTemplate {
$out->addModuleStyles( $styles ); $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. * Adds classes to the body element.
* *

View file

@ -38,7 +38,29 @@ $wgAutoloadClasses['VectorTemplate'] = __DIR__ . '/VectorTemplate.php';
$wgMessagesDirs['Vector'] = __DIR__ . '/i18n'; $wgMessagesDirs['Vector'] = __DIR__ . '/i18n';
// Register skin // 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 // Register modules
$wgResourceModules['skins.vector.styles'] = array( $wgResourceModules['skins.vector.styles'] = array(
@ -86,19 +108,3 @@ $wgResourceModuleSkinStyles['vector'] = array(
'remoteSkinPath' => 'Vector', 'remoteSkinPath' => 'Vector',
'localBasePath' => __DIR__, '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;

View file

@ -33,12 +33,10 @@ class VectorTemplate extends BaseTemplate {
* Outputs the entire contents of the (X)HTML page * Outputs the entire contents of the (X)HTML page
*/ */
public function execute() { public function execute() {
global $wgVectorUseIconWatch;
// Build additional attributes for navigation urls // Build additional attributes for navigation urls
$nav = $this->data['content_navigation']; $nav = $this->data['content_navigation'];
if ( $wgVectorUseIconWatch ) { if ( $this->config->get( 'VectorUseIconWatch' ) ) {
$mode = $this->getSkin()->getUser()->isWatched( $this->getSkin()->getRelevantTitle() ) $mode = $this->getSkin()->getUser()->isWatched( $this->getSkin()->getRelevantTitle() )
? 'unwatch' ? 'unwatch'
: 'watch'; : 'watch';
@ -362,8 +360,6 @@ class VectorTemplate extends BaseTemplate {
* @param array $elements * @param array $elements
*/ */
protected function renderNavigation( $elements ) { protected function renderNavigation( $elements ) {
global $wgVectorUseSimpleSearch;
// If only one element was given, wrap it in an array, allowing more // If only one element was given, wrap it in an array, allowing more
// flexible arguments // flexible arguments
if ( !is_array( $elements ) ) { if ( !is_array( $elements ) ) {
@ -546,7 +542,7 @@ class VectorTemplate extends BaseTemplate {
<form action="<?php $this->text( 'wgScript' ) ?>" id="searchform"> <form action="<?php $this->text( 'wgScript' ) ?>" id="searchform">
<?php <?php
if ( $wgVectorUseSimpleSearch ) { if ( $this->config->get( 'VectorUseSimpleSearch' ) ) {
?> ?>
<div id="simpleSearch"> <div id="simpleSearch">
<?php <?php