Re: [PATCHv2] git-remote-mediawiki: export File: attachments
- From
Matthieu Moy <matthieu.moy@grenoble-inp.fr>
- Date
- Jun 12, 2012, 12:52 UTC
- Message-ID
- <vpqvciwu1yl.fsf@bauges.imag.fr>
- In-Reply-To
- <1339505176-2962-1-git-send-email-nguyenkimthuat@gmail.com>
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.
Show 10 quoted lines
> @@ -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.
Show 10 quoted lines
> + 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?
Show 14 quoted lines
> +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/