Bug 9735 - Choose language using URL parameters in any page
Summary: Choose language using URL parameters in any page
Status: CLOSED FIXED
Alias: None
Product: Koha
Classification: Unclassified
Component: OPAC (show other bugs)
Version: Main
Hardware: All All
: P5 - low enhancement (vote)
Assignee: Tomás Cohen Arazi
QA Contact:
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-02-28 15:53 UTC by Tomás Cohen Arazi
Modified: 2014-12-07 20:02 UTC (History)
5 users (show)

See Also:
Change sponsored?: Sponsored
Patch complexity: Small patch
Documentation contact:
Documentation submission:
Text to go in the release notes:
Version(s) released in:


Attachments
Bug 9735 - Let the language be selected through URL parameters (3.72 KB, patch)
2013-03-03 01:48 UTC, Tomás Cohen Arazi
Details | Diff | Splinter Review
Bug 9735 - Let the language be selected through URL parameters (3.77 KB, patch)
2013-03-12 22:33 UTC, Brendan Gallagher
Details | Diff | Splinter Review
[SIGNED-OFF] Bug 9735 - Let the language be selected through URL parameters (3.89 KB, patch)
2013-03-13 13:30 UTC, Bernardo Gonzalez Kriegel
Details | Diff | Splinter Review
Bug 9735 - Let the language be selected through URL parameters (3.92 KB, patch)
2013-05-30 06:53 UTC, Chris Cormack
Details | Diff | Splinter Review
Bug 9735 - Build the cookie array correctly (2.48 KB, patch)
2013-06-05 18:04 UTC, Tomás Cohen Arazi
Details | Diff | Splinter Review
Bug 9735: Unit tests for get_template_and_user (cookies handling) (4.92 KB, patch)
2013-09-09 14:08 UTC, Tomás Cohen Arazi
Details | Diff | Splinter Review
Bug 9735 - Let the language be selected through URL parameters (3.99 KB, patch)
2013-09-24 15:04 UTC, Julian Maurice
Details | Diff | Splinter Review
Bug 9735 - Build the cookie array correctly (2.55 KB, patch)
2013-09-24 15:05 UTC, Julian Maurice
Details | Diff | Splinter Review
Bug 9735: Unit tests for get_template_and_user (cookies handling) (4.99 KB, patch)
2013-09-24 15:05 UTC, Julian Maurice
Details | Diff | Splinter Review
[PASSED QA] Bug 9735 - Let the language be selected through URL parameters (4.11 KB, patch)
2013-09-27 20:50 UTC, Katrin Fischer
Details | Diff | Splinter Review
[PASSED QA] Bug 9735 - Build the cookie array correctly (2.61 KB, patch)
2013-09-27 20:51 UTC, Katrin Fischer
Details | Diff | Splinter Review
[PASSED QA] Bug 9735: Unit tests for get_template_and_user (cookies handling) (5.28 KB, patch)
2013-09-27 20:51 UTC, Katrin Fischer
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Tomás Cohen Arazi 2013-02-28 15:53:53 UTC
The key idea was pointed by kf on Bug 7514: having a 'language' parameter parsed to circumvent cookies and browser detection for language selection.

On that bug it was provided a way to have a URL for retreiving the OPAC's homepage in the desired language (http://OPAC_FQDN/cgi-bin/koha/changelanguage.pl?language=<LANG_CODE>) [1]

This bugs ask for the implementation of this OPAC-wide, not just for the homepage.

Regards
To+

[1] After 9731 is applied http://OPAC_FQDN/cgi-bin/koha/opac-changelanguage.pl?language=<LANG_CODE>  should be used
Comment 1 Tomás Cohen Arazi 2013-03-03 01:48:19 UTC Comment hidden (obsolete)
Comment 2 Brendan Gallagher 2013-03-12 22:33:06 UTC Comment hidden (obsolete)
Comment 3 Bernardo Gonzalez Kriegel 2013-03-13 13:30:37 UTC Comment hidden (obsolete)
Comment 4 Chris Cormack 2013-05-30 06:53:07 UTC Comment hidden (obsolete)
Comment 5 Galen Charlton 2013-06-05 16:11:38 UTC
Reading the code, I see an issue with how the arrayref of cookies is managed.  Specifically, consider this scenario:

[1] OPAC user starts using the catalog anonymously and builds up some recent searches.
[2] OPAC user decides to log in.  As it happens, the OPAC has been customized so that the login form permits the user to set their preferred language via the new language parameter.

If you trace through the code, it looks like the cookie structure that gets returned in that case would be something like this:

[ [ $original_session_cookie, $search_cookie ], $languagecookie ]

When this arrayref-inside-arrayref structure is passed to CGI's header method, some testing I did shows that CGI.pm doesn't flatten the list, so the header returned would look like this:

Status: 200 OK
Set-Cookie: ARRAY(0x222ad48)
Set-Cookie: (language cookie)
Date: Wed, 05 Jun 2013 16:07:59 GMT
Pragma: no-cache
Cache-control: no-cache
Content-Type: text/html; charset=UTF-8

The end result is that the login would fail.

I admit that this example is a little contrived, but it's not beyond the realm of possibility that somebody would want to do this.

Consequently, I'm setting this to Failed QA.  Please follow up by adjusting the code to ensure that if multiple cookies are set by get_template_and_user(), they all come back as a flat arrayref, not a nested on.
Comment 6 Tomás Cohen Arazi 2013-06-05 18:04:09 UTC Comment hidden (obsolete)
Comment 7 Tomás Cohen Arazi 2013-08-30 16:33:44 UTC
The followup for this is really simple
Comment 8 Tomás Cohen Arazi 2013-09-09 14:08:38 UTC Comment hidden (obsolete)
Comment 9 Julian Maurice 2013-09-24 15:04:46 UTC Comment hidden (obsolete)
Comment 10 Julian Maurice 2013-09-24 15:05:25 UTC Comment hidden (obsolete)
Comment 11 Julian Maurice 2013-09-24 15:05:56 UTC Comment hidden (obsolete)
Comment 12 Julian Maurice 2013-09-24 15:06:39 UTC
works nicely, unit tests pass
Signed off
Comment 13 Katrin Fischer 2013-09-27 20:50:55 UTC
Created attachment 21526 [details] [review]
[PASSED QA] Bug 9735 - Let the language be selected through URL parameters

Passing language=<valid_language_code> as a parameter in any Koha's URL
can be used to set the desired language.
This patch touches
 - C4::Templates
 - C4::Auth

Adds a new method getlanguagecookie that does exactly that, for use in
get_template_and_user.
Also modifies getlanguage so it checks (a) if there's a 'language'
parameter in the CGI object and (b) checks if its valid and enabled for
the desired interface.

To test:
* Without the patch
  - access any koha page
  - add ?language=code to the end of the URL (change code for a valid language code
    it needs to be installed using perl translate install code, and enabled either for
    the staff or opac interface, depending where are you testing)
  - Nothing happens with the language parameter
* With the patch
  - access any koha page
  - add ?language=code (the same as before) and hit enter
  - the language should be changed to the one you chose
  - if you browse through some links, you will see
    koha 'remembers' the language you passed as a parameter
    (i.e. the language cookie has been updated).

Regards
To+

Sponsored-by: Universidad Nacional de Córdoba
Signed-off-by: Brendan <brendan@bywatersolutions.com>
Signed-off-by: Bernardo Gonzalez Kriegel <bgkriegel@gmail.com>

Comment: Works very well. No errors.
Signed-off-by: Chris Cormack <chrisc@catalyst.net.nz>
Signed-off-by: Julian Maurice <julian.maurice@biblibre.com>
Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de>
Passes all tests and QA script.
More comments on last patch.
Comment 14 Katrin Fischer 2013-09-27 20:51:07 UTC
Created attachment 21527 [details] [review]
[PASSED QA] Bug 9735 - Build the cookie array correctly

The current implementation didn't build the cookie array correctly,
yielding login problems in some scenarios.

Regards
To+

Sponsored-by: Universidad Nacional de Córdoba

http://bugs.koha-community.org/show_bug.cgi?id=6735
Signed-off-by: Julian Maurice <julian.maurice@biblibre.com>
Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de>
Comment 15 Katrin Fischer 2013-09-27 20:51:16 UTC
Created attachment 21528 [details] [review]
[PASSED QA] Bug 9735: Unit tests for get_template_and_user (cookies handling)

Galen found a case where the cookies array was not built flat. I add a
unit test for that (check the cookie array is flat) and also test the
cookies output of get_template_and_user so we are sure the &language=
parameter is correctly handled.

Regards
To+

Sponsored-by: Universidad Nacional de Cordoba
Signed-off-by: Julian Maurice <julian.maurice@biblibre.com>
Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de>
- Tests in t/db_dependent/Auth.t pass
- Tested in intranet, OPAC logged in, OPAC logged out
  * Adding a valid language code to the URL switches the language
    as expected
  * Adding an invalid language code causes no change

Nice feature!
Comment 16 Galen Charlton 2013-10-04 03:30:32 UTC
Pushed to master.  Thanks, Tomás!