diff --git a/DESCRIPTION b/DESCRIPTION index 8219e5e8abd447985d76bc327e14f015ed2e451c..1d8a7a4740de58283fa7691b5b49ca0bb97f3228 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: mediawikir Type: Package Title: Connects to a mediawiki instance and writes in it what you want -Version: 0.1.3 +Version: 0.1.4 Author: Mathieu Loiseau Maintainer: Mathieu Loiseau <loiseaum@univ-grenoble-alpes.fr> Description: It can be used to post the output of an R script directly into a mediawiki instance diff --git a/R/class.R b/R/class.R index afd7821c165cfce1a156902ca5019e1b295a18dd..1e1c0e9a9dfe70620ee0f75ca1564dfe8663b2f3 100644 --- a/R/class.R +++ b/R/class.R @@ -255,8 +255,7 @@ Batchator <- R6Class("Batchator", public = list( author = NULL, wiki = NULL, - page_prefix ="", - page_names=NULL, + page_name_pattern=NULL, template = NULL, field_list = NULL, content = NULL, @@ -264,10 +263,9 @@ Batchator <- R6Class("Batchator", ###### # initialize ###### - initialize = function (wiki,author,pass,prefix){ + initialize = function (wiki,author,pass){ tryCatch({ self$wiki <- Mediawikir$new(wiki, author, pass) - self$page_prefix <- prefix }, error = function(e){ print(e$message) @@ -287,6 +285,13 @@ Batchator <- R6Class("Batchator", }) }, + ###### + # setPageNamePattern + ###### + setPageNamePattern = function(naming_pattern){ + self$page_name_pattern = naming_pattern + }, + ###### # loadContent ###### @@ -294,7 +299,6 @@ Batchator <- R6Class("Batchator", tryCatch({ csvM <- read.csv(file=file_path, header = FALSE) self$field_list <- as.vector(t(csvM[1,])) - self$page_names <- csvM[-1,1] self$content <- csvM[-1,] }, error = function(e){ @@ -309,17 +313,19 @@ Batchator <- R6Class("Batchator", tryCatch({ if (is.null(self$content) | is.null(self$field_list) | - is.null(self$page_names) | + is.null(self$page_name_pattern) | is.null(self$template)) { - warning("Either no content or no template, use loadContent and/or loadTemplate.") + warning("Either no content or no templates, use loadContent, setPageNamePattern and/or loadTemplate.") } else{ for(i in 1:nrow(self$content)){ self$wiki$resetContent(str_replace_all(self$template, setNames(as.vector(t(self$content[i,])), self$field_list))) - self$wiki$setPage(paste(self$page_prefix,self$page_names[i],sep = "")) - #self$wiki$postContent() + self$wiki$setPage(str_replace_all(self$page_name_pattern, + setNames(as.vector(t(self$content[i,])), + self$field_list))) + self$wiki$postContent() } } },