From 6ae35bf49023aba499763e7f45d860162cd5b581 Mon Sep 17 00:00:00 2001
From: Moritz Strohm <strohm@data-quest.de>
Date: Fri, 16 Dec 2022 10:04:55 +0000
Subject: [PATCH] TIC 1388, closes #1388

Closes #1388

Merge request studip/studip!1161
---
 app/controllers/settings/accessibility.php    |  1 -
 app/controllers/settings/general.php          |  1 -
 app/views/settings/accessibility.php          | 12 --------
 .../5.3.13_remove_skiplinks_enable.php        | 28 +++++++++++++++++
 lib/classes/SkipLinks.php                     | 30 +------------------
 lib/include/html_head.inc.php                 |  2 ++
 .../assets/stylesheets/scss/skiplinks.scss    | 13 --------
 templates/header.php                          |  3 +-
 templates/layouts/base.php                    |  3 +-
 9 files changed, 35 insertions(+), 58 deletions(-)
 create mode 100644 db/migrations/5.3.13_remove_skiplinks_enable.php

diff --git a/app/controllers/settings/accessibility.php b/app/controllers/settings/accessibility.php
index 6e53cc0531e..5ca4e8dc1a1 100644
--- a/app/controllers/settings/accessibility.php
+++ b/app/controllers/settings/accessibility.php
@@ -36,7 +36,6 @@ class Settings_AccessibilityController extends Settings_SettingsController
         CSRFProtection::verifyUnsafeRequest();
 
         $this->config->store('USER_HIGH_CONTRAST', Request::bool('enable_high_contrast'));
-        $this->config->store('SKIPLINKS_ENABLE', Request::bool('skiplinks_enable'));
 
         PageLayout::postSuccess(_('Ihre Einstellungen wurden gespeichert.'));
         $this->redirect('settings/accessibility');
diff --git a/app/controllers/settings/general.php b/app/controllers/settings/general.php
index 3c17eb66dab..8b6ef0edfb9 100644
--- a/app/controllers/settings/general.php
+++ b/app/controllers/settings/general.php
@@ -64,7 +64,6 @@ class Settings_GeneralController extends Settings_SettingsController
 
         $this->config->store('PERSONAL_STARTPAGE', Request::int('personal_startpage'));
         $this->config->store('SHOWSEM_ENABLE', Request::int('showsem_enable'));
-        $this->config->store('SKIPLINKS_ENABLE', Request::int('skiplinks_enable'));
         $this->config->store('TOUR_AUTOSTART_DISABLE', Request::int('tour_autostart_disable'));
         $this->config->store('WIKI_COMMENTS_ENABLE', Request::int('wiki_comments_enable'));
         if ($this->show_room_management_autor_config) {
diff --git a/app/views/settings/accessibility.php b/app/views/settings/accessibility.php
index 7bd19a26ede..366992e6e2b 100644
--- a/app/views/settings/accessibility.php
+++ b/app/views/settings/accessibility.php
@@ -12,18 +12,6 @@
                 _('Mit dieser Einstellung wird ein Farbschema mit hohem Kontrast aktiviert.')
             ) ?>
         </label>
-
-        <label>
-            <input type="checkbox" name="skiplinks_enable"
-                   value="1"
-                <? if ($config->SKIPLINKS_ENABLE) echo 'checked'; ?>>
-            <?= _('Skiplinks einblenden') ?>
-            <?= tooltipIcon(_('Mit dieser Einstellung wird nach dem ersten Drücken der Tab-Taste eine '
-                .'Liste mit Skiplinks eingeblendet, mit deren Hilfe Sie mit der Tastatur '
-                .'schneller zu den Hauptinhaltsbereichen der Seite navigieren können. '
-                .'Zusätzlich wird der aktive Bereich einer Seite hervorgehoben.')) ?>
-        </label>
-
     </fieldset>
 
     <footer>
diff --git a/db/migrations/5.3.13_remove_skiplinks_enable.php b/db/migrations/5.3.13_remove_skiplinks_enable.php
new file mode 100644
index 00000000000..e1f7d1408d3
--- /dev/null
+++ b/db/migrations/5.3.13_remove_skiplinks_enable.php
@@ -0,0 +1,28 @@
+<?php
+
+
+class RemoveSkiplinksEnable extends Migration
+{
+    public function description()
+    {
+        return 'Removes SKIPLINKS_ENABLE.';
+    }
+
+    protected function up()
+    {
+        $db = DBManager::get();
+        $db->exec("DELETE FROM `config_values` WHERE `field` = 'SKIPLINKS_ENABLE'");
+        $db->exec("DELETE FROM `config` WHERE `field` = 'SKIPLINKS_ENABLE'");
+    }
+
+    protected function down()
+    {
+        $db = DBManager::get();
+        $db->exec(
+            "INSERT INTO `config`
+            (`field`, `value`, `type`, `range`, `section`, `mkdate`, `chdate`, `description`)
+            VALUES
+            ('SKIPLINKS_ENABLE', '', 'boolean', 'user', 'privacy', 1311411856, 1311411856, 'Wählen Sie diese Option, um Skiplinks beim ersten Drücken der Tab-Taste anzuzeigen (Systemdefault).')"
+        );
+    }
+}
diff --git a/lib/classes/SkipLinks.php b/lib/classes/SkipLinks.php
index 796206d0f11..3d44ab12c46 100644
--- a/lib/classes/SkipLinks.php
+++ b/lib/classes/SkipLinks.php
@@ -25,34 +25,6 @@ class SkipLinks
      */
     private static $links = [];
 
-    /**
-     * Returns whether skiplinks are enabled.
-     *
-     * @return boolean
-     */
-    public static function isEnabled()
-    {
-        if (isset($GLOBALS['user']->id)) {
-            //Use the user configuration:
-            return UserConfig::get($GLOBALS['user']->id)->SKIPLINKS_ENABLE;
-        } else {
-            //Use the global configuration:
-            return Config::get()->SKIPLINKS_ENABLE;
-        }
-    }
-
-    /**
-     * Inserts container for skip links in page layout.
-     */
-    public static function insertContainer()
-    {
-        if (!self::isEnabled()) {
-            return;
-        }
-
-        PageLayout::addBodyElements('<div id="skip_link_navigation" aria-busy="true"></div>');
-    }
-
     /**
      * Adds a link to the list of skip links.
      *
@@ -92,7 +64,7 @@ class SkipLinks
      */
     public static function getHTML()
     {
-        if (!self::isEnabled() || count(self::$links) === 0) {
+        if (count(self::$links) === 0) {
             return '';
         }
 
diff --git a/lib/include/html_head.inc.php b/lib/include/html_head.inc.php
index a7f2c21e1c4..f1108ce7536 100644
--- a/lib/include/html_head.inc.php
+++ b/lib/include/html_head.inc.php
@@ -62,3 +62,5 @@ $lang_attr = str_replace('_', '-', $_SESSION['_language']);
 </head>
 
 <body id="<?= PageLayout::getBodyElementId() ?>">
+    <div id="skip_link_navigation" aria-busy="true"></div>
+    <?= PageLayout::getBodyElements() ?>
diff --git a/resources/assets/stylesheets/scss/skiplinks.scss b/resources/assets/stylesheets/scss/skiplinks.scss
index da8cc52e44b..dd25f8bdde8 100644
--- a/resources/assets/stylesheets/scss/skiplinks.scss
+++ b/resources/assets/stylesheets/scss/skiplinks.scss
@@ -41,16 +41,3 @@ button.skiplink {
         transition: color 0.3s;
     }
 }
-
-body.enable-skiplinks {
-    *:not(:empty):focus {
-        outline: 2px dashed $orange;
-    }
-
-    #tabs {
-        a:focus {
-            position: relative;
-            z-index: 100;
-        }
-    }
-}
diff --git a/templates/header.php b/templates/header.php
index c59d081627c..be445e73ea2 100644
--- a/templates/header.php
+++ b/templates/header.php
@@ -50,7 +50,8 @@ if ($navigation) {
 }
 
 ?>
-<? SkipLinks::insertContainer() ?>
+<div id="skip_link_navigation" aria-busy="true"></div>
+<? SkipLinks::addIndex(_('Hauptinhalt'), 'content', 100) ?>
 <?= PageLayout::getBodyElements() ?>
 
 <!-- Begin main site header -->
diff --git a/templates/layouts/base.php b/templates/layouts/base.php
index e3eb6c39ec1..ddf8b1b4da7 100644
--- a/templates/layouts/base.php
+++ b/templates/layouts/base.php
@@ -70,7 +70,8 @@ $lang_attr = str_replace('_', '-', $_SESSION['_language']);
 </script>
 </head>
 
-<body id="<?= PageLayout::getBodyElementId() ?>" <? if (SkipLinks::isEnabled()) echo 'class="enable-skiplinks"'; ?>>
+<body id="<?= PageLayout::getBodyElementId() ?>" class="enable-skiplinks">
+    <div id="skip_link_navigation" aria-busy="true"></div>
     <? SkipLinks::addIndex(_('Hauptinhalt'), 'content', 100) ?>
 
     <? include 'lib/include/header.php' ?>
-- 
GitLab