git-remote-mediawiki: change separator of some regexps
[gitweb.git] / contrib / mw-to-git / git-remote-mediawiki.perl
index aaaf759965a78b9d9cb723128d92ff3682d145e3..e4d86ed65b7e71f9f4a70e4d1833e18e7657d60c 100755 (executable)
@@ -91,6 +91,9 @@
        $fetch_strategy = "by_page";
 }
 
+# Remember the timestamp corresponding to a revision id.
+my %basetimestamps;
+
 # Dumb push: don't update notes and mediawiki ref to reflect the last push.
 #
 # Configurable with mediawiki.dumbPush, or per-remote with
 $dumb_push = ($dumb_push eq "true");
 
 my $wiki_name = $url;
-$wiki_name =~ s/[^\/]*:\/\///;
+$wiki_name =~ s{[^/]*://}{};
 # If URL is like http://user:password@example.com/, we clearly don't
 # want the password in $wiki_name. While we're there, also remove user
 # and '@' sign, to avoid author like MWUser@HTTPUser@host.com
@@ -368,7 +371,7 @@ sub get_all_mediafiles {
 
 sub get_linked_mediafiles {
        my $pages = shift;
-       my @titles = map $_->{title}, values(%{$pages});
+       my @titles = map { $_->{title} } values(%{$pages});
 
        # The query is split in small batches because of the MW API limit of
        # the number of links to be returned (500 links max).
@@ -396,11 +399,13 @@ sub get_linked_mediafiles {
                while (my ($id, $page) = each(%{$result->{query}->{pages}})) {
                        my @media_titles;
                        if (defined($page->{links})) {
-                               my @link_titles = map $_->{title}, @{$page->{links}};
+                               my @link_titles
+                                   = map { $_->{title} } @{$page->{links}};
                                push(@media_titles, @link_titles);
                        }
                        if (defined($page->{images})) {
-                               my @image_titles = map $_->{title}, @{$page->{images}};
+                               my @image_titles
+                                   = map { $_->{title} } @{$page->{images}};
                                push(@media_titles, @image_titles);
                        }
                        if (@media_titles) {
@@ -480,9 +485,6 @@ sub get_last_local_revision {
        return $lastrevision_number;
 }
 
-# Remember the timestamp corresponding to a revision id.
-my %basetimestamps;
-
 # Get the last remote revision without taking in account which pages are
 # tracked or not. This function makes a single request to the wiki thus
 # avoid a loop onto all tracked pages. This is useful for the fetch-by-rev
@@ -562,7 +564,7 @@ sub mediawiki_smudge {
 
 sub mediawiki_clean_filename {
        my $filename = shift;
-       $filename =~ s/@{[SLASH_REPLACEMENT]}/\//g;
+       $filename =~ s{@{[SLASH_REPLACEMENT]}}{/}g;
        # [, ], |, {, and } are forbidden by MediaWiki, even URL-encoded.
        # Do a variant of URL-encoding, i.e. looks like URL-encoding,
        # but with _ added to prevent MediaWiki from thinking this is
@@ -576,7 +578,7 @@ sub mediawiki_clean_filename {
 
 sub mediawiki_smudge_filename {
        my $filename = shift;
-       $filename =~ s/\//@{[SLASH_REPLACEMENT]}/g;
+       $filename =~ s{/}{@{[SLASH_REPLACEMENT]}}g;
        $filename =~ s/ /_/g;
        # Decode forbidden characters encoded in mediawiki_clean_filename
        $filename =~ s/_%_([0-9a-fA-F][0-9a-fA-F])/sprintf("%c", hex($1))/ge;
@@ -759,7 +761,7 @@ sub get_more_refs {
        my @refs;
        while (1) {
                my $line = <STDIN>;
-               if ($line =~ m/^$cmd (.*)$/) {
+               if ($line =~ /^$cmd (.*)$/) {
                        push(@refs, $1);
                } elsif ($line eq "\n") {
                        return @refs;
@@ -833,7 +835,7 @@ sub mw_import_ref_by_pages {
        my ($n, @revisions) = fetch_mw_revisions(\@pages, $fetch_from);
 
        @revisions = sort {$a->{revid} <=> $b->{revid}} @revisions;
-       my @revision_ids = map $_->{revid}, @revisions;
+       my @revision_ids = map { $_->{revid} } @revisions;
 
        return mw_import_revids($fetch_from, \@revision_ids, \%pages_hash);
 }
@@ -1165,11 +1167,11 @@ sub mw_push_revision {
                my @local_ancestry = split(/\n/, run_git("rev-list --boundary --parents $local ^$parsed_sha1"));
                my %local_ancestry;
                foreach my $line (@local_ancestry) {
-                       if (my ($child, $parents) = $line =~ m/^-?([a-f0-9]+) ([a-f0-9 ]+)/) {
-                               foreach my $parent (split(' ', $parents)) {
+                       if (my ($child, $parents) = $line =~ /^-?([a-f0-9]+) ([a-f0-9 ]+)/) {
+                               foreach my $parent (split(/ /, $parents)) {
                                        $local_ancestry{$parent} = $child;
                                }
-                       } elsif (!$line =~ m/^([a-f0-9]+)/) {
+                       } elsif (!$line =~ /^([a-f0-9]+)/) {
                                die "Unexpected output from git rev-list: $line";
                        }
                }
@@ -1246,8 +1248,8 @@ sub get_allowed_file_extensions {
                siprop => 'fileextensions'
                };
        my $result = $mediawiki->api($query);
-       my @file_extensions= map $_->{ext},@{$result->{query}->{fileextensions}};
-       my %hashFile = map {$_ => 1}@file_extensions;
+       my @file_extensions = map { $_->{ext}} @{$result->{query}->{fileextensions}};
+       my %hashFile = map { $_ => 1 } @file_extensions;
 
        return %hashFile;
 }
@@ -1331,7 +1333,8 @@ sub get_mw_namespace_id {
 }
 
 sub get_mw_namespace_id_for_page {
-       if (my ($namespace) = $_[0] =~ /^([^:]*):/) {
+       my $namespace = shift;
+       if ($namespace =~ /^([^:]*):/) {
                return get_mw_namespace_id($namespace);
        } else {
                return;