Commit c01ee249 authored by mrodzis's avatar mrodzis 🐸
Browse files

Feature/check wikis

parent bec85078
......@@ -10,7 +10,7 @@ To be able to maintain the pages containing content about project, documentation
and other stuff a comfortable editor and a system that stores the history of a
document is very helpful. In many cases projects use wikis for communication,
coordination and as a general knowledge base. By adding selected pages to a
white-list, the wiki may be become the place for editing the textual content of
white-list, the wiki may become the place for editing the textual content of
the SADE webpage.
DokuWiki is a common wiki software. To include a page from DokuWiki the following
......
......@@ -18,52 +18,50 @@ declare namespace xhtml="http://www.w3.org/1999/xhtml";
declare variable $confluence:collection := $config:app-root || '/docs';
declare function confluence:confluence($node as node(), $model as map(*), $id as xs:string) as node()* {
let $lastRevinDb := confluence:getLastRevInDb($id)
let $revisionInWiki := confluence:getLastRevInWiki($id)
let $revisionInWiki := if ($revisionInWiki=-1) then ($lastRevinDb) else ()
let $lastRevinDb := confluence:getLastRevInDb($id)
let $revisionInWiki := confluence:getLastRevInWiki($id)
let $revisionInWiki := if ($revisionInWiki=-1) then ($lastRevinDb) else ()
(: Only for debugging, needs to be commented out for productive state :)
(: let $lastRevinDb := 0:)
(: Only for debugging, needs to be commented out for productive state :)
(: let $lastRevinDb := 0:)
let $config-lang := string(config:get("lang.default", "multilanguage"))
let $lang := if($config-lang = "") then "" else app:getLanguage()
let $config-lang := string(config:get("lang.default", "multilanguage"))
let $lang := if($config-lang = "") then "" else app:getLanguage()
return
if( $revisionInWiki = $lastRevinDb )
then doc($confluence:collection || "/" || $id || '_' || $lang || '.rev' || $lastRevinDb || '.xml' )
else (
let $login := xmldb:login("/db", "admin", "" )
let $remove :=
xmldb:get-child-resources( $confluence:collection )[starts-with(., $id)]
! xmldb:remove($confluence:collection , . )
let $url:= xs:anyURI(config:get("confluence.url", "wiki") || $id || '?expand=body.storage')
let $persist := false()
let $request-headers:= ()
let $export := httpclient:get(xs:anyURI($url), false(), $request-headers)
let $map := xs:base64Binary($export//httpclient:body/text())
=> string()
=> util:base64-decode()
=> parse-json()
let $result := map:get(map:get(map:get($map, "body")[1], "storage"), "value")
let $result := local:replaceParsingErrors($result)
let $result := '<ac:confluence xmlns:ac="http://www.atlassian.com/schema/confluence/4/ac/" xmlns:ri="http://www.atlassian.com/schema/confluence/4/ri/" xmlns="http://www.atlassian.com/schema/confluence/4/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.atlassian.com/schema/confluence/4/ac/ ">' || $result || "</ac:confluence>"
let $result as element() := parse-xml( $result )/*
let $result := local:remove-element-ns-deep( $result )
let $result := <div id="wiki">{ local:confluenceparser($result, $id) }</div>
let $allLanguages := app:getAllLanguages()
let $forLoop := map:new(
for $el in $allLanguages
let $resultLangSpecific := local:confluenceparseLanguage($result, $el)
let $store := xmldb:store( $confluence:collection, $id || '_' || $el || '.rev' || $revisionInWiki || '.xml' , $resultLangSpecific )
return map:entry($el, $store)
)
return
if( $revisionInWiki = $lastRevinDb )
then doc($confluence:collection || "/" || $id || '_' || $lang || '.rev' || $lastRevinDb || '.xml' )
else (
let $login := xmldb:login("/db", "admin", "" )
let $remove :=
xmldb:get-child-resources( $confluence:collection )[starts-with(., $id)]
! xmldb:remove($confluence:collection , . )
let $url:= xs:anyURI(config:get("confluence.url", "wiki") || $id || '?expand=body.storage')
let $persist := false()
let $request-headers:= ()
let $export := httpclient:get(xs:anyURI($url), false(), $request-headers)
let $map := xs:base64Binary($export//httpclient:body/text())
=> string()
=> util:base64-decode()
=> parse-json()
let $result := map:get(map:get(map:get($map, "body")[1], "storage"), "value")
let $result := local:replaceParsingErrors($result)
let $result := '<ac:confluence xmlns:ac="http://www.atlassian.com/schema/confluence/4/ac/" xmlns:ri="http://www.atlassian.com/schema/confluence/4/ri/" xmlns="http://www.atlassian.com/schema/confluence/4/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.atlassian.com/schema/confluence/4/ac/ ">' || $result || "</ac:confluence>"
let $result as element() := parse-xml( $result )/*
let $result := local:remove-element-ns-deep( $result )
let $result := <div id="wiki">{ local:confluenceparser($result, $id) }</div>
let $result := doc( $forLoop( $lang ) )
return ($result)
)
let $allLanguages := app:getAllLanguages()
let $forLoop := map:new(
for $el in $allLanguages
let $resultLangSpecific := local:confluenceparseLanguage($result, $el)
let $store := xmldb:store( $confluence:collection, $id || '_' || $el || '.rev' || $revisionInWiki || '.xml' , $resultLangSpecific )
return map:entry($el, $store)
)
let $result := doc( $forLoop( $lang ) )
return ($result)
)
};
(:~
......@@ -74,132 +72,142 @@ if( $revisionInWiki = $lastRevinDb )
: @param $lang – the target language
: :)
declare function local:confluenceparseLanguage($nodes as node()*, $lang){
for $node in $nodes return
typeswitch($node)
case element ( structured-macro ) return
if( string($node/@name) = (config:get("confluence.lang", "wiki")[@code=$lang]/string(@name)))
then
element xhtml:div {
local:confluenceparseLanguage($node/rich-text-body/node(), $lang)
}
else ()
(: error( QName("https://sade.textgrid.de/ns/wiki", "CONF02"), "Language ("|| $lang ||") not supported. Request was: "||$node/@name):)
case element( * ) return
element {local-name($node)} {
$node/@*,
local:confluenceparseLanguage($node/node(), $lang)
}
case text() return $node
default return local:confluenceparseLanguage($node/node(), $lang)
for $node in $nodes return
typeswitch($node)
case element ( structured-macro ) return
if( string($node/@name) = (config:get("confluence.lang", "wiki")[@code=$lang]/string(@name)))
then
element xhtml:div {
local:confluenceparseLanguage($node/rich-text-body/node(), $lang)
}
else ()
(: error( QName("https://sade.textgrid.de/ns/wiki", "CONF02"), "Language ("|| $lang ||") not supported. Request was: "||$node/@name):)
case element( * ) return
element {local-name($node)} {
$node/@*,
local:confluenceparseLanguage($node/node(), $lang)
}
case text() return $node
default return local:confluenceparseLanguage($node/node(), $lang)
};
declare function local:confluenceparser($nodes as node()*, $id){
for $node in $nodes return
typeswitch($node)
(:Confluence often returns an empty p element at the beginning:)
case element (p) return
switch ($node/@class)
case "auto-cursor-target"
return ()
default
return
element {local-name($node)} {
$node/@*,
local:confluenceparser($node/node(), $id)
}
(:
case element (p) return
element xhtml:p {
attribute class {"lead"},
for $att in $node/@*
let $att-name := name($att)
return if ($att-name != "class") then attribute {$att-name} {$att}
else (),
local:confluenceparser($node/node(), $id)
}:)
case element ( image ) return
element xhtml:img {
attribute src { "https://wiki.de.dariah.eu/download/attachments/" || $id || "/" || ($node/attachment/@filename) },
attribute alt { ($node/@title) },
attribute height { ($node/@height) }
(: attribute width { ($node/@width) } ---->: Width can't be set in Confluence! :)
}
(:Transform heading h1 to the theme specific style:)
case element ( h1 ) return
element xhtml:h1 {
attribute class {"block-header"},
<span>{ $node/text() }</span>
}
case element ( h2 ) return
element xhtml:h2 {
attribute class {"block-header alt"},
<span>{ $node/text() }</span>
}
(: Structured Macros of Confluence needs to be transformed :)
case element ( structured-macro ) return
if(matches($node/@name, "^[a-zA-Z]"))
then (
switch ($node/@name)
case "info"
return
element xhtml:div {
attribute class {"info-board info-board-primary"},
local:confluenceparser($node/rich-text-body/node(), $id)
}
case "warning"
return
element xhtml:div {
attribute class {"alert alert-danger"},
local:confluenceparser($node/rich-text-body/node(), $id)
}
case "tip"
return
element xhtml:div {
attribute class {"alert alert-success"},
local:confluenceparser($node/rich-text-body/node(), $id)
}
case "code"
return
element xhtml:code {
local:confluenceparser($node/plain-text-body/node(), $id)
}
default
return
if( string($node/@name) = (config:get("confluence.lang", "wiki")/string(@name))[.!=""])
then
element {local-name($node)} {
$node/@*,
local:confluenceparser($node/node(), $id)
for $node in $nodes return
typeswitch($node)
(:Confluence often returns an empty p element at the beginning:)
case element (p) return
switch ($node/@class)
case "auto-cursor-target"
return ()
default
return
element {local-name($node)} {
$node/@*,
local:confluenceparser($node/node(), $id)
}
(:
case element (p) return
element xhtml:p {
attribute class {"lead"},
for $att in $node/@*
let $att-name := name($att)
return if ($att-name != "class") then attribute {$att-name} {$att}
else (),
local:confluenceparser($node/node(), $id)
}:)
case element ( image ) return
element xhtml:img {
attribute src { "https://wiki.de.dariah.eu/download/attachments/" || $id || "/" || ($node/attachment/@filename) },
attribute alt { ($node/@title) },
attribute height { ($node/@height) }
(: attribute width { ($node/@width) } ---->: Width can't be set in Confluence! :)
}
(:Transform heading h1 to the theme specific style:)
case element ( h1 ) return
element xhtml:h1 {
attribute class {"block-header"},
<span>{ $node/text() }</span>
}
case element ( h2 ) return
element xhtml:h2 {
attribute class {"block-header alt"},
<span>{ $node/text() }</span>
}
(: Structured Macros of Confluence needs to be transformed :)
case element ( structured-macro ) return
if(matches($node/@name, "^[a-zA-Z]"))
then (
switch ($node/@name)
case "info"
return
element xhtml:div {
attribute class {"info-board info-board-primary"},
local:confluenceparser($node/rich-text-body/node(), $id)
}
else error( QName("https://sade.textgrid.de/ns/wiki", "CONF03"), "Structured macro ("|| string($node/@name) ||") unknown to the parser.")
)
else error( QName("https://sade.textgrid.de/ns/wiki", "CONF01"), "Structured Macro has no valid name.")
case element ( table ) return
element table {
attribute class {"table table-responsive"},
$node/@*,
local:confluenceparser($node/node(), $id)
}
(: Edit links to open external ones in a new tab :)
case element ( a ) return
element a {
if (starts-with($node/@href,"/")) then (
attribute href {$node/@href},
$node/text())
else (
(:attribute href {$node/@href},:)
attribute target {"_blank"},
case "warning"
return
element xhtml:div {
attribute class {"alert alert-danger"},
local:confluenceparser($node/rich-text-body/node(), $id)
}
case "tip"
return
element xhtml:div {
attribute class {"alert alert-success"},
local:confluenceparser($node/rich-text-body/node(), $id)
}
case "code"
return
element xhtml:pre {
element xhtml:code {
local:confluenceparser($node/plain-text-body/node(), $id)
}
}
case "pagetitle"
return
(util:log-system-out($node),
element xhtml:h2 {
attribute class {"block-header"},
element xhtml:span {
attribute class {"title"}
}
})
default
return
element xhtml:span {
attribute class {"unprocessed-structured-macro"}
}
)
else error( QName("https://sade.textgrid.de/ns/wiki", "CONF01"), "Structured Macro has no valid name.")
case element ( table ) return
element table {
if($node/@class) then
attribute class {$node/@class || " table table-responsive"}
else
attribute class {"table table-responsive"},
$node/(@* except @class),
local:confluenceparser($node/node(), $id)
}
(: Edit links to open external ones in a new tab :)
case element ( a ) return
element a {
if (starts-with($node/@href,"/")) then (
attribute href {$node/@href},
$node/text())
else (
(:attribute href {$node/@href},:)
attribute target {"_blank"},
$node/@*,
local:confluenceparser($node/node(), $id))
}
case element( * ) return
element {local-name($node)} {
$node/@*,
local:confluenceparser($node/node(), $id))
}
case element( * ) return
element {local-name($node)} {
$node/@*,
local:confluenceparser($node/node(), $id)
}
case text() return $node
default return local:confluenceparser($node/node(), $id)
local:confluenceparser($node/node(), $id)
}
case text() return $node
default return local:confluenceparser($node/node(), $id)
};
declare function local:passthru($node as node()*, $id) as item()* {
......@@ -220,14 +228,14 @@ declare function local:retrieveImageUrl($pageId, $imageName) {
};
declare function confluence:getLastRevInDb($id) as xs:integer {
let $num := xmldb:get-child-resources( $confluence:collection )[contains(., $id)][1]
=> substring-after('.rev')
=> substring-before('.xml')
let $num := xmldb:get-child-resources( $confluence:collection )[contains(., $id)][1]
=> substring-after('.rev')
=> substring-before('.xml')
return
if($num = "")
then 0
else $num
return
if($num = "")
then 0
else $num
};
(:~
......@@ -255,11 +263,11 @@ declare function confluence:getLastRevInWiki($id as xs:string) as xs:integer {
};
declare function local:HTML2html($node) {
for $node in $node
return
typeswitch ( $node )
case element() return element { lower-case($node/local-name()) } { $node/@*, local:HTML2html($node/node()) }
default return $node
for $node in $node
return
typeswitch ( $node )
case element() return element { lower-case($node/local-name()) } { $node/@*, local:HTML2html($node/node()) }
default return $node
};
declare function local:remove-element-ns-deep( $nodes as node()*) as node()* {
......
This diff is collapsed.
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment