Jdlrobson has uploaded a new change for review.
https://gerrit.wikimedia.org/r/86290
Change subject: Allow MFResourceLoaderModule to handle templates and files
......................................................................
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
4 files changed, 124 insertions(+), 115 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MobileFrontend
refs/changes/90/86290/1
diff --git a/includes/Resources.php b/includes/Resources.php
index ea50865..c164b8b 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' ),
+ ),
+
// main page
'mobile.mainpage.styles' => $wgMFMobileResourceBoilerplate + array(
'dependencies' => array( 'mobile.startup' ),
@@ -143,7 +146,6 @@
'mobile.head',
),
'scripts' => array(
- 'javascripts/externals/hogan.js',
'javascripts/common/Router.js',
'javascripts/common/api.js',
'javascripts/common/PageApi.js',
@@ -154,64 +156,14 @@
'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',
),
'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',
),
@@ -242,7 +194,6 @@
'mobile.uploads' => $wgMFMobileResourceBoilerplate + array(
'dependencies' => array(
'mobile.stable',
- 'mobile.uploads.plumbing',
),
'scripts' => array(
'javascripts/modules/uploads/LearnMoreOverlay.js',
@@ -253,12 +204,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',
@@ -313,21 +258,14 @@
),
),
- 'mobile.beta.plumbing' => array(
- 'localBasePath' => $localBasePath,
- 'localTemplateBasePath' => $localBasePath . '/templates',
+ 'mobile.beta.common' => $wgMFMobileResourceBoilerplate + array(
'templates' => array(
// notifications.js
'overlays/notifications',
// page.js
'pageActionTutorial',
),
- 'class' => 'MFResourceLoaderModule',
- ),
-
- 'mobile.beta.common' => $wgMFMobileResourceBoilerplate + array(
'dependencies' => array(
- 'mobile.beta.plumbing',
'mobile.stable.common',
),
'scripts' => array(
@@ -383,18 +321,11 @@
'mobile.talk' => $wgMFMobileResourceBoilerplate + array(
'dependencies' => array(
'mobile.beta',
- 'mobile.talk.plumbing',
),
'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',
@@ -427,18 +358,14 @@
'group' => 'other',
),
- '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',
),
'messages' => array(
@@ -493,10 +420,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',
@@ -529,6 +480,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',
),
),
@@ -628,13 +590,6 @@
),
),
- 'mobile.nearby.plumbing' => $wgMFMobileResourceTemplateBoilerplate +
array(
- 'templates' => array(
- 'articleList',
- 'overlays/pagePreview',
- ),
- ),
-
'mobile.nearby.previews' => $wgMFMobileResourceBoilerplate + array(
'dependencies' => array(
'mobile.nearby.scripts',
@@ -657,10 +612,13 @@
),
'mobile.nearby' => $wgMFMobileResourceBoilerplate + array(
+ 'templates' => array(
+ 'articleList',
+ 'overlays/pagePreview',
+ ),
'dependencies' => array(
'mobile.stable.common',
'mobile.nearby.styles',
- 'mobile.nearby.plumbing',
'jquery.json',
),
'messages' => array(
@@ -733,20 +691,16 @@
'stylesheets/specials/userprofile.css',
),
),
- // Special:Uploads
- 'mobile.special.uploads.plumbing' =>
$wgMFMobileResourceTemplateBoilerplate + array(
+ 'mobile.uploads.scripts' => $wgMFMobileResourceBoilerplate + array(
+ 'dependencies' => array(
+ 'mobile.stable.styles',
+ 'mobile.stable.common',
+ 'mobile.uploads',
+ ),
'templates' => array(
'specials/uploads/carousel',
'specials/uploads/photo',
'specials/uploads/userGallery',
- ),
- ),
- 'mobile.uploads.scripts' => $wgMFMobileResourceBoilerplate + array(
- 'dependencies' => array(
- 'mobile.special.uploads.plumbing',
- 'mobile.stable.styles',
- 'mobile.stable.common',
- 'mobile.uploads',
),
'messages' => array(
'mobile-frontend-photo-upload-generic',
diff --git a/includes/modules/MFResourceLoaderModule.php
b/includes/modules/MFResourceLoaderModule.php
index 5961827..7ea4010 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,27 @@
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';
+ // MFResourceLoaderModule must depend on mobile.templates
because
+ // it contains code responsible for compiling templates
+ if ( !in_array( 'mobile.templates', $this->dependencies ) ) {
+ $this->dependencies[] = 'mobile.templates';
}
+ parent::__construct( $options );
}
/**
@@ -129,6 +134,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 +146,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..7de6cfd 100644
--- a/javascripts/common/application.js
+++ b/javascripts/common/application.js
@@ -288,7 +288,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 ) );
--
To view, visit https://gerrit.wikimedia.org/r/86290
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I02ae1476c1ce9cdf877e2ba24c17db6c26800011
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: Jdlrobson <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits