* [PATCHv2] git-remote-mediawiki: export File: attachments
@ 2012-06-12 12:46 Kim Thuat NGUYEN
2012-06-12 12:52 ` Matthieu Moy
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Kim Thuat NGUYEN @ 2012-06-12 12:46 UTC (permalink / raw)
To: git
Cc: nguyenkimthuat, VOLEK Pavel, NGUYEN Kim Thuat,
ROUCHER IGLESIAS Javier, Matthieu Moy
From: nguyenkimthuat <nguyenkimthuat@gmail.com>
This patch adds the functionnality to export the
file attachements from the local git's repository
using the API of mediawiki.
Signed-off-by: VOLEK Pavel <Pavel.Volek@ensimag.imag.fr>
Signed-off-by: NGUYEN Kim Thuat <Kim-Thuat.Nguyen@ensimag.imag.fr>
Signed-off-by: ROUCHER IGLESIAS Javier <roucherj@ensimag.imag.fr>
Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>
---
contrib/mw-to-git/git-remote-mediawiki | 62 +++++++++++++++++++++++++++++++++-
1 file changed, 61 insertions(+), 1 deletion(-)
diff --git a/contrib/mw-to-git/git-remote-mediawiki b/contrib/mw-to-git/git-remote-mediawiki
index c18bfa1..8f711e2 100755
--- a/contrib/mw-to-git/git-remote-mediawiki
+++ b/contrib/mw-to-git/git-remote-mediawiki
@@ -275,6 +275,14 @@ sub run_git {
return $res;
}
+sub run_git_raw {
+ no encoding 'utf8';
+ open(my $g, "-|", "git " . $_[0]);
+ my $r = do { local $/; <$g> };
+ close($g);
+
+ return $r;
+}
sub get_last_local_revision {
# Get note regarding last mediawiki revision
@@ -644,6 +652,10 @@ sub mw_push_file {
my $page_deleted = ($new_sha1 eq NULL_SHA1);
$complete_file_name = mediawiki_clean_filename($complete_file_name);
+ my $path = "File:".$complete_file_name;
+ my @extensions = split(/\./, $complete_file_name);
+ my $extension = pop(@extensions);
+
if (substr($complete_file_name,-3) eq ".mw") {
my $title = substr($complete_file_name,0,-3);
@@ -687,7 +699,40 @@ sub mw_push_file {
$newrevid = $result->{edit}->{newrevid};
print STDERR "Pushed file: $new_sha1 - $title\n";
} else {
- print STDERR "$complete_file_name not a mediawiki file (Not pushable on this version of git-remote-mediawiki).\n"
+ my %hashFiles = get_file_extensions();
+ if (exists($hashFiles{$extension})) {
+ # Deleting and uploading a file require the priviledge of the user
+ if ($page_deleted) {
+ mw_connect_maybe();
+ my $res = $mediawiki->edit( {
+ action => 'delete',
+ title => $path,
+ reason => $summary
+ } )|| die $mediawiki-> {error}->{code} . ':' . $mediawiki->{error}->{details};
+ } else {
+ my $content = run_git_raw("cat-file blob $new_sha1");
+ if ($content ne "") {
+ mw_connect_maybe();
+ $mediawiki->{config}->{upload_url} = "$url/index.php/Special:Upload";
+ my $res = $mediawiki->edit ( {
+ action => 'upload',
+ filename => $complete_file_name,
+ comment => $summary,
+ file => [undef, $complete_file_name, Content => $content ],
+ ignorewarnings=>1,
+ }, {
+ skip_encoding => 1 # Helps with names with accentuated characters
+ } ) || die $mediawiki-> {error}->{code} . ':' . $mediawiki->{error}->{details};
+ my $last_file_page = $mediawiki->get_page({title =>$path});
+ $newrevid = $last_file_page->{revid};
+ print STDERR "Pushed file: $new_sha1 - $complete_file_name\n";
+ } else {
+ print STDERR "Empty file. Can not upload \n ";
+ }
+ }
+ } else {
+ print STDERR "$complete_file_name not a mediawiki file (Not pushable on this version of git-remote-mediawiki).\n";
+ }
}
return ($newrevid, "ok");
}
@@ -825,3 +870,18 @@ sub mw_push_revision {
print STDOUT "ok $remote\n";
return 1;
}
+
+sub get_file_extensions {
+ mw_connect_maybe();
+
+ my $query = {
+ action => 'query',
+ meta => 'siteinfo',
+ siprop => 'fileextensions'
+ };
+ my $result = $mediawiki->api($query);
+ my @file_extensions= map $_->{ext},@{$result->{query}->{fileextensions}};
+ my %hashFile = map {$_ => 1}@file_extensions;
+
+ return %hashFile;
+}
--
1.7.10.GIT
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCHv2] git-remote-mediawiki: export File: attachments
2012-06-12 12:46 [PATCHv2] git-remote-mediawiki: export File: attachments Kim Thuat NGUYEN
@ 2012-06-12 12:52 ` Matthieu Moy
2012-06-12 12:54 ` nguyenki
2012-06-12 13:51 ` Max Horn
2 siblings, 0 replies; 4+ messages in thread
From: Matthieu Moy @ 2012-06-12 12:52 UTC (permalink / raw)
To: Kim Thuat NGUYEN
Cc: git, nguyenkimthuat, VOLEK Pavel, ROUCHER IGLESIAS Javier
Kim Thuat NGUYEN <kim-thuat.nguyen@ensimag.imag.fr> writes:
> From: nguyenkimthuat <nguyenkimthuat@gmail.com>
Please use your @ensimag email for Ensimag-related things. This adress
is the one used in the commit itself, i.e. ~/.gitconfig. "git commit
--reset-author" can help.
> @@ -644,6 +652,10 @@ sub mw_push_file {
> my $page_deleted = ($new_sha1 eq NULL_SHA1);
> $complete_file_name = mediawiki_clean_filename($complete_file_name);
>
> + my $path = "File:".$complete_file_name;
> + my @extensions = split(/\./, $complete_file_name);
> + my $extension = pop(@extensions);
> +
> if (substr($complete_file_name,-3) eq ".mw") {
> my $title = substr($complete_file_name,0,-3);
If you extract the extension explicitely, then you don't need these
"substr(...)" anymore.
> + my %hashFiles = get_file_extensions();
> + if (exists($hashFiles{$extension})) {
> + # Deleting and uploading a file require the priviledge of the user
> + if ($page_deleted) {
> + mw_connect_maybe();
> + my $res = $mediawiki->edit( {
> + action => 'delete',
> + title => $path,
> + reason => $summary
> + } )|| die $mediawiki-> {error}->{code} . ':' . $mediawiki->{error}->{details};
Here and below: you still have too long lines.
> + ignorewarnings=>1,
Spaces around =>.
> + }, {
> + skip_encoding => 1 # Helps with names with accentuated characters
> + } ) || die $mediawiki-> {error}->{code} . ':' . $mediawiki->{error}->{details};
Weird indentation.
> + } else {
> + print STDERR "Empty file. Can not upload \n ";
> + }
No space, but a "." before \n.
> + } else {
> + print STDERR "$complete_file_name not a mediawiki file (Not pushable on this version of git-remote-mediawiki).\n";
> + }
Why does this message keep reappearing?
> +sub get_file_extensions {
> + mw_connect_maybe();
> +
> + my $query = {
> + action => 'query',
> + meta => 'siteinfo',
> + siprop => 'fileextensions'
> + };
> + my $result = $mediawiki->api($query);
> + my @file_extensions= map $_->{ext},@{$result->{query}->{fileextensions}};
> + my %hashFile = map {$_ => 1}@file_extensions;
> +
> + return %hashFile;
> +}
I like the new function much more than the previous one.
--
Matthieu Moy
http://www-verimag.imag.fr/~moy/
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCHv2] git-remote-mediawiki: export File: attachments
2012-06-12 12:46 [PATCHv2] git-remote-mediawiki: export File: attachments Kim Thuat NGUYEN
2012-06-12 12:52 ` Matthieu Moy
@ 2012-06-12 12:54 ` nguyenki
2012-06-12 13:51 ` Max Horn
2 siblings, 0 replies; 4+ messages in thread
From: nguyenki @ 2012-06-12 12:54 UTC (permalink / raw)
To: git
On Tue, 12 Jun 2012 14:46:16 +0200, Kim Thuat NGUYEN wrote:
> + print STDERR "$complete_file_name not a mediawiki file (Not
> pushable on this version of git-remote-mediawiki).\n";
> + }
> }
> return ($newrevid, "ok");
> }
I changed the comment like that, i'll be correct in the nex patch.
- print STDERR "$complete_file_name not a mediawiki file (Not
pushable on this version of git-remote-mediawiki).\n";
+ print STDERR "$complete_file_name is not a permitted file. Check
the configuration of file uploads in your mediawiki \n";
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCHv2] git-remote-mediawiki: export File: attachments
2012-06-12 12:46 [PATCHv2] git-remote-mediawiki: export File: attachments Kim Thuat NGUYEN
2012-06-12 12:52 ` Matthieu Moy
2012-06-12 12:54 ` nguyenki
@ 2012-06-12 13:51 ` Max Horn
2 siblings, 0 replies; 4+ messages in thread
From: Max Horn @ 2012-06-12 13:51 UTC (permalink / raw)
To: Kim Thuat NGUYEN
Cc: git, nguyenkimthuat, VOLEK Pavel, ROUCHER IGLESIAS Javier,
Matthieu Moy
Am 12.06.2012 um 14:46 schrieb Kim Thuat NGUYEN:
> From: nguyenkimthuat <nguyenkimthuat@gmail.com>
>
> This patch adds the functionnality to export the
Minor nitpick:
functionnality => functionality
Cheers,
Max
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2012-06-12 14:10 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-06-12 12:46 [PATCHv2] git-remote-mediawiki: export File: attachments Kim Thuat NGUYEN
2012-06-12 12:52 ` Matthieu Moy
2012-06-12 12:54 ` nguyenki
2012-06-12 13:51 ` Max Horn
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).