Jdlrobson has uploaded a new change for review.
https://gerrit.wikimedia.org/r/56887
Change subject: RL: Add modules and module styles to page as modules found
......................................................................
RL: Add modules and module styles to page as modules found
Set target to none to filter out for devices other than mobile
Change-Id: I1abd8798189e1a3f6375e473ab944daa82daa1e3
---
M includes/skins/SkinMobile.php
1 file changed, 36 insertions(+), 50 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MobileFrontend
refs/changes/87/56887/1
diff --git a/includes/skins/SkinMobile.php b/includes/skins/SkinMobile.php
index 9441043..a5d1064 100644
--- a/includes/skins/SkinMobile.php
+++ b/includes/skins/SkinMobile.php
@@ -237,42 +237,32 @@
$rlSupport = $device->supportsJQuery();
$out = $this->getOutput();
- $out->setTarget( 'mobile' );
- $context = MobileContext::singleton();
-
- $moduleNames = $this->getEnabledModules( $wgResourceModules,
$title );
- $contextModules = $this->attachAdditionalPageResources( $title,
$context );
-
- // attach styles
- $out->addModuleStyles( 'mobile.styles' );
- if ( count( $contextModules['top'] ) > 0 ) {
- $out->addModuleStyles( $contextModules['top'] );
+ if ( $rlSupport ) {
+ $out->setTarget( 'mobile' );
+ } else {
+ $out->setTarget( 'none' );
}
+
+ $out->addModuleStyles( 'mobile.styles' );
+ $this->enableModules( $wgResourceModules, $title );
+
// add device specific css file - add separately to avoid cache
fragmentation
if ( $device->moduleName() ) {
$out->addModuleStyles( $device->moduleName() );
}
- // attach modules
- if ( $rlSupport ) {
- $out->addModules( $moduleNames['top'] );
- $out->addModules( $moduleNames['bottom'] );
- $out->addModules( $contextModules['bottom'] );
+ $this->attachAdditionalPageResources( $title );
- // FIXME: EditPage.php adds an inline script that
breaks editing without this - dirty hack
- if ( in_array( 'mobile.action.edit',
$contextModules['bottom'] ) ) {
- $bottomScripts = Html::inlineScript(
-
'mw.loader.implement("mediawiki.action.edit", [],{},{});' .
- 'mw.toolbar = { addButton:
function(){}, init: function(){} };'
- );
- } else {
- $bottomScripts = '';
- }
-
- $bottomScripts .= $out->getBottomScripts();
+ // FIXME: EditPage.php adds an inline script that breaks
editing without this - dirty hack
+ if ( in_array( 'mobile.action.edit', $out->getModules() ) ) {
+ $bottomScripts = Html::inlineScript(
+ 'mw.loader.implement("mediawiki.action.edit",
[],{},{});' .
+ 'mw.toolbar = { addButton: function(){}, init:
function(){} };'
+ );
} else {
- $bottomScripts = '';
+ $bottomScripts = '';
}
+ $bottomScripts .= $out->getBottomScripts();
$headHtml = $out->getHeadLinks( null, true );
$headHtml .= $out->buildCssLinks();
@@ -290,16 +280,17 @@
}
/**
- * Gathers potential javascript modules to load
+ * Enables RL modules for page
* @param array $modules
* @param Title $title
*
* @return array
*/
- public function getEnabledModules( array $modules, Title $title ) {
+ public function enableModules( array $modules, Title $title ) {
$context = MobileContext::singleton();
$inBeta = $context->isBetaGroupMember();
$inAlpha = $context->isAlphaGroupMember();
+ $out = $this->getOutput();
$headModuleNames = array();
$moduleNames = array();
@@ -331,47 +322,42 @@
}
}
- return array(
- 'top' => $headModuleNames,
- 'bottom' => $moduleNames,
- );
+ // attach modules
+ $out->addModules( $headModuleNames );
+ $out->addModules( $moduleNames );
}
/**
- * @param Title $title
- * @param MobileContext $context
+ * Attaches modules to the page dependencing on the namespace or action
*
* @return array
*/
- protected function attachAdditionalPageResources( Title $title,
MobileContext $context ) {
- global $wgResourceModules;
+ protected function attachAdditionalPageResources() {
+ global $wgResourceModules, $wgUser;
+ $context = MobileContext::singleton();
+ $title = $this->getTitle();
+ $out = $this->getOutput();
$isFilePage = $title->getNamespace() == NS_FILE;
$action = $context->getRequest()->getText( 'action' );
$isSpecialPage = $title->isSpecialPage();
- $moduleNames = array();
- $headModuleNames = array();
-
// specific to current context
if ( $isFilePage ) {
- $moduleNames[] = 'mobile.file.scripts';
- $headModuleNames[] = 'mobile.file.styles';
+ $out->addModules( 'mobile.file.scripts' );
+ $out->addModuleStyles( 'mobile.file.styles' );
}
if ( !$isSpecialPage ) {
- $headModuleNames[] = 'mobile.styles.page';
+ $out->addModuleStyles( 'mobile.styles.page' );
+ } else {
+ // FIXME: login page
}
if ( $action === 'edit' ) {
- $moduleNames[] = 'mobile.action.edit';
+ $out->addModules( 'mobile.action.edit' );
} else if ( $action === 'history' ) {
- $moduleNames[] = 'mobile.action.history';
+ $out->addModules( 'mobile.action.history' );
}
-
- return array(
- 'top' => $headModuleNames,
- 'bottom' => $moduleNames,
- );
}
public function buildLanguageSelection() {
--
To view, visit https://gerrit.wikimedia.org/r/56887
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I1abd8798189e1a3f6375e473ab944daa82daa1e3
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