From 17ef2ab637c9b3af96b1d1d098d730916ae9cd37 Mon Sep 17 00:00:00 2001
From: Andreas Gohr <andi@splitbrain.org>
Date: Fri, 19 May 2017 15:47:41 +0200
Subject: [PATCH] use the new menu classes in DokuWiki template

---
 lib/tpl/dokuwiki/detail.php |  19 ++-----
 lib/tpl/dokuwiki/main.php   |  23 ++------
 lib/tpl/dokuwiki/tpl.php    | 101 ------------------------------------
 3 files changed, 6 insertions(+), 137 deletions(-)
 delete mode 100644 lib/tpl/dokuwiki/tpl.php

diff --git a/lib/tpl/dokuwiki/detail.php b/lib/tpl/dokuwiki/detail.php
index b1ff73287..dae13abf1 100644
--- a/lib/tpl/dokuwiki/detail.php
+++ b/lib/tpl/dokuwiki/detail.php
@@ -93,22 +93,9 @@ header('X-UA-Compatible: IE=edge,chrome=1');
                     <div class="tools">
                         <ul>
                             <?php
-                                $data = array(
-                                    'view' => 'detail-svg',
-                                    'items' => array(
-                                        'mediaManager' => dokuwiki\template\dokuwiki\tpl::pageToolAction('mediaManager'),
-                                        'img_backto' =>   dokuwiki\template\dokuwiki\tpl::pageToolAction('img_backto'),
-                                    )
-                                );
-
-                                // the page tools can be amended through a custom plugin hook
-                                $evt = new Doku_Event('TEMPLATE_PAGETOOLS_DISPLAY', $data);
-                                if($evt->advise_before()) {
-                                    foreach($evt->data['items'] as $k => $html) echo "<li>$html</li>";
-                                }
-                                $evt->advise_after();
-                                unset($data);
-                                unset($evt);
+                                $menu = new \dokuwiki\Menu\DetailMenu();
+                                echo $menu->getListItems();
+                                unset($menu);
                             ?>
                         </ul>
                     </div>
diff --git a/lib/tpl/dokuwiki/main.php b/lib/tpl/dokuwiki/main.php
index 41b3e3c1e..dfd4b12a2 100644
--- a/lib/tpl/dokuwiki/main.php
+++ b/lib/tpl/dokuwiki/main.php
@@ -74,26 +74,9 @@ $showSidebar = $hasSidebar && ($ACT=='show');
                 <div class="tools">
                     <ul>
                         <?php
-                            $data = array(
-                                'view'  => 'main-svg',
-                                'items' => array(
-                                    'edit'      => dokuwiki\template\dokuwiki\tpl::pageToolAction('edit'),
-                                    'revert'    => dokuwiki\template\dokuwiki\tpl::pageToolAction('revert'),
-                                    'revisions' => dokuwiki\template\dokuwiki\tpl::pageToolAction('revisions'),
-                                    'backlink'  => dokuwiki\template\dokuwiki\tpl::pageToolAction('backlink'),
-                                    'subscribe' => dokuwiki\template\dokuwiki\tpl::pageToolAction('subscribe'),
-                                    'top'       => dokuwiki\template\dokuwiki\tpl::pageToolAction('top'),
-                                )
-                            );
-
-                            // the page tools can be amended through a custom plugin hook
-                            $evt = new Doku_Event('TEMPLATE_PAGETOOLS_DISPLAY', $data);
-                            if($evt->advise_before()){
-                                foreach($evt->data['items'] as $k => $html) echo "<li>$html</li>";
-                            }
-                            $evt->advise_after();
-                            unset($data);
-                            unset($evt);
+                            $menu = new \dokuwiki\Menu\PageMenu();
+                            echo $menu->getListItems();
+                            unset($menu);
                         ?>
                     </ul>
                 </div>
diff --git a/lib/tpl/dokuwiki/tpl.php b/lib/tpl/dokuwiki/tpl.php
deleted file mode 100644
index 3e10a3a70..000000000
--- a/lib/tpl/dokuwiki/tpl.php
+++ /dev/null
@@ -1,101 +0,0 @@
-<?php
-
-namespace dokuwiki\template\dokuwiki;
-
-/**
- * Class tpl
- *
- * Provides additional template functions for the dokuwiki template
- * @package dokuwiki\tpl\dokuwiki
- */
-class tpl {
-
-    static $icons = array(
-        'default' => '00-default_checkbox-blank-circle-outline.svg',
-        'edit' => '01-edit_pencil.svg',
-        'create' => '02-create_pencil.svg',
-        'draft' => '03-draft_android-studio.svg',
-        'show' => '04-show_file-document.svg',
-        'source' => '05-source_file-xml.svg',
-        'revert' => '06-revert_replay.svg',
-        'revs' => '07-revisions_history.svg',
-        'backlink' => '08-backlink_link-variant.svg',
-        'subscribe' => '09-subscribe_email-outline.svg',
-        'top' => '10-top_arrow-up.svg',
-        'mediaManager' => '11-mediamanager_folder-image.svg',
-        'img_backto' => '12-back_arrow-left.svg',
-
-    );
-
-    /**
-     * Return the HTML for one of the default actions
-     *
-     * Reimplements parts of tpl_actionlink
-     *
-     * @param string $action
-     * @return string
-     */
-    static public function pageToolAction($action) {
-        $data = tpl_get_action($action);
-        if(!is_array($data)) return '';
-        global $lang;
-
-        if($data['id'][0] == '#') {
-            $linktarget = $data['id'];
-        } else {
-            $linktarget = wl($data['id'], $data['params']);
-        }
-        $caption = $lang['btn_' . $data['type']];
-        if(strpos($caption, '%s')) {
-            $caption = sprintf($caption, $data['replacement']);
-        }
-
-        $svg = __DIR__ . '/images/tools/' . self::$icons[$data['type']];
-
-        return self::pageToolItem(
-            $linktarget,
-            $caption,
-            $svg,
-            array('accesskey' => $data['accesskey'])
-        );
-    }
-
-    /**
-     * Return the HTML for a page action
-     *
-     * Plugins may use this in TEMPLATE_PAGETOOLS_DISPLAY
-     *
-     * @param string $link The link
-     * @param string $caption The label of the action
-     * @param string $svg The icon to show
-     * @param string[] $args HTML attributes for the item
-     * @return string
-     */
-    static public function pageToolItem($link, $caption, $svg, $args = array()) {
-        if(blank($args['title'])) {
-            $args['title'] = $caption;
-        }
-
-        if(!blank($args['accesskey'])) {
-            $args['title'] .= ' [' . strtoupper($args['accesskey']) . ']';
-        }
-
-        if(blank($args['rel'])) {
-            $args['rel'] = 'nofollow';
-        }
-
-        $args['href'] = $link;
-
-        $svg = inlineSVG($svg);
-        if(!$svg) $svg = inlineSVG(__DIR__ . '/images/tools/' . self::$icons['default']);
-
-        $attributes = buildAttributes($args, true);
-
-        $out = "<a $attributes>";
-        $out .= '<span>' . hsc($caption) . '</span>';
-        $out .= $svg;
-        $out .= '</a>';
-
-        return $out;
-    }
-}
-- 
GitLab