Explicitly define module position

Style modules currently added through addModuleStyles default
to being in the head ("top" position). This is an unhealthy default,
since only critical styles that are needed at pageload should be
in the head. In order to be able to switch the default to "bottom",
existing module positions have to be defined explicitly.

Bug: T97410
Change-Id: Ie120a781ac1950abd7963d6f722aa316b5542b51
This commit is contained in:
Gilles Dubuc 2015-05-26 12:28:02 +02:00 committed by BryanDavis
parent 0347b58a87
commit 58c81408f5
4 changed files with 40 additions and 3 deletions

View file

@ -20,6 +20,21 @@
* Custom ResourceLoader module that loads a Geshi.css per-wiki.
*/
class ResourceLoaderGeSHiLocalModule extends ResourceLoaderWikiModule {
/** @var string Position on the page to load this module at */
protected $position = 'bottom';
public function __construct( $options ) {
foreach ( $options as $member => $option ) {
switch ( $member ) {
case 'position':
$this->isPositionDefined = true;
$this->{$member} = (string)$option;
break;
}
}
}
/**
* @param $context ResourceLoaderContext
* @return array
@ -34,4 +49,8 @@ class ResourceLoaderGeSHiLocalModule extends ResourceLoaderWikiModule {
'MediaWiki:Geshi.css' => array( 'type' => 'style' ),
);
}
public function getPosition() {
return $this->position;
}
}

View file

@ -19,16 +19,28 @@
class ResourceLoaderGeSHiModule extends ResourceLoaderModule {
/** @var string Position on the page to load this module at */
protected $position = 'bottom';
/**
* @var string
*/
protected $lang;
/**
* @param array $info Module definition.
* @param array $options Module definition.
*/
function __construct( $info ) {
$this->lang = $info['lang'];
function __construct( $options ) {
foreach ( $options as $member => $option ) {
switch ( $member ) {
case 'position':
$this->isPositionDefined = true;
// Don't break, we want to set the property as well
case 'lang':
$this->{$member} = (string)$option;
break;
}
}
}
/**
@ -77,4 +89,8 @@ class ResourceLoaderGeSHiModule extends ResourceLoaderModule {
);
return $summary;
}
public function getPosition() {
return $this->position;
}
}

View file

@ -550,6 +550,7 @@ class SyntaxHighlight_GeSHi {
foreach ( self::getSupportedLanguages() as $lang ) {
$modules["ext.geshi.language.$lang" ] = array(
'position' => 'top',
'class' => 'ResourceLoaderGeSHiModule',
'lang' => $lang,
);

View file

@ -24,6 +24,7 @@
},
"ResourceModules": {
"ext.geshi.local": {
"position": "top",
"class": "ResourceLoaderGeSHiLocalModule"
}
},