Jdlrobson has uploaded a new change for review.

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

Change subject: Render main menu via a server side template
......................................................................

Render main menu via a server side template

Bug: T97431
Change-Id: Iba0b2a76d063e35d0d9490d3bec407d92fad83f1
---
M includes/skins/MinervaTemplate.php
A resources/mobile.mainMenu/menu.mustache
2 files changed, 42 insertions(+), 36 deletions(-)


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

diff --git a/includes/skins/MinervaTemplate.php 
b/includes/skins/MinervaTemplate.php
index 94c2f11..eff053c 100644
--- a/includes/skins/MinervaTemplate.php
+++ b/includes/skins/MinervaTemplate.php
@@ -354,47 +354,30 @@
        }
 
        /**
-        * Renders the main menu.
-        *
-        * @param array $data Data used to build the page
+        * temporary function that flattens old style menu definitions to 
template compatible definition.
+        * This can be safely removed once we have fully transitioned to menus 
that use templates.
         */
-       protected function renderMainMenu( $data ) {
-               ?>
-               <nav id="mw-mf-page-left" class="navigation-drawer">
-               <?php
-               $this->renderMainMenuItems();
-               ?>
-               </nav>
-               <?php
+       private function flattenLinkArray( $array ) {
+               $menu = array();
+               foreach( $array as $name => $info ) {
+                       $base = isset( $info['links'][0] ) ? $info['links'][0] 
: $info;
+                       $menu[] = array_merge( $base, array( 'name' => $name ) 
);
+               }
+               return $menu;
        }
 
        /**
-        * Renders the contents of the main menu.
+        * Renders the main menu.
         */
-       protected function renderMainMenuItems() {
-               ?>
-               <ul>
-                       <?php
-                               foreach ( $this->getDiscoveryTools() as $key => 
$val ) {
-                                       echo $this->makeListItem( $key, $val );
-                               }
-                       ?>
-                       </ul>
-                       <ul>
-                       <?php
-                               foreach ( $this->getPersonalTools() as $key => 
$val ){
-                                       echo $this->makeListItem( $key, $val );
-                               }
-                       ?>
-                       </ul>
-                       <ul class="hlist">
-                       <?php
-                               foreach ( $this->getSiteLinks() as $key => $val 
) {
-                                       echo $this->makeListItem( $key, $val );
-                               }
-                       ?>
-                       </ul>
-               <?php
+       protected function renderMainMenu( $data ) {
+               $templateParser = new TemplateParser( __DIR__ . 
'/../../resources/mobile.mainMenu/' );
+
+               $data = array(
+                       'discovery' => $this->flattenLinkArray( 
$this->getDiscoveryTools() ),
+                       'personal' => 
$this->flattenLinkArray($this->getPersonalTools() ),
+                       'sitelinks' => $this->flattenLinkArray( 
$this->getSiteLinks() ),
+               );
+               echo $templateParser->processTemplate( 'menu', $data );
        }
 
        /**
diff --git a/resources/mobile.mainMenu/menu.mustache 
b/resources/mobile.mainMenu/menu.mustache
new file mode 100644
index 0000000..bcedf76
--- /dev/null
+++ b/resources/mobile.mainMenu/menu.mustache
@@ -0,0 +1,23 @@
+<nav id="mw-mf-page-left" class="navigation-drawer">
+       <ul>
+               {{#discovery}}
+               <li>
+                       <a href="{{href}}" class="{{class}}" 
data-event-name="{{name}}">{{text}}</a>
+               </li>
+               {{/discovery}}
+       </ul>
+       <ul>
+               {{#personal}}
+               <li>
+                       <a href="{{href}}" class="{{class}}" 
data-event-name="{{data-event-name}}">{{text}}</a>
+               </li>
+               {{/personal}}
+       </ul>
+       <ul class="hlist">
+               {{#sitelinks}}
+               <li>
+                       <a href="{{href}}" class="{{class}}" 
data-event-name="{{data-event-name}}">{{text}}</a>
+               </li>
+               {{/sitelinks}}
+       </ul>
+</nav>

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Iba0b2a76d063e35d0d9490d3bec407d92fad83f1
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

Reply via email to