diff options
Diffstat (limited to 'contrib/mw-to-git')
-rw-r--r-- | contrib/mw-to-git/.gitignore | 1 | ||||
-rw-r--r-- | contrib/mw-to-git/Makefile | 50 | ||||
-rwxr-xr-x | contrib/mw-to-git/git-remote-mediawiki.perl (renamed from contrib/mw-to-git/git-remote-mediawiki) | 22 | ||||
-rw-r--r-- | contrib/mw-to-git/git-remote-mediawiki.txt | 2 | ||||
-rw-r--r-- | contrib/mw-to-git/t/README | 6 | ||||
-rwxr-xr-x | contrib/mw-to-git/t/install-wiki.sh | 2 | ||||
-rw-r--r-- | contrib/mw-to-git/t/install-wiki/LocalSettings.php | 2 | ||||
-rwxr-xr-x | contrib/mw-to-git/t/t9362-mw-to-git-utf8.sh | 40 |
8 files changed, 66 insertions, 59 deletions
diff --git a/contrib/mw-to-git/.gitignore b/contrib/mw-to-git/.gitignore new file mode 100644 index 0000000000..b9196555e5 --- /dev/null +++ b/contrib/mw-to-git/.gitignore @@ -0,0 +1 @@ +git-remote-mediawiki diff --git a/contrib/mw-to-git/Makefile b/contrib/mw-to-git/Makefile index 3ed728b0ef..f14971987c 100644 --- a/contrib/mw-to-git/Makefile +++ b/contrib/mw-to-git/Makefile @@ -1,47 +1,17 @@ # -# Copyright (C) 2012 -# Charles Roussel <charles.roussel@ensimag.imag.fr> -# Simon Cathebras <simon.cathebras@ensimag.imag.fr> -# Julien Khayat <julien.khayat@ensimag.imag.fr> -# Guillaume Sasdy <guillaume.sasdy@ensimag.imag.fr> -# Simon Perrat <simon.perrat@ensimag.imag.fr> +# Copyright (C) 2013 +# Matthieu Moy <Matthieu.Moy@imag.fr> # ## Build git-remote-mediawiki --include ../../config.mak.autogen --include ../../config.mak +SCRIPT_PERL=git-remote-mediawiki.perl +GIT_ROOT_DIR=../.. +HERE=contrib/mw-to-git/ -ifndef PERL_PATH - PERL_PATH = /usr/bin/perl -endif -ifndef gitexecdir - gitexecdir = $(shell git --exec-path) -endif +SCRIPT_PERL_FULL=$(patsubst %,$(HERE)/%,$(SCRIPT_PERL)) -PERL_PATH_SQ = $(subst ','\'',$(PERL_PATH)) -gitexecdir_SQ = $(subst ','\'',$(gitexecdir)) -SCRIPT = git-remote-mediawiki +all: build -.PHONY: install help doc test clean - -help: - @echo 'This is the help target of the Makefile. Current configuration:' - @echo ' gitexecdir = $(gitexecdir_SQ)' - @echo ' PERL_PATH = $(PERL_PATH_SQ)' - @echo 'Run "$(MAKE) install" to install $(SCRIPT) in gitexecdir' - @echo 'Run "$(MAKE) test" to run the testsuite' - -install: - sed -e '1s|#!.*/perl|#!$(PERL_PATH_SQ)|' $(SCRIPT) \ - > '$(gitexecdir_SQ)/$(SCRIPT)' - chmod +x '$(gitexecdir)/$(SCRIPT)' - -doc: - @echo 'Sorry, "make doc" is not implemented yet for $(SCRIPT)' - -test: - $(MAKE) -C t/ test - -clean: - $(RM) '$(gitexecdir)/$(SCRIPT)' - $(MAKE) -C t/ clean +build install clean: + $(MAKE) -C $(GIT_ROOT_DIR) SCRIPT_PERL=$(SCRIPT_PERL_FULL) \ + $@-perl-script diff --git a/contrib/mw-to-git/git-remote-mediawiki b/contrib/mw-to-git/git-remote-mediawiki.perl index 68555d4265..9c14c1f88d 100755 --- a/contrib/mw-to-git/git-remote-mediawiki +++ b/contrib/mw-to-git/git-remote-mediawiki.perl @@ -28,7 +28,7 @@ use warnings; use constant SLASH_REPLACEMENT => "%2F"; # It's not always possible to delete pages (may require some -# priviledges). Deleted pages are replaced with this content. +# privileges). Deleted pages are replaced with this content. use constant DELETED_CONTENT => "[[Category:Deleted]]\n"; # It's not possible to create empty pages. New empty files in Git are @@ -711,6 +711,14 @@ sub fetch_mw_revisions { return ($n, @revisions); } +sub fe_escape_path { + my $path = shift; + $path =~ s/\\/\\\\/g; + $path =~ s/"/\\"/g; + $path =~ s/\n/\\n/g; + return '"' . $path . '"'; +} + sub import_file_revision { my $commit = shift; my %commit = %{$commit}; @@ -738,15 +746,17 @@ sub import_file_revision { print STDOUT "from refs/mediawiki/$remotename/master^0\n"; } if ($content ne DELETED_CONTENT) { - print STDOUT "M 644 inline $title.mw\n"; + print STDOUT "M 644 inline " . + fe_escape_path($title . ".mw") . "\n"; literal_data($content); if (%mediafile) { - print STDOUT "M 644 inline $mediafile{title}\n"; + print STDOUT "M 644 inline " + . fe_escape_path($mediafile{title}) . "\n"; literal_data_raw($mediafile{content}); } print STDOUT "\n\n"; } else { - print STDOUT "D $title.mw\n"; + print STDOUT "D " . fe_escape_path($title . ".mw") . "\n"; } # mediawiki revision number in the git note @@ -831,7 +841,7 @@ sub mw_import_ref { if ($fetch_from == 1 && $n == 0) { print STDERR "You appear to have cloned an empty MediaWiki.\n"; # Something has to be done remote-helper side. If nothing is done, an error is - # thrown saying that HEAD is refering to unknown object 0000000000000000000 + # thrown saying that HEAD is referring to unknown object 0000000000000000000 # and the clone fails. } } @@ -1057,7 +1067,7 @@ sub mw_push_file { my $file_content; if ($page_deleted) { # Deleting a page usually requires - # special priviledges. A common + # special privileges. A common # convention is to replace the page # with this content instead: $file_content = DELETED_CONTENT; diff --git a/contrib/mw-to-git/git-remote-mediawiki.txt b/contrib/mw-to-git/git-remote-mediawiki.txt index 4d211f5b81..23b7ef9f62 100644 --- a/contrib/mw-to-git/git-remote-mediawiki.txt +++ b/contrib/mw-to-git/git-remote-mediawiki.txt @@ -4,4 +4,4 @@ objects from mediawiki just as one would do with a classic git repository thanks to remote-helpers. For more information, visit the wiki at -https://github.com/Bibzball/Git-Mediawiki/wiki +https://github.com/moy/Git-Mediawiki/wiki diff --git a/contrib/mw-to-git/t/README b/contrib/mw-to-git/t/README index 96e97390cf..03f6ee5d72 100644 --- a/contrib/mw-to-git/t/README +++ b/contrib/mw-to-git/t/README @@ -25,7 +25,7 @@ Principles and Technical Choices The test environment makes it easy to install and manipulate one or several MediaWiki instances. To allow developers to run the testsuite -easily, the environment does not require root priviledge (except to +easily, the environment does not require root privilege (except to install the required packages if needed). It starts a webserver instance on the user's account (using lighttpd greatly helps for that), and does not need a separate database daemon (thanks to the use @@ -81,7 +81,7 @@ parameters, please refer to the `test-gitmw-lib.sh` and ** `test_check_wiki_precond`: Check if the tests must be skipped or not. Please use this function -at the beggining of each new test file. +at the beginning of each new test file. ** `wiki_getpage`: Fetch a given page from the wiki and puts its content in the @@ -113,7 +113,7 @@ Tests if a given page exists on the wiki. ** `wiki_reset`: Reset the wiki, i.e. flush the database. Use this function at the -begining of each new test, except if the test re-uses the same wiki +beginning of each new test, except if the test re-uses the same wiki (and history) as the previous test. How to write a new test diff --git a/contrib/mw-to-git/t/install-wiki.sh b/contrib/mw-to-git/t/install-wiki.sh index c6d6fa3aef..70a53f67fd 100755 --- a/contrib/mw-to-git/t/install-wiki.sh +++ b/contrib/mw-to-git/t/install-wiki.sh @@ -15,7 +15,7 @@ fi . "$WIKI_TEST_DIR"/test-gitmw-lib.sh usage () { - echo "Usage: " + echo "usage: " echo " ./install-wiki.sh <install | delete | --help>" echo " install | -i : Install a wiki on your computer." echo " delete | -d : Delete the wiki and all its pages and " diff --git a/contrib/mw-to-git/t/install-wiki/LocalSettings.php b/contrib/mw-to-git/t/install-wiki/LocalSettings.php index 29f125116b..745e47e881 100644 --- a/contrib/mw-to-git/t/install-wiki/LocalSettings.php +++ b/contrib/mw-to-git/t/install-wiki/LocalSettings.php @@ -88,7 +88,7 @@ $wgShellLocale = "en_US.utf8"; ## Set $wgCacheDirectory to a writable directory on the web server ## to make your wiki go slightly faster. The directory should not -## be publically accessible from the web. +## be publicly accessible from the web. #$wgCacheDirectory = "$IP/cache"; # Site language code, should be one of the list in ./languages/Names.php diff --git a/contrib/mw-to-git/t/t9362-mw-to-git-utf8.sh b/contrib/mw-to-git/t/t9362-mw-to-git-utf8.sh index 246d47d8fb..37021e200a 100755 --- a/contrib/mw-to-git/t/t9362-mw-to-git-utf8.sh +++ b/contrib/mw-to-git/t/t9362-mw-to-git-utf8.sh @@ -139,7 +139,7 @@ test_expect_success 'character $ in file name (git -> mw) ' ' ' -test_expect_failure 'capital at the begining of file names' ' +test_expect_failure 'capital at the beginning of file names' ' wiki_reset && git clone mediawiki::'"$WIKI_URL"' mw_dir_10 && ( @@ -156,7 +156,7 @@ test_expect_failure 'capital at the begining of file names' ' ' -test_expect_failure 'special character at the begining of file name from mw to git' ' +test_expect_failure 'special character at the beginning of file name from mw to git' ' wiki_reset && git clone mediawiki::'"$WIKI_URL"' mw_dir_11 && wiki_editpage {char_1 "expect to be renamed {char_1" false && @@ -189,7 +189,7 @@ test_expect_success 'Push page with title containing ":" other than namespace se wiki_page_exist NotANameSpace:Page ' -test_expect_success 'test of correct formating for file name from mw to git' ' +test_expect_success 'test of correct formatting for file name from mw to git' ' wiki_reset && git clone mediawiki::'"$WIKI_URL"' mw_dir_12 && wiki_editpage char_%_7b_1 "expect to be renamed char{_1" false && @@ -207,7 +207,7 @@ test_expect_success 'test of correct formating for file name from mw to git' ' ' -test_expect_failure 'test of correct formating for file name begining with special character' ' +test_expect_failure 'test of correct formatting for file name beginning with special character' ' wiki_reset && git clone mediawiki::'"$WIKI_URL"' mw_dir_13 && ( @@ -215,7 +215,7 @@ test_expect_failure 'test of correct formating for file name begining with speci echo "my new file {char_1" >\{char_1.mw && echo "my new file [char_2" >\[char_2.mw && git add . && - git commit -am "commiting some exotic file name..." && + git commit -am "committing some exotic file name..." && git push && git pull ) && @@ -226,7 +226,7 @@ test_expect_failure 'test of correct formating for file name begining with speci ' -test_expect_success 'test of correct formating for file name from git to mw' ' +test_expect_success 'test of correct formatting for file name from git to mw' ' wiki_reset && git clone mediawiki::'"$WIKI_URL"' mw_dir_14 && ( @@ -234,7 +234,7 @@ test_expect_success 'test of correct formating for file name from git to mw' ' echo "my new file char{_1" >Char\{_1.mw && echo "my new file char[_2" >Char\[_2.mw && git add . && - git commit -m "commiting some exotic file name..." && + git commit -m "committing some exotic file name..." && git push ) && wiki_getallpage ref_page_14 && @@ -318,4 +318,30 @@ test_expect_success 'git push with \ in format control' ' ' +test_expect_success 'fast-import meta-characters in page name (mw -> git)' ' + wiki_reset && + wiki_editpage \"file\"_\\_foo "expect to be called \"file\"_\\_foo" false && + git clone mediawiki::'"$WIKI_URL"' mw_dir_21 && + test_path_is_file mw_dir_21/\"file\"_\\_foo.mw && + wiki_getallpage ref_page_21 && + test_diff_directories mw_dir_21 ref_page_21 +' + + +test_expect_success 'fast-import meta-characters in page name (git -> mw) ' ' + wiki_reset && + git clone mediawiki::'"$WIKI_URL"' mw_dir_22 && + ( + cd mw_dir_22 && + echo "this file is called \"file\"_\\_foo.mw" >\"file\"_\\_foo && + git add . && + git commit -am "file \"file\"_\\_foo" && + git pull && + git push + ) && + wiki_getallpage ref_page_22 && + test_diff_directories mw_dir_22 ref_page_22 +' + + test_done |