From 1ab7dfd1aff44a12f4e22ad811f3c3877278a213 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' syspref value to : /home/koha/xslt/{langcode}/{authtypecode}.xsl 6) Refresh details page 7) Verify that display matches what you expect from your XSLT 8) Go to an authority of another type 9) Verify that the default display is used Example of a minimal XSLT: authority-summary --- 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 a95460958b..9127b8c3f6 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 0000000000..f5d1c64cd3 --- /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 3e6715120d..4b35edeb9a 100644 --- a/installer/data/mysql/mandatory/sysprefs.sql +++ b/installer/data/mysql/mandatory/sysprefs.sql @@ -76,6 +76,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 62dca5a673..b17828d8b1 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:{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:{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 74ab0c56ee..4862ab16d8 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/detail.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/detail.tt @@ -70,6 +70,10 @@ [% END %] + [% IF html %] + [% html | $raw %] + [% ELSE %] + [% WRAPPER tabs id= "authoritiestabs" %] [% WRAPPER tabs_nav %] [% FOREACH BIG_LOO IN BIG_LOOP %] @@ -123,6 +127,7 @@ [% END # /FOREACH BIG_LOO %] [% END # /WRAPPER tab_panels %] [% END # /WRAPPER tabs %] + [% END # /IF html %] [% END # /IF ( unknownauthid ) %] -- 2.42.0