Skip to content

Commit

Permalink
Feature: Show where file is being used on Commons & Other wikis (comm…
Browse files Browse the repository at this point in the history
…ons-app#6006)

* add url to build config

Signed-off-by: parneet-guraya <[email protected]>

* add network call functions

Signed-off-by: parneet-guraya <[email protected]>

* return response asynchronously

Signed-off-by: parneet-guraya <[email protected]>

* inject page size in the request

Signed-off-by: parneet-guraya <[email protected]>

* rename from Commons..Response.kt to ..Response.kt

Signed-off-by: parneet-guraya <[email protected]>

* convert to .kt

Signed-off-by: parneet-guraya <[email protected]>

* ui setup working

Signed-off-by: parneet-guraya <[email protected]>

* fix merge conflict

Signed-off-by: parneet-guraya <[email protected]>

* cleanup

Signed-off-by: parneet-guraya <[email protected]>

* fix CI

Signed-off-by: parneet-guraya <[email protected]>

* use suspend function for network calls

Signed-off-by: parneet-guraya <[email protected]>

* doc

* doc

* doc

* doc

* doc

---------

Signed-off-by: parneet-guraya <[email protected]>
Co-authored-by: Nicolas Raoul <[email protected]>
  • Loading branch information
parneet-guraya and nicolas-raoul authored Dec 9, 2024
1 parent 04a07ed commit 85d9aef
Show file tree
Hide file tree
Showing 13 changed files with 2,587 additions and 1,499 deletions.
7 changes: 5 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,14 @@ dependencies {
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'

// Jetpack Compose
def composeBom = platform('androidx.compose:compose-bom:2024.08.00')
def composeBom = platform('androidx.compose:compose-bom:2024.11.00')

implementation "androidx.activity:activity-compose:1.9.1"
implementation "androidx.activity:activity-compose:1.9.3"
implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.8.4"
implementation (composeBom)
implementation "androidx.compose.runtime:runtime"
implementation "androidx.compose.ui:ui"
implementation "androidx.compose.ui:ui-viewbinding"
implementation "androidx.compose.ui:ui-graphics"
implementation "androidx.compose.ui:ui-tooling"
implementation "androidx.compose.foundation:foundation"
Expand Down Expand Up @@ -313,6 +314,7 @@ android {
buildConfigField "String", "SIGNUP_SUCCESS_REDIRECTION_URL", "\"https://commons.m.wikimedia.org/w/index.php?title=Main_Page&welcome=yes\""
buildConfigField "String", "FORGOT_PASSWORD_URL", "\"https://commons.wikimedia.org/wiki/Special:PasswordReset\""
buildConfigField "String", "PRIVACY_POLICY_URL", "\"https://github.com/commons-app/commons-app-documentation/blob/master/android/Privacy-policy.md\""
buildConfigField "String", "FILE_USAGES_BASE_URL", "\"https://commons.wikimedia.org/w/api.php?action=query&format=json&formatversion=2\""
buildConfigField "String", "ACCOUNT_TYPE", "\"fr.free.nrw.commons\""
buildConfigField "String", "CONTRIBUTION_AUTHORITY", "\"fr.free.nrw.commons.contributions.contentprovider\""
buildConfigField "String", "MODIFICATION_AUTHORITY", "\"fr.free.nrw.commons.modifications.contentprovider\""
Expand Down Expand Up @@ -348,6 +350,7 @@ android {
buildConfigField "String", "SIGNUP_SUCCESS_REDIRECTION_URL", "\"https://commons.m.wikimedia.beta.wmflabs.org/w/index.php?title=Main_Page&welcome=yes\""
buildConfigField "String", "FORGOT_PASSWORD_URL", "\"https://commons.wikimedia.beta.wmflabs.org/wiki/Special:PasswordReset\""
buildConfigField "String", "PRIVACY_POLICY_URL", "\"https://github.com/commons-app/commons-app-documentation/blob/master/android/Privacy-policy.md\""
buildConfigField "String", "FILE_USAGES_BASE_URL", "\"https://commons.wikimedia.org/w/api.php?action=query&format=json&formatversion=2\""
buildConfigField "String", "ACCOUNT_TYPE", "\"fr.free.nrw.commons.beta\""
buildConfigField "String", "CONTRIBUTION_AUTHORITY", "\"fr.free.nrw.commons.beta.contributions.contentprovider\""
buildConfigField "String", "MODIFICATION_AUTHORITY", "\"fr.free.nrw.commons.beta.modifications.contentprovider\""
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package fr.free.nrw.commons.fileusages

import com.google.gson.annotations.SerializedName

/**
* Show where file is being used on Commons and oher wikis.
*/
data class FileUsagesResponse(
@SerializedName("continue") val continueResponse: CommonsContinue?,
@SerializedName("batchcomplete") val batchComplete: Boolean,
@SerializedName("query") val query: Query,
)

data class CommonsContinue(
@SerializedName("fucontinue") val fuContinue: String,
@SerializedName("continue") val continueKey: String
)

data class Query(
@SerializedName("pages") val pages: List<Page>
)

data class Page(
@SerializedName("pageid") val pageId: Int,
@SerializedName("ns") val nameSpace: Int,
@SerializedName("title") val title: String,
@SerializedName("fileusage") val fileUsage: List<FileUsage>
)

data class FileUsage(
@SerializedName("pageid") val pageId: Int,
@SerializedName("ns") val nameSpace: Int,
@SerializedName("title") val title: String,
@SerializedName("redirect") val redirect: Boolean
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package fr.free.nrw.commons.fileusages

/**
* Show where file is being used on Commons and oher wikis.
*/
data class FileUsagesUiModel(
val title: String,
val link: String?
)

fun FileUsage.toUiModel(): FileUsagesUiModel {
return FileUsagesUiModel(title = title, link = "https://commons.wikimedia.org/wiki/$title")
}

fun GlobalFileUsage.toUiModel(): FileUsagesUiModel {
// link is associated with sub items under wiki group (which is not used ATM)
return FileUsagesUiModel(title = wiki, link = null)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package fr.free.nrw.commons.fileusages

import com.google.gson.annotations.SerializedName

/**
* Show where file is being used on Commons and oher wikis.
*/
data class GlobalFileUsagesResponse(
@SerializedName("continue") val continueResponse: GlobalContinue?,
@SerializedName("batchcomplete") val batchComplete: Boolean,
@SerializedName("query") val query: GlobalQuery,
)

data class GlobalContinue(
@SerializedName("gucontinue") val guContinue: String,
@SerializedName("continue") val continueKey: String
)

data class GlobalQuery(
@SerializedName("pages") val pages: List<GlobalPage>
)

data class GlobalPage(
@SerializedName("pageid") val pageId: Int,
@SerializedName("ns") val nameSpace: Int,
@SerializedName("title") val title: String,
@SerializedName("globalusage") val fileUsage: List<GlobalFileUsage>
)

data class GlobalFileUsage(
@SerializedName("title") val title: String,
@SerializedName("wiki") val wiki: String,
@SerializedName("url") val url: String
)
Loading

0 comments on commit 85d9aef

Please sign in to comment.