diff options
author | Matthieu Moy <Matthieu.Moy@imag.fr> | 2012-07-16 21:46:37 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2012-07-16 12:52:40 -0700 |
commit | 2045e293eb69204ac06910c7570718efb09b7059 (patch) | |
tree | d1c02b7c6fd3d1c5437dcf6ee3eedb1527906cfd | |
parent | dcb1ea620d1e8bd1d7e7622b7ca69050d0c119d7 (diff) | |
download | git-2045e293eb69204ac06910c7570718efb09b7059.tar.gz git-2045e293eb69204ac06910c7570718efb09b7059.tar.xz |
git-remote-mediawiki: make mediafiles export optional
It is possible to use git-remote-mediawiki on a tree with both .mw files
and other files. Before git-remote-mediawiki learnt how to export
mediafiles, such mixed trees allowed the user to maintain both the wiki
and other files for the same project in the same repository. With the
newly added support for exporting mediafiles, pushing such mixed trees
would upload unrelated files as mediafiles, which may not be desired.
Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rwxr-xr-x | contrib/mw-to-git/git-remote-mediawiki | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/contrib/mw-to-git/git-remote-mediawiki b/contrib/mw-to-git/git-remote-mediawiki index a2da52f4d..8e46e4e7c 100755 --- a/contrib/mw-to-git/git-remote-mediawiki +++ b/contrib/mw-to-git/git-remote-mediawiki @@ -66,11 +66,16 @@ chomp(@tracked_pages); my @tracked_categories = split(/[ \n]/, run_git("config --get-all remote.". $remotename .".categories")); chomp(@tracked_categories); -# Import media files too. +# Import media files on pull my $import_media = run_git("config --get --bool remote.". $remotename .".mediaimport"); chomp($import_media); $import_media = ($import_media eq "true"); +# Export media files on push +my $export_media = run_git("config --get --bool remote.". $remotename .".mediaexport"); +chomp($export_media); +$export_media = !($export_media eq "false"); + my $wiki_login = run_git("config --get remote.". $remotename .".mwLogin"); # Note: mwPassword is discourraged. Use the credential system instead. my $wiki_passwd = run_git("config --get remote.". $remotename .".mwPassword"); @@ -1068,6 +1073,11 @@ sub mw_push_file { $extension = ""; } if ($extension eq "mw") { + my $ns = get_mw_namespace_id_for_page($complete_file_name); + if ($ns && $ns == get_mw_namespace_id("File") && (!$export_media)) { + print STDERR "Ignoring media file related page: $complete_file_name\n"; + return ($oldrevid, "ok"); + } my $file_content; if ($page_deleted) { # Deleting a page usually requires @@ -1107,10 +1117,12 @@ sub mw_push_file { } $newrevid = $result->{edit}->{newrevid}; print STDERR "Pushed file: $new_sha1 - $title\n"; - } else { + } elsif ($export_media) { $newrevid = mw_upload_file($complete_file_name, $new_sha1, $extension, $page_deleted, $summary); + } else { + print STDERR "Ignoring media file $title\n"; } $newrevid = ($newrevid or $oldrevid); return ($newrevid, "ok"); @@ -1328,3 +1340,11 @@ sub get_mw_namespace_id { die "No such namespace $name on MediaWiki."; } } + +sub get_mw_namespace_id_for_page { + if (my ($namespace) = $_[0] =~ /^([^:]*):/) { + return get_mw_namespace_id($namespace); + } else { + return; + } +} |