From 15f02e6ff63d47e901f4e02b362a300ddc94577c Mon Sep 17 00:00:00 2001 From: Fridolin Somers Date: Thu, 9 Nov 2023 11:20:43 -1000 Subject: [PATCH] Bug 35305: Add XSLT for authority details page in staff interface This adds a new system preference 'AuthorityXSLTDetailsDisplay'. If set, authority MARCXML will be transformed using the XSLT at the given filename or URL. The HTML output will be displayed in place of tabs in details page. The syspref value can contain {langcode} and {authtypecode} which will be replaced by the appropriate value (resp. current language and authority type code). Test plan: 1) Apply patch and run updatedatabase 2) Search for an authority type GEOGR_NAME and view details page 3) Verify that display is not affected yet 4) Create an XSLT file (for example in /home/koha/xslt/en/GEOGR_NAME.xsl) 5) Set 'AuthorityXSLTDetailsDisplay' system preference to : /home/koha/xslt/{langcode}/{authtypecode}.xsl 6) Refresh details page 7) Verify that display matches what you expect from the XSLT 8) Set 'AuthorityXSLTDetailsDisplay' system preference to : /koha-tmpl/intranet-tmpl/prog/en/xslt/UNIMARCauthDetails.xsl 8) Refresh details page 9) Verify that display matches what you expect from your XSLT Example of a minimal XSLT: authority-summary Signed-off-by: David Nind Signed-off-by: Martin Renvoize --- authorities/detail.pl | 28 ++++++++++++++++--- .../data/mysql/atomicupdate/bug_35305.pl | 15 ++++++++++ installer/data/mysql/mandatory/sysprefs.sql | 1 + .../admin/preferences/staff_interface.pref | 5 ++++ .../prog/en/modules/authorities/detail.tt | 5 ++++ 5 files changed, 50 insertions(+), 4 deletions(-) create mode 100755 installer/data/mysql/atomicupdate/bug_35305.pl diff --git a/authorities/detail.pl b/authorities/detail.pl index 8915781dbd5..83f42dfdfbd 100755 --- a/authorities/detail.pl +++ b/authorities/detail.pl @@ -38,16 +38,19 @@ parameters tables. use Modern::Perl; +use CGI qw ( -utf8 ); + use C4::Auth qw( get_template_and_user ); use C4::AuthoritiesMarc qw( GetAuthority GenerateHierarchy GetTagsLabels ); use C4::Context; -use C4::Output qw( output_html_with_http_headers ); -use CGI qw ( -utf8 ); use C4::Koha; -use Koha::Authorities; +use C4::Languages; +use C4::Output qw( output_html_with_http_headers ); +use Koha::Authorities; use Koha::Authority::Types; use Koha::Token; +use Koha::XSLT::Base; use Koha::Z3950Servers; our ($tagslib); @@ -213,7 +216,24 @@ while (my ($tagfield) = $sth->fetchrow) { } chop $biblio_fields if $biblio_fields; -build_tabs ($template, $record, $dbh,"",$query); +my $AuthorityXSLTDetailsDisplay = C4::Context->preference('AuthorityXSLTDetailsDisplay'); +if ( $AuthorityXSLTDetailsDisplay ) { + my $xsl = $AuthorityXSLTDetailsDisplay; + my $lang = C4::Languages::getlanguage(); + $xsl =~ s/\{langcode\}/$lang/g; + $xsl =~ s/\{authtypecode\}/$authtypecode/g; + + my $xslt_engine = Koha::XSLT::Base->new; + my $output = $xslt_engine->transform({ xml => $authobj->marcxml, file => $xsl }); + if ($xslt_engine->err) { + warn "XSL transformation failed ($xsl): " . $xslt_engine->err; + next; + } + + $template->param( html => $output ); +} else { + build_tabs ($template, $record, $dbh,"",$query); +} my $servers = Koha::Z3950Servers->search( { diff --git a/installer/data/mysql/atomicupdate/bug_35305.pl b/installer/data/mysql/atomicupdate/bug_35305.pl new file mode 100755 index 00000000000..f5d1c64cd37 --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_35305.pl @@ -0,0 +1,15 @@ +use Modern::Perl; + +return { + bug_number => "35305", + description => "Add XSLT for authority details display in staff interface", + up => sub { + my ($args) = @_; + my ( $dbh, $out ) = @$args{qw(dbh out)}; + $dbh->do(q{ + INSERT IGNORE INTO systempreferences (`variable`, `value`, `options`, `explanation`, `type`) + VALUES ('AuthorityXSLTDetailsDisplay','','','Enable XSL stylesheet control over authority details page display on intranet','Free') + }); + say $out "Added new system preference 'AuthorityXSLTDetailsDisplay'"; + }, +}; diff --git a/installer/data/mysql/mandatory/sysprefs.sql b/installer/data/mysql/mandatory/sysprefs.sql index ede74e6d3fa..7ede0912cbe 100644 --- a/installer/data/mysql/mandatory/sysprefs.sql +++ b/installer/data/mysql/mandatory/sysprefs.sql @@ -78,6 +78,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('AuthoritySeparator','--','10','Used to separate a list of authorities in a display. Usually --','free'), ('AuthorityXSLTOpacDetailsDisplay','','','Enable XSL stylesheet control over authority details page in the OPAC','Free'), ('AuthorityXSLTOpacResultsDisplay','','','Enable XSL stylesheet control over authority results page in the OPAC','Free'), +('AuthorityXSLTDetailsDisplay','','','Enable XSL stylesheet control over authority details page display on intranet','Free'), ('AuthorityXSLTResultsDisplay','','','Enable XSL stylesheet control over authority results page display on intranet','Free'), ('AuthorLinkSortBy','default','call_number|pubdate|acqdate|title','Specify the default field used for sorting when click author links','Choice'), ('AuthorLinkSortOrder','asc','asc|dsc|az|za','Specify the default sort order for author links','Choice'), diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/staff_interface.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/staff_interface.pref index d4a5c401708..cda10110303 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/staff_interface.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/staff_interface.pref @@ -5,6 +5,11 @@ Staff interface: - pref: AuthorityXSLTResultsDisplay class: file - '
Options:
  • Put a path to define a xslt file
  • Put an URL for an external specific stylesheet.
{langcode} will be replaced with current interface language and {authtypecode} will be replaced by the authority type code' + - + - 'Display authority details in the staff interface using XSLT stylesheet at: ' + - pref: AuthorityXSLTDetailsDisplay + class: file + - '
Options:
  • Put a path to define a xslt file
  • Put an URL for an external specific stylesheet.
{langcode} will be replaced with current interface language and {authtypecode} will be replaced by the authority type code' - - "Display language selector on " - pref: StaffLangSelectorMode diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/detail.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/detail.tt index ba04a3561bc..3884efcc865 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/detail.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/detail.tt @@ -75,6 +75,10 @@ [% END %] + [% IF html %] + [% html | $raw %] + [% ELSE %] + [% WRAPPER tabs id= "authoritiestabs" %] [% WRAPPER tabs_nav %] [% FOREACH BIG_LOO IN BIG_LOOP %] @@ -128,6 +132,7 @@ [% END # /FOREACH BIG_LOO %] [% END # /WRAPPER tab_panels %] [% END # /WRAPPER tabs %] + [% END # /IF html %] [% END # /IF ( unknownauthid ) %] -- 2.47.0