Skip used images (#5160)

* Only Review Images That Has No Usage

* Coding Standard Related Changes

* Coding Standard Changes - 1

* small change
This commit is contained in:
Arin Modi 2023-03-07 11:16:36 +05:30 committed by GitHub
parent b917fe3229
commit 496933654b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 109 additions and 5 deletions

View file

@ -6,6 +6,7 @@ import android.content.Intent;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
@ -161,14 +162,31 @@ public class ReviewActivity extends BaseActivity {
hasNonHiddenCategories = false;
progressBar.setVisibility(View.VISIBLE);
reviewPager.setCurrentItem(0);
// Finds non-hidden categories from Media instance
compositeDisposable.add(reviewHelper.getRandomMedia()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(media -> {
.subscribe(this::checkWhetherFileIsUsedInWikis));
return true;
}
/**
* Check whether media is used or not in any Wiki Page
*/
@SuppressLint("CheckResult")
private void checkWhetherFileIsUsedInWikis(final Media media) {
compositeDisposable.add(reviewHelper.checkFileUsage(media.getFilename())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(result -> {
// result false indicates media is not used in any wiki
if (!result) {
// Finds non-hidden categories from Media instance
findNonHiddenCategories(media);
}));
return true;
} else {
runRandomizer();
}
}));
}
/**

View file

@ -100,6 +100,19 @@ public class ReviewHelper {
.map(response -> response.query().firstPage().revisions().get(0));
}
/**
* Checks Whether Given File is used in any Wiki page or not
* by calling api for given file
*
* @param filename
* @return
*/
Observable<Boolean> checkFileUsage(final String filename) {
return reviewInterface.getGlobalUsageInfo(filename)
.map(mwQueryResponse -> mwQueryResponse.query().firstPage()
.checkWhetherFileIsUsedInWikis());
}
/**
* Checks if the change is reviewable or not.
* - checks the type and revisionId of the change

View file

@ -15,4 +15,7 @@ public interface ReviewInterface {
@GET("w/api.php?action=query&format=json&formatversion=2&prop=revisions&rvprop=timestamp|ids|user&rvdir=newer&rvlimit=1")
Observable<MwQueryResponse> getFirstRevisionOfFile(@Query("titles") String titles);
@GET("w/api.php?action=query&format=json&formatversion=2&prop=fileusage|globalusage")
Observable<MwQueryResponse> getGlobalUsageInfo(@Query("titles") String title);
}