Florianschmidtwelzow has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/233481

Change subject: Separate Search Api code from search frontend modules
......................................................................

Separate Search Api code from search frontend modules

* Instead of loading all search code in one module, including all
"backend" and frontend, separate these parts into two (including beta: 4)
modules that are loaded conditionally.

* Merge the module config in the search init script into one object with
all needed information to start the search workflow.

* Add a new event, mobilefrontend.searchModule, which allows a third party
extension (e.g. Wikibase) to replace specific parts of the module config and,
e.g., load it's own api or frontend module (which needs to be compatible with
the MobileFrontend code, though).

Bug: T110069
Change-Id: I4e5979dfd82c370977c76528e898c760c972bec8
---
M includes/Resources.php
R resources/mobile.search.api/SearchApi.js
R resources/mobile.search.beta.api/SearchApi.js
M resources/mobile.search/SearchOverlay.js
M resources/mobile.search/init.js
5 files changed, 46 insertions(+), 15 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MobileFrontend 
refs/changes/81/233481/1

diff --git a/includes/Resources.php b/includes/Resources.php
index a6f1f03..43212ce 100644
--- a/includes/Resources.php
+++ b/includes/Resources.php
@@ -734,13 +734,11 @@
                        'mobile.pagelist.scripts',
                        'mobile.overlays',
                        'mobile.loggingSchemas',
-                       'mediawiki.Title',
                ),
                'styles' => array(
                        'resources/mobile.search/SearchOverlay.less',
                ),
                'scripts' => array(
-                       'resources/mobile.search/SearchApi.js',
                        'resources/mobile.search/SearchOverlay.js',
                        'resources/mobile.search/MobileWebSearchLogger.js',
                        'resources/mobile.search/init.js',
@@ -759,6 +757,15 @@
                ),
        ),
 
+       'mobile.search.api' => $wgMFResourceParsedMessageModuleBoilerplate + 
array(
+               'dependencies' => array(
+                       'mediawiki.Title',
+               ),
+               'scripts' => array(
+                       'resources/mobile.search.api/SearchApi.js',
+               ),
+       ),
+
        'mobile.search.beta' => $wgMFResourceParsedMessageModuleBoilerplate + 
array(
                'dependencies' => array(
                        'mobile.search',
@@ -766,8 +773,14 @@
                'styles' => array(
                        'resources/mobile.search.beta/SearchOverlay.less',
                ),
+       ),
+
+       'mobile.search.beta.api' => $wgMFResourceParsedMessageModuleBoilerplate 
+ array(
+               'dependencies' => array(
+                       'mobile.search.api',
+               ),
                'scripts' => array(
-                       'resources/mobile.search.beta/SearchApi.js',
+                       'resources/mobile.search.beta.api/SearchApi.js',
                ),
        ),
 
diff --git a/resources/mobile.search/SearchApi.js 
b/resources/mobile.search.api/SearchApi.js
similarity index 100%
rename from resources/mobile.search/SearchApi.js
rename to resources/mobile.search.api/SearchApi.js
diff --git a/resources/mobile.search.beta/SearchApi.js 
b/resources/mobile.search.beta.api/SearchApi.js
similarity index 100%
rename from resources/mobile.search.beta/SearchApi.js
rename to resources/mobile.search.beta.api/SearchApi.js
diff --git a/resources/mobile.search/SearchOverlay.js 
b/resources/mobile.search/SearchOverlay.js
index 7a6931a..f653dbf 100644
--- a/resources/mobile.search/SearchOverlay.js
+++ b/resources/mobile.search/SearchOverlay.js
@@ -2,7 +2,6 @@
 
        var
                Overlay = M.require( 'Overlay' ),
-               SearchApi = M.require( 'modules/search/SearchApi' ),
                Anchor = M.require( 'Anchor' ),
                Icon = M.require( 'Icon' ),
                WatchstarPageList = M.require( 'modules/WatchstarPageList' ),
@@ -103,7 +102,8 @@
                initialize: function ( options ) {
                        var self = this;
                        Overlay.prototype.initialize.call( this, options );
-                       this.api = options.api || new SearchApi();
+                       // use the given api module or use the default SearchApi
+                       this.api = options.api || new M.require( 
'modules/search/SearchApi' );
 
                        // FIXME: Remove when search registers route with 
overlay manager
                        // we need this because of the focus/delay hack in 
search.js
diff --git a/resources/mobile.search/init.js b/resources/mobile.search/init.js
index 66cb024..e52b7d2 100644
--- a/resources/mobile.search/init.js
+++ b/resources/mobile.search/init.js
@@ -5,22 +5,25 @@
                context = M.require( 'context' ),
                router = M.require( 'router' ),
                browser = M.require( 'browser' ),
-               searchModule,
-               searchApi,
+               moduleConfig = {
+                       modules: [ 'mobile.search.api', 'mobile.search' ],
+                       api: 'modules/search/SearchApi',
+                       overlay: 'modules/search/SearchOverlay'
+               },
                SearchOverlay,
                SearchApi;
 
        if ( context.isBetaGroupMember() ) {
-               searchModule = 'mobile.search.beta';
-               searchApi = 'modules/search.beta/SearchApi';
-       } else {
-               searchModule = 'mobile.search';
-               searchApi = 'modules/search/SearchApi';
+               moduleConfig = $.extend( moduleConfig, {
+                       modules: [ 'mobile.search.beta.api', 
'mobile.search.beta' ],
+                       api: 'modules/search.beta/SearchApi'
+               } );
        }
 
        /**
         * Reveal the search overlay
         * @param {jQuery.Event} ev
+        * @event mobilefrontend.searchModule
         * @ignore
         */
        function openSearchOverlay( ev ) {
@@ -33,9 +36,24 @@
                        name: 'search'
                } );
 
-               mw.loader.using( searchModule ).done( function () {
-                       SearchApi = M.require( searchApi );
-                       SearchOverlay = M.require( 
'modules/search/SearchOverlay' );
+               /**
+                * Allow other extensions to replace the module config with 
it's own. The
+                * passed moduleConfig object should be extended only to 
ensure, that all
+                * required properties are set.
+                *
+                * @see Bug T110069
+                *
+                * Example usage:
+                *
+                * mw.hook( 'mobilefrontend.searchModule' ).add( function( 
config ) {
+                *   config.api = 'ext.mobile.searchModule';
+                * } );
+                */
+               mw.hook( 'mobilefrontend.searchModule' ).fire( moduleConfig );
+
+               mw.loader.using( moduleConfig.modules ).done( function () {
+                       SearchApi = M.require( moduleConfig.api );
+                       SearchOverlay = M.require( moduleConfig.overlay );
 
                        new SearchOverlay( {
                                api: new SearchApi(),

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I4e5979dfd82c370977c76528e898c760c972bec8
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: Florianschmidtwelzow <[email protected]>

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

Reply via email to