From 3c8137c7bb2b2f62ac916352b25f06d9aadf20cc Mon Sep 17 00:00:00 2001
From: Demian Katz <demian.katz@villanova.edu>
Date: Wed, 26 Mar 2014 14:19:13 -0400
Subject: [PATCH] Allow tags to be disabled. - Resolves VUFIND-687.

---
 config/vufind/config.ini                      |  3 +
 .../src/VuFind/Controller/AbstractBase.php    | 12 ++++
 .../src/VuFind/Controller/AbstractRecord.php  |  5 ++
 .../VuFind/Controller/BrowseController.php    | 11 ++-
 .../src/VuFind/Controller/TagController.php   |  3 +
 .../src/VuFind/Recommend/FavoriteFacets.php   |  8 ++-
 .../src/VuFind/View/Helper/Root/Factory.php   | 16 +++++
 .../src/VuFind/View/Helper/Root/UserTags.php  | 68 +++++++++++++++++++
 .../RecordDriver/SolrDefault/core.phtml       | 34 +++++-----
 .../RecordDriver/SolrDefault/list-entry.phtml |  4 +-
 themes/blueprint/templates/cart/save.phtml    |  6 +-
 .../blueprint/templates/myresearch/edit.phtml |  6 +-
 themes/blueprint/templates/record/save.phtml  |  8 ++-
 .../RecordDriver/SolrDefault/core.phtml       | 34 +++++-----
 .../RecordDriver/SolrDefault/list-entry.phtml |  4 +-
 themes/bootstrap/templates/cart/save.phtml    | 12 ++--
 .../bootstrap/templates/myresearch/edit.phtml | 16 +++--
 themes/bootstrap/templates/record/save.phtml  | 14 ++--
 .../RecordDriver/SolrDefault/core.phtml       |  2 +-
 .../RecordDriver/SolrDefault/list-entry.phtml |  4 +-
 .../RecordDriver/SolrDefault/toolbar.phtml    |  4 +-
 .../jquerymobile/templates/record/save.phtml  |  8 ++-
 themes/root/theme.config.php                  |  1 +
 23 files changed, 211 insertions(+), 72 deletions(-)
 create mode 100644 module/VuFind/src/VuFind/View/Helper/Root/UserTags.php

diff --git a/config/vufind/config.ini b/config/vufind/config.ini
index 2163cac3210..e66fd8cb085 100644
--- a/config/vufind/config.ini
+++ b/config/vufind/config.ini
@@ -1068,3 +1068,6 @@ max_tag_length = 64
 [Social]
 ; Comments may be "enabled" or "disabled" (default = "enabled")
 comments = enabled
+; Tags may be "enabled" or "disabled" (default = "enabled")
+; When disabling tags, don't forget to also turn off tag search in searches.ini.
+tags = enabled
diff --git a/module/VuFind/src/VuFind/Controller/AbstractBase.php b/module/VuFind/src/VuFind/Controller/AbstractBase.php
index 617c7ca7793..4b5049e5f31 100644
--- a/module/VuFind/src/VuFind/Controller/AbstractBase.php
+++ b/module/VuFind/src/VuFind/Controller/AbstractBase.php
@@ -456,4 +456,16 @@ class AbstractBase extends AbstractActionController
     {
         return $this->getServiceLocator()->get('VuFind\Search\Memory');
     }
+
+    /**
+     * Are tags enabled?
+     *
+     * @return bool
+     */
+    protected function tagsEnabled()
+    {
+        $config = $this->getServiceLocator()->get('VuFind\Config')->get('config');
+        $tagSetting = isset($config->Social->tags) ? $config->Social->tags : true;
+        return $tagSetting && $tagSetting !== 'disabled';
+    }
 }
diff --git a/module/VuFind/src/VuFind/Controller/AbstractRecord.php b/module/VuFind/src/VuFind/Controller/AbstractRecord.php
index dd8a4ce84e5..cf837ce222f 100644
--- a/module/VuFind/src/VuFind/Controller/AbstractRecord.php
+++ b/module/VuFind/src/VuFind/Controller/AbstractRecord.php
@@ -176,6 +176,11 @@ class AbstractRecord extends AbstractBase
      */
     public function addtagAction()
     {
+        // Make sure tags are enabled:
+        if (!$this->tagsEnabled()) {
+            throw new \Exception('Tags disabled');
+        }
+
         // Force login:
         if (!($user = $this->getUser())) {
             return $this->forceLogin();
diff --git a/module/VuFind/src/VuFind/Controller/BrowseController.php b/module/VuFind/src/VuFind/Controller/BrowseController.php
index c1dfaef0a20..4a1d472ee54 100644
--- a/module/VuFind/src/VuFind/Controller/BrowseController.php
+++ b/module/VuFind/src/VuFind/Controller/BrowseController.php
@@ -121,9 +121,10 @@ class BrowseController extends AbstractBase
         $browseOptions = array();
 
         // First option: tags -- is it enabled in config.ini?  If no setting is
-        // found, assume it is active.
-        if (!isset($this->config->Browse->tag)
-            || $this->config->Browse->tag == true
+        // found, assume it is active. Note that this setting is disabled if tags
+        // are universally turned off.
+        if ((!isset($this->config->Browse->tag) || $this->config->Browse->tag)
+            && $this->tagsEnabled()
         ) {
             $browseOptions[] = $this->buildBrowseOption('Tag', 'Tag');
             $view->tagEnabled = true;
@@ -280,6 +281,10 @@ class BrowseController extends AbstractBase
      */
     public function tagAction()
     {
+        if (!$this->tagsEnabled()) {
+            throw new \Exception('Tags disabled.');
+        }
+
         $this->setCurrentAction('Tag');
         $view = $this->createViewModel();
 
diff --git a/module/VuFind/src/VuFind/Controller/TagController.php b/module/VuFind/src/VuFind/Controller/TagController.php
index 18d4a50420d..5f65bc85fa6 100644
--- a/module/VuFind/src/VuFind/Controller/TagController.php
+++ b/module/VuFind/src/VuFind/Controller/TagController.php
@@ -54,6 +54,9 @@ class TagController extends AbstractSearch
      */
     public function homeAction()
     {
+        if (!$this->tagsEnabled()) {
+            throw new \Exception('Tags disabled');
+        }
         return $this->resultsAction();
     }
 }
diff --git a/module/VuFind/src/VuFind/Recommend/FavoriteFacets.php b/module/VuFind/src/VuFind/Recommend/FavoriteFacets.php
index 57f368ec8da..df14009d6f1 100644
--- a/module/VuFind/src/VuFind/Recommend/FavoriteFacets.php
+++ b/module/VuFind/src/VuFind/Recommend/FavoriteFacets.php
@@ -51,6 +51,12 @@ class FavoriteFacets extends SideFacets
      */
     public function setConfig($settings)
     {
-        $this->mainFacets = array('tags' => 'Your Tags');
+        $config = $this->configLoader->get('config');
+        $tagSetting = isset($config->Social->tags)
+            ? $config->Social->tags : true;
+
+        // Only display tags when enabled:
+        $this->mainFacets = ($tagSetting && $tagSetting !== 'disabled')
+            ? array('tags' => 'Your Tags') : array();
     }
 }
diff --git a/module/VuFind/src/VuFind/View/Helper/Root/Factory.php b/module/VuFind/src/VuFind/View/Helper/Root/Factory.php
index 1336e5d0ec6..4ebaa5de4c1 100644
--- a/module/VuFind/src/VuFind/View/Helper/Root/Factory.php
+++ b/module/VuFind/src/VuFind/View/Helper/Root/Factory.php
@@ -443,6 +443,22 @@ class Factory
         );
     }
 
+    /**
+     * Construct the UserTags helper.
+     *
+     * @param ServiceManager $sm Service manager.
+     *
+     * @return UserTags
+     */
+    public static function getUserTags(ServiceManager $sm)
+    {
+        $cfg = $sm->getServiceLocator()->get('VuFind\Config')->get('config');
+        $mode = !isset($cfg->Social->tags)
+            || ($cfg->Social->tags && $cfg->Social->tags !== 'disabled')
+            ? 'enabled' : 'disabled';
+        return new UserTags($mode);
+    }
+
     /**
      * Construct the VideoClips helper.
      *
diff --git a/module/VuFind/src/VuFind/View/Helper/Root/UserTags.php b/module/VuFind/src/VuFind/View/Helper/Root/UserTags.php
new file mode 100644
index 00000000000..5fc09dd18a4
--- /dev/null
+++ b/module/VuFind/src/VuFind/View/Helper/Root/UserTags.php
@@ -0,0 +1,68 @@
+<?php
+/**
+ * Tag view helper
+ *
+ * PHP version 5
+ *
+ * Copyright (C) Villanova University 2010.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * @category VuFind2
+ * @package  View_Helpers
+ * @author   Demian Katz <demian.katz@villanova.edu>
+ * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
+ * @link     http://vufind.org/wiki/vufind2:developer_manual Wiki
+ */
+namespace VuFind\View\Helper\Root;
+use Zend\View\Helper\AbstractHelper;
+
+/**
+ * Tag view helper
+ *
+ * @category VuFind2
+ * @package  View_Helpers
+ * @author   Demian Katz <demian.katz@villanova.edu>
+ * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
+ * @link     http://vufind.org/wiki/vufind2:developer_manual Wiki
+ */
+class UserTags extends AbstractHelper
+{
+    /**
+     * Tag mode (enabled or disabled)
+     *
+     * @var string
+     */
+    protected $mode;
+
+    /**
+     * Constructor
+     *
+     * @param string $mode Tag mode (enabled or disabled)
+     */
+    public function __construct($mode = 'enabled')
+    {
+        $this->mode = $mode;
+    }
+
+    /**
+     * Get mode
+     *
+     * @return string
+     */
+    public function getMode()
+    {
+        return $this->mode;
+    }
+}
\ No newline at end of file
diff --git a/themes/blueprint/templates/RecordDriver/SolrDefault/core.phtml b/themes/blueprint/templates/RecordDriver/SolrDefault/core.phtml
index 63166c0477c..48b367ce5ad 100644
--- a/themes/blueprint/templates/RecordDriver/SolrDefault/core.phtml
+++ b/themes/blueprint/templates/RecordDriver/SolrDefault/core.phtml
@@ -192,22 +192,24 @@
     </tr>
     <? endif; ?>
 
-    <? $tagList = $this->driver->getTags(); ?>
-    <tr valign="top">
-      <th><?=$this->transEsc('Tags')?>: </th>
-      <td>
-        <span style="float:right;">
-          <a href="<?=$this->recordLink()->getActionUrl($this->driver, 'AddTag')?>" class="tool add tagRecord controller<?=$this->record($this->driver)->getController()?>" title="<?=$this->transEsc('Add Tag')?>" id="tagRecord"><?=$this->transEsc('Add Tag')?></a>
-        </span>
-        <div id="tagList">
-          <? if (count($tagList) > 0): ?>
-            <? $i = 0; foreach ($tagList as $tag): ?><?=($i++ == 0)?'':', '?><a href="<?=$this->url('tag-home')?>?lookfor=<?=urlencode($tag->tag)?>"><?=$this->escapeHtml($tag->tag)?></a> (<?=$this->escapeHtml($tag->cnt)?>)<? endforeach; ?>
-          <? else: ?>
-            <?=$this->transEsc('No Tags')?>, <?=$this->transEsc('Be the first to tag this record')?>!
-          <? endif; ?>
-        </div>
-      </td>
-    </tr>
+    <? if ($this->usertags()->getMode() !== 'disabled'): ?>
+      <? $tagList = $this->driver->getTags(); ?>
+      <tr valign="top">
+        <th><?=$this->transEsc('Tags')?>: </th>
+        <td>
+          <span style="float:right;">
+            <a href="<?=$this->recordLink()->getActionUrl($this->driver, 'AddTag')?>" class="tool add tagRecord controller<?=$this->record($this->driver)->getController()?>" title="<?=$this->transEsc('Add Tag')?>" id="tagRecord"><?=$this->transEsc('Add Tag')?></a>
+          </span>
+          <div id="tagList">
+            <? if (count($tagList) > 0): ?>
+              <? $i = 0; foreach ($tagList as $tag): ?><?=($i++ == 0)?'':', '?><a href="<?=$this->url('tag-home')?>?lookfor=<?=urlencode($tag->tag)?>"><?=$this->escapeHtml($tag->tag)?></a> (<?=$this->escapeHtml($tag->cnt)?>)<? endforeach; ?>
+            <? else: ?>
+              <?=$this->transEsc('No Tags')?>, <?=$this->transEsc('Be the first to tag this record')?>!
+            <? endif; ?>
+          </div>
+        </td>
+      </tr>
+    <? endif; ?>
   </table>
   <?/* End Main Details */?>
 </div>
diff --git a/themes/blueprint/templates/RecordDriver/SolrDefault/list-entry.phtml b/themes/blueprint/templates/RecordDriver/SolrDefault/list-entry.phtml
index dc8ba223317..9713dace5c8 100644
--- a/themes/blueprint/templates/RecordDriver/SolrDefault/list-entry.phtml
+++ b/themes/blueprint/templates/RecordDriver/SolrDefault/list-entry.phtml
@@ -32,10 +32,10 @@
       <?=$this->transEsc('by')?>:
       <a href="<?=$this->record($this->driver)->getLink('author', $listAuthor)?>"><?=$this->escapeHtml($listAuthor)?></a><br/>
     <? endif; ?>
-    <? $listTags = $this->driver->getTags(
+    <? $listTags = ($this->usertags()->getMode() !== 'disabled') ? $this->driver->getTags(
         $list_id, // get tags for all lists if no single list is selected
         $user_id, 'tag'
-       );
+       ) : array();
     ?>
     <? if (count($listTags) > 0): ?>
       <strong><?=$this->transEsc('Your Tags')?>:</strong>
diff --git a/themes/blueprint/templates/cart/save.phtml b/themes/blueprint/templates/cart/save.phtml
index ad10d06980f..e138ded47e4 100644
--- a/themes/blueprint/templates/cart/save.phtml
+++ b/themes/blueprint/templates/cart/save.phtml
@@ -31,8 +31,10 @@
 
   <a href="<?=$this->url('editList', array('id' => 'NEW')) . '?' . implode('&', $idParams) ?>" class="listEdit" id="listEdit" title="<?=$this->transEsc('Create a List') ?>"><?=$this->transEsc('or create a new list');?></a>
 
-  <label class="displayBlock" for="add_mytags"><?=$this->transEsc('Add Tags') ?></label>
-  <input class="mainFocus" id="add_mytags" type="text" name="mytags" value="" size="50"/>
+  <? if ($this->usertags()->getMode() !== 'disabled'): ?>
+    <label class="displayBlock" for="add_mytags"><?=$this->transEsc('Add Tags') ?></label>
+    <input class="mainFocus" id="add_mytags" type="text" name="mytags" value="" size="50"/>
+  <? endif; ?>
   <br/>
   <input class="button" type="submit" name="submit" value="<?=$this->transEsc('Save') ?>"/>
 
diff --git a/themes/blueprint/templates/myresearch/edit.phtml b/themes/blueprint/templates/myresearch/edit.phtml
index d9893c40de8..1c505bcbd2b 100644
--- a/themes/blueprint/templates/myresearch/edit.phtml
+++ b/themes/blueprint/templates/myresearch/edit.phtml
@@ -27,8 +27,10 @@
       <strong><?=$this->transEsc('List') ?>: <?=$this->escapeHtml($current['listTitle'])?></strong>
       <a href="<?=$this->url('userList', array('id' => $current['listId'])) ?>?delete=<?=urlencode($this->driver->getUniqueId())?>&amp;source=<?=urlencode($this->driver->getResourceSource())?>" id="<?=$this->escapeHtml($this->driver->getUniqueId())?>delete<?=$current['listId'] ?>" title="<?=$this->transEsc('confirm_delete')?>" class="holdCancel delete tool"></a>
       <input type="hidden" name="lists[]" value="<?=$current['listId'] ?>"/>
-      <label class="displayBlock" for="edit_tags<?=$current['listId'] ?>"><?=$this->transEsc('Tags') ?>:</label>
-      <input id="edit_tags<?=$current['listId'] ?>" type="text" name="tags<?=$current['listId'] ?>" value="<?=$this->escapeHtml($current['tags'])?>" size="50"/>
+      <? if ($this->usertags()->getMode() !== 'disabled'): ?>
+        <label class="displayBlock" for="edit_tags<?=$current['listId'] ?>"><?=$this->transEsc('Tags') ?>:</label>
+        <input id="edit_tags<?=$current['listId'] ?>" type="text" name="tags<?=$current['listId'] ?>" value="<?=$this->escapeHtml($current['tags'])?>" size="50"/>
+      <? endif; ?>
       <label class="displayBlock" for="edit_notes<?=$current['listId'] ?>"><?=$this->transEsc('Notes') ?>:</label>
       <textarea id="edit_notes<?=$current['listId'] ?>" class="displayBlock" name="notes<?=$current['listId'] ?>" rows="3" cols="50"><?=$this->escapeHtml($current['notes'])?></textarea>
       <br/><br/>
diff --git a/themes/blueprint/templates/record/save.phtml b/themes/blueprint/templates/record/save.phtml
index 176089dc601..b458a19620a 100644
--- a/themes/blueprint/templates/record/save.phtml
+++ b/themes/blueprint/templates/record/save.phtml
@@ -39,9 +39,11 @@
   <a href="<?=$this->url('editList', array('id' => 'NEW'))?>?recordId=<?=urlencode($this->driver->getUniqueId())?>&amp;recordSource=<?=urlencode($this->driver->getResourceSource())?>" class="listEdit controller<?=$this->record($this->driver)->getController()?>" title="<?=$this->transEsc('Create a List') ?>"><? if ($showLists) echo $this->transEsc('or create a new list'); else echo $this->transEsc('Create a List'); ?></a>
 
   <? if ($showLists): ?>
-    <label class="displayBlock" for="add_mytags"><?=$this->transEsc('Add Tags') ?></label>
-    <input class="mainFocus" id="add_mytags" type="text" name="mytags" value="" size="50"/>
-    <p><?=$this->transEsc("add_tag_note") ?></p>
+    <? if ($this->usertags()->getMode() !== 'disabled'): ?>
+      <label class="displayBlock" for="add_mytags"><?=$this->transEsc('Add Tags') ?></label>
+      <input class="mainFocus" id="add_mytags" type="text" name="mytags" value="" size="50"/>
+      <p><?=$this->transEsc("add_tag_note") ?></p>
+    <? endif; ?>
     <label class="displayBlock" for="add_notes"><?=$this->transEsc('Add a Note') ?></label>
     <textarea id="add_notes" name="notes" rows="3" cols="50"></textarea>
     <br/>
diff --git a/themes/bootstrap/templates/RecordDriver/SolrDefault/core.phtml b/themes/bootstrap/templates/RecordDriver/SolrDefault/core.phtml
index 7bba751d311..2b8d16b41b2 100644
--- a/themes/bootstrap/templates/RecordDriver/SolrDefault/core.phtml
+++ b/themes/bootstrap/templates/RecordDriver/SolrDefault/core.phtml
@@ -218,22 +218,24 @@
         </tr>
       <? endif; ?>
 
-      <? $tagList = $this->driver->getTags(); ?>
-      <tr>
-        <th><?=$this->transEsc('Tags')?>: </th>
-        <td>
-          <span class="pull-right">
-            <i class="icon-plus-sign"></i> <a id="tagRecord" href="<?=$this->recordLink()->getActionUrl($this->driver, 'AddTag')?>" title="<?=$this->transEsc('Add Tag')?>"><?=$this->transEsc('Add Tag')?></a>
-          </span>
-          <div id="tagList">
-            <? if (count($tagList) > 0): ?>
-              <? $i = 0; foreach ($tagList as $tag): ?><?=($i++ == 0)?'':', '?><a href="<?=$this->url('tag-home')?>?lookfor=<?=urlencode($tag->tag)?>"><?=$this->escapeHtml($tag->tag)?></a> (<?=$this->escapeHtml($tag->cnt)?>)<? endforeach; ?>
-            <? else: ?>
-              <?=$this->transEsc('No Tags')?>, <?=$this->transEsc('Be the first to tag this record')?>!
-            <? endif; ?>
-          </div>
-        </td>
-      </tr>
+      <? if ($this->usertags()->getMode() !== 'disabled'): ?>
+        <? $tagList = $this->driver->getTags(); ?>
+        <tr>
+          <th><?=$this->transEsc('Tags')?>: </th>
+          <td>
+            <span class="pull-right">
+              <i class="icon-plus-sign"></i> <a id="tagRecord" href="<?=$this->recordLink()->getActionUrl($this->driver, 'AddTag')?>" title="<?=$this->transEsc('Add Tag')?>"><?=$this->transEsc('Add Tag')?></a>
+            </span>
+            <div id="tagList">
+              <? if (count($tagList) > 0): ?>
+                <? $i = 0; foreach ($tagList as $tag): ?><?=($i++ == 0)?'':', '?><a href="<?=$this->url('tag-home')?>?lookfor=<?=urlencode($tag->tag)?>"><?=$this->escapeHtml($tag->tag)?></a> (<?=$this->escapeHtml($tag->cnt)?>)<? endforeach; ?>
+              <? else: ?>
+                <?=$this->transEsc('No Tags')?>, <?=$this->transEsc('Be the first to tag this record')?>!
+              <? endif; ?>
+            </div>
+          </td>
+        </tr>
+      <? endif; ?>
     </table>
     <?/* End Main Details */?>
   </div>
diff --git a/themes/bootstrap/templates/RecordDriver/SolrDefault/list-entry.phtml b/themes/bootstrap/templates/RecordDriver/SolrDefault/list-entry.phtml
index 9e0649a36fe..f427faff32f 100644
--- a/themes/bootstrap/templates/RecordDriver/SolrDefault/list-entry.phtml
+++ b/themes/bootstrap/templates/RecordDriver/SolrDefault/list-entry.phtml
@@ -85,10 +85,10 @@
         }
       } ?>
         
-    <? $listTags = $this->driver->getTags(
+    <? $listTags = ($this->usertags()->getMode() !== 'disabled') ? $this->driver->getTags(
         $list_id, // get tags for all lists if no single list is selected
         $user_id, 'tag'
-       );
+       ) : array();
     ?>
     <? if (count($listTags) > 0): ?>
       <strong><?=$this->transEsc('Your Tags')?>:</strong>
diff --git a/themes/bootstrap/templates/cart/save.phtml b/themes/bootstrap/templates/cart/save.phtml
index edc91fdfa03..cdd1aa52a66 100644
--- a/themes/bootstrap/templates/cart/save.phtml
+++ b/themes/bootstrap/templates/cart/save.phtml
@@ -49,12 +49,14 @@
     </div>
   </div>
 
-  <div class="control-group">
-    <label class="control-label" for="add_mytags"><?=$this->transEsc('Add Tags') ?></label>
-    <div class="controls">
-      <input class="mainFocus" id="add_mytags" type="text" name="mytags" value=""/>
+  <? if ($this->usertags()->getMode() !== 'disabled'): ?>
+    <div class="control-group">
+      <label class="control-label" for="add_mytags"><?=$this->transEsc('Add Tags') ?></label>
+      <div class="controls">
+        <input class="mainFocus" id="add_mytags" type="text" name="mytags" value=""/>
+      </div>
     </div>
-  </div>
+  <? endif; ?>
   <div class="control-group">
     <div class="controls">
       <input class="btn" type="submit" name="submit" value="<?=$this->transEsc('Save') ?>"/>
diff --git a/themes/bootstrap/templates/myresearch/edit.phtml b/themes/bootstrap/templates/myresearch/edit.phtml
index cb7a97eb64a..f8ed5fc8800 100644
--- a/themes/bootstrap/templates/myresearch/edit.phtml
+++ b/themes/bootstrap/templates/myresearch/edit.phtml
@@ -26,14 +26,16 @@
       <fieldset>
         <legend><a href="<?=$this->url('userList', array('id' => $current['listId'])) ?>?delete=<?=urlencode($this->driver->getUniqueId())?>&amp;source=<?=urlencode($this->driver->getResourceSource())?>" id="<?=$this->escapeHtml($this->driver->getUniqueId())?>delete<?=$current['listId'] ?>" title="<?=$this->transEsc('confirm_delete')?>" class="text-error small"><i class="icon-remove-sign"></i></a> <?=$this->transEsc('List') ?>: <?=$this->escapeHtml($current['listTitle'])?></legend>
         <input type="hidden" name="lists[]" value="<?=$current['listId'] ?>"/>
-        <div class="control-group">  
-          <label class="control-label" for="edit_tags<?=$current['listId'] ?>"><?=$this->transEsc('Tags') ?>:</label>
-          <div class="controls">
-            <input class="input-xlarge" id="edit_tags<?=$current['listId'] ?>" type="text" name="tags<?=$current['listId'] ?>" value="<?=$this->escapeHtml($current['tags'])?>"/>
-            <span class="help-block"><?=$this->transEsc("add_tag_note") ?></span>
+        <? if ($this->usertags()->getMode() !== 'disabled'): ?>
+          <div class="control-group">
+            <label class="control-label" for="edit_tags<?=$current['listId'] ?>"><?=$this->transEsc('Tags') ?>:</label>
+            <div class="controls">
+              <input class="input-xlarge" id="edit_tags<?=$current['listId'] ?>" type="text" name="tags<?=$current['listId'] ?>" value="<?=$this->escapeHtml($current['tags'])?>"/>
+              <span class="help-block"><?=$this->transEsc("add_tag_note") ?></span>
+            </div>
           </div>
-        </div>
-        <div class="control-group">  
+        <? endif; ?>
+        <div class="control-group">
           <label class="control-label" for="edit_notes<?=$current['listId'] ?>"><?=$this->transEsc('Notes') ?>:</label>
           <div class="controls">
             <textarea class="input-xlarge" id="edit_notes<?=$current['listId'] ?>" name="notes<?=$current['listId'] ?>" rows="3"><?=$this->escapeHtml($current['notes'])?></textarea>
diff --git a/themes/bootstrap/templates/record/save.phtml b/themes/bootstrap/templates/record/save.phtml
index 670c09fed31..9ca250384bf 100644
--- a/themes/bootstrap/templates/record/save.phtml
+++ b/themes/bootstrap/templates/record/save.phtml
@@ -44,13 +44,15 @@
   </div>
 
   <? if ($showLists): ?>
-    <div class="control-group">
-      <label class="control-label" for="add_mytags"><?=$this->transEsc('Add Tags') ?></label>
-      <div class="controls">
-        <input class="input-xlarge" id="add_mytags" type="text" name="mytags" value=""/>
-        <span class="help-block"><?=$this->transEsc("add_tag_note") ?></span>
+    <? if ($this->usertags()->getMode() !== 'disabled'): ?>
+      <div class="control-group">
+        <label class="control-label" for="add_mytags"><?=$this->transEsc('Add Tags') ?></label>
+        <div class="controls">
+          <input class="input-xlarge" id="add_mytags" type="text" name="mytags" value=""/>
+          <span class="help-block"><?=$this->transEsc("add_tag_note") ?></span>
+        </div>
       </div>
-    </div>
+    <? endif; ?>
     <div class="control-group">
       <label class="control-label" for="add_notes"><?=$this->transEsc('Add a Note') ?></label>
       <div class="controls">
diff --git a/themes/jquerymobile/templates/RecordDriver/SolrDefault/core.phtml b/themes/jquerymobile/templates/RecordDriver/SolrDefault/core.phtml
index cd0d0a8bee9..bebd579a95a 100644
--- a/themes/jquerymobile/templates/RecordDriver/SolrDefault/core.phtml
+++ b/themes/jquerymobile/templates/RecordDriver/SolrDefault/core.phtml
@@ -154,7 +154,7 @@
     </dd>
   <? endif; ?>
 
-  <? $tagList = $this->driver->getTags(); ?>
+  <? $tagList = ($this->usertags()->getMode() !== 'disabled') ? $this->driver->getTags() : array(); ?>
   <? if (count($tagList) > 0): ?>
     <dt><?=$this->transEsc('Tags')?>: </dt>
     <dd>
diff --git a/themes/jquerymobile/templates/RecordDriver/SolrDefault/list-entry.phtml b/themes/jquerymobile/templates/RecordDriver/SolrDefault/list-entry.phtml
index af10d29eb69..c468c8b28cd 100644
--- a/themes/jquerymobile/templates/RecordDriver/SolrDefault/list-entry.phtml
+++ b/themes/jquerymobile/templates/RecordDriver/SolrDefault/list-entry.phtml
@@ -26,10 +26,10 @@
     <? $listAuthor = $this->driver->getPrimaryAuthor(); if (!empty($listAuthor)): ?>
       <p><?=$this->transEsc('by')?> <?=$this->escapeHtml($listAuthor)?></p>
     <? endif; ?>
-    <? $listTags = $this->driver->getTags(
+    <? $listTags = ($this->usertags()->getMode() !== 'disabled') ? $this->driver->getTags(
         $list_id, // get tags for all lists if no single list is selected
         $user_id, 'tag'
-       );
+       ) : array();
     ?>
     <? if (count($listTags) > 0): ?>
       <p>
diff --git a/themes/jquerymobile/templates/RecordDriver/SolrDefault/toolbar.phtml b/themes/jquerymobile/templates/RecordDriver/SolrDefault/toolbar.phtml
index 6c060b5574e..32dc3343e81 100644
--- a/themes/jquerymobile/templates/RecordDriver/SolrDefault/toolbar.phtml
+++ b/themes/jquerymobile/templates/RecordDriver/SolrDefault/toolbar.phtml
@@ -1,6 +1,8 @@
 <div data-role="controlgroup">
   <a href="<?=$this->recordLink()->getActionUrl($this->driver, 'Save')?>" data-role="button" rel="external"><?=$this->transEsc("Add to favorites")?></a>
-  <a href="<?=$this->recordLink()->getActionUrl($this->driver, 'AddTag')?>" data-role="button" rel="external"><?=$this->transEsc("Add Tag")?></a>
+  <? if ($this->usertags()->getMode() !== 'disabled'): ?>
+    <a href="<?=$this->recordLink()->getActionUrl($this->driver, 'AddTag')?>" data-role="button" rel="external"><?=$this->transEsc("Add Tag")?></a>
+  <? endif; ?>
   <a href="<?=$this->recordLink()->getActionUrl($this->driver, 'Cite')?>" data-role="button" rel="external"><?=$this->transEsc("Cite this")?></a>
   <a href="<?=$this->recordLink()->getActionUrl($this->driver, 'Email')?>" data-role="button" rel="external"><?=$this->transEsc("Email this")?></a>
   <a href="<?=$this->recordLink()->getActionUrl($this->driver, 'SMS')?>" data-role="button" rel="external"><?=$this->transEsc("Text this")?></a>
diff --git a/themes/jquerymobile/templates/record/save.phtml b/themes/jquerymobile/templates/record/save.phtml
index 29a1cd5a10a..fb22ba7a224 100644
--- a/themes/jquerymobile/templates/record/save.phtml
+++ b/themes/jquerymobile/templates/record/save.phtml
@@ -40,9 +40,11 @@
         <a rel="external" data-role="button" data-rel="dialog" href="<?=$this->url('editList', array('id' => 'NEW')) ?>?recordId=<?=urlencode($this->driver->getUniqueId())?>&amp;recordSource=<?=urlencode($this->driver->getResourceSource())?>" class="listEdit controller<?=$this->record($this->driver)->getController()?>" title="<?=$this->transEsc('Create a List') ?>"><? if ($showLists) echo $this->transEsc('or create a new list'); else echo $this->transEsc('Create a List'); ?></a>
 
         <? if ($showLists): ?>
-          <label class="displayBlock" for="add_mytags"><?=$this->transEsc('Add Tags') ?></label>
-          <input class="mainFocus" id="add_mytags" type="text" name="mytags" value="" size="50"/>
-          <p><?=$this->transEsc("add_tag_note") ?></p>
+          <? if ($this->usertags()->getMode() !== 'disabled'): ?>
+            <label class="displayBlock" for="add_mytags"><?=$this->transEsc('Add Tags') ?></label>
+            <input class="mainFocus" id="add_mytags" type="text" name="mytags" value="" size="50"/>
+            <p><?=$this->transEsc("add_tag_note") ?></p>
+          <? endif; ?>
           <label class="displayBlock" for="add_notes"><?=$this->transEsc('Add a Note') ?></label>
           <textarea id="add_notes" name="notes"></textarea>
           </div><div data-role="fieldcontain">
diff --git a/themes/root/theme.config.php b/themes/root/theme.config.php
index 473db887b26..f10e81f2fd2 100644
--- a/themes/root/theme.config.php
+++ b/themes/root/theme.config.php
@@ -32,6 +32,7 @@ return array(
             'searchtabs' => 'VuFind\View\Helper\Root\Factory::getSearchTabs',
             'syndeticsplus' => 'VuFind\View\Helper\Root\Factory::getSyndeticsPlus',
             'systememail' => 'VuFind\View\Helper\Root\Factory::getSystemEmail',
+            'usertags' => 'VuFind\View\Helper\Root\Factory::getUserTags',
             'videoclips' => 'VuFind\View\Helper\Root\Factory::getVideoClips',
             'worldcat' => 'VuFind\View\Helper\Root\Factory::getWorldCat',
         ),
-- 
GitLab