Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
mediawikiR
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Mathieu Loiseau
mediawikiR
Commits
34ea860c
Commit
34ea860c
authored
7 years ago
by
Mathieu Loiseau
Browse files
Options
Downloads
Patches
Plain Diff
file upload
parent
64af7977
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
R/class.R
+52
-4
52 additions, 4 deletions
R/class.R
man/Mediawikir.Rd
+9
-0
9 additions, 0 deletions
man/Mediawikir.Rd
with
61 additions
and
4 deletions
R/class.R
+
52
−
4
View file @
34ea860c
...
@@ -22,6 +22,7 @@ library(R6)
...
@@ -22,6 +22,7 @@ library(R6)
#' mwHandler$addContent("This is an introduction to Mediawikir")
#' mwHandler$addContent("This is an introduction to Mediawikir")
#' mwHandler$addContent("First step","h2")
#' mwHandler$addContent("First step","h2")
#' mwHandler$addContent("First step of the first step","h3")
#' mwHandler$addContent("First step of the first step","h3")
#' mwHandler$uploadFile("path/toFile.png","My beautiful image.png")
#' mwHandler$postContent()
#' mwHandler$postContent()
#'@section Methods:
#'@section Methods:
#'\describe{
#'\describe{
...
@@ -45,6 +46,12 @@ library(R6)
...
@@ -45,6 +46,12 @@ library(R6)
#' }}
#' }}
#' }}
#' }}
#' \item{\code{postContent()}}{To replace the content of \code{page_name} with \code{content}}
#' \item{\code{postContent()}}{To replace the content of \code{page_name} with \code{content}}
#' \item{\code{uploadFile(file_path, file_name)}}{To upload a file to the server (will overwrite existing files)
#' \describe{
#' \item{\code{file_path}}{Path to the file to upload to the server}
#' \item{\code{file_name}}{Name under which to store it}
#' \item{Returns the title of the wiki page containing the file or \code{FALSE} on error}{}
#' }}
#'}
#'}
Mediawikir
<-
R6Class
(
"Mediawikir"
,
Mediawikir
<-
R6Class
(
"Mediawikir"
,
public
=
list
(
public
=
list
(
...
@@ -54,6 +61,7 @@ Mediawikir <- R6Class("Mediawikir",
...
@@ -54,6 +61,7 @@ Mediawikir <- R6Class("Mediawikir",
page_name
=
NULL
,
page_name
=
NULL
,
content
=
""
,
content
=
""
,
connect
=
function
(
pass
){
connect
=
function
(
pass
){
token
<-
1
"une super méthode"
"une super méthode"
tryCatch
(
tryCatch
(
{
#get login token
{
#get login token
...
@@ -81,9 +89,6 @@ Mediawikir <- R6Class("Mediawikir",
...
@@ -81,9 +89,6 @@ Mediawikir <- R6Class("Mediawikir",
if
(
response
$
clientlogin
$
status
!=
"PASS"
){
if
(
response
$
clientlogin
$
status
!=
"PASS"
){
stop
(
paste
(
response
$
clientlogin
,
"\n"
))
stop
(
paste
(
response
$
clientlogin
,
"\n"
))
}
}
else
{
return
(
token
)
}
},
},
error
=
function
(
e
)
error
=
function
(
e
)
{
{
...
@@ -134,7 +139,6 @@ Mediawikir <- R6Class("Mediawikir",
...
@@ -134,7 +139,6 @@ Mediawikir <- R6Class("Mediawikir",
query
<-
httr
::
POST
(
self
$
url
,
query
<-
httr
::
POST
(
self
$
url
,
body
=
list
(
action
=
"query"
,
body
=
list
(
action
=
"query"
,
prop
=
"info|revisions"
,
prop
=
"info|revisions"
,
#intoken = "edit",
meta
=
"tokens"
,
meta
=
"tokens"
,
rvprop
=
"timestamp"
,
rvprop
=
"timestamp"
,
titles
=
self
$
page_name
,
titles
=
self
$
page_name
,
...
@@ -161,6 +165,50 @@ Mediawikir <- R6Class("Mediawikir",
...
@@ -161,6 +165,50 @@ Mediawikir <- R6Class("Mediawikir",
success
<-
FALSE
success
<-
FALSE
})
})
return
(
success
)
return
(
success
)
},
######
# uploadFile
######
uploadFile
=
function
(
file_path
,
file_name
){
success
<-
TRUE
tryCatch
(
{
#get edit token
query
<-
httr
::
POST
(
self
$
url
,
body
=
list
(
action
=
"query"
,
prop
=
"info|revisions"
,
meta
=
"tokens"
,
rvprop
=
"timestamp"
,
titles
=
paste
(
"file:"
,
file_name
,
sep
=
""
),
format
=
"json"
))
httr
::
stop_for_status
(
query
)
response
<-
httr
::
content
(
query
,
"parsed"
,
"application/json"
)
#perform edit
the_file
<-
upload_file
(
file_path
)
query
<-
httr
::
POST
(
self
$
url
,
body
=
list
(
action
=
"upload"
,
filename
=
file_name
,
comment
=
"R generated content"
,
format
=
"json"
,
ignorewarnings
=
1
,
file
=
the_file
,
token
=
response
$
query
$
tokens
$
csrftoken
,
ignorewarnings
=
1
),
encode
=
"multipart"
)
httr
::
stop_for_status
(
query
)
response
<-
httr
::
content
(
query
,
"parsed"
,
"application/json"
)
if
(
response
$
upload
$
result
!=
"Success"
){
stop
(
paste
(
"Failed to upload "
,
file_path
,
"\n"
,
response
))
}
else
{
success
<-
paste
(
"File:"
,
file_name
,
sep
=
""
)
}
},
error
=
function
(
e
){
print
(
e
$
message
)
success
<-
FALSE
})
return
(
success
)
}
}
)
)
)
)
This diff is collapsed.
Click to expand it.
man/Mediawikir.Rd
+
9
−
0
View file @
34ea860c
...
@@ -24,6 +24,8 @@ A Mediawikir controller serves to connect to a mediawiki API as a registered use
...
@@ -24,6 +24,8 @@ A Mediawikir controller serves to connect to a mediawiki API as a registered use
\item{\code{page_name}}{the page which will be modified (including its namespace)}
\item{\code{page_name}}{the page which will be modified (including its namespace)}
\item{\code{content}}{the future content of \code{page_name}, which will be incrementally constructed using object methods}
\item{\code{content}}{the future content of \code{page_name}, which will be incrementally constructed using object methods}
\item{\code{user_name}}{the user to credit for the changes}
}}
}}
\section{Methods}{
\section{Methods}{
...
@@ -49,6 +51,12 @@ A Mediawikir controller serves to connect to a mediawiki API as a registered use
...
@@ -49,6 +51,12 @@ A Mediawikir controller serves to connect to a mediawiki API as a registered use
}}
}}
}}
}}
\item{\code{postContent()}}{To replace the content of \code{page_name} with \code{content}}
\item{\code{postContent()}}{To replace the content of \code{page_name} with \code{content}}
\item{\code{uploadFile(file_path, file_name)}}{To upload a file to the server (will overwrite existing files)
\describe{
\item{\code{file_path}}{Path to the file to upload to the server}
\item{\code{file_name}}{Name under which to store it}
\item{Returns the title of the wiki page containing the file or \code{FALSE} on error}{}
}}
}
}
}
}
...
@@ -57,6 +65,7 @@ A Mediawikir controller serves to connect to a mediawiki API as a registered use
...
@@ -57,6 +65,7 @@ A Mediawikir controller serves to connect to a mediawiki API as a registered use
mwHandler$addContent("This is an introduction to Mediawikir")
mwHandler$addContent("This is an introduction to Mediawikir")
mwHandler$addContent("First step","h2")
mwHandler$addContent("First step","h2")
mwHandler$addContent("First step of the first step","h3")
mwHandler$addContent("First step of the first step","h3")
mwHandler$uploadFile("path/toFile.png","My beautiful image.png")
mwHandler$postContent()
mwHandler$postContent()
}
}
\keyword{mediawiki}
\keyword{mediawiki}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment