<?php
$curuserprefs = $user->getPreferences();
$dbh = $request->getDbh();
$isAdmin = $user->isAdmin();
$pagename = $page->getName();
$isActionPage = isActionPage($pagename);
$isBrowse = $request->getArg('action') == 'browse';
?>

  <nav id="actionbuttons">
  <ul>
    <?php if (!string_ends_with($pagename, SUBPAGE_SEPARATOR._("Discussion"))) { ?>
    <?php $talk = new WikiPageName('Talk:'.$pagename); ?>
      <li class="bold">
      <?php echo Button(array(), $isActionPage ? _("Action Page") : _("Page"), $talk->getParent()) ?>
      </li>
      <?php if (!$isActionPage) { ?>
        <?php if ($dbh->isWikiPage($talk->getName())) { ?>
          <li>
          <?php echo Button(array('action'=>'browse'), _("Discussion"), $talk->getName()) ?>
          </li>
        <?php } else { ?>
          <li>
          <?php echo Button(array('action'=>'create',
                                 'template'=>_("Template/Talk")),
                           _("Discussion"), $talk->getName()) ?>
          </li>
        <?php } ?>
      <?php } ?>
    <?php } else {
      $talk = new WikiPageName($pagename); ?>
      <li>
      <?php echo Button(array(), $isActionPage ? _("Action Page") : _("Page"), $talk->getParent()) ?>
      </li>
      <li class="bold">
      <?php echo Button(array(), _("Discussion"), $talk->getName()) ?>
      </li>
    <?php } ?>
  </ul>

  <ul>
    <?php if ($user->isAdmin() or (!($page->get('locked')) and (mayAccessPage('edit', $page->getName())))) { ?>
      <li class="bold">
      <?php if (! $dbh->isWikiPage($page->getName())) { ?>
      <?php echo Button("edit", _("Create Page")) ?>
      <?php } else if ($revision && (($revision->isCurrent()) || ($revision->hasDefaultContents()))) { ?>
      <?php echo Button("edit", _("Edit")) ?>
      <?php } else { ?>
      <?php echo Button("edit", _("Edit Old Revision")) ?>
      <?php } ?>
      </li>
    <?php } else if ($dbh->isWikiPage($page->getName())) { ?>
      <li><?php echo Button("viewsource", _("View Source")) ?></li>
    <?php } ?>

    <?php if ($dbh->isWikiPage($page->getName())) { ?>

    <li><?php echo Button(__("PageHistory"), _("History")) ?></li>

    <?php if ($curuserprefs->get('diffMenuItem')) { ?>
      <li><?php echo Button("diff", _("Last Difference")) ?> </li>
    <?php } ?>

    <?php if ($revision && $curuserprefs->get('revertMenuItem')) { ?>
      <li><?php echo Button('revert',_("Revert"), $revision->isCurrent() ? $page->GetRevisionBefore() : $revision) ?></li>
    <?php } ?>

      <li><?php echo Button(__("PageInfo"), _("Page Info")) ?></li>

      <li><?php echo Button(array('action'=>__("BackLinks")), _("Back Links"),$page->getName()) ?></li>

    <?php if (defined('USE_EXTERNAL_HTML2PDF') and USE_EXTERNAL_HTML2PDF) { ?>
      <?php if ($curuserprefs->get('pdfMenuItem')) { ?>
        <li><?php echo Button("pdf") ?></li>
      <?php } ?>
    <?php } ?>
  </ul>

  <ul>
    <?php if ($user->isAdmin() or mayAccessPage('change', $page->getName())) { ?>
      <?php if ($curuserprefs->get('lockMenuItem')) { ?>
        <?php if ($page->get('locked')) { ?>
          <li><?php echo Button('unlock', _("Unlock")) ?></li>
        <?php } else { ?>
          <li><?php echo Button('lock', _("Lock")) ?></li>
        <?php } ?>
      <?php } ?>

      <?php if (ENABLE_PAGEPERM and mayAccessPage('change', $page->getName())) { ?>
        <?php if ($curuserprefs->get('chownMenuItem')) { ?>
          <li><?php echo Button('chown', _("Change Owner")) ?></li>
        <?php } ?>

        <?php if ($curuserprefs->get('setaclMenuItem')) { ?>
          <li><?php echo Button('setaclsimple', _("Access Rights")) ?></li>
        <?php } ?>
      <?php } ?>
    <?php } ?>

    <?php if (($user->isAdmin() or mayAccessPage('rename', $page->getName())) && $revision) { ?>
        <li><?php echo Button('rename', _("Rename")) ?></li>
    <?php } ?>

    <?php if (($user->isAdmin() or mayAccessPage('purge', $page->getName())) && $revision) { ?>
        <li><?php echo Button('purge', _("Purge")) ?></li>
    <?php } ?>

    <?php } ?>
  </ul>

  <ul>
    <li><?php echo Button(__("WatchPage"), _("Watch Page")) ?></li>
  </ul>
  </nav>
