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
545013f4
Commit
545013f4
authored
6 years ago
by
Mathieu Loiseau
Browse files
Options
Downloads
Patches
Plain Diff
Set page by title or id
parent
33c5b676
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
DESCRIPTION
+3
-3
3 additions, 3 deletions
DESCRIPTION
R/class.R
+46
-23
46 additions, 23 deletions
R/class.R
man/Mediawikir.Rd
+5
-5
5 additions, 5 deletions
man/Mediawikir.Rd
with
54 additions
and
31 deletions
DESCRIPTION
+
3
−
3
View file @
545013f4
Package:
m
ediawikir
Package:
M
ediawikir
Type: Package
Title: Connects to a mediawiki instance and writes in it what you want
Version: 0.1.
6
Version: 0.1.
7
Author: Mathieu Loiseau
Maintainer: Mathieu Loiseau <loiseaum@univ-grenoble-alpes.fr>
Description: Mediawikir class can be used to post the output of an R script directly into a mediawiki instance. Batchator class allows batch page creation.
License: MIT
Encoding: UTF-8
LazyData: true
RoxygenNote: 6.
0
.1
RoxygenNote: 6.
1
.1
Imports: httr,R6,stringr
This diff is collapsed.
Click to expand it.
R/class.R
+
46
−
23
View file @
545013f4
...
...
@@ -18,8 +18,8 @@ library(stringr)
#'@return Object of \code{\link{R6Class}} with methods to interact with mediawiki instance
#'@field url the mediawiki instance base url
#'@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 content the future content of \code{page
_name
}, which will be incrementally constructed using object methods
#'@field page the page
(name or id)
which will be modified (including its namespace
, if the name is provided
)
#'@field content the future content of \code{page}, which will be incrementally constructed using object methods
#'@field user_name the user to credit for the changes
#'@examples
#' mwHandler <- Mediawikir$new("http://my.wiki.org", "reg_user", "mypassword")
...
...
@@ -38,9 +38,9 @@ library(stringr)
#' \item{\code{user}}{The screen name of the user who will be credited for the changes in the wiki}
#' \item{\code{pass}}{The user's password}
#' }}
#' \item{\code{setPage(pageName)}}{To set the page for the next post
#' \item{\code{setPage(pageName
OrId
)}}{To set the page for the next post
#' \describe{
#' \item{\code{pageName}}{The name of the wiki page which contains the changes}
#' \item{\code{pageName
OrId
}}{The name
(or id)
of the wiki page which contains the changes}
#' }}
#' \item{\code{connect(pass)}}{Should not be called directly (see initialize for detail)}
#' \item{\code{resetContent(baseContent="")}}{To reset the content of the page for the next post
...
...
@@ -58,7 +58,7 @@ library(stringr)
#' \item{\code{h5} → Level 5 title}{}
#' }}
#' }}
#' \item{\code{postContent()}}{To replace the content of \code{page
_name
} with \code{content}}
#' \item{\code{postContent()}}{To replace the content of \code{page} 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}
...
...
@@ -71,7 +71,7 @@ Mediawikir <- R6Class("Mediawikir",
url
=
NULL
,
user_name
=
NULL
,
auth_token
=
NULL
,
page
_name
=
""
,
page
=
""
,
content
=
""
,
connect
=
function
(
pass
){
token
<-
1
...
...
@@ -130,8 +130,8 @@ Mediawikir <- R6Class("Mediawikir",
######
# setPage
######
setPage
=
function
(
pageName
){
self
$
page
_name
<-
pageName
setPage
=
function
(
pageName
OrId
){
self
$
page
<-
pageName
OrId
},
######
...
...
@@ -162,33 +162,56 @@ Mediawikir <- R6Class("Mediawikir",
success
<-
TRUE
tryCatch
(
{
#Verify that a page has been selected
if
(
self
$
page
_name
==
""
){
if
(
self
$
page
==
""
){
warning
(
"No page to write to, use “setPage” method before calling “postContent”."
)
}
else
{
if
(
is.character
(
self
$
page
)){
fields
<-
list
(
action
=
"query"
,
prop
=
"info|revisions"
,
meta
=
"tokens"
,
rvprop
=
"timestamp"
,
titles
=
self
$
page
,
format
=
"json"
)
}
else
{
fields
<-
list
(
action
=
"query"
,
prop
=
"info|revisions"
,
meta
=
"tokens"
,
rvprop
=
"timestamp"
,
pageids
=
self
$
page
,
format
=
"json"
)
}
#get edit token
query
<-
httr
::
POST
(
self
$
url
,
body
=
list
(
action
=
"query"
,
prop
=
"info|revisions"
,
meta
=
"tokens"
,
rvprop
=
"timestamp"
,
titles
=
self
$
page_name
,
format
=
"json"
))
body
=
fields
)
httr
::
stop_for_status
(
query
)
response
<-
httr
::
content
(
query
,
"parsed"
,
"application/json"
)
#perform edit
if
(
is.character
(
self
$
page
)){
fields
<-
list
(
action
=
"edit"
,
title
=
self
$
page
,
#basetimestamp = "TODO",
summary
=
"R generated content"
,
format
=
"json"
,
text
=
self
$
content
,
token
=
response
$
query
$
tokens
$
csrftoken
)
}
else
{
fields
<-
list
(
action
=
"edit"
,
pageid
=
self
$
page
,
#basetimestamp = "TODO",
summary
=
"R generated content"
,
format
=
"json"
,
text
=
self
$
content
,
token
=
response
$
query
$
tokens
$
csrftoken
)
}
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
))
body
=
fields
)
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
))
stop
(
paste
(
"Failed to edit "
,
self
$
page
,
"\n"
,
response
))
}
}
},
...
...
This diff is collapsed.
Click to expand it.
man/Mediawikir.Rd
+
5
−
5
View file @
545013f4
...
...
@@ -21,9 +21,9 @@ A Mediawikir controller serves to connect to a mediawiki API as a registered use
\item{\code{auth_token}}{the current token used to edit the wiki (cf. https://www.mediawiki.org/wiki/Manual:Edit_token)}
\item{\code{page
_name
}}{the page which will be modified (including its namespace)}
\item{\code{page}}{the page
(name or id)
which will be modified (including its namespace
, if the name is provided
)}
\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}, which will be incrementally constructed using object methods}
\item{\code{user_name}}{the user to credit for the changes}
}}
...
...
@@ -37,9 +37,9 @@ A Mediawikir controller serves to connect to a mediawiki API as a registered use
\item{\code{user}}{The screen name of the user who will be credited for the changes in the wiki}
\item{\code{pass}}{The user's password}
}}
\item{\code{setPage(pageName)}}{To set the page for the next post
\item{\code{setPage(pageName
OrId
)}}{To set the page for the next post
\describe{
\item{\code{pageName}}{The name of the wiki page which contains the changes}
\item{\code{pageName
OrId
}}{The name
(or id)
of the wiki page which contains the changes}
}}
\item{\code{connect(pass)}}{Should not be called directly (see initialize for detail)}
\item{\code{resetContent(baseContent="")}}{To reset the content of the page for the next post
...
...
@@ -57,7 +57,7 @@ A Mediawikir controller serves to connect to a mediawiki API as a registered use
\item{\code{h5} → Level 5 title}{}
}}
}}
\item{\code{postContent()}}{To replace the content of \code{page
_name
} with \code{content}}
\item{\code{postContent()}}{To replace the content of \code{page} 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}
...
...
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