Hi,
i upload the files to the mediawiki using the API. i use the code bellow:
use strict;
use MediaWiki::API;
use DateTime::Format::ISO8601;
#use encoding 'utf8';
binmode STDERR, ":utf8";
use URI::Escape;
use warnings;
use MediaWiki::API;
my $url="http://localhost/mediawiki";
my $wiki_login="nguyenki";
my $wiki_passwd="linh";
my $wiki_domain="";
my $mediawiki;
mw_connect_maybe();
# configure the special upload location.
$mediawiki->{config}->{upload_url} = "$url/index.php/Special:Upload";
* my @extensionFiles =
("png","gif","jpg","jpeg","doc","xls","mpp","pdf","ppt","tiff","bmp","docx",
"xlsx", "pptx","ps","odt","ods","odp","odg","txt");*
my %hashFiles = map { $_ => 1} @extensionFiles;
#Test with a file .png
*my $name="somefile.png"; *
if(exists($hashFiles{substr($name,-3)}) ||
exists($hashFiles{substr($name,-4)}))
{
# upload a file to MediaWiki
open (my $toi, $name) or die "can't open UTF-8 encoded filename: $!";
binmode $toi;
my ($buffer, $data);
while (my $n=read($toi, $buffer, 65536) ) {
$data .= $buffer;
print STDERR "$n bytes read\n";
}
close($toi);
$mediawiki->upload( { title => $name,
summary => 'This is the summary to go on the Image:file.jpg
page',
data => $data } ) || die $mediawiki->{error}->{code} . ': '
. $mediawiki->{error}->{details};
}
else
{
print "FILE TYPE NOT SUPPORTED\n";
}
sub mw_connect_maybe {
if ($mediawiki) {
return;
}
$mediawiki = MediaWiki::API->new;
$mediawiki->{config}->{api_url} = "$url/api.php";
if ($wiki_login) {
if (!$mediawiki->login({
lgname => $wiki_login,
lgpassword => $wiki_passwd,
lgdomain => $wiki_domain,
})) {
print STDERR "Failed to log in mediawiki user \"$wiki_login\"
on $url\n";
print STDERR "(error " .
$mediawiki->{error}->{code} . ': ' .
$mediawiki->{error}->{details} . ")\n";
exit 1;
} else {
print STDERR "Logged in with user \"$wiki_login\".\n";
}
}
}
To test the type of file supported, i have to use this variable:
* my @extensionFiles =
("png","gif","jpg","jpeg","doc","xls","mpp","pdf","ppt","tiff","bmp","docx",
"xlsx", "pptx","ps","odt","ods","odp","odg","txt");
*if the file name *$name* is not in the array, I'll generate a message
error. : *print "FILE TYPE NOT SUPPORTED\n";
*My question is if the user change the type of file supported in the *
LocalSettings.php* , this programme is not true any more.
How can i get the array *$wgFileExtensions* from the *LocalSettings.php*?
Thank.
*
*
Hello,
I would like to ask, if the attached files (images, pdf , etc.) have a
revision number, or the different revisions of media file differ only in
the time stamp?
Thank you for response.
Pavel Volek
Hi,
I'm trying to delete the upload file automatically via the
Mediawiki::Api->api
For the moment, i'm using the code following:
*use strict;
use MediaWiki::API;
use DateTime::Format::ISO8601;
binmode STDERR, ":utf8";
use URI::Escape;
use warnings;
use MediaWiki::API;
my $url="http://localhost/mediawiki";
my $wiki_login="nguyenki";
my $wiki_passwd="linh";
my $wiki_domain="";
chomp($wiki_login);
chomp($wiki_passwd);
chomp($wiki_domain);
my $mediawiki;
mw_connect_maybe();
my $name="Te5.txt";
my $file="/index.php/File:";
my $path= $url.$file.$name;
#my $path= $url.$name
# the url to the file: http://localhost/mediawiki/index.php/File:Te5.txt
print "$path\n";
#delete a file via mediawiki::API->api
$mediawiki->edit({
action => 'delete',
title => $path,
reason => 'no longer nedded'
}) || die $mediawiki-> {error}->{code} . ':' .
$mediawiki->{error}->{details};
# Methode to login to mediawiki
sub mw_connect_maybe {
if ($mediawiki) {
return;
}
$mediawiki = MediaWiki::API->new;
$mediawiki->{config}->{api_url} = "$url/api.php";
if ($wiki_login) {
if (!$mediawiki->login({
lgname => $wiki_login,
lgpassword => $wiki_passwd,
lgdomain => $wiki_domain,
})) {
print STDERR "Failed to log in mediawiki user \"$wiki_login\"
on $url\n";
print STDERR "(error " .
$mediawiki->{error}->{code} . ': ' .
$mediawiki->{error}->{details} . ")\n";
exit 1;
} else {
print STDERR "Logged in with user \"$wiki_login\".\n";
}
}
}
*
But it generated the error:
*5:Unable to delete page 'http://localhost/mediawiki/index.php/File:Te5.txt'.
Page does not exist. at delete.pl line 26.*
Maybe the path to the file doesn't exact but i don't know how to correct it.
Hope somebody can give me the ideas.
Thank.
Hi,
I'm trying to upload an image to the mediawiki using the
Mediawiki::API->upload. To do so, i'm using this code:
*# Open a file whose name is $name = "1.jpg"*
* open (my $toi,$name) or die "can't open UTF-8 encoded filename: $!";
binmode $toi;
my ($buffer, $data);
while (my $n=read($toi, $buffer, 65536)) {
$data .= $buffer;
print STDERR " $n bytes read \n";
}
close($toi);
*
*#upload file
my $kq= $mediawiki->upload( {
title => $name,
summary => 'upload file',
data => $data
} ) || die $mediawiki-> {error}->{code} . ':' .
$mediawiki->{error}->{details};*
And it generated an error:
*HTTP::Message content must be bytes
at /usr/share/perl5/HTTP/Request/Common.pm line 91*
I don't know how to correct it.
Any suggestion?
Thank.
I'm adding an API module to retrieve UploadWizard upload campaign
information, which we need for the upcoming mobile application for Wiki
Loves Monuments. Essentially the app will include a very limited
implementation of a couple steps of UploadWizard for things like license
selection and filling the ID field and description, so we have one
consistent set of configuration for both web upload (using UploadWizard)
and mobile uploads (using the app).
The change waiting review in gerrit:
https://gerrit.wikimedia.org/r/#/c/7832/
If anybody's got a prime usage in mind for reading UploadWizard campaign
data from the API and has recommendations for adjusting the output format
(maybe for making the editing view more AJAX-y) please give a shout -- this
is not final and we can adjust it.
Currently it'll return XML like this:
<?xml version="1.0"?><api>
<uploadcampaign>
<campaigns>
<campaign name="wlm-es" id="2" isenabled="0" autoCategories=""
autoWikiText="" defaultAlt="" defaultCategories=""
defaultDescription="" defaultLat="" defaultLon=""
defaultOwnWorkLicence="cc-by-sa-3.0" headerLabelPage="sdfsdf"
idField="sdfafsdfd" idFieldInitialValue="" idFieldLabel=""
idFieldLabelPage="" idFieldMaxLength="25"
licensesOwnWork="cc-by-sa-3.0|cc-by-3.0|cc-zero"
ownWorkOption="choice" skipTutorial="" thanksLabelPage=""
tutorialHelpdeskCoords="27, 1319, 691, 1384"
tutorialTemplate="Licensing_tutorial_$1.svg" tutorialWidth="720" />
</campaigns>
</uploadcampaign></api>
or JSON like this:
{
"uploadcampaign": {
"campaigns": [
{
"name": "wlm-es",
"id": 2,
"isenabled": 0,
"autoCategories": "",
"autoWikiText": "",
"defaultAlt": "",
"defaultCategories": "",
"defaultDescription": "",
"defaultLat": "",
"defaultLon": "",
"defaultOwnWorkLicence": "cc-by-sa-3.0",
"headerLabelPage": "sdfsdf",
"idField": "sdfafsdfd",
"idFieldInitialValue": "",
"idFieldLabel": "",
"idFieldLabelPage": "",
"idFieldMaxLength": "25",
"licensesOwnWork": "cc-by-sa-3.0|cc-by-3.0|cc-zero",
"ownWorkOption": "choice",
"skipTutorial": "",
"thanksLabelPage": "",
"tutorialHelpdeskCoords": "27, 1319, 691, 1384",
"tutorialTemplate": "Licensing_tutorial_$1.svg",
"tutorialWidth": "720"
}
]
}
}
-- brion
Hello all,
There's been a fair amount of discussion on the wikitech-l list about
oauth, but I realized some people may be here that are not on that list so
I'm cross-posting. Since api users are probably one of the most likely
groups to use oauth, I wanted to make sure everyone here had a chance to
give input on the requirements.
We're collecting user stories here:
http://www.mediawiki.org/wiki/OAuth/User_stories, and hoping to compile a
list of requirements and priorities before the Berlin hackathon. So if you
see any uses that are missing from that list, please add it. Or vote for
any use cases there that are similar to cases you would use. If you have
any projects currently that you would like to use oauth with, please post
as many details as possible, so we make sure that the implementation covers
as many use cases as we can.
Thanks!
Hi All,
>From this morning the mobile api returns a 500 status code error
here is the error
If you report this error to the Wikimedia System Administrators, please
include the details below.
PHP fatal error in
/usr/local/apache/common-local/php-1.20wmf2/extensions/MobileFrontend/WmlContext.php
line 12:
Argument 1 passed to WmlContext::__construct() must be an instance of
ExtMobileFrontend, none given, called in
/usr/local/apache/common-local/php-1.20wmf2/extensions/MobileFrontend/api/ApiParseExtender.php
on line 72 and defined
here is the url
http://en.wikipedia.org/w/api.php?action=parse&page=Beyond_the_Gates_(disam…
I got this error for all the pages I tried.
Yesterday I was getting the data, was there a change in the API? When I
remove the mobileformat parameter I get the data.
Thanks
Asher Szmulewicz
Dear Team,
I am planning to start a new website containing celebrities from different
areas like in sports, movies and politics. For this I am planning to exract
data from Wikipedia using API in XML or JSON format. Can someone send me
Wikipedia API and the format of response I get? I am pretty much new to
this type of technical stuff. I tried going through the document but could
not understand much in detail. An example format will be of great use.
Thanks in advance.
Regards
M.Krishna Kranth
Team works means more We less Me.
Hi All,
I am using url like
http://en.wikipedia.org//w/api.php?action=parse&format=json&page=New_York_C…
I am getting the full content of the mobile page without the buttons:
History,Geography,Demographics etc...
Is it possible to get the full mobile content with the section buttons?
Thanks
Asher Szmulewicz