Wiki source code of SkinEditorMacros
Last modified by Normann P. Nielsen on 2026/11/17 21:00
Hide last authors
| author | version | line-number | content |
|---|---|---|---|
| |
1.1 | 1 | ## |
| 2 | ## = Macros = | ||
| 3 | ## | ||
| 4 | #** | ||
| 5 | * @macro Check if there is a lock on the skin (or SX) file passed. | ||
| 6 | * @param $skinDoc the document which holds the skin or SX file | ||
| 7 | * @param filename a composed filename pointing to the file (macro.vm or XWiki.JavaScriptExtension_0) | ||
| 8 | * @param isFileLocked the return value: wikiname of the locker or empty string | ||
| 9 | *# | ||
| 10 | #macro(isLocked $sc $skinDoc $filename $isFileLocked) | ||
| 11 | #set($isFileLocked = "") | ||
| 12 | #if(!$sc.getAttribute("pseudolocks")) ## Lazy lock map creation in memory in case it's not there already | ||
| 13 | #set($ok = $sc.setAttribute("pseudolocks", $util.hashMap)) | ||
| 14 | #end | ||
| 15 | #set($locks = $sc.getAttribute("pseudolocks")) | ||
| 16 | #if($locks.containsKey("${context.database}:${skinDoc.fullName}_${filename}")) | ||
| 17 | #set($lockData = $locks.get("${context.database}:${skinDoc.fullName}_${filename}")) | ||
| 18 | #set($lockedUntil = $listtool.get($lockData, 0)) | ||
| 19 | #if($lockedUntil < $util.date.time) | ||
| 20 | ## Lock is timed-out, let's remove it | ||
| 21 | #set($ok = $locks.remove("${context.database}:${skinDoc.fullName}_${filename}")) | ||
| 22 | #else | ||
| 23 | #set($locker = $listtool.get($lockData, 1)) | ||
| 24 | #if($locker != "$context.user") ## The locker is different from the context user | ||
| 25 | #set($isFileLocked=$locker) | ||
| 26 | #end | ||
| 27 | #end | ||
| 28 | #end | ||
| 29 | #end | ||
| 30 | #* | ||
| 31 | * @macro displays a nice list of files for a skin. | ||
| 32 | * TODO: refactor to not manage in-editor and out-editor in the same macro. | ||
| 33 | *# | ||
| 34 | #macro(skinFilesList $sc $skindoc $file $zoomOption $xunderline) ## { | ||
| 35 | #if($skindoc.getObject('XWiki.XWikiSkins')) ## We have a skin. Let's iterate over its properties | ||
| 36 | #set($skin = $skindoc.getObject('XWiki.XWikiSkins')) | ||
| 37 | <ul class="xlist"> | ||
| 38 | #foreach($pName in $skin.getPropertyNames()) | ||
| 39 | ## We have to use a protected API to retrieve the type of the prop :( | ||
| 40 | #set($prop = $skin.getProperty($pName).property) | ||
| 41 | #if($prop.classType == "com.xpn.xwiki.objects.LargeStringProperty") | ||
| 42 | ## we got something bespineditable :) | ||
| 43 | #if($prop.value.trim() == "") #set($isEmpty = true) #else #set($isEmpty = false) #end | ||
| 44 | #if((!$codeContainerContent && !$isEmpty && "$!file" == "") || "$!file" == $pName) | ||
| 45 | #set($codeContainerContent = $prop.value) | ||
| 46 | #set($codeContainerFile = $prop.name) | ||
| 47 | #set($selected=true) | ||
| 48 | #else | ||
| 49 | #set($selected=false) | ||
| 50 | #end | ||
| 51 | <li class="xitem#if($xunderline) xunderline#end xhighlight skinfile#if($isEmpty) empty#end#if($selected) selected#end"> | ||
| 52 | <div class="xitemcontainer"> | ||
| 53 | <div class="filename" style="float:left"><tt>$prop.name</tt></div> | ||
| 54 | #set($pLocked = "") | ||
| 55 | #isLocked($sc $skindoc, "XWiki.XWikiSkins_0_${pName}", $pLocked) | ||
| 56 | #if("$!pLocked"!="")<span style="float:left" class="locked" title="Locked by $xwiki.getUserName($pLocked, false)"></span>#end | ||
| 57 | <div class="xmore"> </div> | ||
| 58 | </div> | ||
| 59 | <div class="xshowonhover actions"> | ||
| 60 | #if($skindoc.hasAccessLevel("edit")) | ||
| 61 | #set($editLink = $skindoc.getURL("view","xpage=plain&type=skin&file=$prop.name")) | ||
| 62 | <a href="$editLink">edit</a> | ||
| 63 | #end | ||
| 64 | #if(!$isEmpty && $zoomOption)<span class="xshowcode"><a href="#">zoom</a></span>#end | ||
| 65 | </div> | ||
| 66 | <div class="hidden code">$code${prop.value}$code</div> | ||
| 67 | <div class="xspacer"> </div> | ||
| 68 | </li> | ||
| 69 | #end | ||
| 70 | #end | ||
| 71 | #end | ||
| 72 | </ul> | ||
| 73 | #end ## } end macro #skinFileList | ||
| 74 | #* | ||
| 75 | * @macro displays a nice list of files for a SX document. | ||
| 76 | * TODO: refactor to not manage in-editor and out-editor in the same macro. | ||
| 77 | *# | ||
| 78 | #macro(sxFilesList $sc $skindoc $file $zoomOption $xunderline) ## { | ||
| 79 | <ul class="xlist"> | ||
| 80 | #foreach($className in ["XWiki.JavaScriptExtension","XWiki.StyleSheetExtension"]) | ||
| 81 | #if($className == "XWiki.JavaScriptExtension") #set($ext="js") #else #set($ext="css") #end | ||
| 82 | #foreach($object in $skindoc.getObjects($className)) | ||
| 83 | ## We have to use a protected API to retrieve the type of the prop :( | ||
| 84 | #set($prop = "${xwiki.clearName($object.get('name').replaceAll(' ','')).toLowerCase()}.${ext}") | ||
| 85 | ## we got something bespineditable :) | ||
| 86 | #set($sxcode = $object.getProperty('code').value) | ||
| 87 | #if($sxcode == "") #set($isEmpty = true) #else #set($isEmpty = false) #end | ||
| 88 | #if((!$codeContainerContent && !$isEmpty && "$!file" == "") || "$!file" == "${className}_${object.number}") | ||
| 89 | #set($codeContainerContent = $sxcode) | ||
| 90 | #set($codeContainerFile = $prop) | ||
| 91 | #set($selected=true) | ||
| 92 | #else | ||
| 93 | #set($selected=false) | ||
| 94 | #end | ||
| 95 | <li class="xitem#if($xunderline) xunderline#end xhighlight skinfile#if($isEmpty) empty#end#if($selected) selected#end"> | ||
| 96 | <div class="xitemcontainer"> | ||
| 97 | <div class="filename" style="float:left"><tt>$prop</tt></div> | ||
| 98 | #set($pLocked = "") | ||
| 99 | #isLocked($sc $skindoc, "${className}_${object.number}.${ext}", $pLocked) | ||
| 100 | #if("$!pLocked"!="")<span style="float:left" class="locked" title="Locked by $xwiki.getUserName($pLocked, false)"></span>#end | ||
| 101 | <div class="xmore"> </div> | ||
| 102 | </div> | ||
| 103 | <div class="xshowonhover actions"> | ||
| 104 | #set($editLink = $skindoc.getURL("view","xpage=plain&type=sx&ext=${ext}&nb=${object.number}")) | ||
| 105 | <a href="$editLink">edit</a> | ||
| 106 | #if(!$isEmpty && $zoomOption)<span class="xshowcode"><a href="#">zoom</a></span>#end | ||
| 107 | </div> | ||
| 108 | <div class="hidden code">$code${sxcode}$code</div> | ||
| 109 | <div class="xspacer"> </div> | ||
| 110 | </li> | ||
| 111 | #end | ||
| 112 | #end | ||
| 113 | </ul> | ||
| 114 | #end ## } end macro #skinFileList |