/usr/share/doc/git/contrib/mw-to-git
Edit: /usr/share/doc/git/contrib/mw-to-git/git-mw.perl (9605B)
#!/usr/bin/perl
# Copyright (C) 2013
# Benoit Person
# Celestin Matte
# License: GPL v2 or later
# Set of tools for git repo with a mediawiki remote.
# Documentation & bugtracker: https://github.com/Git-Mediawiki/Git-Mediawiki
use strict;
use warnings;
use Getopt::Long;
use URI::URL qw(url);
use LWP::UserAgent;
use HTML::TreeBuilder;
use Git;
use MediaWiki::API;
use Git::Mediawiki qw(clean_filename connect_maybe
EMPTY HTTP_CODE_PAGE_NOT_FOUND);
# By default, use UTF-8 to communicate with Git and the user
binmode STDERR, ':encoding(UTF-8)';
binmode STDOUT, ':encoding(UTF-8)';
# Global parameters
my $verbose = 0;
sub v_print {
if ($verbose) {
return print {*STDERR} @_;
}
return;
}
# Preview parameters
my $file_name = EMPTY;
my $remote_name = EMPTY;
my $preview_file_name = EMPTY;
my $autoload = 0;
sub file {
$file_name = shift;
return $file_name;
}
my %commands = (
'help' =>
[\&help, {}, \&help],
'preview' =>
[\&preview, {
'<>' => \&file,
'output|o=s' => \$preview_file_name,
'remote|r=s' => \$remote_name,
'autoload|a' => \$autoload
}, \&preview_help]
);
# Search for sub-command
my $cmd = $commands{'help'};
for (0..@ARGV-1) {
if (defined $commands{$ARGV[$_]}) {
$cmd = $commands{$ARGV[$_]};
splice @ARGV, $_, 1;
last;
}
};
GetOptions( %{$cmd->[1]},
'help|h' => \&{$cmd->[2]},
'verbose|v' => \$verbose);
# Launch command
&{$cmd->[0]};
############################# Preview Functions ################################
sub preview_help {
print {*STDOUT} <<'END';
USAGE: git mw preview [--remote|-r ] [--autoload|-a]
[--output|-o