Bug 335493 - Fix issues when metadata are loaded by MediaWiki tool [patch]
Summary: Fix issues when metadata are loaded by MediaWiki tool [patch]
Status: RESOLVED FIXED
Alias: None
Product: digikam
Classification: Applications
Component: Plugin-WebService-MediaWiki (show other bugs)
Version: 4.11.0
Platform: Compiled Sources Linux
: NOR normal
Target Milestone: ---
Assignee: Digikam Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-05-28 20:23 UTC by H Law
Modified: 2018-01-30 21:25 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In: 4.11.0
Sentry Crash Report:


Attachments
attachment-2274-0.html (1.41 KB, text/html)
2015-05-21 05:28 UTC, Adrián Chaves (Gallaecio)
Details
patch updated to work with git/master (9.10 KB, patch)
2015-05-21 08:33 UTC, caulier.gilles
Details

Note You need to log in before you can comment on or make changes to this bug.
Description H Law 2014-05-28 20:23:17 UTC
This patch fixes two issues with the loading of metadata for the mediawiki plugin

Reproducible: Always

Steps to Reproduce:
1. In digikam, select two pictures for export to mediawiki, the first one (pic1) with geolocation in its metadata, the second one (pic2) without.
2. In the mediawiki export dialog, add one picture (pic3) managed by digikam into the export list

Actual Results:  
1. Both pictures, pic1 and pic2, get the geolocation from pic1.  This is because the loop in WmWidget::loadImageInfoFirstLoad does not clear the lat / lon data between iterations.
2. Pic3 will not contain the metadata from digiKam, because WmWidget::loadImageInfoFirstLoad is only called for the initial list of pictures.

Expected Results:  
1. The geolocation for pic2 should remain blank.
2. Metadata for pic3 should be loaded from digikam.

Patch file:
====
diff --git a/mediawiki/wmwidget.cpp b/mediawiki/wmwidget.cpp
index d08c67c..64ccd22 100644
--- a/mediawiki/wmwidget.cpp
+++ b/mediawiki/wmwidget.cpp
@@ -781,56 +781,54 @@ void WmWidget::loadImageInfoFirstLoad()
 {
     KUrl::List urls = d->imgList->imageUrls(false);
 
-    QString title;
-    QString date;
-    QString description;
-    QString currentCategories;
-    QString latitude;
-    QString longitude;
-
     d->imagesDescInfo.clear();
 
-    for(int j = 0; j < urls.size(); j++)
+    for (int j = 0; j < urls.size(); j++) 
     {
-        KPImageInfo info(urls.at(j).path());
-        QStringList keywar = info.keywords();
-        date               = info.date().toString(Qt::ISODate);
-        date               = date.replace("T", " ", Qt::CaseSensitive);
-        title              = info.name();
-        description        = info.title();
-        currentCategories  = "";
-
-        for( int i = 0; i < keywar.size(); i++)
-        {
-            if(i == keywar.size()-1)
-            {
-                currentCategories.append(keywar.at(i));
-            }
-            else
-            {
-                currentCategories.append(keywar.at(i)).append("\n");
-            }
-        }
+        loadImageInfo(urls.at(j));
+    }
+}
 
-        if(info.hasLatitude())
+void WmWidget::loadImageInfo(const KUrl url)
+{
+    KPImageInfo info(url.path());
+    QStringList keywar = info.keywords();
+    QString date       = info.date().toString(Qt::ISODate).replace("T", " ", Qt::CaseSensitive);
+    QString title      = info.name();
+    QString description = info.title();
+    QString currentCategories  = "";
+    QString latitude = "";
+    QString longitude = "";
+
+    for (int i = 0; i < keywar.size(); i++) 
+    {
+        if (i == keywar.size() - 1)
         {
-            latitude = QString::number(info.latitude(), 'f', 9);
-        }
-
-        if(info.hasLongitude())
+            currentCategories.append(keywar.at(i));
+        } else 
         {
-            longitude = QString::number(info.longitude(), 'f', 9);
+            currentCategories.append(keywar.at(i)).append("\n");
         }
+    }
 
-        QMap<QString, QString> imageMetaData;
-        imageMetaData["title"]       = title;
-        imageMetaData["date"]        = date;
-        imageMetaData["categories"]  = currentCategories;
-        imageMetaData["description"] = description;
-        imageMetaData["latitude"]    = latitude;
-        imageMetaData["longitude"]   = longitude;
-        d->imagesDescInfo.insert(urls.at(j).path(), imageMetaData);
+    if (info.hasLatitude()) 
+    {
+        latitude = QString::number(info.latitude(), 'f', 9);
+    }
+
+    if (info.hasLongitude()) 
+    {
+        longitude = QString::number(info.longitude(), 'f', 9);
     }
+
+    QMap<QString, QString> imageMetaData;
+    imageMetaData["title"]       = title;
+    imageMetaData["date"]        = date;
+    imageMetaData["categories"]  = currentCategories;
+    imageMetaData["description"] = description;
+    imageMetaData["latitude"]    = latitude;
+    imageMetaData["longitude"]   = longitude;
+    d->imagesDescInfo.insert(url.path(), imageMetaData);
 }
 
 void WmWidget::clearEditFields()
@@ -847,8 +845,14 @@ void WmWidget::slotLoadImagesDesc(QTreeWidgetItem* item)
 {
     QList<QTreeWidgetItem*> selectedItems = d->imgList->listView()->selectedItems();
     KPImagesListViewItem* l_item          = dynamic_cast<KPImagesListViewItem*>(item);
-    QMap<QString, QString> imageMetaData  = d->imagesDescInfo[l_item->url().path()];
-
+    QMap<QString, QString> imageMetaData;
+  
+    if (!d->imagesDescInfo.contains(l_item->url().path())) 
+    {
+        loadImageInfo(l_item->url());
+    }
+    imageMetaData  = d->imagesDescInfo[l_item->url().path()];
+        
     d->titleEdit->setText(imageMetaData["title"]);
     d->dateEdit->setText(imageMetaData["date"].replace("T", " ", Qt::CaseSensitive));
     d->latitudeEdit->setText(imageMetaData["latitude"]);
diff --git a/mediawiki/wmwidget.h b/mediawiki/wmwidget.h
index c2f971d..f623651 100644
--- a/mediawiki/wmwidget.h
+++ b/mediawiki/wmwidget.h
@@ -96,6 +96,7 @@ public:
     void readSettings(KConfigGroup& group);
     void saveSettings(KConfigGroup& group);
     void loadImageInfoFirstLoad();
+    void loadImageInfo(const KUrl url);
     void clearEditFields();
 
 Q_SIGNALS:
====
Comment 1 caulier.gilles 2014-08-15 07:18:18 UTC
H Law,

I review your patch from bug #335250 and applied it to code for 4.3.0 release.

Can you update patch from this entry to be applied to current implementation from git/master, please

Thanks in advance

Gilles Caulier
Comment 2 caulier.gilles 2014-08-15 07:19:47 UTC
Adrian,

Another patch for Media Wiki kipi tool to review. Can you take a look please.

Thanks in advance

Gilles Caulier
Comment 3 Adrián Chaves (Gallaecio) 2014-08-15 08:24:11 UTC
Looks great.
Comment 4 caulier.gilles 2015-05-20 09:18:07 UTC
Adrian, 

Did you review this patch for Media Wiki tool ?

Gilles Caulier
Comment 5 Adrián Chaves (Gallaecio) 2015-05-21 05:28:36 UTC
Created attachment 92753 [details]
attachment-2274-0.html

I did, I left a comment :)

2015-05-20 11:18 GMT+02:00 Gilles Caulier <caulier.gilles@gmail.com>:

> https://bugs.kde.org/show_bug.cgi?id=335493
>
> Gilles Caulier <caulier.gilles@gmail.com> changed:
>
>            What    |Removed                     |Added
>
> ----------------------------------------------------------------------------
>             Summary|Fix for issues in loading   |Fix issues when metadata
>                    |metadata into mediawiki     |are loaded by MediaWiki
>                    |kipi-plugin [patch]         |tool [patch]
>
> --- Comment #4 from Gilles Caulier <caulier.gilles@gmail.com> ---
> Adrian,
>
> Did you review this patch for Media Wiki tool ?
>
> Gilles Caulier
>
> --
> You are receiving this mail because:
> You are on the CC list for the bug.
>
Comment 6 caulier.gilles 2015-05-21 08:33:43 UTC
Created attachment 92754 [details]
patch updated to work with git/master
Comment 7 caulier.gilles 2015-05-21 08:45:04 UTC
Andian,

This patch introduce errors at end of uploading. I tried to wikipedia and mediawiki with my account. Without patch it's work, with patch, tool said that you must have right to upload.

Why ?

Gilles Caulier
Comment 8 Adrián Chaves (Gallaecio) 2015-05-22 06:36:49 UTC
Sorry, I’ll test the code on Saturday and try to “fix the fix”.
Comment 9 caulier.gilles 2015-05-22 07:42:38 UTC
Thanks Adrian

Gilles
Comment 10 Adrián Chaves (Gallaecio) 2015-05-23 08:15:06 UTC
Gilles, could you please recheck?
I’ve uploaded a file to Wikimedia Commons both with and without the patch, and both succeeded.
Without the patch: https://commons.wikimedia.org/wiki/File:Heckert_GNU_white.svg.png
With the patch: https://commons.wikimedia.org/wiki/File:Heckert_GNU_%28test%29.png

Also, the patch is quite straightforward, and it touches nothing that could possibly affect the upload process, if just affects the uploaded content (the information of the page of each file).
Comment 11 caulier.gilles 2015-05-23 10:18:24 UTC
Confirmed. I successfully downloaded a file with a without this patch but only in "wikimedia common" server. My previous test was been processed into "wikipedia" server as well, where extra right must be set i suppose.
Comment 12 caulier.gilles 2015-05-23 10:20:33 UTC
Git commit 7d76ea4aae956f7886fb10df6afe3aaf243094c7 by Gilles Caulier.
Committed on 23/05/2015 at 10:19.
Pushed by cgilles into branch 'master'.

apply patch #92754 to fix metadata on image before to upload file on wikimedia server
FIXED-IN: 4.11.0

M  +2    -1    NEWS
M  +67   -59   mediawiki/wmwidget.cpp
M  +3    -2    mediawiki/wmwidget.h

http://commits.kde.org/kipi-plugins/7d76ea4aae956f7886fb10df6afe3aaf243094c7
Comment 13 caulier.gilles 2015-05-23 10:28:29 UTC
Git commit 78068fb1e869241432e218b9d11ba3b0a3866442 by Gilles Caulier.
Committed on 23/05/2015 at 10:27.
Pushed by cgilles into branch 'frameworks'.

backport commit #7d76ea4aae956f7886fb10df6afe3aaf243094c7 from git/master to frameworks branch

M  +65   -57   PORT.KF5/FACTORIZE/mediawiki/wmwidget.cpp
M  +1    -0    PORT.KF5/FACTORIZE/mediawiki/wmwidget.h

http://commits.kde.org/kipi-plugins/78068fb1e869241432e218b9d11ba3b0a3866442