Jdlrobson has uploaded a new change for review.
https://gerrit.wikimedia.org/r/70323
Change subject: Sandbox alpha and beta skins from stable
......................................................................
Sandbox alpha and beta skins from stable
* Add logic for beta and alpha skins into their own classes
* refactor MinervaTemplate to have two more
overrideable methods - renderHistoryLink and renderMainMenu
* Add the logic for main menu headers into MobileTemplateBeta and
reflect changes in MinervaTemplate
Change-Id: Ie848c604e25784b7c82175956e71a6f81edbbccb
---
M MobileFrontend.php
M includes/MobileFrontend.hooks.php
M includes/skins/MinervaTemplate.php
M includes/skins/MobileTemplateBeta.php
M includes/skins/SkinMobile.php
A includes/skins/SkinMobileAlpha.php
A includes/skins/SkinMobileBeta.php
7 files changed, 277 insertions(+), 186 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MobileFrontend
refs/changes/23/70323/1
diff --git a/MobileFrontend.php b/MobileFrontend.php
index bad0eaf..2aaa3ef 100644
--- a/MobileFrontend.php
+++ b/MobileFrontend.php
@@ -70,6 +70,8 @@
'MobileTemplateWML' => 'skins/MobileTemplateWML',
'SkinMinerva' => 'skins/SkinMinerva',
'SkinMobile' => 'skins/SkinMobile',
+ 'SkinMobileBeta' => 'skins/SkinMobileBeta',
+ 'SkinMobileAlpha' => 'skins/SkinMobileAlpha',
'SkinMobileWML' => 'skins/SkinMobileWML',
'UserLoginAndCreateTemplate' => 'skins/UserLoginAndCreateTemplate',
'UserLoginMobileTemplate' => 'skins/UserLoginMobileTemplate',
diff --git a/includes/MobileFrontend.hooks.php
b/includes/MobileFrontend.hooks.php
index ea92aeb..a658c88 100644
--- a/includes/MobileFrontend.hooks.php
+++ b/includes/MobileFrontend.hooks.php
@@ -77,7 +77,13 @@
# Grab the skin class and initialise it.
$skin = new SkinMobileWML( $wgExtMobileFrontend );
} else {
- $skin = new $wgMFDefaultSkinClass( $wgExtMobileFrontend
);
+ $skinName = $wgMFDefaultSkinClass;
+ if ( $mobileContext->isAlphaGroupMember() ) {
+ $skinName .= 'Alpha';
+ } else if ( $mobileContext->isBetaGroupMember() ) {
+ $skinName .= 'Beta';
+ }
+ $skin = new $skinName( $wgExtMobileFrontend );
}
return false;
diff --git a/includes/skins/MinervaTemplate.php
b/includes/skins/MinervaTemplate.php
index 2397f11..e4303fe 100644
--- a/includes/skins/MinervaTemplate.php
+++ b/includes/skins/MinervaTemplate.php
@@ -89,6 +89,15 @@
?></ul><?php
}
+ protected function renderHistoryLink( $data ) {
+ if ( isset( $data['historyLink'] ) ) {
+ $historyLink = $data['historyLink'];
+ $historyLabel = $historyLink['text'];
+ unset( $historyLink['text'] );
+ echo Html::element( 'a', $historyLink, $historyLabel );
+ }
+ }
+
protected function renderContentWrapper( $data ) {
$isSpecialPage = $this->getSkin()->getTitle()->isSpecialPage();
?>
@@ -101,49 +110,43 @@
}
echo $data[ 'bodytext' ];
$this->renderLanguages();
- echo $data['postbodytext'];
+ $this->renderHistoryLink( $data );
?>
</div><!-- close #content -->
</div><!-- close #content_wrapper -->
<?php
}
+ protected function renderMainMenu( $data ) {
+ ?>
+ <ul id="mw-mf-menu-main">
+ <?php
+ foreach( $this->getDiscoveryTools() as $key => $val ):
+ echo $this->makeListItem( $key, $val );
+ endforeach;
+ ?>
+ </ul>
+ <ul>
+ <?php
+ foreach( $this->getPersonalTools() as $key => $val ):
+ echo $this->makeListItem( $key, $val );
+ endforeach;
+ ?>
+ </ul>
+ <?php
+ }
+
protected function render( $data ) { // FIXME: replace with template
engines
$isSpecialPage = $this->getSkin()->getTitle()->isSpecialPage();
- $showMenuHeaders = isset( $this->data['_show_menu_headers'] )
&& $this->data['_show_menu_headers'];
// begin rendering
echo $data[ 'headelement' ];
?>
<div id="mw-mf-viewport">
<div id="mw-mf-page-left">
- <?php if ( $showMenuHeaders ) { ?>
- <h2><?php echo wfMessage(
'mobile-frontend-main-menu-discovery' )->text() ?></h2>
- <?php } ?>
- <ul id="mw-mf-menu-main">
<?php
- foreach( $this->getDiscoveryTools() as $key =>
$val ):
- echo $this->makeListItem( $key, $val );
- endforeach;
+ $this->renderMainMenu( $data );
?>
- </ul>
- <?php if ( $showMenuHeaders ) { ?>
- <h2><?php echo wfMessage(
'mobile-frontend-main-menu-personal' )->text() ?></h2>
- <?php } ?>
- <ul>
- <?php
- foreach( $this->getPersonalTools() as $key =>
$val ):
- echo $this->makeListItem( $key, $val );
- endforeach;
- ?>
- </ul>
- <ul class="hlist">
- <?php
- foreach( $this->getSiteLinks() as $key => $val
):
- echo $this->makeListItem( $key, $val );
- endforeach;
- ?>
- </ul>
</div>
<div id='mw-mf-page-center'>
<!-- start -->
diff --git a/includes/skins/MobileTemplateBeta.php
b/includes/skins/MobileTemplateBeta.php
index d2033b2..66492d0 100644
--- a/includes/skins/MobileTemplateBeta.php
+++ b/includes/skins/MobileTemplateBeta.php
@@ -1,5 +1,35 @@
<?php
class MobileTemplateBeta extends MobileTemplate {
+ protected function renderMainMenu( $data ) {
+ echo Html::element( 'h2', array(), wfMessage(
'mobile-frontend-main-menu-discovery' )->text() );
+ ?>
+ <ul id="mw-mf-menu-main">
+ <?php
+ foreach( $this->getDiscoveryTools() as $key => $val ):
+ echo $this->makeListItem( $key, $val );
+ endforeach;
+ ?>
+ </ul>
+ <?php
+ echo Html::element( 'h2', array(), wfMessage(
'mobile-frontend-main-menu-personal' )->text() );
+ ?>
+ <ul>
+ <?php
+ foreach( $this->getPersonalTools() as $key => $val ):
+ echo $this->makeListItem( $key, $val );
+ endforeach;
+ ?>
+ </ul>
+ <ul class="hlist">
+ <?php
+ foreach( $this->getSiteLinks() as $key => $val ):
+ echo $this->makeListItem( $key, $val );
+ endforeach;
+ ?>
+ </ul>
+ <?php
+ }
+
protected function renderContentWrapper( $data ) {
$isSpecialPage = $this->getSkin()->getTitle()->isSpecialPage();
?>
@@ -14,7 +44,7 @@
<?php
echo $data[ 'bodytext' ];
$this->renderLanguages( $data );
- echo $data['postbodytext'];
+ $this->renderHistoryLink( $data );
?>
</div><!-- close #content -->
</div><!-- close #content_wrapper -->
diff --git a/includes/skins/SkinMobile.php b/includes/skins/SkinMobile.php
index 8ff52d1..c4c6d11 100644
--- a/includes/skins/SkinMobile.php
+++ b/includes/skins/SkinMobile.php
@@ -12,21 +12,15 @@
/** @var array of classes that should be present on the body tag */
private $pageClassNames = array();
+ protected function getModeClass() {
+ return 'stable';
+ }
+
public function __construct( ExtMobileFrontend $extMobileFrontend ) {
$this->setContext( $extMobileFrontend );
$this->extMobileFrontend = $extMobileFrontend;
- $ctx = MobileContext::singleton();
- if ( $ctx->isBetaGroupMember() ) {
- $this->template = 'MobileTemplateBeta';
- }
$this->addPageClass( 'mobile' );
- if ( $ctx->isAlphaGroupMember() ) {
- $this->addPageClass( 'alpha' );
- } else if ( $ctx->isBetaGroupMember() ) {
- $this->addPageClass( 'beta' );
- } else {
- $this->addPageClass( 'stable' );
- }
+ $this->addPageClass( $this->getModeClass() );
}
public function outputPage( OutputPage $out = null ) {
@@ -96,111 +90,15 @@
return $className . implode( ' ', array_keys(
$this->pageClassNames ) );
}
- public function initPage( OutputPage $out ) {
- parent::initPage( $out );
- $ctx = MobileContext::singleton();
- if ( $ctx->isBetaGroupMember() ) {
- $out->addModuleStyles( 'mobile.styles.beta' );
- }
+ protected function getSearchPlaceHolderText() {
+ return wfMessage( 'mobile-frontend-placeholder' )->escaped();
}
public function prepareData( BaseTemplate $tpl ) {
parent::prepareData( $tpl );
- $context = MobileContext::singleton();
- $inBeta = $context->isBetaGroupMember();
- $menuHeaders = true;
$search = $tpl->data['searchBox'];
- if ( $context->isAlphaGroupMember() ) {
- $search['placeholder'] = wfMessage(
'mobile-frontend-placeholder-alpha' )->escaped();
- } else if ( $inBeta ) {
- $search['placeholder'] = wfMessage(
'mobile-frontend-placeholder-beta' )->escaped();
- } else { // stable mode
- $menuHeaders = false;
- }
- $tpl->set( '_show_menu_headers', $menuHeaders );
+ $search['placeholder'] = $this->getSearchPlaceHolderText();
$tpl->set( 'searchBox', $search );
-
- if ( $inBeta ) {
- $this->prepareDataBeta( $tpl );
- }
- }
-
- /**
- * Prepares data required by the mobile beta skin only. This runs after
prepareData
- * @param $tpl BaseTemplate
- */
- protected function prepareDataBeta( BaseTemplate $tpl ) {
- $tpl->set( 'site_urls', array(
- array(
- 'href' => Title::newFromText( 'About',
NS_PROJECT )->getLocalUrl(),
- 'text'=> $this->msg(
'mobile-frontend-main-menu-about' )->escaped(),
- ),
- array(
- 'href' => Title::newFromText(
'General_disclaimer', NS_PROJECT )->getLocalUrl(),
- 'text'=> $this->msg(
'mobile-frontend-main-menu-disclaimer' )->escaped(),
- ),
- ) );
-
- // Reuse template data variable from SkinTemplate to construct
page menu
- $menu = array();
- $actions = $tpl->data['content_navigation']['actions'];
- $namespaces = $tpl->data['content_navigation']['namespaces'];
-
- // empty placeholder for edit photos which both require js
- $menu['edit'] = array( 'id' => 'ca-edit', 'text' => '' );
- $menu['photo'] = array( 'id' => 'ca-upload', 'text' => '' );
-
- if ( isset( $namespaces['talk'] ) ) {
- $menu['talk'] = $namespaces['talk'];
- if ( isset( $tpl->data['_talkdata'] ) ) {
- $menu['talk']['text'] =
$tpl->data['_talkdata']['text'];
- $menu['talk']['class'] =
$tpl->data['_talkdata']['class'];
- }
- }
-
- $watchTemplate = array(
- 'id' => 'ca-watch',
- 'class' => 'watch-this-article',
- );
- // standardise watch article into one menu item
- if ( isset( $actions['watch'] ) ) {
- $menu['watch'] = array_merge( $actions['watch'],
$watchTemplate );
- } else if ( isset( $actions['unwatch'] ) ) {
- $menu['watch'] = array_merge( $actions['unwatch'],
$watchTemplate );
- $menu['watch']['class'] .= ' watched';
- } else {
- // placeholder for not logged in
- $menu['watch'] = $watchTemplate;
- // FIXME: makeLink (used by makeListItem) when no text
is present defaults to use the key
- $menu['watch']['text'] = '';
- $menu['watch']['class'] = 'cta';
- }
-
- $tpl->set( 'page_actions', $menu );
-
- $this->prepareUserButton( $tpl );
- }
-
- /**
- * Prepares the user button.
- * @param $tpl BaseTemplate
- */
- protected function prepareUserButton( $tpl ) {
- if ( class_exists( 'MWEchoNotifUser' ) ) {
- $user = $this->getUser();
- // FIXME: cap higher counts
- $count = $user->isLoggedIn() ?
MWEchoNotifUser::newFromUser( $user )->getNotificationCount() : 0;
-
- $tpl->set( 'userButton',
- Html::openElement( 'a', array(
- 'title' => wfMessage(
'mobile-frontend-user-button-tooltip' ),
- 'href' => SpecialPage::getTitleFor(
'Notifications' )->getLocalURL(),
- 'id'=> 'user-button',
- ) ) .
- Html::element( 'span', array( 'class' => $count
? '' : 'zero' ), $count ) .
- Html::closeElement( 'a' )
- );
- }
}
public function getSkinConfigVariables() {
@@ -223,7 +121,6 @@
$ctx = MobileContext::singleton();
$out = $this->getOutput();
- $inAlpha = $ctx->isAlphaGroupMember();
$device = $ctx->getDevice();
// add device specific css file - add separately to avoid cache
fragmentation
@@ -234,31 +131,22 @@
}
$modules = parent::getDefaultModules();
- $mode = 'stable';
- if ( $ctx->isBetaGroupMember() ) {
- $modules['beta'] = array( 'mobile.beta' );
- $mode = 'beta';
- }
- if ( $inAlpha ) {
- $modules['alpha'] = array( 'mobile.alpha' );
- $mode = 'alpha';
- }
// main page special casing
if ( $this->getTitle()->isMainPage() ) {
- if ( $inAlpha ) {
- $out->addModuleStyles( 'mobile.mainpage.styles'
);
- } else {
- $modules['mainpage'] = array(
'mobile.mainpage.scripts' );
- }
+ $modules['mainpage'] = array( 'mobile.mainpage.scripts'
);
}
// flush unnecessary modules
$modules['content'] = array();
$modules['legacy'] = array();
- wfRunHooks( 'EnableMobileModules', array( $out, $mode ) );
+ $this->addExternalModules( $out );
return $modules;
+ }
+
+ protected function addExternalModules( $out ) {
+ wfRunHooks( 'EnableMobileModules', array( $out, 'stable' ) );
}
protected function prepareTemplate() {
@@ -472,32 +360,8 @@
$isSpecialPage = $title->isSpecialPage();
$user = $this->getUser();
$ctx = MobileContext::singleton();
- $inAlpha = $ctx->isAlphaGroupMember();
- $postBodyText = '';
if ( !$isSpecialPage ) {
-
- // talk page link for logged in alpha users
- if ( $inAlpha && $user->isLoggedIn() &&
!$title->isTalkPage() ) {
- $talkTitle = $title->getTalkPage();
- if ( $talkTitle->getArticleID() ) {
- $dbr = wfGetDB( DB_SLAVE );
- $numTopics = $dbr->selectField(
'page_props', 'pp_value',
- array( 'pp_page' =>
$talkTitle->getArticleID(), 'pp_propname' => 'page_top_level_section_count' ),
- __METHOD__
- );
- } else {
- $numTopics = 0;
- }
- if ( $numTopics ) {
- $talkLabel =
$this->getLanguage()->formatNum( $numTopics );
- $class = 'count';
- } else {
- $talkLabel = wfMessage(
'mobile-frontend-talk-overlay-header' );
- $class = '';
- }
- $tpl->set( '_talkdata', array( 'text' =>
$talkLabel, 'class' => $class ) );
- }
// add last modified timestamp
$revId = $this->getRevisionId();
@@ -507,16 +371,15 @@
$this->getLanguage()->userTime( $timestamp,
$user )
)->parse();
$timestamp = wfTimestamp( TS_UNIX, $timestamp );
- $historyUrl = $inAlpha ? SpecialPage::getTitleFor(
'MobileDiff', $revId )->getLocalUrl() :
- $ctx->getMobileUrl( $title->getFullURL(
'action=history' ) );
- $postBodyText = Html::element( 'a', array(
+ $historyUrl = $ctx->getMobileUrl( $title->getFullURL(
'action=history' ) );
+ $historyLink = array(
'id' => 'mw-mf-last-modified',
'data-timestamp' => $timestamp,
- 'href' => $historyUrl
- ), $lastModified );
+ 'href' => $historyUrl,
+ 'text' => $lastModified,
+ );
+ $tpl->set( 'historyLink', $historyLink );
}
-
- $tpl->set( 'postbodytext', $postBodyText );
}
/**
diff --git a/includes/skins/SkinMobileAlpha.php
b/includes/skins/SkinMobileAlpha.php
new file mode 100644
index 0000000..43db2c4
--- /dev/null
+++ b/includes/skins/SkinMobileAlpha.php
@@ -0,0 +1,74 @@
+<?php
+
+class SkinMobileAlpha extends SkinMobileBeta {
+ public $template = 'MobileTemplateBeta';
+
+ protected function getSearchPlaceHolderText() {
+ return wfMessage( 'mobile-frontend-placeholder-alpha'
)->escaped();
+ }
+
+ protected function addExternalModules( $out ) {
+ wfRunHooks( 'EnableMobileModules', array( $out, 'alpha' ) );
+ }
+
+ protected function getModeClass() {
+ return 'alpha';
+ }
+
+ public function getDefaultModules() {
+ $modules = parent::getDefaultModules();
+ $modules['alpha'] = array( 'mobile.alpha' );
+ // main page special casing
+ if ( $this->getTitle()->isMainPage() ) {
+ $out->addModuleStyles( 'mobile.mainpage.styles' );
+ $modules['mainpage'] = array();
+ }
+ return $modules;
+ }
+
+ public function prepareData( BaseTemplate $tpl ) {
+ parent::prepareData( $tpl );
+ $this->prepareTalkLabel( $tpl );
+ $this->prepareHistoryLink( $tpl );
+ }
+
+ protected function prepareHistoryLink( $tpl ) {
+ $revId = $this->getRevisionId();
+ $h = $tpl->data['historyLink'];
+ $h['href'] = SpecialPage::getTitleFor( 'MobileDiff', $revId
)->getLocalUrl();
+ $tpl->set( 'historyLink', $h );
+ }
+
+ protected function prepareTalkLabel( $tpl ) {
+ $title = $this->getTitle();
+ $user = $this->getUser();
+ $isSpecialPage = $title->isSpecialPage();
+
+ // talk page link for logged in alpha users
+ if ( !$isSpecialPage && !$title->isTalkPage() ) {
+ $talkTitle = $title->getTalkPage();
+ if ( $talkTitle->getArticleID() ) {
+ $dbr = wfGetDB( DB_SLAVE );
+ $numTopics = $dbr->selectField( 'page_props',
'pp_value',
+ array( 'pp_page' =>
$talkTitle->getArticleID(), 'pp_propname' => 'page_top_level_section_count' ),
+ __METHOD__
+ );
+ } else {
+ $numTopics = 0;
+ }
+ if ( $numTopics ) {
+ $talkLabel = $this->getLanguage()->formatNum(
$numTopics );
+ $class = 'count';
+ } else {
+ $talkLabel = wfMessage(
'mobile-frontend-talk-overlay-header' );
+ $class = '';
+ }
+ $menu = $tpl->data['page_actions'];
+ if ( isset( $menu['talk'] ) ) {
+ $menu['talk']['text'] = $talkLabel;
+ $menu['talk']['class'] = $class;
+ }
+ $tpl->set( 'page_actions', $menu );
+ }
+ }
+}
diff --git a/includes/skins/SkinMobileBeta.php
b/includes/skins/SkinMobileBeta.php
new file mode 100644
index 0000000..6e466e3
--- /dev/null
+++ b/includes/skins/SkinMobileBeta.php
@@ -0,0 +1,113 @@
+<?php
+
+class SkinMobileBeta extends SkinMobile {
+ public $template = 'MobileTemplateBeta';
+
+ protected function getModeClass() {
+ return 'beta';
+ }
+
+ protected function getSearchPlaceHolderText() {
+ return wfMessage( 'mobile-frontend-placeholder-beta'
)->escaped();
+ }
+
+ public function initPage( OutputPage $out ) {
+ parent::initPage( $out );
+ $out->addModuleStyles( 'mobile.styles.beta' );
+ }
+
+ public function prepareData( BaseTemplate $tpl ) {
+ parent::prepareData( $tpl );
+ $this->prepareDataBeta( $tpl );
+ }
+
+ /**
+ * Prepares data required by the mobile beta skin only. This runs after
prepareData
+ * @param $tpl BaseTemplate
+ */
+ protected function prepareDataBeta( BaseTemplate $tpl ) {
+ $tpl->set( 'site_urls', array(
+ array(
+ 'href' => Title::newFromText( 'About',
NS_PROJECT )->getLocalUrl(),
+ 'text'=> $this->msg(
'mobile-frontend-main-menu-about' )->escaped(),
+ ),
+ array(
+ 'href' => Title::newFromText(
'General_disclaimer', NS_PROJECT )->getLocalUrl(),
+ 'text'=> $this->msg(
'mobile-frontend-main-menu-disclaimer' )->escaped(),
+ ),
+ ) );
+
+ // Reuse template data variable from SkinTemplate to construct
page menu
+ $menu = array();
+ $actions = $tpl->data['content_navigation']['actions'];
+ $namespaces = $tpl->data['content_navigation']['namespaces'];
+
+ // empty placeholder for edit photos which both require js
+ $menu['edit'] = array( 'id' => 'ca-edit', 'text' => '' );
+ $menu['photo'] = array( 'id' => 'ca-upload', 'text' => '' );
+
+ if ( isset( $namespaces['talk'] ) ) {
+ $menu['talk'] = $namespaces['talk'];
+ if ( isset( $tpl->data['_talkdata'] ) ) {
+ $menu['talk']['text'] =
$tpl->data['_talkdata']['text'];
+ $menu['talk']['class'] =
$tpl->data['_talkdata']['class'];
+ }
+ }
+
+ $watchTemplate = array(
+ 'id' => 'ca-watch',
+ 'class' => 'watch-this-article',
+ );
+ // standardise watch article into one menu item
+ if ( isset( $actions['watch'] ) ) {
+ $menu['watch'] = array_merge( $actions['watch'],
$watchTemplate );
+ } else if ( isset( $actions['unwatch'] ) ) {
+ $menu['watch'] = array_merge( $actions['unwatch'],
$watchTemplate );
+ $menu['watch']['class'] .= ' watched';
+ } else {
+ // placeholder for not logged in
+ $menu['watch'] = $watchTemplate;
+ // FIXME: makeLink (used by makeListItem) when no text
is present defaults to use the key
+ $menu['watch']['text'] = '';
+ $menu['watch']['class'] = 'cta';
+ }
+
+ $tpl->set( 'page_actions', $menu );
+
+ $this->prepareUserButton( $tpl );
+ }
+
+ /**
+ * Prepares the user button.
+ * @param $tpl BaseTemplate
+ */
+ protected function prepareUserButton( $tpl ) {
+ if ( class_exists( 'MWEchoNotifUser' ) ) {
+ $user = $this->getUser();
+ // FIXME: cap higher counts
+ $count = $user->isLoggedIn() ?
MWEchoNotifUser::newFromUser( $user )->getNotificationCount() : 0;
+
+ $tpl->set( 'userButton',
+ Html::openElement( 'a', array(
+ 'title' => wfMessage(
'mobile-frontend-user-button-tooltip' ),
+ 'href' => SpecialPage::getTitleFor(
'Notifications' )->getLocalURL(),
+ 'id'=> 'user-button',
+ ) ) .
+ Html::element( 'span', array( 'class' => $count
? '' : 'zero' ), $count ) .
+ Html::closeElement( 'a' )
+ );
+ }
+ }
+
+ public function getDefaultModules() {
+ $modules = parent::getDefaultModules();
+ $modules['beta'] = array( 'mobile.beta' );
+
+ return $modules;
+ }
+
+ protected function addExternalModules( $out ) {
+ wfRunHooks( 'EnableMobileModules', array( $out, 'beta' ) );
+ }
+
+}
--
To view, visit https://gerrit.wikimedia.org/r/70323
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie848c604e25784b7c82175956e71a6f81edbbccb
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