NAME

Commons::Link - Object for creating link for Wikimedia Commons.

SYNOPSIS

use Commons::Link;

my $obj = Commons::Link->new(%params);
my $link = $obj->link($file);
my $mw_file_link = $obj->mw_file_link($file);
my $mw_link = $obj->mw_link($object);
my $mw_user_link = $obj->mw_user_link($user);
my $thumb_link = $obj->thumb_link($file, $width_in_pixels);

METHODS

new

my $obj = Commons::Link->new(%params);

Constructor.

Returns instance of object.

  • utf-8

    UTF-8 mode. In UTF-8 mode input string will be encoded to bytes and compute md5 hash.

    Default value is 1.

my $link = $obj->link($file);

Get URL from Wikimedia Commons computed from file name. File name could be with 'Image:' and 'File:' prefix or directly file. Spaces are translated to '_'.

Returns string with URL.

my $mw_file_link = $obj->mw_file_link($file);

Get URL from Wikimedia Commons MediaWiki view page defined by file name. File name could be with 'Image:' and 'File:' prefix or directly file.

Returns string with URL.

my $mw_link = $obj->mw_link($object);

Get URL from Wikimedia Commons MediaWiki view page defined by object name. e.g. File:__FILENAME__, User:__USERNAME__, Category:__CATEGORY__

Returns string with URL.

my $mw_user_link = $obj->mw_user_link($user);

Get URL from Wikimedia Commons MediaWiki view page defined by user name. File name could be with 'User:' prefix or directly file.

Returns string with URL.

my $thumb_link = $obj->thumb_link($file, $width_in_pixels);

Get URL from Wikimedia Commons computed from file name and image width in pixels. File name could be with 'Image:' and 'File:' prefix or directly file. Spaces are translated to '_'.

Returns string with URL.

ERRORS

new():
        From Class::Utils::set_params():
                Unknown parameter '%s'.

EXAMPLE1

use strict;
use warnings;

use Commons::Link;

# Object.
my $obj = Commons::Link->new;

# Input name.
my $commons_file = 'Michal from Czechia.jpg';

# URL to file.
my $commons_url = $obj->link($commons_file);

# Print out.
print 'Input file: '.$commons_file."\n";
print 'Output link: '.$commons_url."\n";

# Output:
# Input file: Michal from Czechia.jpg
# Output link: http://upload.wikimedia.org/wikipedia/commons/a/a4/Michal_from_Czechia.jpg

EXAMPLE2

use strict;
use warnings;

use Commons::Link;

# Object.
my $obj = Commons::Link->new;

# Input name.
my $commons_file = 'File:Michal from Czechia.jpg';

# URL to file.
my $commons_url = $obj->link($commons_file);

# Print out.
print 'Input file: '.$commons_file."\n";
print 'Output link: '.$commons_url."\n";

# Output:
# Input file: File:Michal from Czechia.jpg
# Output link: http://upload.wikimedia.org/wikipedia/commons/a/a4/Michal_from_Czechia.jpg

EXAMPLE3

use strict;
use warnings;

use Commons::Link;

# Object.
my $obj = Commons::Link->new;

# Input name.
my $commons_file = 'File:Michal from Czechia.jpg';

# URL to thumbnail file.
my $commons_url = $obj->thumb_link($commons_file, 200);

# Print out.
print 'Input file: '.$commons_file."\n";
print 'Output thumbnail link: '.$commons_url."\n";

# Output:
# Input file: File:Michal from Czechia.jpg
# Output thumbnail link: http://upload.wikimedia.org/wikipedia/commons/thumb/a/a4/Michal_from_Czechia.jpg/200px-Michal_from_Czechia.jpg

DEPENDENCIES

Class::Utils, Digest::MD5, Readonly, Unicode::UTF8, URI.

REPOSITORY

https://github.com/michal-josef-spacek/Commons-Link

AUTHOR

Michal Josef Špaček mailto:skim@cpan.org

http://skim.cz

LICENSE AND COPYRIGHT

© 2021-2022 Michal Josef Špaček

BSD 2-Clause License

VERSION

0.08