Skip to content

Feature: Show where file is being used on Commons & Other wikis #6006

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
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
Loading