Jdlrobson has uploaded a new change for review.
https://gerrit.wikimedia.org/r/245598
Change subject: Hygiene: Generalise main menu code.
......................................................................
Hygiene: Generalise main menu code.
The template belongs to Minerva. Generalise the method to allow
any skin to decide how to render its own main menu.
This is prep work necessary before breaking out Minerva.
Change-Id: Iaf429bb3f53a00647a680cd0b28befbd65f7c92f
---
M i18n/en.json
M i18n/qqq.json
M includes/Resources.php
M includes/skins/MinervaTemplate.php
M includes/skins/SkinMinerva.php
M includes/specials/SpecialMobileMenu.php
R resources/skins.minerva.scripts/menu.mustache
7 files changed, 38 insertions(+), 34 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MobileFrontend
refs/changes/98/245598/1
diff --git a/i18n/en.json b/i18n/en.json
index 68a1e93..39bff1a 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -212,6 +212,7 @@
"mobile-frontend-logged-in-toast-notification": "Logged in as $1.",
"mobile-frontend-logged-out": "Not logged in",
"mobile-frontend-login": "Sign in",
+ "mobile-frontend-special-mobilemenu": "The navigation menu for this
page should now be visible. If not please contact the skin author.",
"mobile-frontend-main-menu": "Main Menu",
"mobile-frontend-main-menu-back": "Go back",
"mobile-frontend-main-menu-account-create": "Create account",
diff --git a/i18n/qqq.json b/i18n/qqq.json
index 4e710fc..16dc85f 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -208,6 +208,7 @@
"mobile-frontend-logged-in-toast-notification": "Message telling user
that they are logged in. Shows as a notification at bottom of page\n*$1 -
username",
"mobile-frontend-logged-out": "Message telling user they are not logged
in on settings page.\n{{Identical|Not logged in}}",
"mobile-frontend-login": "Button text for login in Wikimedia mobile
user interface.\n{{Identical|Sign in}}",
+ "mobile-frontend-special-mobilemenu": "Body content (usually invisible)
for Special:MobileMenu.",
"mobile-frontend-main-menu": "Message that is displayed as a tooltip
for the main menu icon in the header",
"mobile-frontend-main-menu-back": "Message that is displayed as a
tooltip for the back button in the header of the Special:MobileMenu
page\n{{Identical|Go back}}",
"mobile-frontend-main-menu-account-create": "Account creation link in
main menu.\n{{Identical|Create account}}",
diff --git a/includes/Resources.php b/includes/Resources.php
index 81bd208..3ee669a 100644
--- a/includes/Resources.php
+++ b/includes/Resources.php
@@ -222,9 +222,6 @@
'resources/mobile.mainMenu/mainmenu.less',
'resources/mobile.mainMenu/icons.less',
),
- 'templates' => array(
- 'menu.hogan' =>
'resources/mobile.mainMenu/menu.mustache',
- ),
'scripts' => array(
'resources/mobile.mainMenu/MainMenu.js',
),
@@ -1506,6 +1503,9 @@
'mobile-frontend-last-modified-with-user-years',
'mobile-frontend-last-modified-with-user-just-now',
),
+ 'templates' => array(
+ 'menu.hogan' =>
'resources/skins.minerva.scripts/menu.mustache',
+ ),
'scripts' => array(
// FIXME: Merge preInit and init files.
'resources/skins.minerva.scripts/preInit.js',
diff --git a/includes/skins/MinervaTemplate.php
b/includes/skins/MinervaTemplate.php
index ce4bb91..1686514 100644
--- a/includes/skins/MinervaTemplate.php
+++ b/includes/skins/MinervaTemplate.php
@@ -286,23 +286,6 @@
}
/**
- * Gets the main menu only on Special:MobileMenu.
- * On other pages the menu is rendered via JS.
- * @param array [$data] Data used to build the page
- * @return string
- */
- protected function getMainMenuHtml( $data ) {
- if ( $this->isSpecialMobileMenuPage ) {
- $templateParser = new TemplateParser(
- __DIR__ . '/../../resources/mobile.mainMenu/' );
-
- return $templateParser->processTemplate( 'menu',
$data['menu_data'] );
- } else {
- return '';
- }
- }
-
- /**
* Get HTML for header elements
* @param array $data Data used to build the header
* @return string
@@ -328,7 +311,7 @@
?>
<div id="mw-mf-viewport">
<nav id="mw-mf-page-left" class="navigation-drawer
view-border-box">
- <?php echo $this->getMainMenuHtml( $data ); ?>
+ <?php echo $data['menuhtml'] ?>
</nav>
<div id="mw-mf-page-center">
<div class="banner-container">
diff --git a/includes/skins/SkinMinerva.php b/includes/skins/SkinMinerva.php
index 618a4cb..9677975 100644
--- a/includes/skins/SkinMinerva.php
+++ b/includes/skins/SkinMinerva.php
@@ -9,6 +9,8 @@
* @ingroup Skins
*/
class SkinMinerva extends SkinTemplate {
+ /** @var boolean $isMenuEnabled whether to render the menu */
+ protected $isMenuEnabled = false;
/** @var boolean $isMobileMode Describes whether reader is on a mobile
device */
protected $isMobileMode = false;
/** @var string $skinname Name of this skin */
@@ -78,10 +80,33 @@
$this->prepareUserButton( $tpl );
$this->prepareLanguages( $tpl );
+ if ( $this->isMenuEnabled ) {
+ $templateParser = new TemplateParser(
+ __DIR__ .
'/../../resources/skins.minerva.scripts/' );
+ $tpl->set( 'menuhtml',
$templateParser->processTemplate( 'menu', $tpl->data['menu_data'] ) );
+ } else {
+ $tpl->set( 'menuhtml', '' );
+ }
return $tpl;
}
/**
+ * Enables rendering of the main menu on the current page. Menus will
be omitted from the page html if
+ * function is not called.
+ * @param QuickTemplate $tpl
+ */
+ public function enableMenu() {
+ $this->isMenuEnabled = true;
+ $out = $this->getOutput();
+ $out->setProperty( 'bodyClassName', 'navigation-enabled
navigation-full-screen' );
+ $out->addModuleStyles(
+ array(
+ 'mobile.mainMenu',
+ )
+ );
+ }
+
+ /**
* Prepares the header and the content of a page
* Stores in QuickTemplate prebodytext, postbodytext keys
* @param QuickTemplate $tpl
diff --git a/includes/specials/SpecialMobileMenu.php
b/includes/specials/SpecialMobileMenu.php
index 2692a2d..af18894 100644
--- a/includes/specials/SpecialMobileMenu.php
+++ b/includes/specials/SpecialMobileMenu.php
@@ -9,32 +9,26 @@
* @todo FIXME: Rename from MobileMenu to NavigationMenu
* @ingroup SpecialPage
*/
-class SpecialMobileMenu extends MobileSpecialPage {
+class SpecialMobileMenu extends SpecialPage {
/**
* Construct function
*/
public function __construct() {
parent::__construct( 'MobileMenu' );
- $supported = array( 'vector', 'minerva' );
- $name = $this->getSkin()->getSkinName();
- if ( array_search( $name, $supported ) !== false ) {
- $this->hasDesktopVersion = true;
- }
}
/**
* Render the navigation menu
* @param string $par never used
*/
- public function executeWhenAvailable( $par = '' ) {
+ public function execute( $par = '' ) {
$this->setHeaders();
$out = $this->getOutput();
+ $skin = $out->getSkin();
$out->setPageTitle( wfMessage(
'mobile-frontend-main-menu-page-title' )->text() );
- $out->setProperty( 'bodyClassName', 'navigation-enabled
navigation-full-screen' );
- $out->addModuleStyles(
- array(
- 'mobile.mainMenu',
- )
- );
+ if ( method_exists( $skin, 'enableMenu' ) ) {
+ $skin->enableMenu();
+ }
+ $out->addHtml( $this->msg( 'mobile-frontend-special-mobilemenu'
) );
}
}
diff --git a/resources/mobile.mainMenu/menu.mustache
b/resources/skins.minerva.scripts/menu.mustache
similarity index 100%
rename from resources/mobile.mainMenu/menu.mustache
rename to resources/skins.minerva.scripts/menu.mustache
--
To view, visit https://gerrit.wikimedia.org/r/245598
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Iaf429bb3f53a00647a680cd0b28befbd65f7c92f
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