Änderungen von Dokument Makros für benutzerspezifisch konfigurierbare Bereiche
Zuletzt geändert von Daniel Herrmann am 2026/02/07 23:23
Auf Version
2.1
bearbeitet von Daniel Herrmann
am 2026/02/07 23:23
am 2026/02/07 23:23
Änderungskommentar:
Install extension [org.xwiki.platform:xwiki-platform-administration-ui/18.0.1]
Zusammenfassung
Details
- Seiteneigenschaften
-
- Dokument-Autor
-
... ... @@ -1,1 +1,1 @@ 1 -XWiki. admin1 +XWiki.dherrman - Inhalt
-
... ... @@ -4,12 +4,12 @@ 4 4 #set($nameOfThisDocument = 'XWiki.ConfigurableClass') 5 5 6 6 7 -#* 7 +#** 8 8 * Try to determine whether a document was edited by a user who has edit right on this page. This is tricky because 9 9 * documents are imported with the name XWiki.XWikiGuest who has no access to anything after import. 10 10 * 11 11 * @param theDoc - Document who's editor should be checked for edit access on this document. 12 - *###12 +*# 13 13 #macro(checkDocumentSavedByAuthorizedUser, $docToCheck, $currentDoc, $hasAccess) 14 14 ## The system is started and the only user is XWikiGuest who has admin right but gives it up when he imports the default 15 15 ## documents, we are checking to see if this looks like the guest imported the document with the first import. ... ... @@ -27,21 +27,18 @@ 27 27 #end 28 28 29 29 30 -#* 30 +#** 31 31 * Find names of documents which contain objects of the class 'XWiki.ConfigurableClass' 32 32 * 33 33 * @param $section - String - Look for apps which specify that they should be configured in this section, 34 34 * if null or "" then returns them for all sections. 35 - * 36 36 * @param $globaladmin - boolean - If true then we will look for applications which should be configured globally. 37 - * 38 38 * @param $space - String - If not looking for apps which are configured globally, then this is the space where we 39 39 * will look for apps in. If null or "" or if $globaladmin is true, then all spaces will be 40 40 * searched. 41 - * 42 42 * @param $outputList - List - The returns from this macro will be put in this list, passing the list as a parameter 43 43 * a safety measure because macros can't return values. 44 - *###41 +*# 45 45 #macro(findNamesOfAppsToConfigure, $section, $globaladmin, $space, $outputList) 46 46 ## We keep looking in the old configureGlobally property since we do not provide a migration for it: 47 47 ## this choice has been made to avoid any problem during the upgrade of old wikis. ... ... @@ -131,27 +131,32 @@ 131 131 #end 132 132 #end 133 133 134 -#* 135 - * Augment the $adminMenu variable with all $nameOfThisDocument (i.e. XWiki.ConfigurableClass) xobjects found on this wiki. 136 - *### 137 -#macro(findCustomSectionsToConfigure $adminMenu) 138 - #set ($outputList = []) 139 - #set ($global = ($editor == 'globaladmin')) 140 - #findNamesOfAppsToConfigure('', $global, $currentSpace, $outputList) 141 - #set ($sectionsByName = {}) 131 +#** 132 + * Utility for findCustomSectionsToConfigure to get an adminMenu. 133 + * 134 + * @param appNames (List of Strings) Name of applications to build the adminMenu from 135 + * @param adminMenu the pre-filled content for the administration menu (macro is non-destructive on this parameter) 136 + * @param outputList 137 +*# 138 +#macro(_buildAdminMenuFromNameOfApps, $appNames, $adminMenu, $outputList) 139 + ## We start by copying what's already in the adminMenu. 140 + ## We can't use addAll directly because we want to make a deep copy of the structure 141 + #set ($discard = $outputList.addAll($jsontool.fromString($jsontool.serialize($adminMenu)))) 142 + ## Reset the category and section helper hashmaps so that they point to $outputlist and not $adminMenu anymore. 142 142 #set ($categoriesByName = {}) 143 - #foreach ($category in $adminMenu) 144 + #set ($sectionsByName = {}) 145 + #foreach ($category in $outputList) 144 144 #set ($discard = $categoriesByName.put($category.id, $category)) 145 145 #foreach ($section in $category.children) 146 146 #set ($discard = $sectionsByName.put($section.id, $section)) 147 147 #end 148 148 #end 149 - ## 151 + ## The $query variable is used as a basis for the URL used in sections. (search for ${query} ) 150 150 #set ($query = "editor=$escapetool.url(${editor})") 151 151 #if ($editor != 'globaladmin') 152 152 #set ($query = $query + "&space=$escapetool.url(${currentSpace})") 153 153 #end 154 - #foreach ($appName in $ outputList)156 + #foreach ($appName in $appNames) 155 155 ## 156 156 ## Get the configurable application 157 157 #set ($app = $xwiki.getDocument($appName)) ... ... @@ -182,7 +182,7 @@ 182 182 }) 183 183 #set ($discard = $categoriesByName.put($displayInCategory, $appCategory)) 184 184 ## Insert the category at the end for now. We'll sort the categories after we add all of them. 185 - #set ($discard = $ adminMenu.add($appCategory))187 + #set ($discard = $outputList.add($appCategory)) 186 186 #end 187 187 #set ($categoryIcon = $app.getValue('categoryIcon', $configurableObject)) 188 188 #if ("$!categoryIcon" != '') ... ... @@ -252,15 +252,23 @@ 252 252 #end 253 253 #end## Foreach configurable object in this app. 254 254 #end## Foreach application which is configurable. 255 - ## 256 - ## Sort the categories 257 - ## 258 - #foreach ($category in $adminMenu) 257 +#end 258 + 259 +#** 260 + * Computes the scores of categories and sorts the list. The first category will be the one with the highest score. 261 + * 262 + * @param completeOrderMenu the list of categories, containing all of the necessary ordering information; 263 + * This macro is destructive on $completeOrderMenu. 264 +*# 265 +#macro(_computeScores, $completeOrderMenu) 266 + ## Initialize scores 267 + #foreach ($category in $completeOrderMenu) 259 259 #set ($category.score = 0) 260 260 #end 261 - #foreach ($round in [1..$adminMenu.size()]) 270 + ## Compute scores 271 + #foreach ($round in [1..$completeOrderMenu.size()]) 262 262 #set ($scoreChanged = false) 263 - #foreach ($category in $ adminMenu)273 + #foreach ($category in $completeOrderMenu) 264 264 #if ($category.displayBeforeCategory) 265 265 #set ($newScore = $categoriesByName.get($category.displayBeforeCategory).score + 1) 266 266 #if ($newScore && $newScore > $category.score) ... ... @@ -273,17 +273,82 @@ 273 273 #break 274 274 #end 275 275 #end 276 - #set ($adminMenu = $collectiontool.sort($adminMenu, 'score:desc')) 277 277 #end 278 278 288 +#** 289 + * Utility macro to compute the full order of categories, which is contained sparsely through xobjects 290 + * that are not always retrieved when building the menu. 291 + * 292 + * @param adminMenu the list of categories to use in the menu (macro is non-destructive on this parameter) 293 + * @param outputList the full list of categories, in order. Even categories without any child will be returned. 294 +*# 295 +#macro(_getCategoriesInOrder, $adminMenu, $outputList) 296 + #set ($params = { 297 + 'className' : $nameOfThisDocument, 298 + 'global': ['WIKI','WIKI+ALL_SPACES'] 299 + }) 300 + #set ($appNames = []) 301 + #set ($discard = $appNames.addAll($services.query.hql($statement).bindValues($params).execute())) 302 + ## $completeOrderMenu contains a menu that contains all the information needed for sorting, no matter what. 303 + #set ($completeOrderMenu = []) 304 + #_buildAdminMenuFromNameOfApps($appNames, $adminMenu, $completeOrderMenu) 305 + ## We use $completeOrderMenu to set the score of each category. 306 + #_computeScores($completeOrderMenu) 307 + #set ($completeOrderMenu = $collectiontool.sort($completeOrderMenu, 'score:desc')) 308 + ## Write the now sorted $completeOrderMenu to the output variable. 309 + #set ($discard = $outputList.addAll($completeOrderMenu)) 310 +#end 279 279 280 -#* 312 +#** 313 + * Augment the $adminMenu variable with all $nameOfThisDocument (i.e. XWiki.ConfigurableClass) 314 + * XObjects found on this wiki. 315 + * 316 + * @param adminMenu the basis of the menu on which to add on (the macro makes hard to reverse changes on $adminMenu) 317 +*# 318 +#macro(findCustomSectionsToConfigure $adminMenu) 319 + #set ($appNames = []) 320 + #set ($global = ($editor == 'globaladmin')) 321 + #findNamesOfAppsToConfigure('', $global, $currentSpace, $appNames) 322 + ## 323 + ## $completedAdminMenu contains most of the info needed to build the administration menu. 324 + #set ($completedAdminMenu = []) 325 + #_buildAdminMenuFromNameOfApps($appNames, $adminMenu, $completedAdminMenu) 326 + #set ($adminMenu = []) 327 + #set ($discard = $adminMenu.addAll($completedAdminMenu)) 328 + ## Sort the categories 329 + ## The information in $adminMenu is sometimes not enough to create a full order 330 + ## in those case we need to retrieve more information to build the full order. 331 + ## $categoriesFullOrder contains all the categories and their associated ordering information 332 + #if (!$global) 333 + #set ($categoriesFullOrder = []) 334 + #_getCategoriesInOrder($adminMenu, $categoriesFullOrder) 335 + ## Once it's retrieved, we use this total order on the categories in contained $adminMenu. 336 + #set ($sortedAdminMenu = []) 337 + #foreach ($orderedCategory in $categoriesFullOrder) 338 + #foreach ($menuCategory in $adminMenu) 339 + #if ($orderedCategory.id == $menuCategory.id) 340 + #set ($discard = $sortedAdminMenu.add($menuCategory)) 341 + #break 342 + #end 343 + #end 344 + #end 345 + #set ($adminMenu = []) 346 + #set ($discard = $adminMenu.addAll($sortedAdminMenu)) 347 + #else 348 + ## We're in the case where all the categories and sections are already in $adminMenu 349 + ## We can easily figure out an order 350 + #_computeScores($adminMenu) 351 + #set ($adminMenu = $collectiontool.sort($adminMenu, 'score:desc')) 352 + #end 353 +#end 354 + 355 + 356 +#** 281 281 * Show the heading for configuration for a given application. 282 282 * 283 - * $appName (String) Name of the application to show configuration heading for. 284 - * 285 - * $headingAlreadyShowing (boolean) If true then we don't make another heading. Otherwise it is set to true. 286 - *### 359 + * @param appName (String) Name of the application to show configuration heading for. 360 + * @param headingAlreadyShowing (boolean) If true then we don't make another heading. Otherwise it is set to true. 361 +*# 287 287 #macro(showHeading, $appName, $headingAlreadyShowing) 288 288 #if(!$headingAlreadyShowing) 289 289 #set($headingAlreadyShowing = true)