Subject: | Patch for accepting utf8 strings out of box |
Date: | Sun, 1 Aug 2010 19:03:12 +0400 |
To: | bug-MediaWiki-API [...] rt.cpan.org |
From: | Nikolay Shaplov <n [...] shaplov.ru> |
In attached file there is patch that allows to accept utf-8 parameters
out of box. The main idea are there... May be you would prefer to
change formatting and fix spelling (I am not good in writing English)
To test the patch I used this script:
use strict;
use MediaWiki::API;
use utf8;
my $mw = MediaWiki::API->new();
$mw->{config}->{api_url} = 'http://fr.wiktionary.org/w/api.php';
$mw->{config}->{use_http_get}=0;
my $articles = $mw->list ( {
action => 'query',
list => 'categorymembers',
cmtitle => 'Catégorie:français',
cmlimit => 'max' }, {skip_encoding => 0} ) || die
$mw->{error}->{code} . ': ' . $mw->{error}->{details};
foreach (@{$articles})
{ print $_->{title};
if (Encode::is_utf8($_->{title}))
{
print " - utf-8\n";
} else
{
print "\n";
}
}
While testing I run script with both use_http_get on and off. It is also
wise to check both cases with skip_encoding on.
French words are very difficult for perl utf-8 because they can be
written in Latin1 and perl tries to use latin1 wherever is possible, if
utf8 pragma is not on. So if it works for these lot of them, it will
work anywhere ;-)
And one more: this patch works correctly only with
$URI::VERSION >= "1.36", the earlier versions it does not encode utf-8
to the url correctly. I do not know where this fact should be mentioned,
in the code, or in META.yml, I thing you knows this better
That's all. Hope it will help you and all other users of the module ;-)
Message body is not shown because sender requested not to inline it.