git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 3/8] git-remote-mediawiki: make mediafiles export optional

From
Matthieu Moy <matthieu.moy@imag.fr>
Date
Jul 16, 2012, 12:00 UTC
Message-ID
<1342440053-3058-4-git-send-email-Matthieu.Moy@imag.fr>
In-Reply-To
<1342440053-3058-1-git-send-email-Matthieu.Moy@imag.fr>
Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>
---
 contrib/mw-to-git/git-remote-mediawiki | 24 ++++++++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)
diff --git a/contrib/mw-to-git/git-remote-mediawiki b/contrib/mw-to-git/git-remote-mediawiki
index a2da52f..8e46e4e 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;
+	}
+}
-- 
1.7.11.1.30.g7e1baf9.dirty
Previous: Junio C HamanoNext: Junio C Hamano
Message 8 of 33 in “git-remote-mediawiki: fixes, optimizations, and progress report”
  1. 0/8 git-remote-mediawiki: fixes, optimizations, and progress reportMatthieu Moy, Jul 16, 2012
  2. 1/8 git-remote-mediawiki: don't split namespaces with spacesMatthieu Moy, Jul 16, 2012
  3. Junio C HamanoJul 16, 2012
  4. 2/8 git-remote-mediawiki: actually send empty comment when they're emptyMatthieu Moy, Jul 16, 2012
  5. Junio C HamanoJul 16, 2012
  6. Matthieu MoyJul 16, 2012
  7. Junio C HamanoJul 16, 2012
  8. 3/8 git-remote-mediawiki: make mediafiles export optionalMatthieu Moy, Jul 16, 2012
  9. Junio C HamanoJul 16, 2012
  10. Matthieu MoyJul 16, 2012
  11. 4/8 git-remote-mediawiki: get rid of O(N^2) loopMatthieu Moy, Jul 16, 2012
  12. Junio C HamanoJul 16, 2012
  13. Matthieu MoyJul 16, 2012
  14. 5/8 git-remote-mediawiki: use --force when adding notesMatthieu Moy, Jul 16, 2012
  15. 6/8 git-remote-mediawiki: show progress information when listing pagesMatthieu Moy, Jul 16, 2012
  16. 7/8 git-remote-mediawiki: show progress information when getting last remote revisionMatthieu Moy, Jul 16, 2012
  17. 8/8 git-remote-mediawiki: properly deal with invalid remote revisionsMatthieu Moy, Jul 16, 2012
  18. Junio C HamanoJul 16, 2012
  19. 0/8 git-remote-mediawiki: fixes, optimizations, and progress reportMatthieu Moy, Jul 16, 2012
  20. 1/8 git-remote-mediawiki: don't split namespaces with spacesMatthieu Moy, Jul 16, 2012
  21. 2/8 git-remote-mediawiki: actually send empty comment when they're emptyMatthieu Moy, Jul 16, 2012
  22. 3/8 git-remote-mediawiki: make mediafiles export optionalMatthieu Moy, Jul 16, 2012
  23. 4/8 git-remote-mediawiki: get rid of O(N^2) loopMatthieu Moy, Jul 16, 2012
  24. 5/8 git-remote-mediawiki: use --force when adding notesMatthieu Moy, Jul 16, 2012
  25. 6/8 git-remote-mediawiki: show progress information when listing pagesMatthieu Moy, Jul 16, 2012
  26. 7/8 git-remote-mediawiki: show progress information when getting last remote revisionMatthieu Moy, Jul 16, 2012
  27. 8/8 git-remote-mediawiki: properly deal with invalid remote revisionsMatthieu Moy, Jul 16, 2012
  28. Junio C HamanoJul 16, 2012
  29. 0/2 git-remote-mediawiki: two more fixesMatthieu Moy, Jul 17, 2012
  30. 1/2 git-remote-mediawiki: fix incorrect test usage in testMatthieu Moy, Jul 17, 2012
  31. 2/2 git-remote-mediawiki: allow page names with a ':'Matthieu Moy, Jul 17, 2012
  32. Dan JohnsonJul 20, 2012
  33. Matthieu MoyJul 23, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.