From e2d7c0a25dafb921c54b3d250df11bae99cb3e2e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Marc=20V=C3=A9ron?= <veron@veron.ch>
Date: Wed, 2 Dec 2015 09:49:02 +0100
Subject: [PATCH] Bug 15288: Staff error pages: Code duplication removal and
 better translatability

This patch changes the 400, 401, 402, 403, 404, 500 error pages to be handled
by one template only.

Additionally it removes a translatability issue due to a sentence split by html tags.

To test:
- Apply patch
- Trigger 404 error by calling a page that does not exist
- Try to trigger other error pages and/or carefully review code changes
  in the *.pl files
---
 errors/400.pl                                      |    7 +++--
 errors/401.pl                                      |    7 +++--
 errors/402.pl                                      |    7 +++--
 errors/403.pl                                      |    7 +++--
 errors/404.pl                                      |    7 +++--
 errors/500.pl                                      |    7 +++--
 .../intranet-tmpl/prog/en/modules/errors/400.tt    |   29 -------------------
 .../intranet-tmpl/prog/en/modules/errors/401.tt    |   30 --------------------
 .../intranet-tmpl/prog/en/modules/errors/402.tt    |   29 -------------------
 .../intranet-tmpl/prog/en/modules/errors/403.tt    |   29 -------------------
 .../intranet-tmpl/prog/en/modules/errors/500.tt    |   29 -------------------
 .../en/modules/errors/{404.tt => errorpage.tt}     |   16 +++++------
 12 files changed, 38 insertions(+), 166 deletions(-)
 delete mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/errors/400.tt
 delete mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/errors/401.tt
 delete mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/errors/402.tt
 delete mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/errors/403.tt
 delete mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/errors/500.tt
 rename koha-tmpl/intranet-tmpl/prog/en/modules/errors/{404.tt => errorpage.tt} (77%)

diff --git a/errors/400.pl b/errors/400.pl
index 23dc5ae..7c947db 100755
--- a/errors/400.pl
+++ b/errors/400.pl
@@ -27,12 +27,15 @@ my $query = CGI->new;
 my $admin = C4::Context->preference('KohaAdminEmailAddress');
 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
     {
-        template_name   => 'errors/400.tt',
+        template_name   => 'errors/errorpage.tt',
         query           => $query,
         type            => 'intranet',
         authnotrequired => 1,
         debug           => 1,
     }
 );
-$template->param( admin => $admin );
+$template->param (
+    admin => $admin,
+    errno => 400,
+);
 output_with_http_headers $query, $cookie, $template->output, 'html', '400 Bad Request';
diff --git a/errors/401.pl b/errors/401.pl
index 88c88d8..fcd2d88 100755
--- a/errors/401.pl
+++ b/errors/401.pl
@@ -26,12 +26,15 @@ my $query = CGI->new;
 my $admin = C4::Context->preference('KohaAdminEmailAddress');
 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
     {
-        template_name   => 'errors/401.tt',
+        template_name   => 'errors/errorpage.tt',
         query           => $query,
         type            => 'intranet',
         authnotrequired => 1,
         debug           => 1,
     }
 );
-$template->param( admin => $admin );
+$template->param (
+    admin => $admin,
+    errno => 401,
+);
 output_with_http_headers $query, $cookie, $template->output, 'html', '401 Unauthorized';
diff --git a/errors/402.pl b/errors/402.pl
index 552398b..1a9f3a6 100755
--- a/errors/402.pl
+++ b/errors/402.pl
@@ -27,12 +27,15 @@ my $query = CGI->new;
 my $admin = C4::Context->preference('KohaAdminEmailAddress');
 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
     {
-        template_name   => 'errors/402.tt',
+        template_name   => 'errors/errorpage.tt',
         query           => $query,
         type            => 'intranet',
         authnotrequired => 1,
         debug           => 1,
     }
 );
-$template->param( admin => $admin );
+$template->param (
+    admin => $admin,
+    errno => 402,
+);
 output_with_http_headers $query, $cookie, $template->output, 'html', '402 Payment Required';
diff --git a/errors/403.pl b/errors/403.pl
index 11918c3..3a46f68 100755
--- a/errors/403.pl
+++ b/errors/403.pl
@@ -27,12 +27,15 @@ my $query = CGI->new;
 my $admin = C4::Context->preference('KohaAdminEmailAddress');
 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
     {
-        template_name   => 'errors/403.tt',
+        template_name   => 'errors/errorpage.tt',
         query           => $query,
         type            => 'intranet',
         authnotrequired => 1,
         debug           => 1,
     }
 );
-$template->param( admin => $admin );
+$template->param (
+    admin => $admin,
+    errno => 403,
+);
 output_with_http_headers $query, $cookie, $template->output, 'html', '403 Forbidden';
diff --git a/errors/404.pl b/errors/404.pl
index e7e0071..57191f1 100755
--- a/errors/404.pl
+++ b/errors/404.pl
@@ -27,12 +27,15 @@ my $query = CGI->new;
 my $admin = C4::Context->preference('KohaAdminEmailAddress');
 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
     {
-        template_name   => 'errors/404.tt',
+        template_name   => 'errors/errorpage.tt',
         query           => $query,
         type            => 'intranet',
         authnotrequired => 1,
         debug           => 1,
     }
 );
-$template->param( admin => $admin );
+$template->param (
+    admin => $admin,
+    errno => 404,
+);
 output_with_http_headers $query, $cookie, $template->output, 'html', '404 Not Found';
diff --git a/errors/500.pl b/errors/500.pl
index 9fb6e0c..0008faf 100755
--- a/errors/500.pl
+++ b/errors/500.pl
@@ -27,12 +27,15 @@ my $query = CGI->new;
 my $admin = C4::Context->preference('KohaAdminEmailAddress');
 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
     {
-        template_name   => 'errors/500.tt',
+        template_name   => 'errors/errorpage.tt',
         query           => $query,
         type            => 'intranet',
         authnotrequired => 1,
         debug           => 1,
     }
 );
-$template->param( admin => $admin );
+$template->param (
+    admin => $admin,
+    errno => 500,
+);
 output_with_http_headers $query, $cookie, $template->output, 'html', '500 Internal Server Error';
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/errors/400.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/errors/400.tt
deleted file mode 100644
index 350f629..0000000
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/errors/400.tt
+++ /dev/null
@@ -1,29 +0,0 @@
-[% INCLUDE 'doc-head-open.inc' %]
-<title>Koha &rsaquo; Error</title>
-[% INCLUDE 'doc-head-close.inc' %]
-</head>
-<body id="err_400" class="err">
-
-[% INCLUDE 'header.inc' %]
-[% INCLUDE 'cat-search.inc' %]
-
-<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; Error 400</div>
-
-<div id="doc" class="yui-t7">
-   
-   <div id="bd">
-	<div id="yui-main">
-	<div class="yui-b"><div class="yui-g">
-    <h1>An error has occurred!</h1>
-    <h2>Error 400</h2>
-    <ul style="margin-bottom: 1em; padding-bottom: 1em; border-bottom: 1px solid #CCC;">
-    <li>This error means that the link was broken and that the page doesn't exist</li>	
-    <li>To report this error, you can <a href="mailto:[% admin %]">email the Koha administrator</a>.</li>
-    <li>Use top menu bar to navigate to another part of Koha.</li>
-    </ul>
-</div>
-
-</div>
-</div>
-
-[% INCLUDE 'intranet-bottom.inc' %]
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/errors/401.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/errors/401.tt
deleted file mode 100644
index 5c0d3cf..0000000
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/errors/401.tt
+++ /dev/null
@@ -1,30 +0,0 @@
-[% INCLUDE 'doc-head-open.inc' %]
-<title>Koha &rsaquo; Error 401</title>
-[% INCLUDE 'doc-head-close.inc' %]
-</head>
-<body id="err_401" class="err">
-
-[% INCLUDE 'header.inc' %]
-[% INCLUDE 'cat-search.inc' %]
-
-<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; Error 401</div>
-
-<div id="doc" class="yui-t7">
-   
-   <div id="bd">
-	<div id="yui-main">
-	<div class="yui-b"><div class="yui-g">
-    <h1>An error has occurred!</h1>
-    <h2>Error 401</h2>
-    <ul style="margin-bottom: 1em; padding-bottom: 1em; border-bottom: 1px solid #CCC;">
-        <li>This error means that you aren't authorized to view this page.</li>
-        <li>Please <a href="/cgi-bin/koha/mainpage.pl">log in</a> and try again.
-        <li>To report this error, you can <a href="mailto:[% admin %]">email the Koha administrator</a>.</li>
-        <li>Use top menu bar to navigate to another part of Koha.</li>
-    </ul>
-</div>
-
-</div>
-</div>
-
-[% INCLUDE 'intranet-bottom.inc' %]
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/errors/402.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/errors/402.tt
deleted file mode 100644
index 8656499..0000000
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/errors/402.tt
+++ /dev/null
@@ -1,29 +0,0 @@
-[% INCLUDE 'doc-head-open.inc' %]
-<title>Koha &rsaquo; Error 402</title>
-[% INCLUDE 'doc-head-close.inc' %]
-</head>
-<body id="err_402" class="err">
-
-[% INCLUDE 'header.inc' %]
-[% INCLUDE 'cat-search.inc' %]
-
-<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; Error 402</div>
-
-<div id="doc" class="yui-t7">
-   
-   <div id="bd">
-	<div id="yui-main">
-	<div class="yui-b"><div class="yui-g">
-    <h1>An error has occurred!</h1>
-    <h2>Error 402</h2>
-    <ul style="margin-bottom: 1em; padding-bottom: 1em; border-bottom: 1px solid #CCC;">
-        <li>This error means that the link was broken and that the page doesn't exist</li>	
-        <li>To report this error, you can <a href="mailto:[% admin %]">email the Koha administrator</a>.</li>
-        <li>Use top menu bar to navigate to another part of Koha.</li>
-    </ul>
-</div>
-
-</div>
-</div>
-
-[% INCLUDE 'intranet-bottom.inc' %]
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/errors/403.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/errors/403.tt
deleted file mode 100644
index 6ed5c3a..0000000
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/errors/403.tt
+++ /dev/null
@@ -1,29 +0,0 @@
-[% INCLUDE 'doc-head-open.inc' %]
-<title>Koha &rsaquo; Error 403</title>
-[% INCLUDE 'doc-head-close.inc' %]
-</head>
-<body id="err_403" class="err">
-
-[% INCLUDE 'header.inc' %]
-[% INCLUDE 'cat-search.inc' %]
-
-<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; Error 403</div>
-
-<div id="doc" class="yui-t7">
-   
-   <div id="bd">
-	<div id="yui-main">
-	<div class="yui-b"><div class="yui-g">
-    <h1>An error has occurred!</h1>
-    <h2>Error 403</h2>
-    <ul style="margin-bottom: 1em; padding-bottom: 1em; border-bottom: 1px solid #CCC;">
-    <li>This error means that you are forbidden to view this page.</li>
-    <li>To report this error, you can <a href="mailto:[% admin %]">email the Koha administrator</a>.</li>
-    <li>Use top menu bar to navigate to another part of Koha.</li>
-    </ul>
-</div>
-
-</div>
-</div>
-
-[% INCLUDE 'intranet-bottom.inc' %]
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/errors/500.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/errors/500.tt
deleted file mode 100644
index bab01b6..0000000
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/errors/500.tt
+++ /dev/null
@@ -1,29 +0,0 @@
-[% INCLUDE 'doc-head-open.inc' %]
-<title>Koha &rsaquo; Error 500</title>
-[% INCLUDE 'doc-head-close.inc' %]
-</head>
-<body id="err_500" class="err">
-
-[% INCLUDE 'header.inc' %]
-[% INCLUDE 'cat-search.inc' %]
-
-<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; Error 500</div>
-
-<div id="doc" class="yui-t7">
-   
-   <div id="bd">
-	<div id="yui-main">
-	<div class="yui-b"><div class="yui-g">
-    <h1>An error has occurred!</h1>
-    <h2>Error 500</h2>
-    <ul style="margin-bottom: 1em; padding-bottom: 1em; border-bottom: 1px solid #CCC;">
-        <li>In Koha this typically means that the Koha team is working on new features</li>	
-        <li>Wait while system maintenance is being done or <a href="mailto:[% admin %]">email the Koha administrator</a>.</li>
-        <li>Use top menu bar to navigate to another part of Koha.</li>
-    </ul>
-</div>
-
-</div>
-</div>
-
-[% INCLUDE 'intranet-bottom.inc' %]
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/errors/404.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/errors/errorpage.tt
similarity index 77%
rename from koha-tmpl/intranet-tmpl/prog/en/modules/errors/404.tt
rename to koha-tmpl/intranet-tmpl/prog/en/modules/errors/errorpage.tt
index 422aba3..78d6059 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/errors/404.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/errors/errorpage.tt
@@ -1,21 +1,21 @@
 [% INCLUDE 'doc-head-open.inc' %]
-<title>Koha &rsaquo; Error 404</title>
+<title>Koha &rsaquo; Error [% errno %]</title>
 [% INCLUDE 'doc-head-close.inc' %]
 </head>
-<body id="err_404" class="err">
+<body id="err_[% errno %]" class="err">
 
 [% INCLUDE 'header.inc' %]
 [% INCLUDE 'cat-search.inc' %]
 
-<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; Error 404</div>
+<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; Error [% errno %]</div>
 
 <div id="doc" class="yui-t7">
-   
+
    <div id="bd">
-	<div id="yui-main">
-	<div class="yui-b"><div class="yui-g">
+        <div id="yui-main">
+        <div class="yui-b"><div class="yui-g">
     <h1>An error has occurred!</h1>
-    <h3><em>Error 404</em></h3>
+    <h2><em>Error [% errno %]</em></h2>
         <h3>This message may have been caused by any of the following reasons:</h3>
         <ul style="padding-bottom: 0.5em;">
             <li>You made use of an external link to an item that is no longer available</li>
@@ -26,7 +26,7 @@
         <h3>What's next?</h3>
         <ul style="margin-bottom: 1em; padding-bottom: 1em; border-bottom: 1px solid #CCC;">
             <li>Use top menu bar to navigate to another part of Koha.</li>
-            <li>To report a broken link or any other issue, please send an <a href="mailto:[% admin %]">email to the Koha Administrator</a></li>
+            <li>To report a broken link or any other issue, please contact the Koha Administrator <a href="mailto:[% admin %]">Email</a></li>
     </ul>
 </div>
 
-- 
1.7.10.4