jenkins-bot has submitted this change and it was merged.

Change subject: Hygiene: Allow MFResourceLoaderModule to handle templates and 
files
......................................................................


Hygiene: Allow MFResourceLoaderModule to handle templates and files

* In debug mode use a load.php url if templates or parsed messages
are present
* Make all our modules use MFResourceLoaderModule
* Remove the need for plumbing modules

Change-Id: I02ae1476c1ce9cdf877e2ba24c17db6c26800011
---
M includes/Resources.php
M includes/modules/MFResourceLoaderModule.php
M javascripts/common/application.js
A javascripts/common/templates.js
M tests/modules/MFResourceLoaderModuleTest.php
5 files changed, 137 insertions(+), 157 deletions(-)

Approvals:
  JGonera: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/Resources.php b/includes/Resources.php
index 556f8b5..670d4c1 100644
--- a/includes/Resources.php
+++ b/includes/Resources.php
@@ -28,19 +28,11 @@
 $remoteExtPath = 'MobileFrontend';
 
 /**
- * A boilerplate containing common properties for all RL modules served to 
mobile site
+ * A boilerplate for the MFResourceLoaderModule that supports templates
  */
 $wgMFMobileResourceBoilerplate = array(
        'localBasePath' => $localBasePath,
        'remoteExtPath' => $remoteExtPath,
-       'targets' => array( 'mobile', 'desktop' ),
-);
-
-/**
- * A boilerplate for the MFResourceLoaderModule that supports templates
- */
-$wgMFMobileResourceTemplateBoilerplate = array(
-       'localBasePath' => $localBasePath,
        'localTemplateBasePath' => $localBasePath . '/templates',
        'class' => 'MFResourceLoaderModule',
 );
@@ -70,6 +62,17 @@
 );
 
 $wgResourceModules = array_merge( $wgResourceModules, array(
+       // FIXME: Upstream to core
+       'mobile.templates' => array(
+               'localBasePath' => $localBasePath,
+               'remoteExtPath' => $remoteExtPath,
+               'scripts' => array(
+                       'javascripts/externals/hogan.js',
+                       'javascripts/common/templates.js'
+               ),
+               'targets' => array( 'mobile', 'desktop' ),
+       ),
+
        // EventLogging
        'mobile.loggingSchemas' => $wgMFMobileResourceBoilerplate + array(
                'dependencies' => array(
@@ -77,7 +80,7 @@
                ),
                'scripts' => array(
                        'javascripts/loggingSchemas/MobileWebClickTracking.js',
-               )
+               ),
        ),
 
        'mobile.file.scripts' => $wgMFMobileResourceBoilerplate + array(
@@ -134,9 +137,9 @@
        'mobile.startup' => $wgMFMobileResourceBoilerplate + array(
                'dependencies' => array(
                        'mobile.head',
+                       'mobile.templates',
                ),
                'scripts' => array(
-                       'javascripts/externals/hogan.js',
                        'javascripts/common/Router.js',
                        'javascripts/common/api.js',
                        'javascripts/common/PageApi.js',
@@ -147,64 +150,15 @@
                'position' => 'bottom',
        ),
 
-       'mobile.stable.plumbing' => array(
-               'messages' => array(
-                       // page.js
-                       'mobile-frontend-talk-overlay-header',
-                       'mobile-frontend-language-article-heading',
-                       // editor.js
-                       'mobile-frontend-editor-disabled',
-                       'mobile-frontend-editor-unavailable',
-                       'mobile-frontend-editor-cta',
-                       'mobile-frontend-editor-edit',
-                       // modules/editor/EditorOverlay.js and modules/talk.js
-                       'mobile-frontend-editor-save',
-               ),
-               'localBasePath' => $localBasePath,
-               'localTemplateBasePath' => $localBasePath . '/templates',
-               'templates' => array(
-                       'LoadingOverlay',
-                       'section',
-                       'wikitext/commons-upload',
-                       // LanguageOverlay.js
-                       'overlays/languages',
-                       'overlay',
-                       'overlays/cleanup',
-                       // search-2.js
-                       'articleList',
-                       'overlays/search/search',
-                       // page.js
-                       'page',
-                       'languageSection',
-                       // PhotoUploaderButton.js
-                       // For new page action menu
-                       'uploads/LeadPhotoUploaderButton',
-                       // FIXME: this should be in special.uploads.plumbing 
(need to split
-                       // code in PhotoUploaderButton.js into separate files 
too)
-                       'uploads/PhotoUploaderButton',
-
-                       'ctaDrawer',
-                       // mf-references.js
-                       'ReferencesDrawer',
-               ),
-               'class' => 'MFResourceLoaderModule',
-       ),
-
        'mobile.editor' => $wgMFMobileResourceBoilerplate + array(
                'dependencies' => array(
                        'mobile.stable',
-                       'mobile.editor.plumbing',
+                       'mobile.templates',
                ),
                'scripts' => array(
                        'javascripts/modules/editor/EditorApi.js',
                        'javascripts/modules/editor/EditorOverlay.js',
                ),
-       ),
-
-       'mobile.editor.plumbing' => array(
-               'class' => 'MFResourceLoaderModule',
-               'localBasePath' => $localBasePath,
-               'localTemplateBasePath' => $localBasePath . '/templates',
                'templates' => array(
                        'overlays/editor',
                ),
@@ -235,7 +189,7 @@
        'mobile.uploads' => $wgMFMobileResourceBoilerplate + array(
                'dependencies' => array(
                        'mobile.stable',
-                       'mobile.uploads.plumbing',
+                       'mobile.templates',
                ),
                'scripts' => array(
                        'javascripts/modules/uploads/LearnMoreOverlay.js',
@@ -246,12 +200,6 @@
                        'javascripts/modules/uploads/LeadPhoto.js',
                        'javascripts/modules/uploads/PhotoUploader.js',
                ),
-       ),
-
-       'mobile.uploads.plumbing' => array(
-               'class' => 'MFResourceLoaderModule',
-               'localBasePath' => $localBasePath,
-               'localTemplateBasePath' => $localBasePath . '/templates',
                'templates' => array(
                        'uploads/PhotoUploadPreview',
                        'uploads/PhotoUploadProgress',
@@ -306,23 +254,17 @@
                ),
        ),
 
-       'mobile.beta.plumbing' => array(
-               'localBasePath' => $localBasePath,
-               'localTemplateBasePath' => $localBasePath . '/templates',
+       'mobile.beta.common' => $wgMFMobileResourceBoilerplate + array(
                'templates' => array(
                        // NotificationsOverlay.js
                        'overlays/notifications',
                        // page.js
                        'pageActionTutorial',
                ),
-               'class' => 'MFResourceLoaderModule',
-       ),
-
-       'mobile.beta.common' => $wgMFMobileResourceBoilerplate + array(
                'dependencies' => array(
-                       'mobile.beta.plumbing',
                        'mobile.stable.common',
                        'mobile.loggingSchemas',
+                       'mobile.templates',
                ),
                'scripts' => array(
                        'javascripts/common/ContentOverlay.js',
@@ -376,18 +318,12 @@
        'mobile.talk' => $wgMFMobileResourceBoilerplate + array(
                'dependencies' => array(
                        'mobile.beta',
-                       'mobile.talk.plumbing',
+                       'mobile.templates',
                ),
                'scripts' => array(
                        'javascripts/modules/talk/TalkSectionOverlay.js',
                        'javascripts/modules/talk/TalkOverlay.js',
                ),
-       ),
-
-       'mobile.talk.plumbing' => array(
-               'class' => 'MFResourceLoaderModule',
-               'localBasePath' => $localBasePath,
-               'localTemplateBasePath' => $localBasePath . '/templates',
                'templates' => array(
                        // talk.js
                        'overlays/talk',
@@ -410,19 +346,16 @@
                ),
        ),
 
-       'mobile.alpha.plumbing' => $wgMFMobileResourceTemplateBoilerplate + 
array(
+       'mobile.alpha' => $wgMFMobileResourceBoilerplate + array(
                'templates' => array(
                        'overlays/nearby',
                        'modules/ImageOverlay',
                ),
-       ),
-
-       'mobile.alpha' => $wgMFMobileResourceBoilerplate + array(
                'dependencies' => array(
                        'mobile.stable',
                        'mobile.beta',
-                       'mobile.alpha.plumbing',
                        'mobile.nearby',
+                       'mobile.templates',
                ),
                'messages' => array(
 
@@ -475,10 +408,34 @@
        'mobile.stable.common' => $wgMFMobileResourceBoilerplate + array(
                'dependencies' => array(
                        'mobile.startup',
-                       'mobile.stable.plumbing',
                        'mobile.toast.styles',
                        'mediawiki.jqueryMsg',
                        'mediawiki.util',
+               ),
+               'templates' => array(
+                       'LoadingOverlay',
+                       'section',
+                       'wikitext/commons-upload',
+                       // LanguageOverlay.js
+                       'overlays/languages',
+                       'overlay',
+                       'overlays/cleanup',
+                       // search-2.js
+                       'articleList',
+                       'overlays/search/search',
+                       // page.js
+                       'page',
+                       'languageSection',
+                       // PhotoUploaderButton.js
+                       // For new page action menu
+                       'uploads/LeadPhotoUploaderButton',
+                       // FIXME: this should be in special.uploads (need to 
split
+                       // code in PhotoUploaderButton.js into separate files 
too)
+                       'uploads/PhotoUploaderButton',
+
+                       'ctaDrawer',
+                       // mf-references.js
+                       'ReferencesDrawer',
                ),
                'scripts' => array(
                        'javascripts/common/View.js',
@@ -511,6 +468,17 @@
                        'mobile-frontend-language-header',
                        'mobile-frontend-language-site-choose',
                        'mobile-frontend-language-footer',
+
+                       // page.js
+                       'mobile-frontend-talk-overlay-header',
+                       'mobile-frontend-language-article-heading',
+                       // editor.js
+                       'mobile-frontend-editor-disabled',
+                       'mobile-frontend-editor-unavailable',
+                       'mobile-frontend-editor-cta',
+                       'mobile-frontend-editor-edit',
+                       // modules/editor/EditorOverlay.js and modules/talk.js
+                       'mobile-frontend-editor-save',
                ),
        ),
 
@@ -520,6 +488,7 @@
                        'mobile.stable.common',
                        'mediawiki.util',
                        'mobile.stable.styles',
+                       'mobile.templates',
                ),
                'scripts' => array(
                        'javascripts/modules/editor/editor.js',
@@ -610,13 +579,6 @@
                ),
        ),
 
-       'mobile.nearby.plumbing' => $wgMFMobileResourceTemplateBoilerplate + 
array(
-               'templates' => array(
-                       'articleList',
-                       'overlays/pagePreview',
-               ),
-       ),
-
        'mobile.nearby.previews' => $wgMFMobileResourceBoilerplate + array(
                'dependencies' => array(
                        'mobile.nearby.scripts',
@@ -639,12 +601,16 @@
        ),
 
        'mobile.nearby' => $wgMFMobileResourceBoilerplate + array(
+               'templates' => array(
+                       'articleList',
+                       'overlays/pagePreview',
+               ),
                'dependencies' => array(
                        'mobile.stable.common',
                        'mobile.nearby.styles',
-                       'mobile.nearby.plumbing',
                        'jquery.json',
                        'mediawiki.language',
+                       'mobile.templates',
                ),
                'messages' => array(
                        // NearbyApi.js
@@ -745,7 +711,7 @@
                ),
        ),
        // Special:Uploads
-       'mobile.special.uploads.plumbing' => 
$wgMFMobileResourceTemplateBoilerplate + array(
+       'mobile.special.uploads.plumbing' => $wgMFMobileResourceBoilerplate + 
array(
                'templates' => array(
                        'specials/uploads/carousel',
                        'specials/uploads/photo',
@@ -754,10 +720,15 @@
        ),
        'mobile.uploads.scripts' => $wgMFMobileResourceBoilerplate + array(
                'dependencies' => array(
-                       'mobile.special.uploads.plumbing',
                        'mobile.stable.styles',
                        'mobile.stable.common',
                        'mobile.uploads',
+                       'mobile.templates',
+               ),
+               'templates' => array(
+                       'specials/uploads/carousel',
+                       'specials/uploads/photo',
+                       'specials/uploads/userGallery',
                ),
                'messages' => array(
                        'mobile-frontend-photo-upload-generic',
diff --git a/includes/modules/MFResourceLoaderModule.php 
b/includes/modules/MFResourceLoaderModule.php
index 5961827..d33e227 100644
--- a/includes/modules/MFResourceLoaderModule.php
+++ b/includes/modules/MFResourceLoaderModule.php
@@ -3,7 +3,7 @@
  * ResourceLoaderModule subclass for mobile
  * Allows basic parsing of messages without arguments
  */
-class MFResourceLoaderModule extends ResourceLoaderModule {
+class MFResourceLoaderModule extends ResourceLoaderFileModule {
        protected $dependencies = array();
        protected $parsedMessages = array();
        protected $messages = array();
@@ -12,6 +12,8 @@
        protected $targets = array( 'mobile', 'desktop' );
        /** String: The local path to where templates are located, see 
__construct() */
        protected $localTemplateBasePath = '';
+       private $hasParsedMessages = false;
+       private $hasTemplates = false;
 
        /**
         * Registers core modules and runs registration hooks.
@@ -20,24 +22,22 @@
                foreach ( $options as $member => $option ) {
                        switch ( $member ) {
                                case 'localTemplateBasePath':
-                               case 'localBasePath':
                                        $this->{$member} = (string) $option;
                                        break;
                                case 'templates':
-                               case 'dependencies':
+                                       $this->hasTemplates = true;
                                        $this->{$member} = (array) $option;
                                        break;
                                case 'messages':
                                        $this->processMessages( $option );
+                                       $this->hasParsedMessages = true;
+                                       // Prevent them being reinitialised 
when parent construct is called.
+                                       unset( $options[$member] );
                                        break;
                        }
                }
 
-               // MFResourceLoaderModule must depend on mobile.startup because
-               // mobile.startup contains code responsible for compiling 
templates
-               if ( !in_array( 'mobile.startup', $this->dependencies ) ) {
-                       $this->dependencies[] = 'mobile.startup';
-               }
+               parent::__construct( $options );
        }
 
        /**
@@ -79,7 +79,7 @@
                        $localPath = $this->getLocalTemplatePath( $templateName 
);
                        if ( file_exists( $localPath ) ) {
                                $content = file_get_contents( $localPath );
-                               $js .= Xml::encodeJsCall( 
'mw.mobileFrontend.template.add', array( $templateName, $content ) );
+                               $js .= Xml::encodeJsCall( 'mw.template.add', 
array( $templateName, $content ) );
                        } else {
                                $msg = __METHOD__.": template file not found: 
\"$localPath\"";
                                throw new MWException( $msg );
@@ -129,6 +129,11 @@
                return $this->messages;
        }
 
+       public function supportsURLLoading() {
+               // When templates or parsed messages are present in the module 
force load.php urls
+               return $this->hasTemplates || $this->hasParsedMessages ? false 
: true;
+       }
+
        /**
         * Gets all scripts for a given context concatenated together including 
processed messages
         *
@@ -136,7 +141,8 @@
         * @return String: JavaScript code for $context
         */
        public function getScript( ResourceLoaderContext $context ) {
-               return $this->addParsedMessages() . $this->getTemplateScript();
+               $script = parent::getScript( $context );
+               return $this->addParsedMessages() . $this->getTemplateScript() 
. $script;
        }
 
        /**
diff --git a/javascripts/common/application.js 
b/javascripts/common/application.js
index de06fd2..5bb215b 100644
--- a/javascripts/common/application.js
+++ b/javascripts/common/application.js
@@ -3,44 +3,7 @@
 ( function( M, $ ) {
        var Router = M.require( 'Router' ),
                PageApi = M.require( 'PageApi' ),
-               $viewportMeta, viewport,
-               template,
-               templates = {};
-
-       template = {
-               /**
-                * Define template using html. Compiles newly added templates
-                *
-                * @param {string} name: Name of template to add
-                * @param {string} markup: Associated markup (html)
-                */
-               add: function( name, markup ) {
-                       templates[ name ] = this.compile( markup );
-               },
-               /**
-                * Retrieve defined template
-                *
-                * @param {string} name: Name of template to be retrieved
-                * @return {Hogan.Template}
-                * accepts template data object as its argument.
-                */
-               get: function( name ) {
-                       if ( !templates[ name ] ) {
-                               throw new Error( 'Template not found: ' + name 
);
-                       }
-                       return templates[ name ];
-               },
-               /**
-                * Wraps our template engine of choice (currently Hogan).
-                *
-                * @param {string} templateBody Template body.
-                * @return {Hogan.Template}
-                * accepts template data object as its argument.
-                */
-               compile: function( templateBody ) {
-                       return Hogan.compile( templateBody );
-               }
-       };
+               $viewportMeta, viewport;
 
        // http://www.quirksmode.org/blog/archives/2010/12/the_fifth_posit.html
        // https://github.com/Modernizr/Modernizr/issues/167
@@ -288,7 +251,8 @@
                supportsGeoLocation: supportsGeoLocation,
                supportsPositionFixed: supportsPositionFixed,
                prettyEncodeTitle: prettyEncodeTitle,
-               template: template,
+               // FIXME: Replace all instances of M.template with mw.template
+               template: mw.template,
                unlockViewport: unlockViewport,
                router: new Router(),
                pageApi: new PageApi(),
diff --git a/javascripts/common/templates.js b/javascripts/common/templates.js
new file mode 100644
index 0000000..d5d397d
--- /dev/null
+++ b/javascripts/common/templates.js
@@ -0,0 +1,43 @@
+( function( $ ) {
+var
+       templates = {},
+       template = {
+               /**
+                * Define template using html. Compiles newly added templates
+                *
+                * @param {string} name: Name of template to add
+                * @param {string} markup: Associated markup (html)
+                */
+               add: function( name, markup ) {
+                       templates[ name ] = this.compile( markup );
+               },
+               /**
+                * Retrieve defined template
+                *
+                * @param {string} name: Name of template to be retrieved
+                * @return {Hogan.Template}
+                * accepts template data object as its argument.
+                */
+               get: function( name ) {
+                       if ( !templates[ name ] ) {
+                               throw new Error( 'Template not found: ' + name 
);
+                       }
+                       return templates[ name ];
+               },
+               /**
+                * Wraps our template engine of choice (currently Hogan).
+                *
+                * @param {string} templateBody Template body.
+                * @return {Hogan.Template}
+                * accepts template data object as its argument.
+                */
+               compile: function( templateBody ) {
+                       return Hogan.compile( templateBody );
+               }
+       };
+
+       $.extend( mw, {
+               template: template
+       } );
+
+}( jQuery ) );
diff --git a/tests/modules/MFResourceLoaderModuleTest.php 
b/tests/modules/MFResourceLoaderModuleTest.php
index f6ea0df..7233120 100644
--- a/tests/modules/MFResourceLoaderModuleTest.php
+++ b/tests/modules/MFResourceLoaderModuleTest.php
@@ -27,6 +27,11 @@
                        )
                ),
 
+               'dependenciesTemplatesModule' => array(
+                       'templates' => array( 'foo' ),
+                       'dependencies' => array( 'dependency1', 'dependency2' )
+               ),
+
                'dependenciesModule' => array(
                        'dependencies' => array( 'dependency1', 'dependency2' )
                )
@@ -145,14 +150,5 @@
                $js = $rl->getTemplateScript();
 
                $this->assertEquals( $js, $expected );
-       }
-
-       public function testGetDependencies() {
-               $rlModule = new MFResourceLoaderModule( 
$this->modules['dependenciesModule'] );
-               $dependencies = $rlModule->getDependencies();
-
-               $this->assertContains( 'dependency1', $dependencies );
-               $this->assertContains( 'dependency2', $dependencies );
-               $this->assertContains( 'mobile.startup', $dependencies );
        }
 }

-- 
To view, visit https://gerrit.wikimedia.org/r/86290
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I02ae1476c1ce9cdf877e2ba24c17db6c26800011
Gerrit-PatchSet: 10
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: Jdlrobson <[email protected]>
Gerrit-Reviewer: JGonera <[email protected]>
Gerrit-Reviewer: Jdlrobson <[email protected]>
Gerrit-Reviewer: Kaldari <[email protected]>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to