]> git.openstreetmap.org Git - rails.git/blobdiff - script/misc/update-wiki-pages
Simplify step mapping function
[rails.git] / script / misc / update-wiki-pages
index 0bef30d03f113de844f19e0b4f3bc2d860db6480..84205fa35b95b36dde4c805ef45d6dd766cd2af9 100755 (executable)
@@ -3,20 +3,11 @@ use 5.010;
 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 Getopt::Long;
+use Pod::Usage;
 use MediaWiki::API;
+use Test::More qw(no_plan);
 use YAML::XS qw(Dump);
-use Test::More 'no_plan';
 
 =head1 NAME
 
@@ -50,7 +41,9 @@ help() unless -f $out_file;
 # 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';
+$mw->{config}->{api_url} = 'https://wiki.openstreetmap.org/w/api.php';
+$mw->{config}->{retries} = 5;
+$mw->{config}->{retry_delay} = 30;
 
 # All our goodies
 my (%feature, %count);
@@ -67,14 +60,26 @@ for my $lang ('', map { "${_}:" } qw[ Pt Fi De It HU Cz Fr RU Pl ]) {
     ok(1, "    Got $cnt key pages");
     $count{key} += $cnt;
 
+    # Key prefix pages
+    ok(1, "    Getting key prefix pages");
+    $cnt = stick_content_in_hash("key", "Template:${lang}KeyPrefixDescription", \%feature);
+    ok(1, "    Got $cnt key prefix pages");
+    $count{keyprefix} += $cnt;
+
     # Value pages
     ok(1, "    Getting value pages");
     $cnt = stick_content_in_hash("tag", "Template:${lang}ValueDescription", \%feature);
     ok(1, "    Got $cnt value pages");
     $count{value} += $cnt;
+
+    # ChangesetKey pages
+    ok(1, "    Getting changeset key pages");
+    $cnt = stick_content_in_hash("key", "Template:${lang}ChangesetKeyDescription", \%feature, "ChangesetKey");
+    ok(1, "    Got $cnt changeset key pages");
+    $count{changesetkey} += $cnt;
 }
 
-ok(1, "Got a total of $count{$_} ${_}s") for qw[ key value ];
+ok(1, "Got a total of $count{$_} ${_}s") for qw[ key keyprefix changesetkey value ];
 
 # Dump to .yml file
 open my $out, ">", $out_file or die "Can't open file '$out_file' supplied on the command line";
@@ -88,8 +93,9 @@ exit 0;
 
 sub stick_content_in_hash
 {
-    my ($key, $title, $hash) = @_;
+    my ($key, $title, $hash, $namespace) = @_;
     my $ukey = ucfirst $key;
+    $namespace ||= $ukey;
 
     my $space_to_underscore = sub {
         my $txt = shift;
@@ -106,7 +112,7 @@ sub stick_content_in_hash
         my $title = $link->{title};
         my $lang;
         my $key_name;
-        if ($title =~ /^$ukey:(?<key_name>.*?)$/) {
+        if ($title =~ /^($namespace|$ukey):(?<key_name>.*?)$/) {
             # English by default
             $lang = "en";
             $key_name = $space_to_underscore->($+{key_name});