1
1
package fr .free .nrw .commons .wikidata ;
2
2
3
3
import static fr .free .nrw .commons .depictions .Media .DepictedImagesFragment .PAGE_ID_PREFIX ;
4
- import static fr .free .nrw .commons .di .NetworkingModule .NAMED_COMMONS_CSRF ;
5
4
6
5
import android .annotation .SuppressLint ;
7
6
import android .content .Context ;
13
12
import fr .free .nrw .commons .upload .UploadResult ;
14
13
import fr .free .nrw .commons .upload .WikidataItem ;
15
14
import fr .free .nrw .commons .upload .WikidataPlace ;
16
- import fr .free .nrw .commons .upload .mediaDetails .CaptionInterface ;
17
15
import fr .free .nrw .commons .utils .ConfigUtils ;
18
16
import fr .free .nrw .commons .utils .ViewUtil ;
19
17
import io .reactivex .Observable ;
27
25
import javax .inject .Named ;
28
26
import javax .inject .Singleton ;
29
27
import org .jetbrains .annotations .NotNull ;
30
- import org .wikipedia .csrf .CsrfTokenClient ;
31
28
import org .wikipedia .dataclient .mwapi .MwPostResponse ;
32
29
import timber .log .Timber ;
33
30
@@ -45,26 +42,20 @@ public class WikidataEditService {
45
42
private final Context context ;
46
43
private final WikidataEditListener wikidataEditListener ;
47
44
private final JsonKvStore directKvStore ;
48
- private final CaptionInterface captionInterface ;
49
- private final WikiBaseClient wikiBaseClient ;
45
+ private final WikiBaseClient wikiBaseClient ;
50
46
private final WikidataClient wikidataClient ;
51
- private final CsrfTokenClient csrfTokenClient ;
52
47
53
- @ Inject
48
+ @ Inject
54
49
public WikidataEditService (final Context context ,
55
50
final WikidataEditListener wikidataEditListener ,
56
51
@ Named ("default_preferences" ) final JsonKvStore directKvStore ,
57
52
final WikiBaseClient wikiBaseClient ,
58
- final CaptionInterface captionInterface ,
59
- final WikidataClient wikidataClient ,
60
- @ Named (NAMED_COMMONS_CSRF ) final CsrfTokenClient csrfTokenClient ) {
53
+ final WikidataClient wikidataClient ) {
61
54
this .context = context ;
62
55
this .wikidataEditListener = wikidataEditListener ;
63
56
this .directKvStore = directKvStore ;
64
- this .captionInterface = captionInterface ;
65
57
this .wikiBaseClient = wikiBaseClient ;
66
58
this .wikidataClient = wikidataClient ;
67
- this .csrfTokenClient = csrfTokenClient ;
68
59
}
69
60
70
61
/**
@@ -162,7 +153,7 @@ public void createCaptions(final UploadResult uploadResult, final Map<String, St
162
153
.subscribe (fileEntityId -> {
163
154
if (fileEntityId != null ) {
164
155
for (final Map .Entry <String , String > entry : captions .entrySet ()) {
165
- wikidataAddLabels (fileEntityId , entry .getKey (), entry .getValue ());
156
+ addCaption (fileEntityId , entry .getKey (), entry .getValue ());
166
157
}
167
158
} else {
168
159
Timber .d ("Error acquiring EntityId for image" );
@@ -180,12 +171,9 @@ public void createCaptions(final UploadResult uploadResult, final Map<String, St
180
171
*/
181
172
182
173
@ SuppressLint ("CheckResult" )
183
- private void wikidataAddLabels (final Long fileEntityId , final String languageCode ,
174
+ private void addCaption (final Long fileEntityId , final String languageCode ,
184
175
final String captionValue ) {
185
-
186
- csrfToken ()
187
- .subscribeOn (Schedulers .io ())
188
- .switchMap (editToken -> captionInterface .addLabelstoWikidata (fileEntityId , editToken , languageCode , captionValue ))
176
+ wikiBaseClient .addLabelstoWikidata (fileEntityId , languageCode , captionValue )
189
177
.subscribe (mwPostResponse -> onAddCaptionResponse (fileEntityId , mwPostResponse ),
190
178
throwable -> {
191
179
Timber .e (throwable , "Error occurred while setting Captions" );
@@ -202,17 +190,6 @@ private void onAddCaptionResponse(Long fileEntityId, MwPostResponse revisionId)
202
190
}
203
191
}
204
192
205
- private Observable <String > csrfToken () {
206
- return Observable .fromCallable (() -> {
207
- try {
208
- return csrfTokenClient .getTokenBlocking ();
209
- } catch (Throwable throwable ) {
210
- throwable .printStackTrace ();
211
- return null ;
212
- }
213
- });
214
- }
215
-
216
193
public void createImageClaim (@ Nullable final WikidataPlace wikidataPlace , final UploadResult imageUpload ) {
217
194
if (!(directKvStore .getBoolean ("Picture_Has_Correct_Location" , true ))) {
218
195
Timber .d ("Image location and nearby place location mismatched, so Wikidata item won't be edited" );
0 commit comments