mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-29 13:53:54 +01:00
Added Wikitalk Page (#5740)
* Added wikitalk page and improved bottomsheet for landscape mode * Improved wikitalk page * Fixed italics * Fixed little bug * Improved the wiki talk page * . * changed commons url to wikidata url * changed commons url to wikidata url + 1 * fixed bookmark issue * Added kdoc and javadoc --------- Co-authored-by: Nicolas Raoul <nicolas.raoul@gmail.com>
This commit is contained in:
parent
36905711d0
commit
3779cfb6a5
16 changed files with 1142 additions and 545 deletions
|
|
@ -4,6 +4,7 @@ import fr.free.nrw.commons.auth.csrf.InvalidLoginTokenException
|
|||
import io.reactivex.Observable
|
||||
import io.reactivex.Single
|
||||
import fr.free.nrw.commons.auth.csrf.CsrfTokenClient
|
||||
import timber.log.Timber
|
||||
|
||||
/**
|
||||
* This class acts as a Client to facilitate wiki page editing
|
||||
|
|
@ -27,7 +28,41 @@ class PageEditClient(
|
|||
fun edit(pageTitle: String, text: String, summary: String): Observable<Boolean> {
|
||||
return try {
|
||||
pageEditInterface.postEdit(pageTitle, summary, text, csrfTokenClient.getTokenBlocking())
|
||||
.map { editResponse -> editResponse.edit()!!.editSucceeded() }
|
||||
.map { editResponse ->
|
||||
editResponse.edit()!!.editSucceeded()
|
||||
}
|
||||
} catch (throwable: Throwable) {
|
||||
if (throwable is InvalidLoginTokenException) {
|
||||
throw throwable
|
||||
} else {
|
||||
Observable.just(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new page with the given title, text, and summary.
|
||||
*
|
||||
* @param pageTitle The title of the page to be created.
|
||||
* @param text The content of the page in wikitext format.
|
||||
* @param summary The edit summary for the page creation.
|
||||
* @return An observable that emits true if the page creation succeeded, false otherwise.
|
||||
* @throws InvalidLoginTokenException If an invalid login token is encountered during the process.
|
||||
*/
|
||||
fun postCreate(pageTitle: String, text: String, summary: String): Observable<Boolean> {
|
||||
return try {
|
||||
pageEditInterface.postCreate(
|
||||
pageTitle,
|
||||
summary,
|
||||
text,
|
||||
"text/x-wiki",
|
||||
"wikitext",
|
||||
true,
|
||||
true,
|
||||
csrfTokenClient.getTokenBlocking()
|
||||
).map { editResponse ->
|
||||
editResponse.edit()!!.editSucceeded()
|
||||
}
|
||||
} catch (throwable: Throwable) {
|
||||
if (throwable is InvalidLoginTokenException) {
|
||||
throw throwable
|
||||
|
|
|
|||
|
|
@ -36,6 +36,33 @@ interface PageEditInterface {
|
|||
@Field("token") token: String
|
||||
): Observable<Edit>
|
||||
|
||||
/**
|
||||
* This method creates or edits a page for nearby items.
|
||||
*
|
||||
* @param title Title of the page to edit. Cannot be used together with pageid.
|
||||
* @param summary Edit summary. Also used as the section title when section=new and sectiontitle is not set.
|
||||
* @param text Text of the page.
|
||||
* @param contentformat Format of the content (e.g., "text/x-wiki").
|
||||
* @param contentmodel Model of the content (e.g., "wikitext").
|
||||
* @param minor Whether the edit is a minor edit.
|
||||
* @param recreate Whether to recreate the page if it does not exist.
|
||||
* @param token A "csrf" token. This should always be sent as the last field of form data.
|
||||
*/
|
||||
@FormUrlEncoded
|
||||
@Headers("Cache-Control: no-cache")
|
||||
@POST(MW_API_PREFIX + "action=edit")
|
||||
fun postCreate(
|
||||
@Field("title") title: String,
|
||||
@Field("summary") summary: String,
|
||||
@Field("text") text: String,
|
||||
@Field("contentformat") contentformat: String,
|
||||
@Field("contentmodel") contentmodel: String,
|
||||
@Field("minor") minor: Boolean,
|
||||
@Field("recreate") recreate: Boolean,
|
||||
// NOTE: This csrf shold always be sent as the last field of form data
|
||||
@Field("token") token: String
|
||||
): Observable<Edit>
|
||||
|
||||
/**
|
||||
* This method posts such that the Content which the page
|
||||
* has will be appended with the value being passed to the
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue