Merge branch 'master' into openID
This commit is contained in:
commit
9448eab143
10 changed files with 1626 additions and 4 deletions
|
@ -15,4 +15,34 @@ module BrowseHelper
|
|||
end
|
||||
return name
|
||||
end
|
||||
|
||||
def format_key(key)
|
||||
if url = wiki_link("key", key)
|
||||
link_to h(key), url, :title => t('browse.tag_details.wiki_link.key', :key => key)
|
||||
else
|
||||
h(key)
|
||||
end
|
||||
end
|
||||
|
||||
def format_value(key, value)
|
||||
if url = wiki_link("tag", "#{key}=#{value}")
|
||||
link_to h(value), url, :title => t('browse.tag_details.wiki_link.tag', :key => key, :value => value)
|
||||
else
|
||||
linkify h(value)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def wiki_link(type, lookup)
|
||||
locale = I18n.locale.to_s
|
||||
|
||||
if page = WIKI_PAGES[locale][type][lookup] rescue nil
|
||||
url = "http://wiki.openstreetmap.org/wiki/#{page}?uselang=#{locale}"
|
||||
elsif page = WIKI_PAGES["en"][type][lookup] rescue nil
|
||||
url = "http://wiki.openstreetmap.org/wiki/#{page}?uselang=#{locale}"
|
||||
end
|
||||
|
||||
return url
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
<tr>
|
||||
<td><%= h(tag[0]) %> = <%= linkify(h(tag[1])) %></td>
|
||||
<td><%= format_key(tag[0]) %> = <%= format_value(tag[0], tag[1]) %></td>
|
||||
</tr>
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
<%= render :partial => 'search' %>
|
||||
|
||||
<%
|
||||
session[:token] = @user.tokens.create.token unless session[:token]
|
||||
session[:token] = @user.tokens.create.token unless session[:token] and UserToken.find_by_token(session[:token])
|
||||
|
||||
# Decide on a lat lon to initialise potlatch with. Various ways of doing this
|
||||
if params['lon'] and params['lat']
|
||||
|
|
1
config/initializers/wiki_pages.rb
Normal file
1
config/initializers/wiki_pages.rb
Normal file
|
@ -0,0 +1 @@
|
|||
WIKI_PAGES = YAML.load_file("#{RAILS_ROOT}/config/wiki_pages.yml")
|
|
@ -233,6 +233,9 @@ en:
|
|||
# There is no 'relation' type because it is not represented in OpenLayers
|
||||
tag_details:
|
||||
tags: "Tags:"
|
||||
wiki_link:
|
||||
key: "The wiki description page for the {{key}} tag"
|
||||
tag: "The wiki description page for the {{key}}={{value}} tag"
|
||||
way_details:
|
||||
nodes: "Nodes:"
|
||||
part_of: "Part of:"
|
||||
|
|
1433
config/wiki_pages.yml
Normal file
1433
config/wiki_pages.yml
Normal file
File diff suppressed because it is too large
Load diff
1
db/.gitignore
vendored
Normal file
1
db/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
*_structure.sql
|
2
db/functions/.gitignore
vendored
Normal file
2
db/functions/.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
*.o
|
||||
*.so
|
|
@ -22,7 +22,7 @@ Disallow: /*relation=
|
|||
|
||||
User-agent: Slurp
|
||||
Disallow: /user/*/traces/
|
||||
Disallow: /user/*/edits/
|
||||
Disallow: /user/*/edits
|
||||
Disallow: /user/*/diary/
|
||||
Allow: /user/
|
||||
Disallow: /traces/tag/
|
||||
|
@ -48,7 +48,7 @@ Disallow: /*relation=
|
|||
|
||||
User-agent: Googlebot
|
||||
Disallow: /user/*/traces/
|
||||
Disallow: /user/*/edits/
|
||||
Disallow: /user/*/edits
|
||||
Disallow: /user/*/diary/
|
||||
Allow: /user/
|
||||
Disallow: /traces/tag/
|
||||
|
|
152
script/misc/update-wiki-pages
Normal file
152
script/misc/update-wiki-pages
Normal file
|
@ -0,0 +1,152 @@
|
|||
#!/usr/bin/env perl
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Pod::Usage ();
|
||||
use Getopt::Long ();
|
||||
|
||||
BEGIN {
|
||||
eval "require MediaWiki::API; require YAML::XS;" or do {
|
||||
print "You have to install some modules via CPAN to run this:\n";
|
||||
print " sudo cpanp MediaWiki::API YAML::XS\n";
|
||||
exit 1;
|
||||
};
|
||||
}
|
||||
|
||||
use MediaWiki::API;
|
||||
use YAML::XS qw(Dump);
|
||||
use Test::More 'no_plan';
|
||||
|
||||
=head1 NAME
|
||||
|
||||
update-wiki-pages - Screen-scrape the wiki for key/value wiki description pages
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
perl script/misc/update-wiki-pages config/wiki_pages.yml
|
||||
|
||||
=head1 BUGS
|
||||
|
||||
This will break if there are more than 500 key or value pages. Paging
|
||||
needs to be implemenented.
|
||||
|
||||
That or using a proper API or something (if it's there) or making a
|
||||
direct query to the wiki database.
|
||||
|
||||
=cut
|
||||
|
||||
# Get the command-line options
|
||||
Getopt::Long::Parser->new(
|
||||
config => [ qw< bundling no_ignore_case no_require_order pass_through > ],
|
||||
)->getoptions(
|
||||
'h|help' => \my $help,
|
||||
) or help();
|
||||
|
||||
# On --help
|
||||
help() if $help;
|
||||
|
||||
help() unless $ARGV[0];
|
||||
|
||||
# Get a API interface
|
||||
my $mw = MediaWiki::API->new();
|
||||
ok($mw, "Got a MediaWiki API");
|
||||
$mw->{config}->{api_url} = 'http://wiki.openstreetmap.org/w/api.php';
|
||||
|
||||
# All our goodies
|
||||
my (%feature, %count);
|
||||
|
||||
# This is what you get on:
|
||||
## http://wiki.openstreetmap.org/w/index.php?search=Template:KeyDescription&fulltext=Search&fulltext=Search
|
||||
for my $lang ('', map { "${_}:" } qw[ Pt Fi De It HU Cz Fr RU Pl ]) {
|
||||
ok(1, " Templates for language '$lang'");
|
||||
|
||||
# Key pages
|
||||
ok(1, " Getting key pages");
|
||||
my $cnt = stick_content_in_hash("key", "Template:${lang}KeyDescription", \%feature);
|
||||
ok(1, " Got $cnt key pages");
|
||||
$count{key} += $cnt;
|
||||
|
||||
# Value pages
|
||||
ok(1, " Getting value pages");
|
||||
my $cnt = stick_content_in_hash("tag", "Template:${lang}ValueDescription", \%feature);
|
||||
ok(1, " Got $cnt value pages");
|
||||
$count{value} += $cnt;
|
||||
}
|
||||
|
||||
ok(1, "Got a total of $count{$_} ${_}s") for qw[ key value ];
|
||||
|
||||
# Dump to .yml file
|
||||
open my $out, ">", $ARGV[0] or die "Can't open file '$ARGV[0]' supplied on the command line";
|
||||
say $out "# THIS FILE IS AUTOGENERATED WITH THE script/misc/update-wiki-pages";
|
||||
say $out "# PROGRAM DO NOT MANUALLY EDIT IT";
|
||||
say $out "";
|
||||
say $out Dump(\%feature);
|
||||
close $out;
|
||||
|
||||
exit 0;
|
||||
|
||||
sub stick_content_in_hash
|
||||
{
|
||||
my ($key, $title, $hash) = @_;
|
||||
my $ukey = ucfirst $key;
|
||||
|
||||
my $space_to_underscore = sub {
|
||||
my $txt = shift;
|
||||
$txt =~ s/ /_/g;
|
||||
$txt;
|
||||
};
|
||||
|
||||
my $count = 0;
|
||||
get_embeddedin(
|
||||
$title,
|
||||
sub {
|
||||
my ($links) = @_;
|
||||
my (@links) = @$links;
|
||||
ok(1, " ... got " . scalar(@links) . " more links");
|
||||
for my $link (@links) {
|
||||
$count++;
|
||||
my $title = $link->{title};
|
||||
|
||||
if ($title =~ /^$ukey:(?<key_name>.*?)$/) {
|
||||
# English by default
|
||||
$hash->{en}->{$key}->{ $space_to_underscore->($+{key_name}) } = $title;
|
||||
} elsif ($title =~ /^(?<lang>[^:]+):$ukey:(?<key_name>.*?)$/) {
|
||||
$hash->{lc $+{lang}}->{$key}->{ $space_to_underscore->($+{key_name}) } = $title;
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
return $count;
|
||||
}
|
||||
|
||||
sub get_embeddedin
|
||||
{
|
||||
my ($title, $callback) = @_;
|
||||
my $articles = $mw->list(
|
||||
{
|
||||
action => 'query',
|
||||
list => 'embeddedin',
|
||||
eititle => $title,
|
||||
eifilterredir => 'nonredirects',
|
||||
# Doesn't work for De:* and anything non-en. Odd.
|
||||
# einamespace => '0|8',
|
||||
eilimit => '200',
|
||||
},
|
||||
{
|
||||
max => '0',
|
||||
hook => $callback,
|
||||
skip_encoding => 1,
|
||||
}
|
||||
) || die $mw->{error}->{code} . ': ' . $mw->{error}->{details};
|
||||
}
|
||||
|
||||
sub help
|
||||
{
|
||||
my %arg = @_;
|
||||
|
||||
Pod::Usage::pod2usage(
|
||||
-verbose => $arg{ verbose },
|
||||
-exitval => $arg{ exitval } || 0,
|
||||
);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue