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
64af7977
Commit
64af7977
authored
7 years ago
by
Mathieu Loiseau
Browse files
Options
Downloads
Patches
Plain Diff
Post content to mediawiki
parent
0b0f5c01
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
+44
-2
44 additions, 2 deletions
R/class.R
man/Mediawikir.Rd
+2
-0
2 additions, 0 deletions
man/Mediawikir.Rd
with
46 additions
and
2 deletions
R/class.R
+
44
−
2
View file @
64af7977
...
@@ -16,11 +16,13 @@ library(R6)
...
@@ -16,11 +16,13 @@ library(R6)
#'@field auth_token the current token used to edit the wiki (cf. https://www.mediawiki.org/wiki/Manual:Edit_token)
#'@field auth_token the current token used to edit the wiki (cf. https://www.mediawiki.org/wiki/Manual:Edit_token)
#'@field page_name the page which will be modified (including its namespace)
#'@field page_name the page which will be modified (including its namespace)
#'@field content the future content of \code{page_name}, which will be incrementally constructed using object methods
#'@field content the future content of \code{page_name}, which will be incrementally constructed using object methods
#'@field user_name the user to credit for the changes
#'@examples
#'@examples
#' mwHandler <- Mediawikir$new("http://my.wiki.org", "reg_user", "mypassword", "wikiPage")
#' mwHandler <- Mediawikir$new("http://my.wiki.org", "reg_user", "mypassword", "wikiPage")
#' 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$postContent()
#'@section Methods:
#'@section Methods:
#'\describe{
#'\describe{
#' \item{\code{initialize(instance_url, user, page, pass)}}{Creates a new Mediawikir object out of:
#' \item{\code{initialize(instance_url, user, page, pass)}}{Creates a new Mediawikir object out of:
...
@@ -42,6 +44,7 @@ library(R6)
...
@@ -42,6 +44,7 @@ library(R6)
#' \item{\code{h5} → Level 5 title}{}
#' \item{\code{h5} → Level 5 title}{}
#' }}
#' }}
#' }}
#' }}
#' \item{\code{postContent()}}{To replace the content of \code{page_name} with \code{content}}
#'}
#'}
Mediawikir
<-
R6Class
(
"Mediawikir"
,
Mediawikir
<-
R6Class
(
"Mediawikir"
,
public
=
list
(
public
=
list
(
...
@@ -84,7 +87,7 @@ Mediawikir <- R6Class("Mediawikir",
...
@@ -84,7 +87,7 @@ Mediawikir <- R6Class("Mediawikir",
},
},
error
=
function
(
e
)
error
=
function
(
e
)
{
{
print
(
paste
(
"Could not login
to"
,
self
$
url
,
e
$
message
))
print
(
paste
(
"Could not login
"
,
self
$
user_name
,
"
to"
,
self
$
url
,
e
$
message
))
token
<-
0
token
<-
0
}
}
)
)
...
@@ -116,9 +119,48 @@ Mediawikir <- R6Class("Mediawikir",
...
@@ -116,9 +119,48 @@ Mediawikir <- R6Class("Mediawikir",
h3
=
theContent
<-
paste
(
"==="
,
theContent
,
"==="
),
h3
=
theContent
<-
paste
(
"==="
,
theContent
,
"==="
),
h4
=
theContent
<-
paste
(
"===="
,
theContent
,
"===="
),
h4
=
theContent
<-
paste
(
"===="
,
theContent
,
"===="
),
h5
=
theContent
<-
paste
(
"====="
,
theContent
,
"====="
),
h5
=
theContent
<-
paste
(
"====="
,
theContent
,
"====="
),
p
=
theContent
<-
paste
(
theContent
,
"\n"
,
sep
=
""
)
,
p
=
theContent
<-
paste
(
theContent
,
"\n"
,
sep
=
""
)
)
)
self
$
content
<-
paste
(
self
$
content
,
theContent
,
sep
=
"\n"
)
self
$
content
<-
paste
(
self
$
content
,
theContent
,
sep
=
"\n"
)
},
######
# postContent
######
postContent
=
function
(){
success
<-
TRUE
tryCatch
(
{
#get edit token
query
<-
httr
::
POST
(
self
$
url
,
body
=
list
(
action
=
"query"
,
prop
=
"info|revisions"
,
#intoken = "edit",
meta
=
"tokens"
,
rvprop
=
"timestamp"
,
titles
=
self
$
page_name
,
format
=
"json"
))
httr
::
stop_for_status
(
query
)
response
<-
httr
::
content
(
query
,
"parsed"
,
"application/json"
)
#perform edit
query
<-
httr
::
POST
(
self
$
url
,
body
=
list
(
action
=
"edit"
,
title
=
self
$
page_name
,
#basetimestamp = "TODO",
summary
=
"R generated content"
,
format
=
"json"
,
text
=
self
$
content
,
token
=
response
$
query
$
tokens
$
csrftoken
))
httr
::
stop_for_status
(
query
)
response
<-
httr
::
content
(
query
,
"parsed"
,
"application/json"
)
if
(
response
$
edit
$
result
!=
"Success"
){
stop
(
paste
(
"Failed to edit "
,
self
$
page_name
,
"\n"
,
response
))
}
},
error
=
function
(
e
){
print
(
e
$
message
)
success
<-
FALSE
})
return
(
success
)
}
}
)
)
)
)
This diff is collapsed.
Click to expand it.
man/Mediawikir.Rd
+
2
−
0
View file @
64af7977
...
@@ -48,6 +48,7 @@ A Mediawikir controller serves to connect to a mediawiki API as a registered use
...
@@ -48,6 +48,7 @@ A Mediawikir controller serves to connect to a mediawiki API as a registered use
\item{\code{h5} → Level 5 title}{}
\item{\code{h5} → Level 5 title}{}
}}
}}
}}
}}
\item{\code{postContent()}}{To replace the content of \code{page_name} with \code{content}}
}
}
}
}
...
@@ -56,5 +57,6 @@ A Mediawikir controller serves to connect to a mediawiki API as a registered use
...
@@ -56,5 +57,6 @@ 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$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