Skip to content

Commit e26f231

Browse files
committed
#3529 Captions/depictions are not saved to Commons - mark Media fields private - weaken types - remove partly implemented fields
1 parent 4a7ebff commit e26f231

11 files changed

+140
-196
lines changed

app/src/main/java/fr/free/nrw/commons/Media.java

+63-102
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@
1111
import fr.free.nrw.commons.utils.MediaDataExtractorUtil;
1212
import java.text.ParseException;
1313
import java.util.ArrayList;
14-
import java.util.Collections;
1514
import java.util.Date;
16-
import java.util.HashMap;
1715
import java.util.List;
1816
import java.util.Locale;
1917
import java.util.Map;
@@ -30,53 +28,42 @@ public class Media implements Parcelable {
3028

3129
// Primary metadata fields
3230
@Nullable
33-
public Uri localUri;
34-
public String thumbUrl;
35-
public String imageUrl;
36-
public String filename;
37-
public String thumbnailTitle;
38-
/**
31+
private Uri localUri;
32+
private String thumbUrl;
33+
private String imageUrl;
34+
private String filename;
35+
private String thumbnailTitle;
36+
/*
3937
* Captions are a feature part of Structured data. They are meant to store short, multilingual descriptions about files
4038
* This is a replacement of the previously used titles for images (titles were not multilingual)
4139
* Also now captions replace the previous convention of using title for filename
4240
*/
4341
private String caption;
44-
public String description; // monolingual description on input...
45-
public String discussion;
42+
private String description; // monolingual description on input...
43+
private String discussion;
4644
private long dataLength;
47-
public Date dateCreated;
48-
@Nullable public Date dateUploaded;
49-
public String license;
50-
public String licenseUrl;
51-
public String creator;
45+
private Date dateCreated;
46+
@Nullable private Date dateUploaded;
47+
private String license;
48+
private String licenseUrl;
49+
private String creator;
5250
/**
5351
* Wikibase Identifier associated with media files
5452
*/
55-
public String pageId;
53+
private String pageId;
5654
private List<String> categories; // as loaded at runtime?
5755
/**
5856
* Depicts is a feature part of Structured data. Multiple Depictions can be added for an image just like categories.
5957
* However unlike categories depictions is multi-lingual
6058
*/
61-
public ArrayList<Map<String, String>> depictionList;
62-
public boolean requestedDeletion;
63-
public HashMap<String, String> descriptions; // multilingual descriptions as loaded
64-
/**
65-
* This hasmap stores the list of multilingual captions, where
66-
* key of the HashMap is the language and value is the caption in the corresponding language
67-
* Ex: key = "en", value: "<caption in short in English>"
68-
* key = "de" , value: "<caption in german>"
69-
*/
70-
public Map<String, String> captions;
71-
@Nullable public LatLng coordinates;
59+
private List<Map<String, String>> depictionList= new ArrayList<>();
60+
private boolean requestedDeletion;
61+
@Nullable private LatLng coordinates;
7262

7363
/**
7464
* Provides local constructor
7565
*/
76-
protected Media() {
77-
this.categories = new ArrayList<>();
78-
this.descriptions = new HashMap<>();
79-
this.captions = new HashMap<>();
66+
public Media() {
8067
}
8168

8269
/**
@@ -85,7 +72,6 @@ protected Media() {
8572
* @param filename Media filename
8673
*/
8774
public Media(String filename) {
88-
this();
8975
this.filename = filename;
9076
}
9177

@@ -94,28 +80,35 @@ public Media(String filename) {
9480
* @param localUri Media URI
9581
* @param imageUrl Media image URL
9682
* @param filename Media filename
97-
* @param captions Media captions
9883
* @param description Media description
9984
* @param dataLength Media date length
10085
* @param dateCreated Media creation date
10186
* @param dateUploaded Media date uploaded
10287
* @param creator Media creator
10388
*/
104-
public Media(Uri localUri, String imageUrl, String filename, Map<String, String> captions, String description,
105-
long dataLength, Date dateCreated, Date dateUploaded, String creator) {
106-
this();
89+
public Media(Uri localUri, String imageUrl, String filename,
90+
String description,
91+
long dataLength, Date dateCreated, Date dateUploaded, String creator) {
10792
this.localUri = localUri;
10893
this.thumbUrl = imageUrl;
10994
this.imageUrl = imageUrl;
11095
this.filename = filename;
111-
this.captions = captions;
11296
this.description = description;
11397
this.dataLength = dataLength;
11498
this.dateCreated = dateCreated;
11599
this.dateUploaded = dateUploaded;
116100
this.creator = creator;
117-
this.categories = new ArrayList<>();
118-
this.descriptions = new HashMap<>();
101+
}
102+
103+
public Media(Uri localUri, String filename,
104+
String description, String creator, List<String> categories) {
105+
this(localUri,null, filename,
106+
description, -1, null, new Date(), creator);
107+
this.categories = categories;
108+
}
109+
110+
public Media(String title, Date date, String user) {
111+
this(null, null, title, "", -1, date, date, user);
119112
}
120113

121114
/**
@@ -135,7 +128,7 @@ public static Media from(MwQueryPage page) {
135128
ExtMetadata metadata = imageInfo.getMetadata();
136129
if (metadata == null) {
137130
Media media = new Media(null, imageInfo.getOriginalUrl(),
138-
page.title(), new HashMap<>() , "", 0, null, null, null);
131+
page.title(), "", 0, null, null, null);
139132
if (!StringUtils.isBlank(imageInfo.getThumbUrl())) {
140133
media.setThumbUrl(imageInfo.getThumbUrl());
141134
}
@@ -145,8 +138,7 @@ public static Media from(MwQueryPage page) {
145138
Media media = new Media(null,
146139
imageInfo.getOriginalUrl(),
147140
page.title(),
148-
new HashMap<>(),
149-
"",
141+
"",
150142
0,
151143
safeParseDate(metadata.dateTime()),
152144
safeParseDate(metadata.dateTime()),
@@ -164,7 +156,7 @@ public static Media from(MwQueryPage page) {
164156
language = "default";
165157
}
166158

167-
media.setDescriptions(Collections.singletonMap(language, metadata.imageDescription()));
159+
media.setDescription(metadata.imageDescription());
168160
media.setCategories(MediaDataExtractorUtil.extractCategoriesFromList(metadata.getCategories()));
169161
String latitude = metadata.getGpsLatitude();
170162
String longitude = metadata.getGpsLongitude();
@@ -202,7 +194,7 @@ public String getPageId() {
202194
/**
203195
*sets pageId for the current media object
204196
*/
205-
private void setPageId(String pageId) {
197+
public void setPageId(String pageId) {
206198
this.pageId = pageId;
207199
}
208200

@@ -313,22 +305,11 @@ public String getCaption() {
313305
/**
314306
* @return depictions associated with the current media
315307
*/
316-
public ArrayList<Map<String, String>> getDepiction() {
308+
public List<Map<String, String>> getDepiction() {
317309
return depictionList;
318310
}
319311

320-
/**
321-
* Captions are a feature part of Structured data. They are meant to store short, multilingual descriptions about files
322-
* This is a replacement of the previously used titles for images (titles were not multilingual)
323-
* Also now captions replace the previous convention of using title for filename
324-
*
325-
* key of the HashMap is the language and value is the caption in the corresponding language
326-
*
327-
* returns list of captions stored in hashmap
328-
*/
329-
public Map<String, String> getCaptions() {
330-
return captions;
331-
}
312+
332313

333314
/**
334315
* Sets the file description.
@@ -451,7 +432,6 @@ public List<String> getCategories() {
451432
return categories;
452433
}
453434

454-
455435
/**
456436
* Sets the categories the file falls under.
457437
* </p>
@@ -463,36 +443,6 @@ public void setCategories(List<String> categories) {
463443
this.categories = categories;
464444
}
465445

466-
/**
467-
* Modifies (or sets) media descriptions
468-
* @param descriptions Media descriptions
469-
*/
470-
void setDescriptions(Map<String, String> descriptions) {
471-
this.descriptions.clear();
472-
this.descriptions.putAll(descriptions);
473-
}
474-
475-
/**
476-
* Gets media description in preferred language
477-
* @param preferredLanguage Language preferred
478-
* @return Description in preferred language
479-
*/
480-
public String getDescription(String preferredLanguage) {
481-
if (descriptions.containsKey(preferredLanguage)) {
482-
// See if the requested language is there.
483-
return descriptions.get(preferredLanguage);
484-
} else if (descriptions.containsKey("en")) {
485-
// Ah, English. Language of the world, until the Chinese crush us.
486-
return descriptions.get("en");
487-
} else if (descriptions.containsKey("default")) {
488-
// No languages marked...
489-
return descriptions.get("default");
490-
} else {
491-
// FIXME: return the first available non-English description?
492-
return "";
493-
}
494-
}
495-
496446
@Nullable private static Date safeParseDate(String dateStr) {
497447
try {
498448
return CommonsDateUtil.getIso8601DateFormatShort().parse(dateStr);
@@ -501,20 +451,19 @@ public String getDescription(String preferredLanguage) {
501451
}
502452
}
503453

504-
505-
506454
/**
507455
* Set requested deletion to true
456+
* @param requestedDeletion
508457
*/
509-
public void setRequestedDeletion(){
510-
requestedDeletion = true;
458+
public void setRequestedDeletion(boolean requestedDeletion){
459+
this.requestedDeletion = requestedDeletion;
511460
}
512461

513462
/**
514463
* Get the value of requested deletion
515464
* @return boolean requestedDeletion
516465
*/
517-
public boolean getRequestedDeletion(){
466+
public boolean isRequestedDeletion(){
518467
return requestedDeletion;
519468
}
520469

@@ -539,15 +488,29 @@ public void setCaption(String caption) {
539488
this.caption = caption;
540489
}
541490

542-
public void setCaptions(HashMap<String, String> captions) {
543-
this.captions = captions;
491+
/* Sets depictions for the current media obtained fro Wikibase API*/
492+
public void setDepictionList(List<Map<String, String>> depictions) {
493+
this.depictionList = depictions;
544494
}
545495

546-
/**
547-
* Sets depictions for the current media obtained fro Wikibase API
548-
*/
549-
public void setDepiction(ArrayList<Map<String, String>> depictions) {
550-
this.depictionList = depictions;
496+
public void setLocalUri(@Nullable final Uri localUri) {
497+
this.localUri = localUri;
498+
}
499+
500+
public void setImageUrl(final String imageUrl) {
501+
this.imageUrl = imageUrl;
502+
}
503+
504+
public void setDateUploaded(@Nullable final Date dateUploaded) {
505+
this.dateUploaded = dateUploaded;
506+
}
507+
508+
public void setLicenseUrl(final String licenseUrl) {
509+
this.licenseUrl = licenseUrl;
510+
}
511+
512+
public List<Map<String, String>> getDepictionList() {
513+
return depictionList;
551514
}
552515

553516
@Override
@@ -581,7 +544,6 @@ public void writeToParcel(Parcel dest, int flags) {
581544
dest.writeStringList(this.categories);
582545
dest.writeList(this.depictionList);
583546
dest.writeByte(this.requestedDeletion ? (byte) 1 : (byte) 0);
584-
dest.writeSerializable(this.descriptions);
585547
dest.writeParcelable(this.coordinates, flags);
586548
}
587549

@@ -608,7 +570,6 @@ protected Media(Parcel in) {
608570
this.categories=list;
609571
in.readList(depictionList,null);
610572
this.requestedDeletion = in.readByte() != 0;
611-
this.descriptions = (HashMap<String, String>) in.readSerializable();
612573
this.coordinates = in.readParcelable(LatLng.class.getClassLoader());
613574
}
614575

app/src/main/java/fr/free/nrw/commons/MediaDataExtractor.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ private Media combineToMedia(final Media media, final Boolean deletionStatus, fi
5555
final String caption, final JsonObject depiction) {
5656
media.setDiscussion(discussion);
5757
media.setCaption(caption);
58-
media.setDepiction(formatDepictions(depiction));
58+
media.setDepictionList(formatDepictions(depiction));
5959
if (deletionStatus) {
60-
media.setRequestedDeletion();
60+
media.setRequestedDeletion(true);
6161
}
6262
return media;
6363
}

0 commit comments

Comments
 (0)