Commit 2394f93a authored by Mathias Goebel's avatar Mathias Goebel 🎠
Browse files

refine wiki module, add documentation and return type

parent 4b997dac
......@@ -39,7 +39,7 @@ let $id:= if($id = doc('/db/sade-projects/textgrid/data/xml/data/2shfj.xml')//te
let $reload := if( request:get-parameter-names() = "reload" ) then local:dokuwikiImageReload($id, $model) else false()
(: get last revision number stored here :)
let $lastRevinDb := local:dokuwikiGetLastRevInDb($id)
let $revisionInWiki := local:dokuwikiNewModification($id, $model, $lastRevinDb)
let $revisionInWiki := local:dokuwikiNewModification($id, $lastRevinDb)
let $doc :=
if( $revisionInWiki = $lastRevinDb )
......@@ -75,23 +75,42 @@ return
: @return the revision number stored in the database
:)
declare function local:dokuwikiGetLastRevInDb($id as xs:string)
as xs:string {
for $item in xmldb:get-child-resources('/sade-projects/textgrid/data/xml/doku/')
where substring-before($item, '.rev') = $id
return
substring-before(substring-after($item, '.rev'), '.xml')
as xs:int? {
for $item in xmldb:get-child-resources('/sade-projects/textgrid/data/xml/doku/')
where substring-before($item, '.rev') = $id
return
substring-after($item, '.rev') => substring-before('.xml')
=> xs:int()
};
declare function local:dokuwikiNewModification($id, $model, $lastRevinDb) as xs:string {
let $wikiList := doc( config:get("dokuwiki.url")||'/feed.php?type=rss2&num=500&ns=fontane&minor=1&mode=list&u='|| config:get("dokuwiki.user") ||'&p='|| config:get("dokuwiki.password"))
let $lastRevinWiki := $wikiList//link[starts-with(., config:get("dokuwiki.url") || '/doku.php?id=fontane:'|| $id ||'&rev=')]/substring-after(., '&rev=')
(:~
: Gets the last revision number from the wikis feed and removes an old version
: in the database. TODO: move remove operation somewhere else
: @param $id – the name of page in the wiki space
: @param $lastRevinDb – revision number of the currently stored resource
: @return the last revsion number from the remote wiki
:)
declare function local:dokuwikiNewModification($id, $lastRevinDb as xs:int?)
as xs:int {
let $wikiList := (config:get("dokuwiki.url")
|| '/feed.php?type=rss2&num=500&ns=fontane&minor=1&mode=list&u='
|| config:get("dokuwiki.user")
|| '&p='
|| config:get("dokuwiki.password"))
=> doc()
let $lastRevinWiki :=
($wikiList//link
[starts-with(., config:get("dokuwiki.url") || '/doku.php?id=fontane:'|| $id ||'&rev=')]
/substring-after(., '&rev='))
=> xs:int()
let $test :=
if( $lastRevinDb != $lastRevinWiki )
then
(
xmldb:login( '/sade-projects/textgrid/data/xml/doku/', config:get('sade.user'), config:get("sade.password")),
xmldb:remove('/sade-projects/textgrid/data/xml/doku/', $id || '.rev' || $lastRevinDb || '.xml' )
xmldb:remove('/sade-projects/textgrid/data/xml/doku/', $id || '.rev' || string($lastRevinDb) || '.xml' )
)
else ()
return
......@@ -175,7 +194,7 @@ for $node in $nodes return
local:dokuwikiparser($node/node(), $char)
)}
case element(br) return
<br/>
element xhtml:br {}
case element(table)
return
element xhtml:table {
......
Markdown is supported
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