From e66262ac09b0a7360d85dc4b56f5f0ab08900122 Mon Sep 17 00:00:00 2001
From: Ere Maijala <ere.maijala@helsinki.fi>
Date: Fri, 22 Feb 2019 13:45:02 +0200
Subject: [PATCH] Bug 21280: Add pref for MARC authority documentation url

Makes the documentation url for authorities separately configurable.

Signed-off-by: Michal Denar <black23@gmail.com>

Signed-off-by: Michal Denar <black23@gmail.com>

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>
---
 installer/data/mysql/atomicupdate/bug_21280.perl             | 12 ++++++++++++
 installer/data/mysql/sysprefs.sql                            |  1 +
 koha-tmpl/intranet-tmpl/prog/en/includes/marc_editor.inc     |  4 ++--
 .../prog/en/modules/admin/preferences/authorities.pref       |  8 ++++++++
 .../intranet-tmpl/prog/en/modules/authorities/authorities.tt |  2 +-
 .../intranet-tmpl/prog/en/modules/cataloguing/addbiblio.tt   |  2 +-
 6 files changed, 25 insertions(+), 4 deletions(-)
 create mode 100644 installer/data/mysql/atomicupdate/bug_21280.perl

diff --git a/installer/data/mysql/atomicupdate/bug_21280.perl b/installer/data/mysql/atomicupdate/bug_21280.perl
new file mode 100644
index 0000000..f52a3ce
--- /dev/null
+++ b/installer/data/mysql/atomicupdate/bug_21280.perl
@@ -0,0 +1,12 @@
+
+$DBversion = 'XXX'; # will be replaced by the RM
+if( CheckVersion( $DBversion ) ) {
+    $dbh->do(q|
+        INSERT IGNORE INTO systempreferences (`variable`, `value`, `options`, `explanation`, `type`) VALUES
+            ('AuthorityMarcFieldDocURL', NULL, NULL, 'URL used for MARC authority record field documentation. Following substitutions are available: {MARC} = marc flavour, eg. "MARC21" or "UNIMARC". {FIELD} = field number, eg. "000" or "048". {LANG} = user language, eg. "en" or "fi-FI"', 'free')
+    |);
+
+    # Always end with this (adjust the bug info)
+    SetVersion( $DBversion );
+    print "Upgrade to $DBversion done (Bug 21280 - Add AuthorityMarcFieldDocURL pref)\n";
+}
diff --git a/installer/data/mysql/sysprefs.sql b/installer/data/mysql/sysprefs.sql
index eae58f6..d8c85ce 100644
--- a/installer/data/mysql/sysprefs.sql
+++ b/installer/data/mysql/sysprefs.sql
@@ -59,6 +59,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `
 ('AuthDisplayHierarchy','0','','Display authority hierarchies','YesNo'),
 ('AuthoritiesLog','1',NULL,'If ON, log edit/create/delete actions on authorities.','YesNo'),
 ('AuthorityControlledIndicators','# PERSO_NAME  100 600 696 700 796 800 896\nmarc21, 100, ind1:auth1\nmarc21, 600, ind1:auth1, ind2:thesaurus\nmarc21, 696, ind1:auth1\nmarc21, 700, ind1:auth1\nmarc21, 796, ind1:auth1\nmarc21, 800, ind1:auth1\nmarc21, 896, ind1:auth1\n# CORPO_NAME  110 610 697 710 797 810 897\nmarc21, 110, ind1:auth1\nmarc21, 610, ind1:auth1, ind2:thesaurus\nmarc21, 697, ind1:auth1\nmarc21, 710, ind1:auth1\nmarc21, 797, ind1:auth1\nmarc21, 810, ind1:auth1\nmarc21, 897, ind1:auth1\n# MEETI_NAME    111 611 698 711 798 811 898\nmarc21, 111, ind1:auth1\nmarc21, 611, ind1:auth1, ind2:thesaurus\nmarc21, 698, ind1:auth1\nmarc21, 711, ind1:auth1\nmarc21, 798, ind1:auth1\nmarc21, 811, ind1:auth1\nmarc21, 898, ind1:auth1\n# UNIF_TITLE        130 440 630 699 730 799 830 899\nmarc21, 130, ind1:auth2\nmarc21, 240, , ind2:auth2\nmarc21, 440, , ind2:auth2\nmarc21, 630, ind1:auth2, ind2:thesaurus\nmarc21, 699, ind1:auth2\nmarc21, 730, ind1:auth2\nmarc21, 799, ind1:auth2\nmarc21, 830, , ind2:auth2\nmarc21, 899, ind1:auth2\n# CHRON_TERM    648 \nmarc21, 648, , ind2:thesaurus\n# TOPIC_TERM      650 654 656 657 658 690\nmarc21, 650, , ind2:thesaurus\n# GEOGR_NAME   651 662 691\nmarc21, 651, , ind2:thesaurus\n# GENRE/FORM    655 \nmarc21, 655, , ind2:thesaurus\n\n# UNIMARC: Always copy the indicators from the authority\nunimarc, *, ind1:auth1, ind2:auth2',NULL,'Authority controlled indicators per biblio field','Free'),
+('AuthorityMarcFieldDocURL', NULL, NULL, 'URL used for MARC authority record field documentation. Following substitutions are available: {MARC} = marc flavour, eg. "MARC21" or "UNIMARC". {FIELD} = field number, eg. "000" or "048". {LANG} = user language, eg. "en" or "fi-FI"', 'free'),
 ('AuthorityMergeLimit','50',NULL,'Maximum number of biblio records updated immediately when an authority record has been modified.','integer'),
 ('AuthorityMergeMode','loose','loose|strict','Authority merge mode','Choice'),
 ('AuthoritySeparator','--','10','Used to separate a list of authorities in a display. Usually --','free'),
diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/marc_editor.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/marc_editor.inc
index 9255dfb..df5da66 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/includes/marc_editor.inc
+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/marc_editor.inc
@@ -42,8 +42,8 @@ $(document).ready(function() {
 });
 
 function PopupMARCFieldDoc(field) {
-    [% IF Koha.Preference('marcfielddocurl') %]
-        var docurl = "[% Koha.Preference('marcfielddocurl').replace('"','&quot;') | html %]";
+    [% IF Koha.Preference(doc_url_pref) %]
+        var docurl = "[% Koha.Preference(doc_url_pref).replace('"','&quot;') | html %]";
         docurl = docurl.replace("{MARC}", "[% marcflavour | html %]");
         docurl = docurl.replace("{FIELD}", ""+field);
         docurl = docurl.replace("{LANG}", "[% lang | html %]");
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/authorities.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/authorities.pref
index 1de239b..ba27d0e 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/authorities.pref
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/authorities.pref
@@ -63,6 +63,14 @@ Authorities:
                   "loose": loose
                   "strict": strict
             - mode. In strict mode subfields that are not found in the authority record, are deleted. Loose mode will keep them. Loose mode is the historical behavior and still the default.
+        -
+            - Use
+            - pref: AuthorityMarcFieldDocURL
+              class: url
+            - as the URL for MARC authority record field documentation.
+            - Possible substitutions are <tt>{MARC}</tt> (marc flavour, eg. "MARC21" or "UNIMARC"), <tt>{FIELD}</tt> (field number, eg. "000" or "048"), <tt>{LANG}</tt> (user language, eg. "en" or "fi-FI").
+            - If left empty, the format documentation on http://loc.gov (MARC21) or http://archive.ifla.org (UNIMARC) is used.
+            - For example <tt>http://fielddoc.example.com/?marc={MARC}&field={FIELD}&language={LANG}</tt>
 
     Linker:
         -
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/authorities.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/authorities.tt
index 3ea5145..9db4649 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/authorities.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/authorities.tt
@@ -156,7 +156,7 @@ function confirmnotdup(redirect){
         </div>
     </div>
 
-    [% INCLUDE 'marc_editor.inc' maindiv='authoritytabs' marc21_doc_base='http://www.loc.gov/marc/authority/ad' unimarc_doc_base='https://www.ifla.org/publications/unimarc-authorities--3rd-edition--updates' %]
+    [% INCLUDE 'marc_editor.inc' maindiv='authoritytabs' marc21_doc_base='http://www.loc.gov/marc/authority/ad' unimarc_doc_base='https://www.ifla.org/publications/unimarc-authorities--3rd-edition--updates' doc_url_pref='AuthorityMarcFieldDocURL' %]
 
 [% IF ( oldauthnumtagfield ) %]
     <input type="hidden" name="tag" value="[% oldauthnumtagfield | html %]" />
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbiblio.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbiblio.tt
index bb4b125..7115f7e 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbiblio.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbiblio.tt
@@ -381,7 +381,7 @@ function Changefwk() {
         <input type="hidden" name="breedingid" value="[% breedingid | html %]" />
         <input type="hidden" name="changed_framework" value="" />
 
-    [% INCLUDE 'marc_editor.inc' maindiv='addbibliotabs' marc21_doc_base='http://www.loc.gov/marc/bibliographic/bd' unimarc_doc_base='https://www.ifla.org/publications/unimarc-bibliographic--3rd-edition--updates-2012-and-updates-2016' %]
+    [% INCLUDE 'marc_editor.inc' maindiv='addbibliotabs' marc21_doc_base='http://www.loc.gov/marc/bibliographic/bd' unimarc_doc_base='https://www.ifla.org/publications/unimarc-bibliographic--3rd-edition--updates-2012-and-updates-2016' doc_url_pref='MarcFieldDocURL' %]
 
 [%# Fields for fast cataloging %]
 <input type="hidden" name="barcode" value="[% barcode | html %]" />
-- 
2.1.4