From 58c81408f5da6a3e91d9875b62a47d0eeca543d4 Mon Sep 17 00:00:00 2001 From: Gilles Dubuc Date: Tue, 26 May 2015 12:28:02 +0200 Subject: [PATCH] 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 --- ResourceLoaderGeSHiLocalModule.php | 19 +++++++++++++++++++ ResourceLoaderGeSHiModule.php | 22 +++++++++++++++++++--- SyntaxHighlight_GeSHi.class.php | 1 + extension.json | 1 + 4 files changed, 40 insertions(+), 3 deletions(-) diff --git a/ResourceLoaderGeSHiLocalModule.php b/ResourceLoaderGeSHiLocalModule.php index ce62224b..8d6564a7 100644 --- a/ResourceLoaderGeSHiLocalModule.php +++ b/ResourceLoaderGeSHiLocalModule.php @@ -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; + } } diff --git a/ResourceLoaderGeSHiModule.php b/ResourceLoaderGeSHiModule.php index 5ce21aae..047ce6b5 100644 --- a/ResourceLoaderGeSHiModule.php +++ b/ResourceLoaderGeSHiModule.php @@ -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; + } } diff --git a/SyntaxHighlight_GeSHi.class.php b/SyntaxHighlight_GeSHi.class.php index c4f0d0c6..bedab08a 100644 --- a/SyntaxHighlight_GeSHi.class.php +++ b/SyntaxHighlight_GeSHi.class.php @@ -550,6 +550,7 @@ class SyntaxHighlight_GeSHi { foreach ( self::getSupportedLanguages() as $lang ) { $modules["ext.geshi.language.$lang" ] = array( + 'position' => 'top', 'class' => 'ResourceLoaderGeSHiModule', 'lang' => $lang, ); diff --git a/extension.json b/extension.json index 4e78e9d4..2787b1be 100644 --- a/extension.json +++ b/extension.json @@ -24,6 +24,7 @@ }, "ResourceModules": { "ext.geshi.local": { + "position": "top", "class": "ResourceLoaderGeSHiLocalModule" } },