Änderungen von Dokument Makros für benutzerspezifisch konfigurierbare Bereiche
Zuletzt geändert von Daniel Herrmann am 2026/02/07 23:23
Von 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.d herrman1 +XWiki.admin - 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,18 +27,21 @@ 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 + * 35 35 * @param $globaladmin - boolean - If true then we will look for applications which should be configured globally. 37 + * 36 36 * @param $space - String - If not looking for apps which are configured globally, then this is the space where we 37 37 * will look for apps in. If null or "" or if $globaladmin is true, then all spaces will be 38 38 * searched. 41 + * 39 39 * @param $outputList - List - The returns from this macro will be put in this list, passing the list as a parameter 40 40 * a safety measure because macros can't return values. 41 -*# 44 + *### 42 42 #macro(findNamesOfAppsToConfigure, $section, $globaladmin, $space, $outputList) 43 43 ## We keep looking in the old configureGlobally property since we do not provide a migration for it: 44 44 ## this choice has been made to avoid any problem during the upgrade of old wikis. ... ... @@ -128,32 +128,27 @@ 128 128 #end 129 129 #end 130 130 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. 143 - #set ($categoriesByName = {}) 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) 144 144 #set ($sectionsByName = {}) 145 - #foreach ($category in $outputList) 142 + #set ($categoriesByName = {}) 143 + #foreach ($category in $adminMenu) 146 146 #set ($discard = $categoriesByName.put($category.id, $category)) 147 147 #foreach ($section in $category.children) 148 148 #set ($discard = $sectionsByName.put($section.id, $section)) 149 149 #end 150 150 #end 151 - ## The $query variable is used as a basis for the URL used in sections. (search for ${query} )149 + ## 152 152 #set ($query = "editor=$escapetool.url(${editor})") 153 153 #if ($editor != 'globaladmin') 154 154 #set ($query = $query + "&space=$escapetool.url(${currentSpace})") 155 155 #end 156 - #foreach ($appName in $ appNames)154 + #foreach ($appName in $outputList) 157 157 ## 158 158 ## Get the configurable application 159 159 #set ($app = $xwiki.getDocument($appName)) ... ... @@ -184,7 +184,7 @@ 184 184 }) 185 185 #set ($discard = $categoriesByName.put($displayInCategory, $appCategory)) 186 186 ## Insert the category at the end for now. We'll sort the categories after we add all of them. 187 - #set ($discard = $ outputList.add($appCategory))185 + #set ($discard = $adminMenu.add($appCategory)) 188 188 #end 189 189 #set ($categoryIcon = $app.getValue('categoryIcon', $configurableObject)) 190 190 #if ("$!categoryIcon" != '') ... ... @@ -254,23 +254,15 @@ 254 254 #end 255 255 #end## Foreach configurable object in this app. 256 256 #end## Foreach application which is configurable. 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) 255 + ## 256 + ## Sort the categories 257 + ## 258 + #foreach ($category in $adminMenu) 268 268 #set ($category.score = 0) 269 269 #end 270 - ## Compute scores 271 - #foreach ($round in [1..$completeOrderMenu.size()]) 261 + #foreach ($round in [1..$adminMenu.size()]) 272 272 #set ($scoreChanged = false) 273 - #foreach ($category in $ completeOrderMenu)263 + #foreach ($category in $adminMenu) 274 274 #if ($category.displayBeforeCategory) 275 275 #set ($newScore = $categoriesByName.get($category.displayBeforeCategory).score + 1) 276 276 #if ($newScore && $newScore > $category.score) ... ... @@ -283,82 +283,17 @@ 283 283 #break 284 284 #end 285 285 #end 276 + #set ($adminMenu = $collectiontool.sort($adminMenu, 'score:desc')) 286 286 #end 287 287 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 311 311 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 -#** 280 +#* 357 357 * Show the heading for configuration for a given application. 358 358 * 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 -*# 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 + *### 362 362 #macro(showHeading, $appName, $headingAlreadyShowing) 363 363 #if(!$headingAlreadyShowing) 364 364 #set($headingAlreadyShowing = true)