Skip to content

Commit

Permalink
Bug 21299: Introduce localReferer in [opac-]changelanguage.pl
Browse files Browse the repository at this point in the history
With the work from the former patch, we now have a nice and easy replace..

NOTE: The additional logic in opac-changelanguage.pl is now also applied
to the intranet counterpart (changelanguage.pl). This effectively makes
changelanguage.pl no longer refer to external URLs (as the opac already
did by testing the referer). Might be just theoretical, but consistent.

Test plan:
Test changing language from various OPAC and staff locations.
Include language=[some_language] in the URL before changing language.
[Bonus] Test calling changelanguage.pl from another server. You should no
longer be referred back to the calling server. (See below.)

Signed-off-by: Marcel de Rooy <[email protected]>
Added link <a href="[mystaffserver]/cgi-bin/koha/changelanguage.pl?language=en">link</a> somewhere on external server.
Verified that without this patch, it hits the staff server and refers back to the caller. But with this patch, it refers to staff homepage.
Signed-off-by: Tomas Cohen Arazi <[email protected]>
Signed-off-by: Martin Renvoize <[email protected]>

Signed-off-by: Nick Clemens <[email protected]>
  • Loading branch information
mderooy authored and kidclamp committed Nov 7, 2018
1 parent db539f4 commit 07d5f76
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 25 deletions.
11 changes: 4 additions & 7 deletions changelanguage.pl
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,12 @@
# along with Koha; if not, see <http://www.gnu.org/licenses>.

use Modern::Perl;

use C4::Templates;
use CGI qw ( -utf8 );
use C4::Templates;
use Koha::Util;

my $query = new CGI;
my $query = new CGI;
my $language = $query->param('language');
my $url = $query->referer();

$url =~ s|(.)language=[\w-]*&?|$1|;
$url =~ s|(&\|\?)$||; # Remove extraneous ? or &
my $url = Koha::Util::localReferer($query, {remove_language => 1, staff => 1});

C4::Templates::setlanguagecookie( $query, $language, $url );
22 changes: 4 additions & 18 deletions opac/opac-changelanguage.pl
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,12 @@
# along with Koha; if not, see <http://www.gnu.org/licenses>.

use Modern::Perl;

use C4::Templates;
use CGI qw ( -utf8 );
use C4::Templates;
use Koha::Util;

my $query = new CGI;
my $query = new CGI;
my $language = $query->param('language');

# Detect where the user came from and save that url
my $requestedUrl = $query->url( -base => 1 );

# Use referer url if it matches $requestedUrl else use $requestedUrl as the url .
my $url =
$query->referer() =~ $requestedUrl ? $query->referer() : $requestedUrl;

# warn "Language : $query // $language // $url";

# If language was set by an external URL the parameter
# 'language=' should be removed from url string, otherwise
# the language picker will not work
$url =~ s|(.)language=[\w-]*&?|$1|;
$url =~ s|(&\|\?)$||; # Remove extraneous ? or &
my $url = Koha::Util::localReferer($query, { remove_language => 1 });

C4::Templates::setlanguagecookie( $query, $language, $url );

0 comments on commit 07d5f76

Please sign in to comment.