From 000c14cd19094b72cb9e1c53fd4e5c24e9df5922 Mon Sep 17 00:00:00 2001
From: Mathieu Loiseau <mathieu.loiseau@univ-grenoble-alpes.fr>
Date: Fri, 7 Dec 2018 19:21:27 +0100
Subject: [PATCH] with page name pattern using csv columns

---
 DESCRIPTION |  2 +-
 R/class.R   | 24 +++++++++++++++---------
 2 files changed, 16 insertions(+), 10 deletions(-)

diff --git a/DESCRIPTION b/DESCRIPTION
index 8219e5e..1d8a7a4 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 afd7821..1e1c0e9 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()
           }
         }
       },
-- 
GitLab