Skip to content

Commit df970e8

Browse files
Merge branch 'main' into Notification_time_ago
2 parents 478f6f3 + 76edcfb commit df970e8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+1295
-364
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package org.wikipedia.analytics.eventplatform
2+
3+
import android.content.Context
4+
import org.wikipedia.WikipediaApp
5+
import org.wikipedia.page.PageTitle
6+
7+
object WatchlistAnalyticsHelper {
8+
fun logAddedToWatchlist(title: PageTitle?, context: Context = WikipediaApp.instance) {
9+
EventPlatformClient.submit(
10+
BreadCrumbLogEvent(
11+
BreadCrumbViewUtil.getReadableScreenName(context),
12+
"Watchlist.itemWiki:${title?.wikiSite?.languageCode.orEmpty()}.added"
13+
)
14+
)
15+
}
16+
17+
fun logRemovedFromWatchlist(title: PageTitle?, context: Context = WikipediaApp.instance) {
18+
EventPlatformClient.submit(
19+
BreadCrumbLogEvent(
20+
BreadCrumbViewUtil.getReadableScreenName(context),
21+
"Watchlist.itemWiki:${title?.wikiSite?.languageCode.orEmpty()}.removed"
22+
)
23+
)
24+
}
25+
26+
fun logAddedToWatchlistSuccess(title: PageTitle?, context: Context = WikipediaApp.instance) {
27+
EventPlatformClient.submit(
28+
BreadCrumbLogEvent(
29+
BreadCrumbViewUtil.getReadableScreenName(context),
30+
"Watchlist.itemWiki:${title?.wikiSite?.languageCode.orEmpty()}.addSuccess"
31+
)
32+
)
33+
}
34+
35+
fun logRemovedFromWatchlistSuccess(title: PageTitle?, context: Context = WikipediaApp.instance) {
36+
EventPlatformClient.submit(
37+
BreadCrumbLogEvent(
38+
BreadCrumbViewUtil.getReadableScreenName(context),
39+
"Watchlist.itemWiki:${title?.wikiSite?.languageCode.orEmpty()}.removeSuccess"
40+
)
41+
)
42+
}
43+
44+
fun logFilterSelection(context: Context, excludedWikiCodes: Set<String>, includedTypeCodes: Set<String>) {
45+
EventPlatformClient.submit(
46+
BreadCrumbLogEvent(
47+
BreadCrumbViewUtil.getReadableScreenName(context),
48+
"WatchlistFilterSelection.appWikis:${WikipediaApp.instance.languageState.appLanguageCodes}.excludedWikiCodes:$excludedWikiCodes.includedTypeCodes:$includedTypeCodes"
49+
)
50+
)
51+
}
52+
}

app/src/main/java/org/wikipedia/categories/CategoryDialogViewModel.kt

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ import androidx.lifecycle.ViewModel
66
import androidx.lifecycle.ViewModelProvider
77
import androidx.lifecycle.viewModelScope
88
import kotlinx.coroutines.CoroutineExceptionHandler
9-
import kotlinx.coroutines.Dispatchers
109
import kotlinx.coroutines.launch
11-
import kotlinx.coroutines.withContext
1210
import org.wikipedia.dataclient.ServiceFactory
1311
import org.wikipedia.page.PageTitle
1412
import org.wikipedia.util.Resource
@@ -26,15 +24,13 @@ class CategoryDialogViewModel(bundle: Bundle) : ViewModel() {
2624
viewModelScope.launch(CoroutineExceptionHandler { _, throwable ->
2725
categoriesData.postValue(Resource.Error(throwable))
2826
}) {
29-
withContext(Dispatchers.IO) {
30-
val response = ServiceFactory.get(pageTitle.wikiSite).getCategories(pageTitle.prefixedText)
31-
val titles = response.query?.pages?.map { page ->
32-
PageTitle(page.title, pageTitle.wikiSite).also {
33-
it.displayText = page.displayTitle(pageTitle.wikiSite.languageCode)
34-
}
35-
}.orEmpty()
36-
categoriesData.postValue(Resource.Success(titles))
37-
}
27+
val response = ServiceFactory.get(pageTitle.wikiSite).getCategories(pageTitle.prefixedText)
28+
val titles = response.query?.pages?.map { page ->
29+
PageTitle(page.title, pageTitle.wikiSite).also {
30+
it.displayText = page.displayTitle(pageTitle.wikiSite.languageCode)
31+
}
32+
}.orEmpty()
33+
categoriesData.postValue(Resource.Success(titles))
3834
}
3935
}
4036

app/src/main/java/org/wikipedia/dataclient/Service.kt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,24 @@ interface Service {
568568
@Field("captchaword") captchaWord: String? = null
569569
): DiscussionToolsEditResponse
570570

571+
@GET(MW_API_PREFIX + "action=query&generator=growthtasks")
572+
suspend fun getGrowthTasks(
573+
@Query("ggttasktypes") taskTypes: String?,
574+
@Query("ggttopics") topics: String?,
575+
@Query("ggtlimit") count: Int
576+
): MwQueryResponse
577+
578+
@GET(MW_API_PREFIX + "action=query&prop=growthimagesuggestiondata")
579+
suspend fun getImageRecommendationForPage(
580+
@Query("titles") titles: String?,
581+
@Query("pageids") pageIds: String? = null
582+
): MwQueryResponse
583+
584+
@GET(MW_API_PREFIX + "action=paraminfo")
585+
suspend fun getParamInfo(
586+
@Query("modules") modules: String
587+
): ParamInfoResponse
588+
571589
companion object {
572590
const val WIKIPEDIA_URL = "https://wikipedia.org/"
573591
const val WIKIDATA_URL = "https://www.wikidata.org/"
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package org.wikipedia.dataclient.growthtasks
2+
3+
import kotlinx.serialization.Serializable
4+
5+
@Suppress("unused")
6+
@Serializable
7+
class GrowthImageSuggestion(
8+
val titleNamespace: Int = 0,
9+
val titleText: String = "",
10+
val datasetId: String = "",
11+
val images: List<ImageItem> = emptyList(),
12+
) {
13+
@Serializable
14+
class ImageItem(
15+
val image: String = "",
16+
val displayFilename: String = "",
17+
val source: String = "",
18+
val projects: List<String> = emptyList(),
19+
val metadata: ImageMetadata? = null,
20+
)
21+
22+
@Serializable
23+
class ImageMetadata(
24+
val descriptionUrl: String = "",
25+
val thumbUrl: String = "",
26+
val fullUrl: String = "",
27+
val originalWidth: Int = 0,
28+
val originalHeight: Int = 0,
29+
val mediaType: String = "",
30+
val description: String = "",
31+
val author: String = "",
32+
val license: String = "",
33+
val date: String = "",
34+
val caption: String = "",
35+
val categories: List<String> = emptyList(),
36+
val reason: String = "",
37+
val contentLanguageName: String = "",
38+
)
39+
}

app/src/main/java/org/wikipedia/dataclient/mwapi/MwQueryPage.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package org.wikipedia.dataclient.mwapi
22

33
import kotlinx.serialization.SerialName
44
import kotlinx.serialization.Serializable
5+
import org.wikipedia.dataclient.growthtasks.GrowthImageSuggestion
56
import org.wikipedia.dataclient.page.Protection
67
import org.wikipedia.gallery.ImageInfo
78
import org.wikipedia.page.Namespace
@@ -39,6 +40,11 @@ class MwQueryPage {
3940
val watched = false
4041
val lastrevid: Long = 0
4142

43+
val tasktype: String? = null
44+
val difficulty: String? = null
45+
val qualityGateIds: List<String>? = null
46+
val growthimagesuggestiondata: List<GrowthImageSuggestion>? = null
47+
4248
fun namespace(): Namespace {
4349
return Namespace.of(ns)
4450
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package org.wikipedia.dataclient.mwapi
2+
3+
import kotlinx.serialization.Serializable
4+
import kotlinx.serialization.json.JsonElement
5+
import kotlinx.serialization.json.jsonArray
6+
import kotlinx.serialization.json.jsonPrimitive
7+
8+
@Suppress("unused")
9+
@Serializable
10+
class ParamInfoResponse : MwResponse() {
11+
12+
val paraminfo: ParamInfo? = null
13+
14+
@Serializable
15+
class ParamInfo {
16+
val modules: List<Module> = emptyList()
17+
}
18+
19+
@Serializable
20+
class Module {
21+
val name = ""
22+
val classname = ""
23+
val path = ""
24+
val source = ""
25+
val parameters: List<Parameter> = emptyList()
26+
}
27+
28+
@Serializable
29+
class Parameter {
30+
val index = 0
31+
val name = ""
32+
val required = false
33+
val multi = false
34+
val type: JsonElement? = null
35+
36+
val typeAsString get() = type?.jsonPrimitive?.content.orEmpty()
37+
val typeAsEnum get() = type?.jsonArray?.map { it.jsonPrimitive.content } ?: emptyList()
38+
}
39+
}

app/src/main/java/org/wikipedia/descriptions/DescriptionEditFragment.kt

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -235,27 +235,22 @@ class DescriptionEditFragment : Fragment() {
235235
L.e(throwable)
236236
analyticsHelper.logApiFailed(requireContext(), throwable, pageTitle)
237237
}) {
238-
val list: List<String>
239-
val isBlp: Boolean
240-
241-
withContext(Dispatchers.IO) {
242-
val response = ServiceFactory[pageTitle.wikiSite, DescriptionSuggestionService.API_URL, DescriptionSuggestionService::class.java]
243-
.getSuggestion(pageTitle.wikiSite.languageCode, pageTitle.prefixedText, 2)
244-
245-
// Perform some post-processing on the predictions.
246-
// 1) Capitalize them, if we're dealing with enwiki.
247-
// 2) Remove duplicates.
248-
list = (if (pageTitle.wikiSite.languageCode == "en") {
249-
response.prediction.map { StringUtil.capitalize(it)!! }
250-
} else response.prediction).distinct()
251-
isBlp = response.blp
252-
analyticsHelper.apiOrderList = list
253-
analyticsHelper.logSuggestionsReceived(requireContext(), response.blp, pageTitle)
254-
L.d("Received suggestion: " + list.first())
255-
L.d("And is it a BLP? " + response.blp)
256-
}
238+
val response = ServiceFactory[pageTitle.wikiSite, DescriptionSuggestionService.API_URL, DescriptionSuggestionService::class.java]
239+
.getSuggestion(pageTitle.wikiSite.languageCode, pageTitle.prefixedText, 2)
240+
241+
// Perform some post-processing on the predictions.
242+
// 1) Capitalize them, if we're dealing with enwiki.
243+
// 2) Remove duplicates.
244+
val list = (if (pageTitle.wikiSite.languageCode == "en") {
245+
response.prediction.map { StringUtil.capitalize(it)!! }
246+
} else response.prediction).distinct()
247+
analyticsHelper.apiOrderList = list
248+
analyticsHelper.logSuggestionsReceived(requireContext(), response.blp, pageTitle)
249+
L.d("Received suggestion: " + list.first())
250+
L.d("And is it a BLP? " + response.blp)
251+
257252
// Randomize the display order
258-
if (!isBlp || MachineGeneratedArticleDescriptionsAnalyticsHelper.abcTest.group == GROUP_3) {
253+
if (!response.blp || MachineGeneratedArticleDescriptionsAnalyticsHelper.abcTest.group == GROUP_3) {
259254
val randomizedListIndex = (0 until 2).random()
260255
val firstSuggestion = if (list.size == 2) list[randomizedListIndex] else list.first()
261256
val secondSuggestion = if (list.size == 2) { if (randomizedListIndex == 0) list.last() else list.first() } else null
@@ -276,7 +271,7 @@ class DescriptionEditFragment : Fragment() {
276271
private fun shouldWriteToLocalWiki(): Boolean {
277272
return (action == DescriptionEditActivity.Action.ADD_DESCRIPTION ||
278273
action == DescriptionEditActivity.Action.TRANSLATE_DESCRIPTION) &&
279-
wikiUsesLocalDescriptions(pageTitle.wikiSite.languageCode)
274+
DescriptionEditUtil.wikiUsesLocalDescriptions(pageTitle.wikiSite.languageCode)
280275
}
281276

282277
private inner class EditViewCallback : DescriptionEditView.Callback {
@@ -552,9 +547,5 @@ class DescriptionEditFragment : Fragment() {
552547
Constants.INTENT_EXTRA_INVOKE_SOURCE to source)
553548
}
554549
}
555-
556-
fun wikiUsesLocalDescriptions(lang: String): Boolean {
557-
return lang == "en"
558-
}
559550
}
560551
}

app/src/main/java/org/wikipedia/descriptions/DescriptionEditLicenseView.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class DescriptionEditLicenseView constructor(context: Context, attrs: AttributeS
4141

4242
fun buildLicenseNotice(arg: String, lang: String? = null) {
4343
if ((arg == ARG_NOTICE_ARTICLE_DESCRIPTION || arg == ARG_NOTICE_DEFAULT) &&
44-
DescriptionEditFragment.wikiUsesLocalDescriptions(lang.orEmpty())) {
44+
DescriptionEditUtil.wikiUsesLocalDescriptions(lang.orEmpty())) {
4545
binding.licenseText.text = StringUtil.fromHtml(context.getString(R.string.edit_save_action_license_logged_in,
4646
context.getString(R.string.terms_of_use_url),
4747
context.getString(R.string.cc_by_sa_3_url)))

app/src/main/java/org/wikipedia/descriptions/DescriptionEditUtil.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,12 @@ object DescriptionEditUtil {
77
private const val DESCRIPTION_SOURCE_LOCAL = "local"
88
private const val DESCRIPTION_SOURCE_WIKIDATA = "central"
99

10+
fun wikiUsesLocalDescriptions(lang: String): Boolean {
11+
return lang == "en" || lang == "test"
12+
}
13+
1014
fun isEditAllowed(page: Page): Boolean {
11-
return if (page.title.wikiSite.languageCode == "en") {
15+
return if (wikiUsesLocalDescriptions(page.title.wikiSite.languageCode)) {
1216
// For English Wikipedia, allow editing the description for all articles, since the
1317
// edit will go directly into the article instead of Wikidata.
1418
true

0 commit comments

Comments
 (0)