https://bugzilla.wikimedia.org/show_bug.cgi?id=58555

--- Comment #1 from aarcos.w...@gmail.com ---
I've been playing with the UI for some days now and I think I have a good idea
on what API's calls are made and came up with curl commands that do the same.
There are a few details missing but these are my main findings so far:

The main workflow for downloading an image using the UW makes the following API
calls:

0) Request an edit token
  https://commons.wikimedia.org/w/api.php?action=tokens&format=json&type=edit

1) Upload the image using stash=1, which means that the file is going to
be downloaded but kept in a temporary space. If the upload succeeds, a
'filekey' is returned that can be used later to actually move the uploaded file
from the temporary space to the permanent storage. Ex:

curl 'https://commons.wikimedia.org/w/api.php' -H <some-header-stuff...> --form
action=upload --form format=json --form
'token=7fcb554f0f44cc77f2c44bcf9ce86496+\' --form
"filename=1387232355370test-image-15x15.gif" --form stash=1 --form
ignorewarnings=true --form "file=@test-image-15x15.gif" --trace-ascii 15x15.out

Response:

{"upload":{"result":"Success","filekey":"11xxgr2del40.36x3m1.3268187.gif","sessionkey":"11xxgr2del40.36x3m1.3268187.gif","imageinfo":{"timestamp":"2013-12-16T23:45:02Z","user":null,"userid":null,"anon":"","size":68,"width":15,"height":15,"parsedcomment":"","comment":null,"url":"https://commons.wikimedia.org/wiki/Special:UploadStash/file/11xxgr2del40.36x3m1.3268187.gif","descriptionurl":"https://commons.wikimedia.org/wiki/Special:UploadStash/file/11xxgr2del40.36x3m1.3268187.gif","sha1":"7b21163f31a7894f43342cd8839da82a6bab0f41","metadata":[{"name":"frameCount","value":1},{"name":"looped","value":false},{"name":"duration","value":0},{"name":"metadata","value":[{"name":"_MW_GIF_VERSION","value":1}]}],"extmetadata":{"DateTime":{"value":"2013-12-16T23:45:02Z","source":"mediawiki-metadata","hidden":""},"ObjectName":{"value":"20131216234502!phpZnZnJB","source":"mediawiki-metadata","hidden":""},"CommonsMetadataExtension":{"value":1.1,"source":"extension","hidden":""},"Categories":{"value":"","source":"commons-categories","hidden":""},"Assessments":{"value":"","source":"commons-categories","hidden":""}},"mime":"image/gif","mediatype":"UNKNOWN","bitdepth":0,"html":";<div>\n<div
class=\"thumb tright\"><div class=\"thumbinner\" style=\"width:182px;\"><a
href=\"/w/index.php?title=Special:Upload&amp;wpDestFile=20131216234502!phpZnZnJB.gif\"
class=\"new\"
title=\"File:20131216234502!phpZnZnJB.gif\">File:20131216234502!phpZnZnJB.gif</a>
 <div class=\"thumbcaption\">Existing file</div></div></div>\n<p><span
id=\"wpUploadWarningFileexists\">A file with this name already exists; please
check <b><a
href=\"/w/index.php?title=File:20131216234502!phpZnZnJB.gif&amp;action=edit&amp;redlink=1\"
class=\"new\" title=\"File:20131216234502!phpZnZnJB.gif (page does not
exist)\">the existing file</a></b> if you are not sure whether you want to
change it. Please choose another filename, unless you are uploading a
technically improved version of the same file. <br>Do not overwrite an image
with a different one of the same topic (see <a
href=\"/wiki/Commons:File_naming\" title=\"Commons:File naming\">file
naming</a>).</span>\n</p>\n<div style=\"clear:both;\"></div>\n</div>\n"}}}

2) An API call to ask for information about the image is made. Probably just to
check that the file doesn't exist already.

https://commons.wikimedia.org/w/api.php?action=query&format=json&titles=File%3AMagenta-dot-for-test%2Egif&prop=info%7Cimageinfo&inprop=protection&iiprop=url%7Cmime%7Csize&iiurlwidth=150

Response:
{"query":{"pages":{"-1":{"ns":6,"title":"File:Magenta-dot-for-test.gif","missing":"","contentmodel":"wikitext","pagelanguage":"en","protection":[],"imagerepository":""}}}}

3) An API call to check if the title should be blacklisted:

 
https://commons.wikimedia.org/w/api.php?action=titleblacklist&format=json&tbaction=create&tbtitle=File%3AMagenta-dot-for-test%2Egif

Response:
  {result:ok}

4) Ask the user for extra information about the image: Description, copyrights,
tags, etc.

5) Request again an edit token
  https://commons.wikimedia.org/w/api.php?action=tokens&format=json&type=edit

6) API call to move the already downloaded file from the stash space to main
and add the extra information we already have, something like:

curl 'https://commons.wikimedia.org/w/api.php' -H '<header_stuff...>'
--data-urlencode 'action=upload' --data-urlencode format=json --data-urlencode
'filekey=11xxgr2del40.36x3m1.3268187.gif' --data-urlencode
'filename=Test-image-15x15.gif' --data-urlencode
'token=7fcb554f0f44cc77f2c44bcf9ce86496+\' --data-urlencode  'comment=Page
uploaded by curl script' --data '<more-data-from-the-user:description, rights,
tags, etc.>'

Response:
{"upload":{"result":"Success","filename":"Test-image-15x15.gif","imageinfo":{"timestamp":"2013-12-16T23:48:59Z","user":"Aaron
arcos","userid":3268187,"size":68,"width":15,"height":15,"parsedcomment":"Page
uploaded by curl script","comment":"Page uploaded by curl
script","url":"https://upload.wikimedia.org/wikipedia/commons/2/2d/Test-image-15x15.gif","descriptionurl":"https://commons.wikimedia.org/wiki/File:Test-image-15x15.gif","sha1":"7b21163f31a7894f43342cd8839da82a6bab0f41","metadata":[{"name":"frameCount","value":1},{"name":"looped","value":false},{"name":"duration","value":0},{"name":"metadata","value":[{"name":"_MW_GIF_VERSION","value":1}]}],"extmetadata":{"DateTime":{"value":"2013-12-16T23:45:02Z","source":"mediawiki-metadata","hidden":""},"ObjectName":{"value":"20131216234502!phpZnZnJB","source":"mediawiki-metadata","hidden":""},"CommonsMetadataExtension":{"value":1.1,"source":"extension","hidden":""},"Categories":{"value":"","source":"commons-categories","hidden":""},"Assessments":{"value":"","source":"commons-categories","hidden":""}},"mime":"image/gif","mediatype":"BITMAP","bitdepth":1,"html":";<div>\n<div
class=\"thumb tright\"><div class=\"thumbinner\" style=\"width:182px;\"><a
href=\"/w/index.php?title=Special:Upload&amp;wpDestFile=Test-image-15x15.gif\"
class=\"new\" title=\"File:Test-image-15x15.gif\">File:Test-image-15x15.gif</a>
 <div class=\"thumbcaption\">Existing file</div></div></div>\n<p><span
id=\"wpUploadWarningFileexists\">A file with this name already exists; please
check <b><a href=\"/wiki/File:Test-image-15x15.gif\"
title=\"File:Test-image-15x15.gif\">the existing file</a></b> if you are not
sure whether you want to change it. Please choose another filename, unless you
are uploading a technically improved version of the same file. <br>Do not
overwrite an image with a different one of the same topic (see <a
href=\"/wiki/Commons:File_naming\" title=\"Commons:File naming\">file
naming</a>).</span>\n</p>\n<div style=\"clear:both;\"></div>\n</div>\n"}}}


  I think that's pretty much it. As you can see above, I've been able to create
curl commands that actually upload to stash area and then move to main,
simulating the whole workflow. I think this would be a good starting point for
smoke test candidates but other suggestions welcome?

  I plan to productionize these curl scripts so they can be run standalone.
Suggestions on what languages (Ruby?, Python?) and testing frameworks to use
are very much welcome.

-- 
You are receiving this mail because:
You are the assignee for the bug.
You are on the CC list for the bug.
_______________________________________________
Wikibugs-l mailing list
Wikibugs-l@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/wikibugs-l

Reply via email to