commons-app / apps-android-commons

The Wikimedia Commons Android app allows users to upload pictures from their Android phone/tablet to Wikimedia Commons
https://commons-app.github.io/
Apache License 2.0
1.01k stars 1.19k forks source link

Media details' "Copy the wikitext to the clipboard" gives invalid wikitext #5075

Open nicolas-raoul opened 1 year ago

nicolas-raoul commented 1 year ago

I don't think the anchor tag should be there?

[[File:SANY R285R excavator in Thailand.jpg|thumb|SANY R285R excavator in Thailand <a href="//commons.wikimedia.org/wiki/File:SANY_R285R_excavator_in_Thailand.jpg#ooui-php-4" title="Edit this at Structured Data on Commons"><img alt="Edit this at Structured Data on Commons" src="https://upload.wikimedia.org/wikipedia/commons/thumb/8/8a/OOjs_UI_icon_edit-ltr-progressive.svg/10px-OOjs_UI_icon_edit-ltr-progressive.svg.png" decoding="async" width="10" height="10" style="vertical-align: text-top" srcset="https://upload.wikimedia.org/wikipedia/commons/thumb/8/8a/OOjs_UI_icon_edit-ltr-progressive.svg/15px-OOjs_UI_icon_edit-ltr-progressive.svg.png 1.5x, https://upload.wikimedia.org/wikipedia/commons/thumb/8/8a/OOjs_UI_icon_edit-ltr-progressive.svg/20px-OOjs_UI_icon_edit-ltr-progressive.svg.png 2x" data-file-width="20" data-file-height="20"></a>]]
RitikaPahwa4444 commented 1 year ago

Hi @nicolas-raoul, while testing the app, I found that this issue exists only for some images on the app. While I have not been able to figure out the reason for this selective behaviour as of now, I found a fix on stackoverflow: https://stackoverflow.com/questions/240546/remove-html-tags-from-a-string#:~:text=replace(%22%26%22%2C,line%20breaks%20String%20clean%20%3D%20Jsoup. EDIT: I have personally tried the replaceAll() method and it worked well for the image which had tags in its fallback description earlier. I can try the other way too if you feel stripping the tags off the fallback description string is an appropriate fix for this issue.

nicolas-raoul commented 1 year ago

Seeing the image's page https://commons.wikimedia.org/wiki/File:SANY_R285R_excavator_in_Thailand.jpg I see that the caption does not contain any tag. So I would suggest trying to:

RitikaPahwa4444 commented 1 year ago

Yes, the caption does not contain any tag. But hovering over the edit icon on the image's page shows the same name as found in the tag above:

title="Edit this at Structured Data on Commons.

I think that since most of the other images do not have this icon, they don't have the anchor tag too.

Edit Icon

Should I check if it is reading the image's description instead of its caption?

nicolas-raoul commented 1 year ago

Yes, finding the API call and what part of the API response we use would be a great start :-)

Please post the API call URL when you find it. Thanks!

RitikaPahwa4444 commented 1 year ago

Thank you for clarifying. Now that I understand the issue better, I will be able to find the cause easily.

RitikaPahwa4444 commented 1 year ago

I tried looking for the API call and found that the app currently makes use of the following API call URL to fetch the metadata of the image:

https://en.wikipedia.org/w/api.php?action=query&format=json&formatversion=2&generator=search&gsrwhat=text&gsrnamespace=6&prop=imageinfo|coordinates&iiprop=url|extmetadata|user&&iiurlwidth=640&iiextmetadatafilter=DateTime|Categories|GPSLatitude|GPSLongitude|ImageDescription|DateTimeOriginal|Artist|LicenseShortName|LicenseUrl

This is what I found about the prop extmetadata in the official API documentation:

extmetadata

Since the results are HTML formatted, I tried looking for an alternate call that returns only the image description or the image details in an appropriate format, directly or indirectly, but couldn't find anything. However, I found this action which converts HTML into wikitext and is more reliable than stripping the string off to remove the tags:

flow-parsoid-utils

nicolas-raoul commented 1 year ago

@RitikaPahwa4444 I am getting an error when clicking the URL you posted. One thing, I guess the API call made by the app should be to the Commons server rather than to Wikipedia?

RitikaPahwa4444 commented 1 year ago

I'm sorry, I should have mentioned that the API call depends on the query at runtime and fetches results accordingly. It needs three parameters: "gsrsearch", "gsrlimit" and "gsroffset". This is the reason why the error code shows: "The \"gsrsearch\" parameter must be set.". I have modified the URL a bit with some sample data so that the results are visible: https://commons.wikimedia.org/w/api.php?action=query&format=json&formatversion=2&generator=search&gsrsearch="SANY R285R excavator in Thailand.jpg"&gsrwhat=text&gsrnamespace=6&prop=imageinfo|coordinates&iiprop=url|extmetadata|user&&iiurlwidth=640&iiextmetadatafilter=DateTime|Categories|GPSLatitude|GPSLongitude|ImageDescription|DateTimeOriginal|Artist|LicenseShortName|LicenseUrl EDIT: I think I got confused as the directory name for the data client was org/wikipedia and both Commons and Wikipedia API have a call for image info. I have modified the API call URL and used the required file for gsrsearch.

mnalis commented 1 year ago

I'm also experiencing this problem on commons app SOMETIMES in latest f-droid 4.1.0 release (on Android 10).

Video:

https://github.com/commons-app/apps-android-commons/assets/156656/df640ba4-9f6a-48dd-b871-011f7389e75d

mnalis commented 1 year ago

This is the log a day after when I just do the copy/paste with results in incorrect value: CommonsAppLogs.zip

And this is a log that seems to contain (among other things) original upload of that problematic File:Statue of Nikola Tesla, Zagreb.jpg: CommonsAppLogs.zip

Does that help track this down?