Re: [PATCH/RFC] Export file attachements in git-remote-mediawiki
- From
- nguyenki <nguyenki@ensibm.imag.fr>
- Date
- Jun 6, 2012, 22:25 UTC
- Message-ID
- <24f8b089a3ca00153ca927d6a5e4090b@ensibm.imag.fr>
- In-Reply-To
- <vpq62b5g047.fsf@bauges.imag.fr>
On Tue, 05 Jun 2012 19:05:44 +0200, Matthieu Moy wrote:
Show 20 quoted lines
> nguyenki <nguyenki@ensibm.imag.fr> writes:
>
>>>> @@ -642,8 +651,14 @@ sub mw_push_file {
>>>> my $old_sha1 = $diff_info_split[2];
>>>> my $page_created = ($old_sha1 eq NULL_SHA1);
>>>> my $page_deleted = ($new_sha1 eq NULL_SHA1);
>>>> + my $file_deleted = ($new_sha1 eq NULL_SHA1);
>>>
>>> This line looks suspiciously similar to the previous one. Do you
>>> need
>>> another variable for the same value?
>> Yes, it's true. I just want the code to be more visible. Because,
>> when
>> we delete a file attachment, it's not a page wiki.
>
> I still don't see a reason to have two variables for the same thing.
> If
> $page_deleted is not a good name, then rename the variable to
> something more general (e.g. $path_deleted ?)
>Show 12 quoted lines
>>>> + else {
>>>> + print STDERR "$complete_file_name is not supported on
>>>> this version of Mediawiki.\n"
>>>
>>> It's not a matter of version, it's a matter of configuration.
>> What do you think if i change it like:
>> else {
>> print STDERR "$complete_file_name is not a permitted file
>> type. Check your configuration for more information\n"
>
> That's better, but it doesn't tell the user which configuration to
> check (Git's one, or the wiki's one).Thank for your advices, i changed the code from your suggestions, now it look like:
@@ -36,6 +36,7 @@ use strict; use MediaWiki::API; use DateTime::Format::ISO8601; +use encoding 'utf8'; # use encoding 'utf8' doesn't change STDERROR # but we're going to output UTF-8 filenames to STDERR @@ -275,7 +276,8 @@ sub run_git { } sub run_git_raw { - open(my $g,"-|","git " . $_[0]); + no encoding 'utf8'; + open(my $g, "-|:utf8", "git " . $_[0]); my $r = do { local $/; <$g> }; close($g); @@ -648,7 +650,6 @@ sub mw_push_file { my $old_sha1 = $diff_info_split[2]; my $page_created = ($old_sha1 eq NULL_SHA1); my $page_deleted = ($new_sha1 eq NULL_SHA1); - my $file_deleted = ($new_sha1 eq NULL_SHA1); $complete_file_name = mediawiki_clean_filename($complete_file_name); my %hashFiles = get_file_extensions_maybe($complete_file_name); @@ -700,28 +701,29 @@ sub mw_push_file { print STDERR "Pushed file: $new_sha1 - $title\n"; } elsif (exists($hashFiles{$extension})) { # Deleting and uploading a file require the priviledge of the user - if ($file_deleted) { + if ($page_deleted) { mw_connect_maybe(); my $res = $mediawiki->edit( { - action => 'delete', - title => $path, - reason => $summary } ) + action => 'delete', + title => $path, + reason => $summary } ) || die $mediawiki-> {error}->{code} . ':' . $mediawiki->{error}->{details}; } else { my $content = run_git_raw("cat-file blob $new_sha1"); mw_connect_maybe(); - $mediawiki->{config}->{upload_url} = "$url/index.php/Special:Upload"; + $mediawiki->{config}->{upload_url} = "$url/index.php/Special:Upload"; - $mediawiki->upload( { + $mediawiki->upload( { title => $complete_file_name, summary => $summary, data => $content, ignorewarnings=>1 - }, { - skip_encoding => 1 # Helps with names with accentuated characters - } ) || die $mediawiki-> {error}->{code} . ':' . $mediawiki->{error}->{details}; - $newrevid = get_reviId_filepage(); + }, { + 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 { @@ -864,29 +866,6 @@ sub mw_push_revision { return 1; } -sub get_reviId_filepage() { - mw_connect_maybe(); - - my $max_rev_num_file = 0; - - my @list_file_pages = get_mw_media_pages(); - - foreach my $file_page (@list_file_pages) { - my $id = $file_page->{pageid}; - - my $query = { - action => 'query', - prop => 'revisions', - rvprop => 'ids', - pageids => $id, - }; - - my $result = $mediawiki->api($query); - - my $lastrev = pop(@{$result->{query}->{pages}->{$id}->{revisions}}); - } -} -