Skip to content
Snippets Groups Projects
Commit 6b864561 authored by Mathieu Loiseau's avatar Mathieu Loiseau
Browse files

0.1.11 w/ config with install dir

parent 9fd7fdb1
No related branches found
No related tags found
No related merge requests found
Package: Mediawikir
Type: Package
Title: Connects to a mediawiki instance and writes in it what you want
Version: 0.1.10
Version: 0.1.11
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.1.1
RoxygenNote: 7.0.2
Imports: httr,R6,stringr
MIT License
Copyright (c) 2018 Mathieu Loiseau
Copyright (c) 2020 Mathieu Loiseau
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
......
......@@ -40,7 +40,9 @@ library(stringr)
#' \item{\code{instance_url}}{The base url to the mediawiki instance}
#' \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{dir}}{In case of \href{https://www.mediawiki.org/wiki/Manual:Short_URL}{short Url configuration},
#' the base url for mediawiki is not the actual directory containing the api and index.php files. In these cases,
#' the user should specify the installation directory of mediawiki from the base_url.}
#' \item{\code{setPage(pageNameOrId)}}{To set the page for the next post
#' \describe{
#' \item{\code{pageNameOrId}}{The name (or id) of the wiki page which contains the changes}
......@@ -134,10 +136,15 @@ Mediawikir <- R6Class("Mediawikir",
######
# initialize
######
initialize = function (instance_url, user, pass){
initialize = function (instance_url, user, pass, dir=""){
tryCatch({
self$base_url <- instance_url
self$api <- paste(instance_url,"/","api.php",sep="")
if(dir !=""){
self$extra_sep <- paste(instance_url,"/",dir ,sep="")
}
else{
self$base_url <- instance_url
}
self$api <- paste(self$base_url,"/","api.php",sep="")
self$user_name <- user
self$auth_token <- self$connect(pass)
},
......@@ -396,6 +403,7 @@ Mediawikir <- R6Class("Mediawikir",
#' \item{\code{wiki}}{The base url to the mediawiki instance}
#' \item{\code{authr}}{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{dir}}{The installation directory of mediawiki, if needed}
#' }}
#' \item{\code{loadTemplate(file_path)}}{Takes the path of a text file containing a template that will serve as base
#' for all the pages generated. The template should contain occurrences of the fields defined in the content file.}
......@@ -424,9 +432,9 @@ Batchator <- R6Class("Batchator",
######
# initialize
######
initialize = function (wiki,author,pass){
initialize = function (wiki,author,pass,dir=""){
tryCatch({
self$wiki <- Mediawikir$new(wiki, author, pass)
self$wiki <- Mediawikir$new(wiki, author, pass, dir)
},
error = function(e){
print(e$message)
......@@ -539,6 +547,9 @@ Batchator <- R6Class("Batchator",
self$wiki$setPage(pageId)
print(paste("processing page '",pageId,"' (",pageIdType,")", sep=""))#/**/
for(j in 2:length(field_list)){
#self$wiki$addContent("test") #debug
#test = self$wiki$postContent() #debug
#print(test) #debug
success = self$wiki$replaceSingleLineTemplateField(toString(field_list[j]),toString(rows[i,j]))
print(paste("new value : |",field_list[j],"=",rows[i,j]," → ",success,sep=""))
}
......
......@@ -5,31 +5,12 @@
\alias{Batchator}
\title{Batchator: Batch input to mediawiki based on a csv and a template}
\format{An \code{\link{R6Class}} generator object}
\usage{
Batchator
}
\value{
Object of \code{\link{R6Class}} with methods to interact with mediawiki instance
}
\description{
Uses \link{Mediawikir} to create/edit a batch of mediawiki pages
}
\section{Fields}{
\describe{
\item{\code{author}}{the mediawiki user who will be the author of the pages/modifications}
\item{\code{wiki}}{a mediawikir object}
\item{\code{page_name_pattern}}{a pattern to name the pages generated}
\item{\code{template}}{the content of a text file with the template for the wikitext of the pages to create in a batch}
\item{\code{field_list}}{the list of symbols that will be replaced (the first line of the csv file that will be sent to the Batchator)}
\item{\code{content}}{a matrix of the words that will replace the symbols in the templates (both content and page names — the next lines of the csv file)}
}}
\section{Methods}{
\describe{
......@@ -38,6 +19,7 @@ Uses \link{Mediawikir} to create/edit a batch of mediawiki pages
\item{\code{wiki}}{The base url to the mediawiki instance}
\item{\code{authr}}{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{dir}}{The installation directory of mediawiki, if needed}
}}
\item{\code{loadTemplate(file_path)}}{Takes the path of a text file containing a template that will serve as base
for all the pages generated. The template should contain occurrences of the fields defined in the content file.}
......@@ -82,3 +64,97 @@ Uses \link{Mediawikir} to create/edit a batch of mediawiki pages
#"Help:full/page/Name","New value for att1","New value for att2"
}
\keyword{mediawiki}
\section{Public fields}{
\if{html}{\out{<div class="r6-fields">}}
\describe{
\item{\code{author}}{the mediawiki user who will be the author of the pages/modifications}
\item{\code{wiki}}{a mediawikir object}
\item{\code{page_name_pattern}}{a pattern to name the pages generated}
\item{\code{template}}{the content of a text file with the template for the wikitext of the pages to create in a batch}
\item{\code{field_list}}{the list of symbols that will be replaced (the first line of the csv file that will be sent to the Batchator)}
\item{\code{content}}{a matrix of the words that will replace the symbols in the templates (both content and page names — the next lines of the csv file)}
}
\if{html}{\out{</div>}}
}
\section{Methods}{
\subsection{Public methods}{
\itemize{
\item \href{#method-new}{\code{Batchator$new()}}
\item \href{#method-loadTemplate}{\code{Batchator$loadTemplate()}}
\item \href{#method-setPageNamePattern}{\code{Batchator$setPageNamePattern()}}
\item \href{#method-loadContent}{\code{Batchator$loadContent()}}
\item \href{#method-applyTemplate}{\code{Batchator$applyTemplate()}}
\item \href{#method-modifyWikiTemplateAttributes}{\code{Batchator$modifyWikiTemplateAttributes()}}
\item \href{#method-clone}{\code{Batchator$clone()}}
}
}
\if{html}{\out{<hr>}}
\if{html}{\out{<a id="method-new"></a>}}
\subsection{Method \code{new()}}{
\subsection{Usage}{
\if{html}{\out{<div class="r">}}\preformatted{Batchator$new(wiki, author, pass, dir = "")}\if{html}{\out{</div>}}
}
}
\if{html}{\out{<hr>}}
\if{html}{\out{<a id="method-loadTemplate"></a>}}
\subsection{Method \code{loadTemplate()}}{
\subsection{Usage}{
\if{html}{\out{<div class="r">}}\preformatted{Batchator$loadTemplate(file_path)}\if{html}{\out{</div>}}
}
}
\if{html}{\out{<hr>}}
\if{html}{\out{<a id="method-setPageNamePattern"></a>}}
\subsection{Method \code{setPageNamePattern()}}{
\subsection{Usage}{
\if{html}{\out{<div class="r">}}\preformatted{Batchator$setPageNamePattern(naming_pattern)}\if{html}{\out{</div>}}
}
}
\if{html}{\out{<hr>}}
\if{html}{\out{<a id="method-loadContent"></a>}}
\subsection{Method \code{loadContent()}}{
\subsection{Usage}{
\if{html}{\out{<div class="r">}}\preformatted{Batchator$loadContent(file_path)}\if{html}{\out{</div>}}
}
}
\if{html}{\out{<hr>}}
\if{html}{\out{<a id="method-applyTemplate"></a>}}
\subsection{Method \code{applyTemplate()}}{
\subsection{Usage}{
\if{html}{\out{<div class="r">}}\preformatted{Batchator$applyTemplate()}\if{html}{\out{</div>}}
}
}
\if{html}{\out{<hr>}}
\if{html}{\out{<a id="method-modifyWikiTemplateAttributes"></a>}}
\subsection{Method \code{modifyWikiTemplateAttributes()}}{
\subsection{Usage}{
\if{html}{\out{<div class="r">}}\preformatted{Batchator$modifyWikiTemplateAttributes(file_path)}\if{html}{\out{</div>}}
}
}
\if{html}{\out{<hr>}}
\if{html}{\out{<a id="method-clone"></a>}}
\subsection{Method \code{clone()}}{
The objects of this class are cloneable with this method.
\subsection{Usage}{
\if{html}{\out{<div class="r">}}\preformatted{Batchator$clone(deep = FALSE)}\if{html}{\out{</div>}}
}
\subsection{Arguments}{
\if{html}{\out{<div class="arguments">}}
\describe{
\item{\code{deep}}{Whether to make a deep clone.}
}
\if{html}{\out{</div>}}
}
}
}
......@@ -5,17 +5,30 @@
\alias{Mediawikir}
\title{Mediawikir: write R output to mediawiki}
\format{An \code{\link{R6Class}} generator object}
\usage{
Mediawikir
}
\value{
Object of \code{\link{R6Class}} with methods to interact with mediawiki instance
}
\description{
A Mediawikir controller serves to connect to a mediawiki API as a registered user in order to edit automatically certain documents based on R scripts
}
\section{Fields}{
\section{}{
NA
}
\examples{
mwHandler <- Mediawikir$new("http://my.wiki.org", "reg_user", "mypassword")
mwHandler$setPage("wikiPage")
mwHandler$addContent("This is an introduction to Mediawikir")
mwHandler$addContent("First step","h2")
mwHandler$addContent("First step of the first step","h3")
fileName <- mwHandler$uploadFile("path/toFile.png","My beautiful image.png")
mwHandler$addContent(paste("[[",fileName,"]]",sep=""))
mwHandler$postContent()
mwHandler$replaceSingleLineTemplateField("attribute", "newValue")
}
\keyword{mediawiki}
\section{Public fields}{
\if{html}{\out{<div class="r6-fields">}}
\describe{
\item{\code{base_url}}{the mediawiki instance base url}
......@@ -28,71 +41,114 @@ A Mediawikir controller serves to connect to a mediawiki API as a registered use
\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}
}}
}
\if{html}{\out{</div>}}
}
\section{Methods}{
\subsection{Public methods}{
\itemize{
\item \href{#method-connect}{\code{Mediawikir$connect()}}
\item \href{#method-new}{\code{Mediawikir$new()}}
\item \href{#method-setPage}{\code{Mediawikir$setPage()}}
\item \href{#method-resetContent}{\code{Mediawikir$resetContent()}}
\item \href{#method-addContent}{\code{Mediawikir$addContent()}}
\item \href{#method-postContent}{\code{Mediawikir$postContent()}}
\item \href{#method-getContent}{\code{Mediawikir$getContent()}}
\item \href{#method-replaceSingleLineTemplateField}{\code{Mediawikir$replaceSingleLineTemplateField()}}
\item \href{#method-uploadFile}{\code{Mediawikir$uploadFile()}}
\item \href{#method-clone}{\code{Mediawikir$clone()}}
}
}
\if{html}{\out{<hr>}}
\if{html}{\out{<a id="method-connect"></a>}}
\subsection{Method \code{connect()}}{
\subsection{Usage}{
\if{html}{\out{<div class="r">}}\preformatted{Mediawikir$connect(pass)}\if{html}{\out{</div>}}
}
\describe{
\item{\code{initialize(instance_url, user, pass)}}{Creates a new \pkg{Mediawikir} object out of:
\describe{
\item{\code{instance_url}}{The base url to the mediawiki instance}
\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(pageNameOrId)}}{To set the page for the next post
\describe{
\item{\code{pageNameOrId}}{The name (or id) of the wiki page which contains the changes}
}}
\item{\code{connect(pass)}}{Should not be called directly (see \code{initialize} for detail)}
\item{\code{resetContent(baseContent="")}}{To reset the content of the page for the next post
\describe{
\item{\code{baseContent}}{The wikitext base for the next post}
}}
\item{\code{addContent(theContent, type="p")}}{To add content that will later on be posted to mediawiki. This is where structuring elements are provided
\describe{
\item{\code{theContent}}{Either text (using mediawiki syntax) or path to a file}
\item{\code{type}}{\describe{
\item{\code{p} → A plain paragraph.}{}
\item{\code{h2} → Level 2 title}{}
\item{\code{h3} → Level 3 title}{}
\item{\code{h4} → Level 4 title}{}
\item{\code{h5} → Level 5 title}{}
\item{\code{raw} → No editing of the content}{}
}}
}}
\item{\code{postContent(comment)}}{To replace the content of the \code{page} (attribute) with \code{content} (attribute).
Parameter \code{comment} specifies the description of the modification, default is \code{“R generated 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}{}
}}
\item{\code{getContent()}}{Returns the \emph{wikitext} of the selected page (cf. \code{setPage})}
\item{\code{replaceSingleLineTemplateField(template, field, newValue)}}{To replace a field of a template in the selected \code{page}.
This method does not work with numbered parameters.
Right now it works only for pages that only contain one occurence of the parameter (it does not take outer context into account)
Additionnally, this function is not meat for templates the value of which spans accross multiple lines.
\describe{
\item{\code{template}}{The template to look for}
\item{\code{field}}{The name of the field concerned}
\item{\code{newValue}}{The new value of the field}
}}
}
\if{html}{\out{<hr>}}
\if{html}{\out{<a id="method-new"></a>}}
\subsection{Method \code{new()}}{
\subsection{Usage}{
\if{html}{\out{<div class="r">}}\preformatted{Mediawikir$new(instance_url, user, pass, dir = "")}\if{html}{\out{</div>}}
}
\examples{
mwHandler <- Mediawikir$new("http://my.wiki.org", "reg_user", "mypassword")
mwHandler$setPage("wikiPage")
mwHandler$addContent("This is an introduction to Mediawikir")
mwHandler$addContent("First step","h2")
mwHandler$addContent("First step of the first step","h3")
fileName <- mwHandler$uploadFile("path/toFile.png","My beautiful image.png")
mwHandler$addContent(paste("[[",fileName,"]]",sep=""))
mwHandler$postContent()
mwHandler$replaceSingleLineTemplateField("attribute", "newValue")
}
\keyword{mediawiki}
\if{html}{\out{<hr>}}
\if{html}{\out{<a id="method-setPage"></a>}}
\subsection{Method \code{setPage()}}{
\subsection{Usage}{
\if{html}{\out{<div class="r">}}\preformatted{Mediawikir$setPage(pageNameOrId)}\if{html}{\out{</div>}}
}
}
\if{html}{\out{<hr>}}
\if{html}{\out{<a id="method-resetContent"></a>}}
\subsection{Method \code{resetContent()}}{
\subsection{Usage}{
\if{html}{\out{<div class="r">}}\preformatted{Mediawikir$resetContent(aContent = "")}\if{html}{\out{</div>}}
}
}
\if{html}{\out{<hr>}}
\if{html}{\out{<a id="method-addContent"></a>}}
\subsection{Method \code{addContent()}}{
\subsection{Usage}{
\if{html}{\out{<div class="r">}}\preformatted{Mediawikir$addContent(theContent, type = "p")}\if{html}{\out{</div>}}
}
}
\if{html}{\out{<hr>}}
\if{html}{\out{<a id="method-postContent"></a>}}
\subsection{Method \code{postContent()}}{
\subsection{Usage}{
\if{html}{\out{<div class="r">}}\preformatted{Mediawikir$postContent(comment = "R generated content")}\if{html}{\out{</div>}}
}
}
\if{html}{\out{<hr>}}
\if{html}{\out{<a id="method-getContent"></a>}}
\subsection{Method \code{getContent()}}{
\subsection{Usage}{
\if{html}{\out{<div class="r">}}\preformatted{Mediawikir$getContent()}\if{html}{\out{</div>}}
}
}
\if{html}{\out{<hr>}}
\if{html}{\out{<a id="method-replaceSingleLineTemplateField"></a>}}
\subsection{Method \code{replaceSingleLineTemplateField()}}{
\subsection{Usage}{
\if{html}{\out{<div class="r">}}\preformatted{Mediawikir$replaceSingleLineTemplateField(
field = "",
newValue = "",
template = ""
)}\if{html}{\out{</div>}}
}
}
\if{html}{\out{<hr>}}
\if{html}{\out{<a id="method-uploadFile"></a>}}
\subsection{Method \code{uploadFile()}}{
\subsection{Usage}{
\if{html}{\out{<div class="r">}}\preformatted{Mediawikir$uploadFile(file_path, file_name)}\if{html}{\out{</div>}}
}
}
\if{html}{\out{<hr>}}
\if{html}{\out{<a id="method-clone"></a>}}
\subsection{Method \code{clone()}}{
The objects of this class are cloneable with this method.
\subsection{Usage}{
\if{html}{\out{<div class="r">}}\preformatted{Mediawikir$clone(deep = FALSE)}\if{html}{\out{</div>}}
}
\subsection{Arguments}{
\if{html}{\out{<div class="arguments">}}
\describe{
\item{\code{deep}}{Whether to make a deep clone.}
}
\if{html}{\out{</div>}}
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment