Re: [PATCH/RFC] Export file attachements in git-remote-mediawiki

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, 04 Jun 2012 23:34:29 +0200, Matthieu Moy wrote:
NGUYEN Kim Thuat <kim-thuat.nguyen@xxxxxxxxxxxxxxx> writes:

+# Get the list of file extensions supported by the current version of mediawiki
+my @list_file_extensions = get_file_extensions();

You should do it only on demand (like $mediawiki is created lazily).
yeah, i changed the code in this part, it look like:

@@ -113,9 +113,6 @@ $wiki_name =~ s/[^\/]*:\/\///;
 # and '@' sign, to avoid author like MWUser@HTTPUser@xxxxxxxx
 $wiki_name =~ s/^.*@//;

-# Get the list of file extensions supported by the current version of mediawiki
-my @list_file_extensions = get_file_extensions();
-
 # Commands parser
 my $entry;
 my @cmd;
@@ -654,7 +651,7 @@ sub mw_push_file {
 	my $file_deleted = ($new_sha1 eq NULL_SHA1);
 	$complete_file_name = mediawiki_clean_filename($complete_file_name);

-	my %hashFiles = map {$_ => 1}@list_file_extensions;
+	my %hashFiles = get_file_extensions_maybe($complete_file_name);
 	my $path = "File:".$complete_file_name;
 	my @extensions = split(/\./,$complete_file_name);
 	my $extension = pop(@extensions);

-sub get_file_extensions {
-	mw_connect_maybe();
-
-	my $query = {
-	action => 'query',
-	meta => 'siteinfo',
-	siprop => 'fileextensions'
-	};
+sub get_file_extensions_maybe {
+	my $file_name = shift;
+	my $est_mw_page = substr($file_name,-3) eq ".mw";
+	if(!$est_mw_page) {
+		mw_connect_maybe();

-	my $result = $mediawiki->api($query);
+		my $query = {
+			action => 'query',
+			meta => 'siteinfo',
+			siprop => 'fileextensions'
+			};

- my @file_extensions = map $_->{ext},@{$result->{query}->{fileextensions}};
+		my $result = $mediawiki->api($query);
+ my @file_extensions = map $_->{ext},@{$result->{query}->{fileextensions}};
+		my %hashFile = map {$_ => 1}@file_extensions;

-	return @file_extensions;
+		return %hashFile;
+	} else {
+		return ;
+	}
 }

 Now, the function will list the file extensions on demand.


@@ -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.

Does this work on wiki configured in foreign languages, like french that
has Spécial:Téléverser instead?


+	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"


--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]