Fixes invalid authorname in explore (#4054)

* Fixes #3341, #4018
* Defined two feild author and user in Media and used them at the corresponding places
Minor bug fixes
-displaying userName in uploadedBy.
-modified HTML parsing in getArtist.
-Replaced creator with author.

* Fixes #3341, #4018
* Defined two feild author and user in Media and used them at the corresponding places
Minor bug fixes
-displaying userName in uploadedBy.
-modified HTML parsing in getArtist.
-Replaced creator with author.
This commit is contained in:
Ashish 2020-12-01 19:26:41 +05:30 committed by GitHub
parent f1b40728b2
commit d720750ab4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 56 additions and 61 deletions

View file

@ -55,13 +55,15 @@ class Media constructor(
val licenseUrl: String? = null,
/**
* Gets the name of the creator of the file.
* @return creator name as a String
* @return author name as a String
*/
/**
* Sets the creator name of the file.
* @param creator creator name as a string
* Sets the author name of the file.
* @param author creator name as a string
*/
var creator: String? = null,
var author: String? = null,
var user:String?=null,
/**
* Gets the categories the file falls under.
@ -83,12 +85,13 @@ class Media constructor(
categories: List<String>?,
filename: String?,
fallbackDescription: String?,
creator: String?
author: String?, user:String?
) : this(
filename = filename,
fallbackDescription = fallbackDescription,
dateUploaded = Date(),
creator = creator,
author = author,
user=user,
categories = categories,
captions = captions
)

View file

@ -28,7 +28,6 @@ public class SessionManager {
private final Context context;
private Account currentAccount; // Unlike a savings account... ;-)
private JsonKvStore defaultKvStore;
private static final String KEY_RAWUSERNAME = "rawusername";
@Inject
public SessionManager(Context context,
@ -99,17 +98,6 @@ public class SessionManager {
return account == null ? null : account.name;
}
@Nullable
private String getRawUserName() {
Account account = getCurrentAccount();
return account == null ? null : accountManager().getUserData(account, KEY_RAWUSERNAME);
}
public String getAuthorName(){
return getRawUserName() == null ? getUserName() : getRawUserName();
}
@Nullable
public String getPassword() {
Account account = getCurrentAccount();

View file

@ -14,7 +14,6 @@ import com.facebook.drawee.view.SimpleDraweeView;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import fr.free.nrw.commons.Media;
import fr.free.nrw.commons.R;
@ -87,9 +86,9 @@ public class GridViewAdapter extends ArrayAdapter {
Media item = data.get(position);
SimpleDraweeView imageView = convertView.findViewById(R.id.categoryImageView);
TextView fileName = convertView.findViewById(R.id.categoryImageTitle);
TextView author = convertView.findViewById(R.id.categoryImageAuthor);
TextView uploader = convertView.findViewById(R.id.categoryImageAuthor);
fileName.setText(item.getMostRelevantCaption());
setAuthorView(item, author);
setUploaderView(item, uploader);
imageView.setImageURI(item.getThumbUrl());
return convertView;
}
@ -107,14 +106,14 @@ public class GridViewAdapter extends ArrayAdapter {
/**
* Shows author information if its present
* @param item
* @param author
* @param uploader
*/
private void setAuthorView(Media item, TextView author) {
if (!TextUtils.isEmpty(item.getCreator())) {
author.setVisibility(View.VISIBLE);
author.setText(getContext().getString(R.string.image_uploaded_by, item.getCreator()));
private void setUploaderView(Media item, TextView uploader) {
if (!TextUtils.isEmpty(item.getAuthor())) {
uploader.setVisibility(View.VISIBLE);
uploader.setText(getContext().getString(R.string.image_uploaded_by, item.getUser()));
} else {
author.setVisibility(View.GONE);
uploader.setVisibility(View.GONE);
}
}
}

View file

@ -57,7 +57,8 @@ data class Contribution constructor(
categories,
item.fileName,
formatDescriptions(item.uploadMediaDetails),
sessionManager.authorName
sessionManager.userName,
sessionManager.userName
),
localUri = item.mediaUri,
decimalCoords = item.gpsCoords.decimalCoords,

View file

@ -18,7 +18,6 @@ import com.facebook.imagepipeline.request.ImageRequestBuilder;
import fr.free.nrw.commons.R;
import fr.free.nrw.commons.contributions.ContributionsListAdapter.Callback;
import fr.free.nrw.commons.media.MediaClient;
import fr.free.nrw.commons.utils.ViewUtil;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.schedulers.Schedulers;
@ -68,7 +67,7 @@ public class ContributionViewHolder extends RecyclerView.ViewHolder {
this.contribution = contribution;
this.position = position;
titleView.setText(contribution.getMedia().getMostRelevantCaption());
authorView.setText(contribution.getMedia().getCreator());
authorView.setText(contribution.getMedia().getAuthor());
imageView.getHierarchy().setPlaceholderImage(R.drawable.image_placeholder);
imageView.getHierarchy().setFailureImage(R.drawable.image_placeholder);

View file

@ -10,7 +10,7 @@ import fr.free.nrw.commons.contributions.ContributionDao
* The database for accessing the respective DAOs
*
*/
@Database(entities = [Contribution::class], version = 6, exportSchema = false)
@Database(entities = [Contribution::class], version = 7, exportSchema = false)
@TypeConverters(Converters::class)
abstract class AppDatabase : RoomDatabase() {
abstract fun contributionDao(): ContributionDao

View file

@ -94,11 +94,10 @@ public class DeleteHelper {
String userPageString = "\n{{subst:idw|" + media.getFilename() +
"}} ~~~~";
String creator = media.getCreator();
String creator = media.getAuthor();
if (creator == null || creator.isEmpty()) {
throw new RuntimeException("Failed to nominate for deletion");
}
String creatorName = creator.replace(" (page does not exist)", "");
return pageEditClient.prependEdit(media.getFilename(), fileDeleteString + "\n", summary)
.flatMap(result -> {
@ -113,7 +112,7 @@ public class DeleteHelper {
throw new RuntimeException("Failed to nominate for deletion");
}).flatMap(result -> {
if (result) {
return pageEditClient.appendEdit("User_Talk:" + creatorName, userPageString + "\n", summary);
return pageEditClient.appendEdit("User_Talk:" + creator, userPageString + "\n", summary);
}
throw new RuntimeException("Failed to nominate for deletion");
});

View file

@ -29,7 +29,8 @@ class MediaConverter @Inject constructor() {
safeParseDate(metadata.dateTime()),
metadata.licenseShortName(),
metadata.prefixedLicenseUrl,
getArtist(metadata),
getAuthor(metadata),
imageInfo.user,
MediaDataExtractorUtil.extractCategoriesFromList(metadata.categories),
metadata.latLng,
entity.labels().mapValues { it.value.value() },
@ -61,11 +62,16 @@ class MediaConverter @Inject constructor() {
* @param metadata
* @return
*/
private fun getArtist(metadata: ExtMetadata): String? {
private fun getAuthor(metadata: ExtMetadata): String? {
return try {
val artistHtml = metadata.artist()
artistHtml.substring(artistHtml.indexOf("title=\""), artistHtml.indexOf("\">"))
.replace("title=\"User:", "")
val authorHtml = metadata.artist()
val anchorStartTagTerminalChars = "\">"
val anchorCloseTag = "</a>"
return authorHtml.substring(
authorHtml.indexOf(anchorStartTagTerminalChars) + anchorStartTagTerminalChars
.length, authorHtml.indexOf(anchorCloseTag)
)
} catch (ex: java.lang.Exception) {
""
}

View file

@ -37,10 +37,10 @@ class SearchImagesViewHolder(containerView: View, val onImageClicked: (Int) -> U
categoryImageView.setOnClickListener { onImageClicked(item.second) }
categoryImageTitle.text = media.mostRelevantCaption
categoryImageView.setImageURI(media.thumbUrl)
if (media.creator?.isNotEmpty() == true) {
if (media.author?.isNotEmpty() == true) {
categoryImageAuthor.visibility = View.VISIBLE
categoryImageAuthor.text =
containerView.context.getString(R.string.image_uploaded_by, media.creator)
containerView.context.getString(R.string.image_uploaded_by, media.user)
} else {
categoryImageAuthor.visibility = View.GONE
}

View file

@ -17,7 +17,6 @@ import android.os.Bundle;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -66,7 +65,6 @@ import fr.free.nrw.commons.di.CommonsDaggerSupportFragment;
import fr.free.nrw.commons.nearby.Label;
import fr.free.nrw.commons.ui.widget.HtmlTextView;
import fr.free.nrw.commons.utils.ViewUtilWrapper;
import io.reactivex.Observable;
import io.reactivex.Single;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
@ -542,10 +540,10 @@ public class MediaDetailFragment extends CommonsDaggerSupportFragment implements
updateCategoryList();
if (media.getCreator() == null || media.getCreator().equals("")) {
if (media.getAuthor() == null || media.getAuthor().equals("")) {
authorLayout.setVisibility(GONE);
} else {
author.setText(media.getCreator());
author.setText(media.getAuthor());
}
}
@ -679,7 +677,7 @@ public class MediaDetailFragment extends CommonsDaggerSupportFragment implements
@SuppressLint("StringFormatInvalid")
@OnClick(R.id.nominateDeletion)
public void onDeleteButtonClicked(){
if (AccountUtil.getUserName(getContext()) != null && AccountUtil.getUserName(getContext()).equals(media.getCreator())) {
if (AccountUtil.getUserName(getContext()) != null && AccountUtil.getUserName(getContext()).equals(media.getAuthor())) {
final ArrayAdapter<String> languageAdapter = new ArrayAdapter<>(getActivity(),
R.layout.simple_spinner_dropdown_list, reasonList);
final Spinner spinner = new Spinner(getActivity());

View file

@ -254,7 +254,7 @@ public class MediaDetailPagerFragment extends CommonsDaggerSupportFragment imple
// Initialize bookmark object
bookmark = new Bookmark(
m.getFilename(),
m.getCreator(),
m.getAuthor(),
BookmarkPicturesContentProvider.uriForName(m.getFilename())
);
updateBookmarkState(menu.findItem(R.id.menu_bookmark_current_image));

View file

@ -11,7 +11,7 @@ import retrofit2.http.QueryMap;
* Interface for interacting with Commons media related APIs
*/
public interface MediaInterface {
String MEDIA_PARAMS="&prop=imageinfo&iiprop=url|extmetadata&iiurlwidth=640" +
String MEDIA_PARAMS="&prop=imageinfo&iiprop=url|extmetadata|user&&iiurlwidth=640" +
"&iiextmetadatafilter=DateTime|Categories|GPSLatitude|GPSLongitude|ImageDescription|DateTimeOriginal" +
"|Artist|LicenseShortName|LicenseUrl";

View file

@ -37,8 +37,8 @@ class PageContentsCreator {
.append("{{Information\n")
.append("|description=").append(media.getFallbackDescription()).append("\n")
.append("|source=").append("{{own}}\n")
.append("|author=[[User:").append(media.getCreator()).append("|")
.append(media.getCreator()).append("]]\n");
.append("|author=[[User:").append(media.getAuthor()).append("|")
.append(media.getAuthor()).append("]]\n");
String templatizedCreatedDate = getTemplatizedCreatedDate(
contribution.getDateCreated(), contribution.getDateCreatedSource());

View file

@ -97,10 +97,10 @@ public class UploadController {
final Media media = contribution.getMedia();
if (store.getBoolean("useAuthorName", false)) {
final String authorName = store.getString("authorName", "");
media.setCreator(authorName);
media.setAuthor(authorName);
}
if (TextUtils.isEmpty(media.getCreator())) {
if (TextUtils.isEmpty(media.getAuthor())) {
final Account currentAccount = sessionManager.getCurrentAccount();
if (currentAccount == null) {
Timber.d("Current account is null");
@ -108,7 +108,7 @@ public class UploadController {
sessionManager.forceLogin(context);
return;
}
media.setCreator(sessionManager.getAuthorName());
media.setAuthor(sessionManager.getUserName());
}
if (media.getFallbackDescription() == null) {

View file

@ -40,7 +40,8 @@ fun media(
dateUploaded: Date? = Date(),
license: String? = "license",
licenseUrl: String? = "licenseUrl",
creator: String? = "creator",
author: String? = "creator",
user:String?="user",
pageId: String = "pageId",
categories: List<String>? = listOf("categories"),
coordinates: LatLng? = LatLng(0.0, 0.0, 0.0f),
@ -56,7 +57,8 @@ fun media(
dateUploaded,
license,
licenseUrl,
creator,
author,
user,
categories,
coordinates,
captions,

View file

@ -56,7 +56,7 @@ class DeleteHelperTest {
whenever(media.displayTitle).thenReturn("Test file")
val creatorName = "Creator"
whenever(media.creator).thenReturn("$creatorName (page does not exist)")
whenever(media.author).thenReturn("$creatorName")
whenever(media.filename).thenReturn("Test file.jpg")
val makeDeletion = deleteHelper.makeDeletion(context, media, "Test reason")?.blockingGet()
@ -78,7 +78,7 @@ class DeleteHelperTest {
.thenReturn(Observable.just(true))
whenever(media.displayTitle).thenReturn("Test file")
whenever(media.filename).thenReturn("Test file.jpg")
whenever(media.creator).thenReturn("Creator (page does not exist)")
whenever(media.author).thenReturn("Creator (page does not exist)")
deleteHelper.makeDeletion(context, media, "Test reason")?.blockingGet()
}
@ -93,7 +93,7 @@ class DeleteHelperTest {
.thenReturn(Observable.just(false))
whenever(media.displayTitle).thenReturn("Test file")
whenever(media.filename).thenReturn("Test file.jpg")
whenever(media.creator).thenReturn("Creator (page does not exist)")
whenever(media.author).thenReturn("Creator (page does not exist)")
deleteHelper.makeDeletion(context, media, "Test reason")?.blockingGet()
}
@ -108,7 +108,7 @@ class DeleteHelperTest {
.thenReturn(Observable.just(true))
whenever(media.displayTitle).thenReturn("Test file")
whenever(media.filename).thenReturn("Test file.jpg")
whenever(media.creator).thenReturn("Creator (page does not exist)")
whenever(media.author).thenReturn("Creator (page does not exist)")
deleteHelper.makeDeletion(context, media, "Test reason")?.blockingGet()
}
@ -125,7 +125,7 @@ class DeleteHelperTest {
whenever(media.displayTitle).thenReturn("Test file")
whenever(media.filename).thenReturn("Test file.jpg")
whenever(media.creator).thenReturn(null)
whenever(media.author).thenReturn(null)
deleteHelper.makeDeletion(context, media, "Test reason")?.blockingGet()
}

View file

@ -52,7 +52,7 @@ class UploadControllerTest {
val contribution = mock(Contribution::class.java)
val media = mock<Media>()
whenever(contribution.media).thenReturn(media)
whenever(media.creator).thenReturn("Creator")
whenever(media.author).thenReturn("Creator")
uploadController!!.startUpload(contribution)
}
}