|
42 | 42 | #set($nameOfThisDocument = 'XWiki.ConfigurableClass') |
43 | 43 |
|
44 | 44 |
|
45 | | -#* |
| 45 | +#** |
46 | 46 | * Try to determine whether a document was edited by a user who has edit right on this page. This is tricky because |
47 | 47 | * documents are imported with the name XWiki.XWikiGuest who has no access to anything after import. |
48 | 48 | * |
49 | 49 | * @param theDoc - Document who's editor should be checked for edit access on this document. |
50 | | - *### |
| 50 | +*# |
51 | 51 | #macro(checkDocumentSavedByAuthorizedUser, $docToCheck, $currentDoc, $hasAccess) |
52 | 52 | ## The system is started and the only user is XWikiGuest who has admin right but gives it up when he imports the default |
53 | 53 | ## documents, we are checking to see if this looks like the guest imported the document with the first import. |
|
65 | 65 | #end |
66 | 66 |
|
67 | 67 |
|
68 | | -#* |
| 68 | +#** |
69 | 69 | * Find names of documents which contain objects of the class 'XWiki.ConfigurableClass' |
70 | 70 | * |
71 | 71 | * @param $section - String - Look for apps which specify that they should be configured in this section, |
72 | 72 | * if null or "" then returns them for all sections. |
73 | | - * |
74 | 73 | * @param $globaladmin - boolean - If true then we will look for applications which should be configured globally. |
75 | | - * |
76 | 74 | * @param $space - String - If not looking for apps which are configured globally, then this is the space where we |
77 | 75 | * will look for apps in. If null or "" or if $globaladmin is true, then all spaces will be |
78 | 76 | * searched. |
79 | | - * |
80 | 77 | * @param $outputList - List - The returns from this macro will be put in this list, passing the list as a parameter |
81 | 78 | * a safety measure because macros can't return values. |
82 | | - *### |
| 79 | +*# |
83 | 80 | #macro(findNamesOfAppsToConfigure, $section, $globaladmin, $space, $outputList) |
84 | 81 | ## We keep looking in the old configureGlobally property since we do not provide a migration for it: |
85 | 82 | ## this choice has been made to avoid any problem during the upgrade of old wikis. |
|
169 | 166 | #end |
170 | 167 | #end |
171 | 168 |
|
172 | | -#* |
173 | | - * Augment the $adminMenu variable with all $nameOfThisDocument (i.e. XWiki.ConfigurableClass) xobjects found on this wiki. |
174 | | - *### |
175 | | -#macro(findCustomSectionsToConfigure $adminMenu) |
176 | | - #set ($outputList = []) |
177 | | - #set ($global = ($editor == 'globaladmin')) |
178 | | - #findNamesOfAppsToConfigure('', $global, $currentSpace, $outputList) |
179 | | - #set ($sectionsByName = {}) |
| 169 | +#** |
| 170 | + * Utility for findCustomSectionsToConfigure to get an adminMenu. |
| 171 | + * |
| 172 | + * @param appNames (List of Strings) Name of applications to build the adminMenu from |
| 173 | + * @param adminMenu the pre-filled content for the administration menu (macro is non-destructive on this parameter) |
| 174 | + * @param outputList |
| 175 | +*# |
| 176 | +#macro(_buildAdminMenuFromNameOfApps, $appNames, $adminMenu, $outputList) |
| 177 | + ## We start by copying what's already in the adminMenu. |
| 178 | + ## We can't use addAll directly because we want to make a deep copy of the structure |
| 179 | + #set ($discard = $outputList.addAll($jsontool.fromString($jsontool.serialize($adminMenu)))) |
| 180 | + ## Reset the category and section helper hashmaps so that they point to $outputlist and not $adminMenu anymore. |
180 | 181 | #set ($categoriesByName = {}) |
181 | | - #foreach ($category in $adminMenu) |
| 182 | + #set ($sectionsByName = {}) |
| 183 | + #foreach ($category in $outputList) |
182 | 184 | #set ($discard = $categoriesByName.put($category.id, $category)) |
183 | 185 | #foreach ($section in $category.children) |
184 | 186 | #set ($discard = $sectionsByName.put($section.id, $section)) |
185 | 187 | #end |
186 | 188 | #end |
187 | | - ## |
188 | | - #set ($query = "editor=$escapetool.url(${editor})") |
189 | | - #if ($editor != 'globaladmin') |
190 | | - #set ($query = $query + "&space=$escapetool.url(${currentSpace})") |
191 | | - #end |
192 | | - #foreach ($appName in $outputList) |
| 189 | + #foreach ($appName in $appNames) |
193 | 190 | ## |
194 | 191 | ## Get the configurable application |
195 | 192 | #set ($app = $xwiki.getDocument($appName)) |
|
220 | 217 | }) |
221 | 218 | #set ($discard = $categoriesByName.put($displayInCategory, $appCategory)) |
222 | 219 | ## Insert the category at the end for now. We'll sort the categories after we add all of them. |
223 | | - #set ($discard = $adminMenu.add($appCategory)) |
| 220 | + #set ($discard = $outputList.add($appCategory)) |
224 | 221 | #end |
225 | 222 | #set ($categoryIcon = $app.getValue('categoryIcon', $configurableObject)) |
226 | 223 | #if ("$!categoryIcon" != '') |
|
290 | 287 | #end |
291 | 288 | #end## Foreach configurable object in this app. |
292 | 289 | #end## Foreach application which is configurable. |
293 | | - ## |
294 | | - ## Sort the categories |
295 | | - ## |
296 | | - #foreach ($category in $adminMenu) |
| 290 | +#end |
| 291 | + |
| 292 | +#** |
| 293 | + * Computes the scores of categories and sorts the list. The first category will be the one with the highest score. |
| 294 | + * |
| 295 | + * @param completeOrderMenu the list of categories, containing all of the necessary ordering information; |
| 296 | + * This macro is destructive on $completeOrderMenu. |
| 297 | +*# |
| 298 | +#macro(_computeScores, $completeOrderMenu) |
| 299 | + ## Initialize scores |
| 300 | + #foreach ($category in $completeOrderMenu) |
297 | 301 | #set ($category.score = 0) |
298 | 302 | #end |
299 | | - #foreach ($round in [1..$adminMenu.size()]) |
| 303 | + ## Compute scores |
| 304 | + #foreach ($round in [1..$completeOrderMenu.size()]) |
300 | 305 | #set ($scoreChanged = false) |
301 | | - #foreach ($category in $adminMenu) |
| 306 | + #foreach ($category in $completeOrderMenu) |
302 | 307 | #if ($category.displayBeforeCategory) |
303 | 308 | #set ($newScore = $categoriesByName.get($category.displayBeforeCategory).score + 1) |
304 | 309 | #if ($newScore && $newScore > $category.score) |
|
311 | 316 | #break |
312 | 317 | #end |
313 | 318 | #end |
314 | | - #set ($adminMenu = $collectiontool.sort($adminMenu, 'score:desc')) |
315 | 319 | #end |
316 | 320 |
|
| 321 | +#** |
| 322 | + * Utility macro to compute the full order of categories, which is contained sparsely through xobjects |
| 323 | + * that are not always retrieved when building the menu. |
| 324 | + * |
| 325 | + * @param adminMenu the list of categories to use in the menu (macro is non-destructive on this parameter) |
| 326 | + * @param outputList the full list of categories, in order. Even categories without any child will be returned. |
| 327 | +*# |
| 328 | +#macro(_getCategoriesInOrder, $adminMenu, $outputList) |
| 329 | + #set ($params = { |
| 330 | + 'className' : $nameOfThisDocument, |
| 331 | + 'global': ['WIKI','WIKI+ALL_SPACES'] |
| 332 | + }) |
| 333 | + #set ($appNames = []) |
| 334 | + #set ($discard = $appNames.addAll($services.query.hql($statement).bindValues($params).execute())) |
| 335 | + ## $completeOrderMenu contains a menu that contains all the information needed for sorting, no matter what. |
| 336 | + #set ($completeOrderMenu = []) |
| 337 | + #_buildAdminMenuFromNameOfApps($appNames, $adminMenu, $completeOrderMenu) |
| 338 | + ## We use $completeOrderMenu to set the score of each category. |
| 339 | + #_computeScores($completeOrderMenu) |
| 340 | + #set ($completeOrderMenu = $collectiontool.sort($completeOrderMenu, 'score:desc')) |
| 341 | + ## Write the now sorted $completeOrderMenu to the output variable. |
| 342 | + #set ($discard = $outputList.addAll($completeOrderMenu)) |
| 343 | +#end |
317 | 344 |
|
318 | | -#* |
319 | | - * Show the heading for configuration for a given application. |
| 345 | +#** |
| 346 | + * Augment the $adminMenu variable with all $nameOfThisDocument (i.e. XWiki.ConfigurableClass) |
| 347 | + * XObjects found on this wiki. |
320 | 348 | * |
321 | | - * $appName (String) Name of the application to show configuration heading for. |
| 349 | + * @param adminMenu the basis of the menu on which to add on (the macro makes hard to reverse changes on $adminMenu) |
| 350 | +*# |
| 351 | +#macro(findCustomSectionsToConfigure $adminMenu) |
| 352 | + #set ($appNames = []) |
| 353 | + #set ($global = ($editor == 'globaladmin')) |
| 354 | + #findNamesOfAppsToConfigure('', $global, $currentSpace, $appNames) |
| 355 | + ## |
| 356 | + ## $completedAdminMenu contains most of the info needed to build the administration menu. |
| 357 | + #set ($completedAdminMenu = []) |
| 358 | + #_buildAdminMenuFromNameOfApps($appNames, $adminMenu, $completedAdminMenu) |
| 359 | + #set ($adminMenu = []) |
| 360 | + #set ($discard = $adminMenu.addAll($completedAdminMenu)) |
| 361 | + ## Sort the categories |
| 362 | + ## The information in $adminMenu is sometimes not enough to create a full order |
| 363 | + ## in those case we need to retrieve more information to build the full order. |
| 364 | + ## $categoriesFullOrder contains all the categories and their associated ordering information |
| 365 | + #if (!$global) |
| 366 | + #set ($categoriesFullOrder = []) |
| 367 | + #_getCategoriesInOrder($adminMenu, $categoriesFullOrder) |
| 368 | + ## Once it's retrieved, we use this total order on the categories in contained $adminMenu. |
| 369 | + #set ($sortedAdminMenu = []) |
| 370 | + #foreach ($orderedCategory in $categoriesFullOrder) |
| 371 | + #foreach ($menuCategory in $adminMenu) |
| 372 | + #if ($orderedCategory.id == $menuCategory.id) |
| 373 | + #set ($discard = $sortedAdminMenu.add($menuCategory)) |
| 374 | + #break |
| 375 | + #end |
| 376 | + #end |
| 377 | + #end |
| 378 | + #set ($adminMenu = []) |
| 379 | + #set ($discard = $adminMenu.addAll($sortedAdminMenu)) |
| 380 | + #else |
| 381 | + ## We're in the case where all the categories and sections are already in $adminMenu |
| 382 | + ## We can easily figure out an order |
| 383 | + #_computeScores($adminMenu) |
| 384 | + #set ($adminMenu = $collectiontool.sort($adminMenu, 'score:desc')) |
| 385 | + #end |
| 386 | +#end |
| 387 | + |
| 388 | + |
| 389 | +#** |
| 390 | + * Show the heading for configuration for a given application. |
322 | 391 | * |
323 | | - * $headingAlreadyShowing (boolean) If true then we don't make another heading. Otherwise it is set to true. |
324 | | - *### |
| 392 | + * @param appName (String) Name of the application to show configuration heading for. |
| 393 | + * @param headingAlreadyShowing (boolean) If true then we don't make another heading. Otherwise it is set to true. |
| 394 | +*# |
325 | 395 | #macro(showHeading, $appName, $headingAlreadyShowing) |
326 | 396 | #if(!$headingAlreadyShowing) |
327 | 397 | #set($headingAlreadyShowing = true) |
|
0 commit comments