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
Created attachment 15832 [details] [review] 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
Created attachment 16081 [details] [review] 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>
Created attachment 16091 [details] [review] [SIGNED-OFF] 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.
Created attachment 18490 [details] [review] 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>
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.
Created attachment 18685 [details] [review] 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
The followup for this is really simple
Created attachment 20915 [details] [review] 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
Created attachment 21421 [details] [review] Bug 9735 - Let the language be selected through URL parameters
Created attachment 21422 [details] [review] Bug 9735 - Build the cookie array correctly
Created attachment 21423 [details] [review] Bug 9735: Unit tests for get_template_and_user (cookies handling)
works nicely, unit tests pass Signed off
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.
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>
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!
Pushed to master. Thanks, Tomás!