Bug 17785: Fix OAI-PMH's XSLT-generated URLs under Plack
authorMarcel de Rooy <m.de.rooy@rijksmuseum.nl>
Tue, 20 Dec 2016 15:11:36 +0000 (16:11 +0100)
committerKyle M Hall <kyle@bywatersolutions.com>
Wed, 28 Dec 2016 13:36:14 +0000 (13:36 +0000)
Look at e.g. the URL for Show More at the end of the output of Records or
Identifiers. If you use Plack, you will see that it refers to
yourserver:/opac/oai.pl, which is not correct.

This is caused by using CGI's self_url in combination with script alias,
mounting point, etc. Note that we cannot solve this problem in the code of
Koha only. Since HTTP::OAI modules also call self_url, we still end up
with some wrong url's.

Instead of a larger architectural operation on Apache and Plack config files,
this patch adjusts the final xslt transformation on the OAI response.
It hardcodes the correct path only once, in a xslt variable. And replaces
all oai:OAI-PMH/oai:request/text() calls, containing wrong URLs, by this
variable.

Test plan:
Run oai.pl. Try the various verbs.
Verify that the URLs point to /cgi-bin/koha/oai.pl.

Edit: changed commit subject

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Works as expected. Good workaround until a definitive solution is implemented.

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
koha-tmpl/opac-tmpl/xslt/OAI.xslt

index 976f0c2..d9faccc 100644 (file)
@@ -18,6 +18,8 @@
 
     <xsl:output method="html" doctype-public="-//W3C//DTD HTML 4.01//EN" doctype-system="http://www.w3.org/TR/html4/strict.dtd" />
 
+    <xsl:variable name="oai_script_name">/cgi-bin/koha/oai.pl</xsl:variable>
+
     <xsl:template match="/">
         <html>
             <head>
@@ -44,7 +46,7 @@
                                         </xsl:if>
                                         <xsl:attribute name="href">
                                             <xsl:value-of
-                                                    select="concat(/oai:OAI-PMH/oai:request/text(), '?verb=Identify')"></xsl:value-of>
+                                                    select="concat($oai_script_name,'?verb=Identify')"></xsl:value-of>
                                         </xsl:attribute>
                                         Identify
                                     </a>
@@ -56,7 +58,7 @@
                                         </xsl:if>
                                         <xsl:attribute name="href">
                                             <xsl:value-of
-                                                    select="concat(/oai:OAI-PMH/oai:request/text(), '?verb=ListSets')"></xsl:value-of>
+                                                    select="concat($oai_script_name, '?verb=ListSets')"></xsl:value-of>
                                         </xsl:attribute>
                                         Sets
                                     </a>
@@ -68,7 +70,7 @@
                                         </xsl:if>
                                         <xsl:attribute name="href">
                                             <xsl:value-of
-                                                    select="concat(/oai:OAI-PMH/oai:request/text(), '?verb=ListRecords&amp;metadataPrefix=oai_dc')"></xsl:value-of>
+                                                    select="concat($oai_script_name, '?verb=ListRecords&amp;metadataPrefix=oai_dc')"></xsl:value-of>
                                         </xsl:attribute>
                                         Records
                                     </a>
@@ -80,7 +82,7 @@
                                         </xsl:if>
                                         <xsl:attribute name="href">
                                             <xsl:value-of
-                                                    select="concat(/oai:OAI-PMH/oai:request/text(), '?verb=ListIdentifiers&amp;metadataPrefix=oai_dc')"></xsl:value-of>
+                                                    select="concat($oai_script_name, '?verb=ListIdentifiers&amp;metadataPrefix=oai_dc')"></xsl:value-of>
                                         </xsl:attribute>
                                         Identifiers
                                     </a>
@@ -93,7 +95,7 @@
                                         </xsl:if>
                                         <xsl:attribute name="href">
                                             <xsl:value-of
-                                                    select="concat(/oai:OAI-PMH/oai:request/text(), '?verb=ListMetadataFormats')"></xsl:value-of>
+                                                    select="concat($oai_script_name, '?verb=ListMetadataFormats')"></xsl:value-of>
                                         </xsl:attribute>
                                         Metadata Formats
                                     </a>
                         <a>
                             <xsl:attribute name="href">
                                 <xsl:value-of
-                                        select="concat(/oai:OAI-PMH/oai:request/text(), '?verb=ListRecords&amp;metadataPrefix=oai_dc&amp;set=', oai:setSpec/text())" />
+                                        select="concat($oai_script_name, '?verb=ListRecords&amp;metadataPrefix=oai_dc&amp;set=', oai:setSpec/text())" />
                             </xsl:attribute>
                             Records
                         </a>
                         <a>
                             <xsl:attribute name="href">
                                 <xsl:value-of
-                                        select="concat(/oai:OAI-PMH/oai:request/text(), '?verb=ListIdentifiers&amp;metadataPrefix=oai_dc&amp;set=', oai:setSpec/text())" />
+                                        select="concat($oai_script_name, '?verb=ListIdentifiers&amp;metadataPrefix=oai_dc&amp;set=', oai:setSpec/text())" />
                             </xsl:attribute>
                             Identifiers
                         </a>
                                         <a>
                                             <xsl:attribute name="href">
                                                 <xsl:value-of
-                                                        select="concat(/oai:OAI-PMH/oai:request/text(), '?verb=ListRecords&amp;metadataPrefix=oai_dc&amp;set=', text())" />
+                                                        select="concat($oai_script_name, '?verb=ListRecords&amp;metadataPrefix=oai_dc&amp;set=', text())" />
                                             </xsl:attribute>
                                             <xsl:value-of select="text()" />
                                         </a>
                                         <a>
                                             <xsl:attribute name="href">
                                                 <xsl:value-of
-                                                        select="concat(/oai:OAI-PMH/oai:request/text(), '?verb=ListRecords&amp;metadataPrefix=oai_dc&amp;set=', text())" />
+                                                        select="concat($oai_script_name, '?verb=ListRecords&amp;metadataPrefix=oai_dc&amp;set=', text())" />
                                             </xsl:attribute>
                                             <xsl:value-of select="text()" />
                                         </a>
                         <div class="col-lg-4">
                             <a class="btn btn-default pull-right">
                                 <xsl:attribute name="href">
-                                    <xsl:value-of select="concat(/oai:OAI-PMH/oai:request/text(), '?verb=GetRecord&amp;metadataPrefix=oai_dc&amp;identifier=', oai:identifier/text())" />
+                                    <xsl:value-of select="concat($oai_script_name, '?verb=GetRecord&amp;metadataPrefix=oai_dc&amp;identifier=', oai:identifier/text())" />
                                 </xsl:attribute>
                                 View Details
                             </a>
                                         <a>
                                             <xsl:attribute name="href">
                                                 <xsl:value-of
-                                                        select="concat(/oai:OAI-PMH/oai:request/text(), '?verb=ListRecords&amp;metadataPrefix=oai_dc&amp;set=', text())" />
+                                                        select="concat($oai_script_name, '?verb=ListRecords&amp;metadataPrefix=oai_dc&amp;set=', text())" />
                                             </xsl:attribute>
                                             <xsl:value-of select="text()" />
                                         </a>
                             <a class="btn btn-default pull-right">
                                 <xsl:attribute name="href">
                                     <xsl:value-of
-                                            select="concat(/oai:OAI-PMH/oai:request/text(), '?verb=ListRecords&amp;metadataPrefix=', oai:metadataPrefix/text())" />
+                                            select="concat($oai_script_name, '?verb=ListRecords&amp;metadataPrefix=', oai:metadataPrefix/text())" />
                                 </xsl:attribute>
                                 List Records
                             </a>
             <div class="text-center">
                 <a class="btn btn-primary">
                 <xsl:attribute name="href">
-                    <xsl:value-of select="concat(/oai:OAI-PMH/oai:request/text(), '?verb=',/oai:OAI-PMH/oai:request/@verb,'&amp;resumptionToken=', text())"></xsl:value-of>
+                    <xsl:value-of select="concat($oai_script_name, '?verb=',/oai:OAI-PMH/oai:request/@verb,'&amp;resumptionToken=', text())"></xsl:value-of>
                 </xsl:attribute>
                     Show More
                 </a>