aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Somerville <matthew@mysociety.org>2011-06-06 11:15:01 +0100
committerMatthew Somerville <matthew@mysociety.org>2011-06-06 11:15:01 +0100
commita6c11ec2e1fa29ffc28fed8fa0102f2fb9d61845 (patch)
treecdbdf8ce8688be284741d29b2f2c2b7950df4c9a
parentcd0ff4b083042c7d9a14d369326c5247893416c5 (diff)
Get rid of some more fake_q etc.
-rw-r--r--perllib/FixMyStreet/App/Controller/Alert.pm20
-rw-r--r--perllib/FixMyStreet/App/Controller/Around.pm4
-rw-r--r--perllib/FixMyStreet/App/Controller/Location.pm2
-rw-r--r--perllib/FixMyStreet/App/View/Web.pm2
-rw-r--r--perllib/FixMyStreet/Cobrand/Barnet.pm2
-rw-r--r--perllib/FixMyStreet/Cobrand/Default.pm8
-rw-r--r--perllib/FixMyStreet/Cobrand/FiksGataMi.pm2
-rw-r--r--perllib/FixMyStreet/DB/Result/Problem.pm2
-rw-r--r--perllib/FixMyStreet/Geocode.pm64
-rw-r--r--perllib/FixMyStreet/Map.pm5
-rw-r--r--perllib/FixMyStreet/Map/Tilma/Original.pm15
-rw-r--r--perllib/Page.pm29
-rwxr-xr-xt/Page.t25
13 files changed, 52 insertions, 128 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Alert.pm b/perllib/FixMyStreet/App/Controller/Alert.pm
index b3067abc9..b5258ae79 100644
--- a/perllib/FixMyStreet/App/Controller/Alert.pm
+++ b/perllib/FixMyStreet/App/Controller/Alert.pm
@@ -86,7 +86,6 @@ sub rss : Private {
$c->go('list');
}
- my $extra_params = $c->cobrand->extra_params( $c->fake_q );
my $url;
if ( $feed =~ /^area:(?:\d+:)+(.*)$/ ) {
( my $id = $1 ) =~ tr{:_}{/+};
@@ -363,27 +362,22 @@ sub setup_coordinate_rss_feeds : Private {
my $rss_feed;
if ( $c->stash->{pretty_pc_text} ) {
- $rss_feed =
- $c->cobrand->uri( "/rss/pc/" . $c->stash->{pretty_pc_text},
- $c->fake_q );
+ $rss_feed = $c->uri_for( "/rss/pc/" . $c->stash->{pretty_pc_text} );
}
else {
- $rss_feed = $c->cobrand->uri(
+ $rss_feed = $c->uri_for(
sprintf( "/rss/l/%s,%s",
$c->stash->{latitude},
- $c->stash->{longitude} ),
- $c->fake_q
+ $c->stash->{longitude} )
);
}
$c->stash->{rss_feed_uri} = $rss_feed;
- $c->stash->{rss_feed_2k} = $c->cobrand->uri( $rss_feed . '/2', $c->fake_q );
- $c->stash->{rss_feed_5k} = $c->cobrand->uri( $rss_feed . '/5', $c->fake_q );
- $c->stash->{rss_feed_10k} =
- $c->cobrand->uri( $rss_feed . '/10', $c->fake_q );
- $c->stash->{rss_feed_20k} =
- $c->cobrand->uri( $rss_feed . '/20', $c->fake_q );
+ $c->stash->{rss_feed_2k} = $c->uri_for( $rss_feed . '/2' );
+ $c->stash->{rss_feed_5k} = $c->uri_for( $rss_feed . '/5' );
+ $c->stash->{rss_feed_10k} = $c->uri_for( $rss_feed . '/10' );
+ $c->stash->{rss_feed_20k} = $c->uri_for( $rss_feed . '/20' );
return 1;
}
diff --git a/perllib/FixMyStreet/App/Controller/Around.pm b/perllib/FixMyStreet/App/Controller/Around.pm
index 4aa37aa08..c554b2bb7 100644
--- a/perllib/FixMyStreet/App/Controller/Around.pm
+++ b/perllib/FixMyStreet/App/Controller/Around.pm
@@ -171,7 +171,7 @@ sub display_location : Private {
# get the map features
my ( $on_map_all, $on_map, $around_map, $distance ) =
- FixMyStreet::Map::map_features( $c->fake_q, $latitude, $longitude,
+ FixMyStreet::Map::map_features( $c, $latitude, $longitude,
$interval );
# copy the found reports to the stash
@@ -266,7 +266,7 @@ sub ajax : Path('/ajax') {
# extract the data from the map
my ( $pins, $on_map, $around_map, $dist ) =
- FixMyStreet::Map::map_pins( $c->fake_q, $x, $y, $sx, $sy, $interval );
+ FixMyStreet::Map::map_pins( $c, $x, $y, $sx, $sy, $interval );
# render templates to get the html
# my $on_map_list_html = $c->forward(
diff --git a/perllib/FixMyStreet/App/Controller/Location.pm b/perllib/FixMyStreet/App/Controller/Location.pm
index 76f54e7b3..c1b119074 100644
--- a/perllib/FixMyStreet/App/Controller/Location.pm
+++ b/perllib/FixMyStreet/App/Controller/Location.pm
@@ -65,7 +65,7 @@ sub determine_location_from_pc : Private {
$c->stash->{pc} = $pc; # for template
my ( $latitude, $longitude, $error ) =
- eval { FixMyStreet::Geocode::lookup( $pc, $c->fake_q ) };
+ eval { FixMyStreet::Geocode::lookup( $pc, $c ) };
# Check that nothing blew up
if ($@) {
diff --git a/perllib/FixMyStreet/App/View/Web.pm b/perllib/FixMyStreet/App/View/Web.pm
index 63aade4c9..b5f6e341d 100644
--- a/perllib/FixMyStreet/App/View/Web.pm
+++ b/perllib/FixMyStreet/App/View/Web.pm
@@ -104,7 +104,7 @@ Return a pretty version of the epoch.
sub prettify_epoch {
my ( $self, $c, $epoch, $short_bool ) = @_;
- return Page::prettify_epoch( $c->req, $epoch, $short_bool );
+ return Page::prettify_epoch( $epoch, $short_bool );
}
=head2 add_links
diff --git a/perllib/FixMyStreet/Cobrand/Barnet.pm b/perllib/FixMyStreet/Cobrand/Barnet.pm
index 2081565cf..26c7c0453 100644
--- a/perllib/FixMyStreet/Cobrand/Barnet.pm
+++ b/perllib/FixMyStreet/Cobrand/Barnet.pm
@@ -66,7 +66,7 @@ sub all_councils_report {
}
sub disambiguate_location {
- my ( $self, $s, $q ) = @_;
+ my ( $self, $s ) = @_;
$s = "ll=51.612832,-0.218169&spn=0.0563,0.09&$s";
return $s;
}
diff --git a/perllib/FixMyStreet/Cobrand/Default.pm b/perllib/FixMyStreet/Cobrand/Default.pm
index 022aff833..0613d0d6e 100644
--- a/perllib/FixMyStreet/Cobrand/Default.pm
+++ b/perllib/FixMyStreet/Cobrand/Default.pm
@@ -285,14 +285,6 @@ includes any disambiguating information available
sub disambiguate_location { "$_[1]&gl=uk" }
-=head2 prettify_epoch
-
-Parameter is EPOCHTIME
-
-=cut
-
-sub prettify_epoch { 0 }
-
=head2 form_elements
Parameters are FORM_NAME, QUERY. Return HTML for any extra needed elements for
diff --git a/perllib/FixMyStreet/Cobrand/FiksGataMi.pm b/perllib/FixMyStreet/Cobrand/FiksGataMi.pm
index 267be6958..a5b71e46b 100644
--- a/perllib/FixMyStreet/Cobrand/FiksGataMi.pm
+++ b/perllib/FixMyStreet/Cobrand/FiksGataMi.pm
@@ -22,7 +22,7 @@ sub enter_postcode_text {
# Is also adding language parameter
sub disambiguate_location {
- my ( $self, $s, $q ) = @_;
+ my ( $self, $s ) = @_;
$s = "hl=no&gl=no&$s";
return $s;
}
diff --git a/perllib/FixMyStreet/DB/Result/Problem.pm b/perllib/FixMyStreet/DB/Result/Problem.pm
index 6a5b01906..c3b387710 100644
--- a/perllib/FixMyStreet/DB/Result/Problem.pm
+++ b/perllib/FixMyStreet/DB/Result/Problem.pm
@@ -278,7 +278,7 @@ sub meta_line {
my ( $problem, $c ) = @_;
my $date_time =
- Page::prettify_epoch( $c->req, $problem->confirmed_local->epoch );
+ Page::prettify_epoch( $problem->confirmed_local->epoch );
my $meta = '';
# FIXME Should be in cobrand
diff --git a/perllib/FixMyStreet/Geocode.pm b/perllib/FixMyStreet/Geocode.pm
index cbfa3c4e7..9419a91f7 100644
--- a/perllib/FixMyStreet/Geocode.pm
+++ b/perllib/FixMyStreet/Geocode.pm
@@ -38,14 +38,14 @@ BEGIN {
# Northern Ireland). The information in the query may be used by cobranded versions
# of the site to diambiguate locations.
sub lookup {
- my ($s, $q) = @_;
+ my ($s, $c) = @_;
my ($latitude, $longitude, $error);
if (mySociety::Config::get('COUNTRY') eq 'GB') {
if ($s =~ /^\d+$/) {
$error = 'FixMyStreet is a UK-based website that currently works in England, Scotland, and Wales. Please enter either a postcode, or a Great British street name and area.';
} elsif (mySociety::PostcodeUtil::is_valid_postcode($s)) {
my $location = mySociety::MaPit::call('postcode', $s);
- unless ($error = Page::mapit_check_error($location)) {
+ unless ($error = mapit_check_error($location)) {
$latitude = $location->{wgs84_lat};
$longitude = $location->{wgs84_lon};
}
@@ -53,20 +53,20 @@ sub lookup {
} elsif (mySociety::Config::get('COUNTRY') eq 'NO') {
if ($s =~ /^\d{4}$/) {
my $location = mySociety::MaPit::call('postcode', $s);
- unless ($error = Page::mapit_check_error($location)) {
+ unless ($error = mapit_check_error($location)) {
$latitude = $location->{wgs84_lat};
$longitude = $location->{wgs84_lon};
}
}
}
unless ($error || defined $latitude) {
- ($latitude, $longitude, $error) = FixMyStreet::Geocode::string($s, $q);
+ ($latitude, $longitude, $error) = FixMyStreet::Geocode::string($s, $c);
}
return ($latitude, $longitude, $error);
}
sub geocoded_string_coordinates {
- my ($js, $q) = @_;
+ my ( $js ) = @_;
my ($latitude, $longitude, $error);
my ($accuracy) = $js =~ /"Accuracy" *: *(\d)/;
if ($accuracy < 4) {
@@ -89,18 +89,18 @@ sub geocoded_string_coordinates {
}
sub results_check {
- my $q = shift;
+ my $c = shift;
my ($error, @valid_locations);
foreach (@_) {
next unless /"address" *: *"(.*?)"/s;
my $address = $1;
- next unless Cobrand::geocoded_string_check(Page::get_cobrand($q), $address, $q);
+ next unless $c->cobrand->geocoded_string_check( $address );
next if $address =~ /BT\d/;
push (@$error, $address);
push (@valid_locations, $_);
}
if (scalar @valid_locations == 1) {
- return geocoded_string_coordinates($valid_locations[0], $q);
+ return geocoded_string_coordinates( $valid_locations[0] );
}
$error = _('Sorry, we could not find that location.') unless $error;
return (undef, undef, $error);
@@ -112,12 +112,12 @@ sub results_check {
# an array of matches if there are more than one. The information in the query
# may be used to disambiguate the location in cobranded versions of the site.
sub string {
- my ($s, $q) = @_;
+ my ($s, $c) = @_;
$s = lc($s);
$s =~ s/[^-&\w ']/ /g;
$s =~ s/\s+/ /g;
$s = URI::Escape::uri_escape_utf8($s);
- $s = Cobrand::disambiguate_location(Page::get_cobrand($q), "q=$s", $q);
+ $s = $c->cobrand->disambiguate_location( "q=$s" );
$s =~ s/%20/+/g;
my $url = 'http://maps.google.com/maps/geo?' . $s;
my $cache_dir = mySociety::Config::get('GEO_CACHE');
@@ -151,42 +151,32 @@ sub string {
} elsif ($js !~ /"code" *: *200/) {
$error = _('Sorry, we could not find that location.');
} elsif ($js =~ /}, *{/) { # Multiple
- return results_check($q, (split /}, *{/, $js));
+ return results_check($c, (split /}, *{/, $js));
} elsif ($js =~ /BT\d/) {
# Northern Ireland, hopefully
$error = _("We do not cover Northern Ireland, I'm afraid, as our licence doesn't include any maps for the region.");
} else {
- return results_check($q, $js);
+ return results_check($c, $js);
}
return (undef, undef, $error);
}
-# list_choices
-# Prints response if there's more than one possible result
-sub list_choices {
- my ($choices, $page, $q) = @_;
- my $url;
- my $cobrand = Page::get_cobrand($q);
- my $message = _('We found more than one match for that location. We show up to ten matches, please try a different search if yours is not here.');
- my $out = '<p>' . $message . '</p>';
- my $choice_list = '<ul>';
- foreach my $choice (@$choices) {
- $choice = decode_utf8($choice);
- $choice =~ s/, United Kingdom//;
- $choice =~ s/, UK//;
- $url = Cobrand::url($cobrand, NewURL($q, -retain => 1, -url => $page, 'pc' => $choice), $q);
- $url =~ s/%20/+/g;
- $choice_list .= '<li><a href="' . $url . '">' . $choice . "</a></li>\n";
+sub mapit_check_error {
+ my $location = shift;
+ if ($location->{error}) {
+ return _('That postcode was not recognised, sorry.') if $location->{code} =~ /^4/;
+ return $location->{error};
}
- $choice_list .= '</ul>';
- $out .= $choice_list;
- my %vars = (message => $message,
- choice_list => $choice_list,
- header => _('More than one match'),
- url_home => Cobrand::url($cobrand, '/', $q));
- my $cobrand_choice = Page::template_include('geocode-choice', $q, Page::template_root($q), %vars);
- return $cobrand_choice if $cobrand_choice;
- return $out;
+ if (mySociety::Config::get('COUNTRY') eq 'GB') {
+ my $island = $location->{coordsyst};
+ if (!$island) {
+ return _("Sorry, that appears to be a Crown dependency postcode, which we don't cover.");
+ }
+ if ($island eq 'I') {
+ return _("We do not cover Northern Ireland, I'm afraid, as our licence doesn't include any maps for the region.");
+ }
+ }
+ return 0;
}
1;
diff --git a/perllib/FixMyStreet/Map.pm b/perllib/FixMyStreet/Map.pm
index 279f799e4..fc3f318c2 100644
--- a/perllib/FixMyStreet/Map.pm
+++ b/perllib/FixMyStreet/Map.pm
@@ -64,7 +64,7 @@ sub display_map {
}
sub map_features {
- my ( $q, $lat, $lon, $interval ) = @_;
+ my ( $c, $lat, $lon, $interval ) = @_;
# TODO - be smarter about calculating the surrounding square
# use deltas that are roughly 500m in the UK - so we get a 1 sq km search box
@@ -78,8 +78,7 @@ sub map_features {
my $max_lon = $lon + $lon_delta;
# list of problems around map can be limited, but should show all pins
- my $around_limit #
- = Cobrand::on_map_list_limit( Page::get_cobrand($q) ) || undef;
+ my $around_limit = $c->cobrand->on_map_list_limit || undef;
my @around_args = ( $min_lat, $max_lat, $min_lon, $max_lon, $interval );
my $around_map_list = Problems::around_map( @around_args, $around_limit );
diff --git a/perllib/FixMyStreet/Map/Tilma/Original.pm b/perllib/FixMyStreet/Map/Tilma/Original.pm
index e1ab34393..75177f3af 100644
--- a/perllib/FixMyStreet/Map/Tilma/Original.pm
+++ b/perllib/FixMyStreet/Map/Tilma/Original.pm
@@ -83,29 +83,28 @@ sub display_map {
}
sub display_pin {
- my ($q, $px, $py, $col, $id, $title, $num) = @_;
+ my ($c, $px, $py, $col, $id, $title, $num) = @_;
$num = '' if !$num || $num > 9;
- my $host = Page::base_url_with_lang($q, undef);
+ my $host = $c->cobrand->base_url_with_lang;
my %cols = (red=>'R', green=>'G', blue=>'B', purple=>'P');
my $out = '<img class="pin" src="' . $host . '/i/pin' . $cols{$col}
. $num . '.gif" alt="' . _('Problem') . '" style="top:' . ($py-59)
. 'px; left:' . ($px) . 'px; position: absolute;">';
return $out unless $id;
- my $cobrand = Page::get_cobrand($q);
- my $url = Cobrand::url($cobrand, NewURL($q, -url => '/report/' . $id), $q);
+ my $url = $c->uri_for( '/report/' . $id );
$out = '<a title="' . ent($title) . '" href="' . $url . '">' . $out . '</a>';
return $out;
}
sub map_pins {
- my ($self, $q, $x, $y, $sx, $sy, $interval) = @_;
+ my ($self, $c, $x, $y, $sx, $sy, $interval) = @_;
my $e = tile_to_os($x);
my $n = tile_to_os($y);
my ( $lat, $lon ) = Utils::convert_en_to_latlon( $e, $n );
my ( $around_map, $around_map_list, $nearby, $dist ) =
- FixMyStreet::Map::map_features( $q, $lat, $lon, $interval );
+ FixMyStreet::Map::map_features( $c, $lat, $lon, $interval );
my $pins = '';
foreach (@$around_map) {
@@ -114,7 +113,7 @@ sub map_pins {
my $px = os_to_px($_->{easting}, $sx);
my $py = os_to_px($_->{northing}, $sy, 1);
my $col = $_->{state} eq 'fixed' ? 'green' : 'red';
- $pins .= display_pin($q, $px, $py, $col, $_->{id}, $_->{title});
+ $pins .= display_pin($c, $px, $py, $col, $_->{id}, $_->{title});
}
foreach (@$nearby) {
@@ -123,7 +122,7 @@ sub map_pins {
my $px = os_to_px($_->{easting}, $sx);
my $py = os_to_px($_->{northing}, $sy, 1);
my $col = $_->{state} eq 'fixed' ? 'green' : 'red';
- $pins .= display_pin($q, $px, $py, $col, $_->{id}, $_->{title});
+ $pins .= display_pin($c, $px, $py, $col, $_->{id}, $_->{title});
}
return ($pins, $around_map_list, $nearby, $dist);
diff --git a/perllib/Page.pm b/perllib/Page.pm
index 39d5b6726..fb7a1dd61 100644
--- a/perllib/Page.pm
+++ b/perllib/Page.pm
@@ -516,10 +516,7 @@ EOF
}
sub prettify_epoch {
- my ($q, $s, $short) = @_;
- my $cobrand = get_cobrand($q);
- my $cobrand_datetime = Cobrand::prettify_epoch($cobrand, $s);
- return $cobrand_datetime if ($cobrand_datetime);
+ my ($s, $short) = @_;
my @s = localtime($s);
my $tt = strftime('%H:%M', @s);
my @t = localtime();
@@ -655,24 +652,6 @@ sub display_problem_text($$) {
return $out;
}
-sub mapit_check_error {
- my $location = shift;
- if ($location->{error}) {
- return _('That postcode was not recognised, sorry.') if $location->{code} =~ /^4/;
- return $location->{error};
- }
- if (mySociety::Config::get('COUNTRY') eq 'GB') {
- my $island = $location->{coordsyst};
- if (!$island) {
- return _("Sorry, that appears to be a Crown dependency postcode, which we don't cover.");
- }
- if ($island eq 'I') {
- return _("We do not cover Northern Ireland, I'm afraid, as our licence doesn't include any maps for the region.");
- }
- }
- return 0;
-}
-
sub short_name {
my ($area, $info) = @_;
# Special case Durham as it's the only place with two councils of the same name
@@ -738,10 +717,4 @@ sub process_photo {
return $photo;
}
-sub scambs_categories {
- return ('Abandoned vehicles', 'Discarded hypodermic needles',
- 'Dog fouling', 'Flytipping', 'Graffiti', 'Lighting (e.g. security lights)',
- 'Litter', 'Neighbourhood noise');
-}
-
1;
diff --git a/t/Page.t b/t/Page.t
index 20af92590..5e55b8e1f 100755
--- a/t/Page.t
+++ b/t/Page.t
@@ -11,7 +11,7 @@
use strict;
use warnings;
-use Test::More tests => 13;
+use Test::More tests => 8;
use Test::Exception;
use FindBin;
@@ -36,28 +36,6 @@ sub set_lang($) {
mySociety::Locale::change();
}
-sub test_geocode_string() {
- my %params = ();
- my $q = new MockQuery( 'nosite', \%params );
-
- # geocode a straightforward string, expect success
- my ( $latitude, $longitude, $error ) =
- FixMyStreet::Geocode::string( 'Buckingham Palace', $q );
- is( $latitude, 51.4949261, 'example easting generated' );
- is( $longitude, -0.1461924, 'example northing generated' );
- is( $error, undef, 'should not generate error for simple example' );
-
- # expect a failure message for Northern Ireland
- ( $latitude, $longitude, $error ) =
- FixMyStreet::Geocode::string( 'Falls Road, Belfast', $q );
- is(
- $error,
- "We do not cover Northern Ireland, I'm afraid, as our licence doesn't "
- . "include any maps for the region.",
- 'error message produced for NI location'
- );
-}
-
sub test_header() {
my $q = mock_query();
my $html;
@@ -104,4 +82,3 @@ sub test_base_url_with_lang {
ok(test_base_url_with_lang() == 1, 'Ran all tests for base_url_with_lang');
ok(test_footer() == 1, 'Ran all tests for the footer function');
ok(test_header() == 1, 'Ran all tests for the header function');
-ok(test_geocode_string() == 1, 'Ran all tests for the geocode_string function');