Make ResourceLoaderWikiModule support custom position
authorGilles Dubuc <gdubuc@wikimedia.org>
Fri, 29 May 2015 20:00:17 +0000 (22:00 +0200)
committerBryanDavis <bdavis@wikimedia.org>
Fri, 29 May 2015 20:30:24 +0000 (20:30 +0000)
Bug: T97410
Change-Id: Ib1180c5b2126f4ba8ac5b54578fcce18a3f35d85

includes/resourceloader/ResourceLoaderWikiModule.php

index 4d207f6..74ad774 100644 (file)
@@ -30,6 +30,8 @@
  * Title::isCssJsSubpage.
  */
 class ResourceLoaderWikiModule extends ResourceLoaderModule {
+       /** @var string Position on the page to load this module at */
+       protected $position = 'bottom';
 
        // Origin defaults to users with sitewide authority
        protected $origin = self::ORIGIN_USER_SITEWIDE;
@@ -50,14 +52,21 @@ class ResourceLoaderWikiModule extends ResourceLoaderModule {
         * @param array $options For back-compat, this can be omitted in favour of overwriting getPages.
         */
        public function __construct( array $options = null ) {
-               if ( isset( $options['styles'] ) ) {
-                       $this->styles = $options['styles'];
+               if ( is_null( $options ) ) {
+                       return;
                }
-               if ( isset( $options['scripts'] ) ) {
-                       $this->scripts = $options['scripts'];
-               }
-               if ( isset( $options['group'] ) ) {
-                       $this->group = $options['group'];
+
+               foreach ( $options as $member => $option ) {
+                       switch ( $member ) {
+                               case 'position':
+                                       $this->isPositionDefined = true;
+                                       // Don't break since we need the member set as well
+                               case 'styles':
+                               case 'scripts':
+                               case 'group':
+                                       $this->{$member} = $option;
+                                       break;
+                       }
                }
        }
 
@@ -305,4 +314,8 @@ class ResourceLoaderWikiModule extends ResourceLoaderModule {
                }
                return $this->titleInfo[$hash];
        }
+
+       public function getPosition() {
+               return $this->position;
+       }
 }