/
menus_content.vm
486 lines (472 loc) · 20.5 KB
/
menus_content.vm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
## ---------------------------------------------------------------------------
## See the NOTICE file distributed with this work for additional
## information regarding copyright ownership.
##
## This is free software; you can redistribute it and/or modify it
## under the terms of the GNU Lesser General Public License as
## published by the Free Software Foundation; either version 2.1 of
## the License, or (at your option) any later version.
##
## This software is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
## Lesser General Public License for more details.
##
## You should have received a copy of the GNU Lesser General Public
## License along with this software; if not, write to the Free
## Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
## 02110-1301 USA, or see the FSF site: http://www.fsf.org.
## ---------------------------------------------------------------------------
##
## Globals
##
#set ($canView = !$doc.isNew() && $xwiki.hasAccessLevel('view'))
## Note: For Copy we would need to check that the user has edit permissions
## (since there's no create permission) for the *target* location. Since the
## user selects the target location in the Copy UI, we need to display the
## copy menu action. Checking if the user (or guest) doesn't have edit
## permissions on the whole wiki (including subwiki) is costly. Thus FTM we
## only check for view permissions.
#set ($canCopy = $canView)
#set ($nbUsers = $doc.getObjectNumbers("XWiki.XWikiUsers"))
#set ($nbGroups = $doc.getObjectNumbers("XWiki.XWikiGroups"))
#set ($hasAdminRights = $xwiki.hasAccessLevel('admin'))
#if ($nbUsers == 0 && $nbGroups == 0 || $hasAdminRights)
#set ($canDelete = !$doc.isNew() && $xwiki.hasAccessLevel('delete'))
#else
#set ($canDelete = false)
#end
#set ($canShare = $canView && $xwiki.exists('XWiki.SharePage') && !$isGuest)
## Add rel='nofollow' to prevent search crawler from navigating the links and indexing them in search results
#set ($extraAttributes = 'rel="nofollow"')
##
## Display the main menus
##
#if ($displayContentMenu)
#template("menus_macros.vm")
##
#set ($topStaticExtensions = [])
##
## TRANSLATE menu
##
#define ($translateMenu)
## Output the translate menu if all the following conditions are met:
## * multilingual is on
## * the user can edit the current document
## * the user is viewing the original document version
## * the document is translatable (either has a default locale specified or it has existing translations)
## * the current UI locale doesn't match the original document locale
#if (
$displayTranslateMenu &&
$xwiki.isMultiLingual() &&
$hasEdit && !$isReadOnly &&
$xcontext.action == 'view' && $tdoc.realLocale == $doc.realLocale &&
("$!doc.realLocale" != '' || !$doc.translationLocales.isEmpty()) &&
$doc.realLocale != $xcontext.locale
)
#displayTranslateMenu()
#end
#end
#set ($discard = $topStaticExtensions.add( { 'content': "$!translateMenu", 'order': 5000}))
##
## EDIT menu
##
#define ($editMenu)
#if ($displayEditMenu && $hasEdit && !$isReadOnly)
#displayEditMenu()
#end
#end
#set ($discard = $topStaticExtensions.add( { 'content': "$!editMenu", 'order': 10000}))
##
## CREATE menu
##
#define ($createMenu)
## Display a create menu if the user has the right to create spaces in the current wiki (since the Create UI supports)
## creating pages in other places in the hierarchy) or if the user has right to create pages in the current location.
## This supports the following 2 use cases for non-admin users:
## - I'm on a space where I don't have permissions to create pages but I have the right to create pages in the wiki.
## Example: I'm on my user profile which is located in the XWiki space (in which users don't have Edit rights by
## default). I can see the Create button. See https://jira.xwiki.org/browse/XWIKI-10999
## - I don't have the right to create pages in the wiki but I have the right to create pages under a given hierarchy.
## Example: I'm allowed to create pages only in the Sandbox space and I'm there. I can see the Create button.
## See https://jira.xwiki.org/browse/XWIKI-13847
#if ($displayCreateMenu && ($hasCreateSpace || $hasCreatePage))
#displayCreateButton()
#end
#end
#set ($discard = $topStaticExtensions.add( { 'content': "$!createMenu", 'order': 20000}))
##
## MORE ACTIONS menu
##
#define ($actionsMenu)
## Note: Both the admin actions and the more actions menus are now merged into one.
#if ($displayAdminMenu || $displayMoreActionsMenu)
#displayOptionsMenu()
#if ($canView)
#template("export_modal.vm")
#exportModal()
#end
#end
#end
#set ($discard = $topStaticExtensions.add( { 'content': "$!actionsMenu", 'order': 40000}))
##
## Display all the extensions points, including the static ones
##
#define ($menuContent)
#displaySecureUIX('org.xwiki.plaftorm.menu.content', $topStaticExtensions)
#end
##
## Display the menu
##
<div id="contentmenu" class="pull-right actionmenu">
$menuContent
#if($keyboardShortcutsEnabled)
#keyboardShortcuts()
#end
</div>
#end
#**
* Display a menu if it has some content.
*
* @param $id the id of the menu
* @param $icon the icon of the menu
* @param $content the content of the menu
* @param $titleKey translation key of the link title to use
* @param $titleAsLabel if the link title should also be used as link label
* @param $actionUrl the link of the top menu entry. If not provided, the top menu entry will act as an activator for the dropdown
* @param $extraAttribute (optional) additional A element attributes to add (such as ref="nofollow" for example)
*
* @since 7.3M2
*#
#macro(displayMenu $id $icon $menuContent $titleKey $titleAsLabel $actionUrl $extraAttribute)
<div class="btn-group" id="$id">
<a class="btn btn-default#if ("$!actionUrl" == '') dropdown-toggle#end" title="$services.localization.render($titleKey)"##
#if ("$!actionUrl" != '')
href="$actionUrl"
#else
data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"
#end
role="button"#if ("$!extraAttribute" != '') ${extraAttribute}#end>
$services.icon.renderHTML($icon)
#if ($titleAsLabel)
<span class="btn-label">$services.localization.render($titleKey)</span>
#end
</a>
#if ($stringtool.isNotBlank("$!menuContent"))
#if ("$!actionUrl" != '')
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<span class="caret"></span>
<span class="sr-only">$services.localization.render('core.menu.toggleDropdown')</span>
</button>
#end
<ul class="dropdown-menu #if ("$!actionUrl" == '')dropdown-menu-right#end">
$menuContent
</ul>
#end
</div>
#end
#**
* Display UI extensions if the author of the UIX has the ADMIN right on the current wiki
*
* @param $name the name of the UI extension to display
* @param $staticExtensions (optional) an array of static extensions to display along with the regular uix.
* e.g. [ { 'content': 'someHTMLcontent', 'order': 20000, 'separator': true } ]
* @param $count out parameter containing the number of entries displayed in the menu
* @since 7.3M1
*
* TODO: replace this macro to stop having "static extensions" but a mechanism to have real UI Extensions in templates.
*#
#macro(displaySecureUIX $name $staticExtensions $count)
#set ($count = 0)
## Add the static UIX to the list of UIX to display
#set ($extensions = [])
#set ($discard = $extensions.addAll($staticExtensions))
## Add the dynamic UIX to the list of of UIX to display
#foreach($uix in $services.uix.getExtensions($name))
#if ($services.security.authorization.hasAccess('admin', $uix.authorReference, $services.wiki.currentWikiDescriptor.reference))
#set ($separator = ("$!uix.getParameters().separator" == 'true'))
#set ($order = $numbertool.toNumber($uix.getParameters().order).intValue())
#if ("$!order" == '')
## Fallback for incomplete/invalid extension orders to avoid breaking the display.
#set ($order = 0)
#end
#set ($uixMap = { 'content' : $services.rendering.render($uix.execute(), 'html/5.0'),
'order' : $order,
'separator': $separator})
#set ($discard = $extensions.add($uixMap))
#end
#end
## Display them, sorted by order
#set ($canHaveMenuSeparator = false)
#foreach($uix in $collectiontool.sort($extensions, 'order'))
## Maybe display a menu separator
#if ("$!uix.separator" == 'true' && $canHaveMenuSeparator)
#submenuseparator()
#set ($canHaveMenuSeparator = false)
#end
#set ($content = $uix.content.toString())
$content
#if ($stringtool.isNotBlank($content))
#set ($canHaveMenuSeparator = true)
#set ($count = $count + 1)
#end
#end
#setVariable("$count", $count)
#end
#macro (submenuheader $titleKey)
<li class="dropdown-header">$services.localization.render($titleKey)</li>
#end
#**
* Display the create button
*#
#macro(displayCreateButton)
#displayMenu('tmCreate', 'add', '', 'core.menu.create', true, $doc.getURL('create'), $extraAttributes)
#end
#**
* Display the Translate button used to translate the current document in the current locale.
*#
#macro(displayTranslateMenu)
#set ($translateHint = $services.localization.render('core.menu.translate.hint',
[$xcontext.locale.getDisplayName($xcontext.locale)]))
#set ($translateDetails = $services.localization.render('core.menu.translate.details', [
$doc.realLocale.getDisplayName($xcontext.locale),
$xcontext.locale.getDisplayName($xcontext.locale)
]))
#set ($translateAttrs = "$!extraAttributes tabindex='0' data-toggle='popover' data-trigger='hover' " +
"data-container='body' data-placement='bottom' data-title='$escapetool.xml($translateHint)' " +
"data-content='$escapetool.xml($translateDetails)'")
#set ($translateURL = $doc.getURL('edit', $escapetool.url({'language': $xcontext.locale})))
#displayMenu('tmTranslate', 'translate', '', 'core.menu.translate', true, $translateURL, $translateAttrs)
#end
#**
* Display the edit menu
*#
#macro(displayEditMenu)
#set ($defaultEditURL = $doc.getURL($doc.getDefaultEditMode(), $!languageparams))
#set ($staticExtensions = [])
#if ($isAdvancedUser)
##
## WYSIWYG
##
## Check if the WYSIWYG supports the current document's syntax and if so add a menu entry to edit the current
## document with the WYSIWYG editor.
#define ($editWYSIWYG)
#if ($services.wysiwyg.isSyntaxSupported($tdoc.syntax.toIdString()))
#submenuitem($doc.getURL('edit', "$!{languageparams}#if ($languageparams != '')&#{end}editor=wysiwyg") $services.localization.render('core.menu.edit.wysiwyg') 'tmEditWysiwyg', '', 'pencil', $extraAttributes)
#end
#end
#set ($discard = $staticExtensions.add( { 'content': $editWYSIWYG, 'order': 20000, 'separator': true}))
##
## WIKI EDITOR
##
#define ($wikiEditor)
#submenuitem($doc.getURL('edit', "$!{languageparams}#if ($languageparams != '')&#{end}editor=wiki") $services.localization.render('core.menu.edit.wiki') 'tmEditWiki', '', 'wrench', $extraAttributes)
#end
#set ($discard = $staticExtensions.add( { 'content': $wikiEditor, 'order': 30000}))
##
## INLINE EDITOR
##
#define ($inlineEditor)
#submenuitem($doc.getURL('edit', "$!{languageparams}#if ($languageparams != '')&#{end}editor=inline") $services.localization.render('core.menu.edit.inline') 'tmEditInline', '', 'list', $extraAttributes)
#end
#set ($discard = $staticExtensions.add( { 'content': $inlineEditor, 'order': 40000}))
##
## RIGHTS
##
## The 'rights' editor is already present in the page administration. So we display it here only if we are not in
## a terminal document or if the user has not the admin right on the space (because right now the page
## administration is still combined with the space administration).
## TODO: create a proprer 'page administration' and stop adding a right editor in this menu
#define ($rightsEditor)
#if ($doc.documentReference.name != 'WebHome' || !$hasSpaceAdmin || !$isAdminAppInstalled)
#submenuitem($doc.getURL('edit', 'editor=rights') $services.localization.render('core.menu.edit.rights') 'tmEditRights', '', 'lock', $extraAttributes)
#end
#end
#set ($discard = $staticExtensions.add( { 'content': $rightsEditor, 'order': 50000, 'separator': true}))
##
## OBJECTS EDITOR
##
#set ($discard = $staticExtensions.add( { 'content': "#submenuitem($doc.getURL('edit', 'editor=object') $services.localization.render('core.menu.edit.object') 'tmEditObject', '', 'bricks', $extraAttributes)", 'order': 60000}))
##
## CLASS EDITOR
##
#set ($discard = $staticExtensions.add( { 'content': "#submenuitem($doc.getURL('edit', 'editor=class') $services.localization.render('core.menu.edit.class') 'tmEditClass', '', 'box', $extraAttributes)", 'order': 70000}))
#end
##
## Display all the extensions points, including the static ones
##
#define ($menuContent)
#displaySecureUIX('org.xwiki.plaftorm.editactions', $staticExtensions)
#end
#displayMenu('tmEdit', 'pencil', $menuContent, 'core.menu.edit', true, $defaultEditURL, $extraAttributes)
#end
#**
* Display admin actions
*#
#macro(displayAdminActions)
#set ($staticExtensions = [])
##
## COPY
##
#if ($canCopy)
#define ($copy)
#submenuitem($xwiki.getURL($doc.documentReference, 'view', 'xpage=copy') $services.localization.render('core.menu.copy') 'tmActionCopy', '' 'copy', $extraAttributes)
#end
#set ($discard = $staticExtensions.add( { 'content': $copy, 'order': 20000}))
#end
##
## DELETE / RENAME
##
#if ($canDelete)
#define ($rename)
#submenuitem($xwiki.getURL($doc.documentReference, 'view', 'xpage=rename&step=1') $services.localization.render('core.menu.rename') 'tmActionRename', '' 'edit', $extraAttributes)
#end
#set ($discard = $staticExtensions.add( { 'content': $rename, 'order': 30000}))
#define ($delete)
#submenuitem($xwiki.getURL($doc.documentReference, 'delete', $!languageparams) $services.localization.render('core.menu.delete') 'tmActionDelete', '', 'remove', $extraAttributes)
#end
#set ($discard = $staticExtensions.add( { 'content': $delete, 'order': 40000}))
#end
##
## Display all the extensions points, including the static ones
##
#displaySecureUIX('org.xwiki.plaftorm.adminactions', $staticExtensions)
#end
#**
* Display "more actions" entries
*#
#macro(displayMoreActions)
#set ($staticExtensions = [])
##
## EXPORT / PRINT / SOURCE / SHARE
##
#if ($canView)
##
## EXPORT (only if we are not in the pdfoptions to export the page)
##
#if ("$!request.xpage" != 'pdfoptions')
#define ($export)
#submenuitem('' $services.localization.render('core.menu.export') 'tmExport', '', 'download', 'data-toggle="modal" data-target="#exportModal"')
#end
#set ($discard = $staticExtensions.add( { 'content': $export, 'order': 80000}))
#end
##
## PRINT
##
#define ($print)
#submenuitem($doc.getURL('view', "xpage=print&$!escapetool.html($request.getQueryString())") $services.localization.render('core.menu.preview') 'tmPrintPreview', '', 'print', $extraAttributes)
#end
#set ($discard = $staticExtensions.add( { 'content': $print, 'order': 90000}))
##
## SHARE BY EMAIL
##
#if ($canShare)
#define ($share)
#submenuitem($xwiki.getURL($doc.documentReference, 'view', 'viewer=share') $services.localization.render('core.menu.share') 'tmActionShare', '', 'envelope', $extraAttributes)
#userPicker_import()
#end
#set ($discard = $staticExtensions.add( { 'content': $share, 'order': 110000}))
$xwiki.jsx.use('XWiki.SharePage')
$xwiki.ssx.use('XWiki.SharePage')
#end
#end
##
## Display all the extensions points, including the static ones
##
#displaySecureUIX('org.xwiki.plaftorm.moreoptions', $staticExtensions)
#end
#**
* Display options menu
*#
#macro(displayOptionsMenu)
##
## Display all the extensions points, including the static ones
##
#define ($menuContent)
#set ($needsSeparator = false)
## Admin actions UIXP
#if ($displayAdminMenu)
#set ($adminActions = "#displayAdminActions()")
#if ($stringtool.isNotBlank("$!adminActions"))
#submenuheader('core.menu.actions.main')
$adminActions
#set ($needsSeparator = true)
#end
#end
## More actions UIXP
#if ($displayMoreActionsMenu)
#set ($moreActions = "#displayMoreActions()")
#if ($stringtool.isNotBlank("$!moreActions"))
#if ($needsSeparator)
#submenuseparator()
#end
#submenuheader('core.menu.actions.others')
$moreActions
#set ($needsSeparator = true)
#end
## ----------------------------
## Display the shortcuts
## ----------------------------
#if($xwiki.hasAccessLevel('view') && $displayShortcuts)
#set ($viewersContent = "#template('shortcuts.vm')")
## Only display a separator if at least one menu entry has been displayed before
#if ($needsSeparator)
#submenuseparator()
#end
#submenuheader('core.menu.actions.viewers')
##
## VIEW SOURCE
##
#if ("$!request.rev" != '')
#set ($revisionParameter = "&rev=$request.rev")
#end
#submenuitem($doc.getURL('view', "viewer=code$!{revisionParameter}") $services.localization.render('core.menu.view.source') 'tmViewSource', '', 'search', $extraAttributes)
$viewersContent
## Display Viewers menu UIX..
#displaySecureUIX('org.xwiki.platform.template.menu.viewers', [])
#set ($needsSeparator = true)
#end
#end
#end
##
## Display the menu if it has some content
##
#displayMenu('tmMoreActions', 'more-vertical', $menuContent, 'core.menu.actions.label')
#end
#**
* Add keyboard shortcuts
*#
#macro(keyboardShortcuts)
<script>
//<![CDATA[
#if ($hasEdit && !$isReadOnly)
shortcut.add("$services.localization.render('core.shortcuts.view.edit')", function() {
var editLink = $('tmEdit').down('a');
// Make sure the shortcut doesn't work when the edit link is disabled.
if (editLink && !editLink.classList.contains('disabled')) {
// Simulate the user click because the edit link can have click listeners registered (which aren't executed if
// we simply change the window location using the link URL).
editLink.click();
}
}, {'disable_in_input': true});
#if($isAdvancedUser)
shortcut.add("$services.localization.render('core.shortcuts.view.wiki')",function() { location.href=$('tmEditWiki').href; }, { 'disable_in_input':true });
shortcut.add("$services.localization.render('core.shortcuts.view.wysiwyg')",function() { location.href=$('tmEditWysiwyg').href; }, { 'disable_in_input':true });
shortcut.add("$services.localization.render('core.shortcuts.view.inline')",function() { location.href=$('tmEditInline').href; }, { 'disable_in_input':true });
shortcut.add("$services.localization.render('core.shortcuts.view.rights')",function() { var editRights = $('tmEditRights'); location.href= editRights ? editRights.href : "$xwiki.getURL($spacePreferencesDocumentReference, 'admin', 'category=1')";}, { 'disable_in_input':true });
shortcut.add("$services.localization.render('core.shortcuts.view.objects')",function() { location.href=$('tmEditObject').href; }, { 'disable_in_input':true });
#if($hasAdmin)
shortcut.add("$services.localization.render('core.shortcuts.view.class')",function() { location.href=$('tmEditClass').href; }, { 'disable_in_input':true });
#end
#end
#end
#if ($canDelete && $displayAdminMenu)
shortcut.add("$services.localization.render('core.shortcuts.view.delete')",function() { location.href=$('tmActionDelete').href; }, { 'disable_in_input':true });
shortcut.add("$services.localization.render('core.shortcuts.view.rename')",function() { location.href=$('tmActionRename').href; }, { 'disable_in_input':true });
#end
#if ($canView && $displayMoreActionsMenu)
shortcut.add("$services.localization.render('core.shortcuts.view.code')", function() { location.href = $('tmViewSource').href; }, { 'disable_in_input': true });
#end
//]]>
</script>
#end