/
macros.vm
3096 lines (2995 loc) · 130 KB
/
macros.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
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
## ---------------------------------------------------------------------------
## 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.
## ---------------------------------------------------------------------------
###############################################################
## Contains various standard Velocity macros automatically
## loaded and usable everywhere (in Velocity).
##
## Note that if you modify that file you will need to restart.
###############################################################
##
## #template("name.vm")
## Searches for the given velocity template and interprets it.
## Only the velocity parser is executed on the file.
## The template is searched in the following locations, in this order:
## - as a property of the XWikiSkins object attached to the current skin document
## - as an attachment to the current skin document
## - as a file in the directory corresponding to the current skin
## - the above 3 locations corresponding to the base skin
## - the above 3 locations corresponding to the default skin
## - as a file in the /templates/ directory
##
#macro(template $tname)
$services.template.render($tname)
#end
##
##
## #renderTemplate("name.vm")
## Searches for the given velocity template and renders it.
## The template is searched in the following locations, in this order:
## - as a property of the XWikiSkins object attached to the current skin document
## - as an attachment to the current skin document
## - as a file in the directory corresponding to the current skin
## - the above 3 locations corresponding to the base skin
## - the above 3 locations corresponding to the default skin
## - as a file in the /templates/ directory
##
#macro(renderTemplate $tname )
$xwiki.renderTemplate($tname)
#end
##
##
## #includeTopic("Space.Document")
## Includes another fully rendered document inside the current response.
## The topic is interpreted and rendered exactly as if it were viewed in a separate response,
## meaning that the $doc variable will point to the included document. The resulting string is
## wrapped with {pre}...{/pre}, in order to prevent double-rendering.
## The platform prevents recursive includes.
## This macro is useful for creating composite documents from smaller parts, or the other way around,
## splitting a large document into smaller distinct chunks which can be edited in parallel.
##
#macro(includeTopic $topic)
$xwiki.includeTopic($topic)
#end
##
##
## #includeMacros("Space.Document")
## Includes the content of another document as velocity macros. Because of the way the velocity
## engine works, trying to place macros in another document and including it with another method
## will not have the expected result. Other than making the macros available, it works just as
## #includeForm($topic)
##
#macro(includeMacros $topic)
$xwiki.includeForm($topic)
#end
##
##
## #includeForm("Space.Document")
## Includes another fully rendered document inside the current response.
## The included content is interpreted and rendered in the current context, meaning that $doc will
## point to the current document (the includer), and not the included one. The resulting string is
## wrapped with {pre}...{/pre}, in order to prevent double-rendering.
## The platform prevents recursive includes.
## This macro is the core of the document-template-sheet functionality of XWiki, where a document
## has an XObject attached to it, its content consists of the "#includeForm('Some.Sheet')" statement,
## and the sheet works just as if it were actually inside the document's content.
##
#macro(includeForm $topic)
$xwiki.includeForm($topic)
#end
##
##
## #includeInContext("Some.Document")
## Alias for #includeForm
##
#macro(includeInContext $topic)
$xwiki.includeForm($topic)
#end
##
##
## #includeServlet("/xwiki/bin/view/Some/Document?params")
## Invokes on the server another servlet corresponding to the passed URL, and returns the output.
## This is done using standard servlet mechanisms (javax.servlet.RequestDispatcher#include).
##
#macro(includeServlet $url)
<!-- including $url -->
$xwiki.invokeServletAndReturnAsString($url)
<!-- included $url -->
#end
##
##
##
##
## #skype("skypeId")
## Displays the status for the given Skype id
##
## @Deprecated
#macro(skype $id)
<a href="skype:${id}?call"><img width="182" height="44" src="http://mystatus.skype.com/bigclassic/${id}" style="border: none;"></a>
#end
##
##
## #yahoo("yahooId")
## Displays the status for the given Yahoo! id
##
## @Deprecated
#macro(yahoo $id)
<img border="0" src="http://opi.yahoo.com/online?u=${id}&m=g&t=1" alt="yahoo $id" />
#end
## #sign("XWiki.Username")
## Displays a "signature", a link to the user's profile page.
##
#macro(sign $username)
#if($username.indexOf(".")==-1)
#set($username = "XWiki.${username}")
#end
#if($xwiki.exists("$username"))
$xwiki.getUserName("$username")
#else
$xwiki.getUserName("xwiki:${username}")
#end
#end
#macro(includeHelp $pagename)
#if($xwiki.exists("xwiki:XWiki.${pagename}"))
$xwiki.includeForm("xwiki:XWiki.${pagename}",false)
#else
#if($xwiki.exists("XWiki.${pagename}"))
$xwiki.includeForm("XWiki.${pagename}",false)
#end
#end
#end
#macro(toc $pinit $pmax $pnumbered)
#set($init = $pinit)
#set($max = $pmax)
#set($numbered = $pnumbered)
#set ($int = 0)
#set ($boolean = false)
#if ($init == "")
#set ($init = 2)
#else
#set ($init = $int.valueOf($init))
#end
#if ($max == "")
#set ($max = 6)
#else
#set ($max = $int.valueOf($max))
#end
#if ($numbered == "")
#set ($numbered = false)
#else
#set ($numbered = $boolean.valueOf($numbered))
#end
#set ($tocData = ${tdoc.getTOC($init, $max, $numbered)})
#set ($xcontext.tocData = $tocData)
#set ($lastLevel = $init - 1)
#set ($depth = 0)
#set ($openeditem = true)
<div class="toc">
#foreach ($tocEntry in $tocData.entrySet())
#set ($level = $tocEntry.value.level)
#if ($level > $lastLevel)
#set ($to = $lastLevel + 1)
#set ($iter = [$level .. $to])
#foreach ($n in $iter)
#if($openeditem)
#set($openeditem = false)
#else
<li>
#end
<ul class="tocLevel">
#set ($depth = $depth + 1)
#end
#elseif ($level < $lastLevel)
#set ($to = $level + 1)
#set ($iter = [$lastLevel .. $to])
</li>
#foreach ($n in $iter)
</ul>
</li>
#set ($depth = $depth - 1)
#end
#else
</li>
#end
<li class="tocEntry"><a href="#$tocEntry.key">$!tocEntry.value.numbering #evaluate($tocEntry.value.text)</a>
#set ($lastLevel = $level)
#set($openeditem = true)
#end
#if ($depth > 0)
#set ($levels = [1 .. $depth])
#foreach($level in $levels)
</li>
</ul>#end
#end
</div>
#end
###
### Separator
###
### Insert a span containing a |
###
#macro(sep)
<span class="separator"> | </span>
#end
#**
* Displays the user avatar and name, linked to the user profile page.
*
* @param arg could be either a string, a reference or a list of them
* @param options various configuration options; default values are {
* showAlias: false, // whether to show the user alias or not
* useInlineHTML: false, // whether to use in-line HTML elements to display the user or not
* wrapAvatar: false // whether to wrap the avatar image with a span or not
* displayLink: true // @since 15.9 ; whether to wrap the user name in a link to the user profile
* }
*#
#macro (displayUser $arg $options)
#if ($stringtool.isEmpty($arg))
#set ($arg = "XWiki.XWikiGuest")
#end
#set ($isList = $arg.iterator())
#if ($isList)
#set ($usersList = $arg)
#else
#set ($usersList = [$arg])
#end
#set ($macro.options = {
'showAlias': false,
'useInlineHTML': false,
'wrapAvatar': false,
'displayLink': true
})
#if ($options.entrySet())
#set ($discard = $macro.options.putAll($options))
#end
#set ($usersTag = 'ul')
#set ($userTag = 'li')
#if ($macro.options.useInlineHTML)
#set ($usersTag = 'span')
#set ($userTag = 'span')
#elseif (!$isList)
#set ($userTag = 'div')
#end
#set ($types = $collectiontool.set)
#set ($output = [])
#foreach ($user in $usersList)
## Since we accept both a String or an EntityReference as input, we first check if we have an Entity Reference
## to a Document and if not then we resolve the String to convert it to a Document Reference.
#set ($userReference = $user.extractReference('DOCUMENT'))
#if (!$userReference)
#set ($userReference = $services.model.resolveDocument($user, 'user/current'))
#end
#set ($userAlias = $userReference.name)
#if ($userAlias == $services.model.getEntityReference('DOCUMENT', 'default'))
#set ($userAlias = $userReference.lastSpaceReference.name)
#end
#set ($userDocument = $xwiki.getDocument($userReference))
#if ($userDocument.getObject('XWiki.XWikiGroups'))
#set ($type = 'group')
#set ($userName = $userDocument.plainTitle)
#if ("$!userName" == '')
#set ($userName = $userAlias)
#end
#else
#set ($type = 'user')
#set ($userName = $xwiki.getPlainUserName($userReference))
#end
#set ($discard = $types.add("${type}s"))
#set ($userAliasDisplay = '')
#if ($macro.options.showAlias && $userAlias != $userName)
#set ($userAliasDisplay = "<span class=""${type}-alias"">" + $escapetool.xml($userAlias) + '</span>')
#end
#set ($escapedUserName = $escapetool.xml($userName))
#getUserAvatarURL($userReference $avatarURL 120)
#set ($avatarWrapperStart = '')
#set ($avatarWrapperEnd = '')
#if ($macro.options.wrapAvatar)
#set ($avatarWrapperStart = "<span class=""${type}-avatar-wrapper"">")
#set ($avatarWrapperEnd = '</span>')
#end
#set($userNameTagAttributes = "class=""${type}-name""")
#if ($macro.options.displayLink)
#set($userNameTag = 'a')
#set($userNameTagAttributes = "$userNameTagAttributes href=""$escapetool.xml($xwiki.getURL($userReference))""")
#else
#set($userNameTag = 'span')
#end
## We avoid the whitespace because the users are displayed as inline blocks.
#set ($discard = $output.addAll([
"<$userTag class=""$type"" data-reference=""$escapetool.xml($userReference)"">",
$avatarWrapperStart,
"<img class=""${type}-avatar"" src=""$escapetool.xml($avatarURL.url)"" alt=""$escapedUserName"" />",
$avatarWrapperEnd,
"<$userNameTag $userNameTagAttributes>$escapedUserName</$userNameTag>",
$userAliasDisplay,
"</$userTag>"
]))
#end
#if ($isList && $output.size() > 0)
#set ($discard = $output.add(0, "<$usersTag class=""$stringtool.join($types, ' ')"">"))
#set ($discard = $output.add("</$usersTag>"))
#end
$stringtool.join($output, '')
#end
#**
* Displays the group avatar and name, linked to the group profile page.
*
* @param arg could be either a string, a reference or a list of them
* @param options various configuration options; default values are {
* showAlias: false, // whether to show the group alias or not
* useInlineHTML: false, // whether to use in-line HTML elements to display the group or not
* wrapAvatar: false // whether to wrap the avatar image with a span or not
* displayLink: true // @since 15.9 ; whether to wrap the group name in a link to the group profile
* }
*#
#macro (displayGroup $arg $options)
#displayUser($arg $options)
#end
###
### useravatar
###
### Display the avatar of a user or a group, or a default image if the user/group has no avatar
###
### @param username The name of the user or group whose avatar will be displayed
###
#macro(getUserAvatarURL $userName $return $size)
#set ($specified = false)
#set ($profileDoc = $xwiki.getDocument($userName))
#if ($profileDoc.getObject('XWiki.XWikiGroups'))
#set ($url = $xwiki.getSkinFile('icons/xwiki/noavatargroup.png', true))
#else
#set ($url = $xwiki.getSkinFile('icons/xwiki/noavatar.png', true))
#end
#if ($profileDoc && !$profileDoc.isNew() && $profileDoc.attachmentList.size() > 0)
#set ($profileObj = $profileDoc.getObject('XWiki.XWikiUsers', 0))
#set ($avatarFileName = $profileObj.getProperty('avatar').value)
#if ("$!avatarFileName" != '')
#set ($avatarAttachment = $profileDoc.getAttachment($avatarFileName))
#elseif ($profileDoc.getObject('XWiki.XWikiGroups'))
## Look for the first image attachment.
#foreach ($attachment in $profileDoc.attachmentList)
#if ($attachment.isImage())
#set ($avatarAttachment = $attachment)
#break
#end
#end
#else
## This ensures that $avatarAttachment is always set before the following "if" is called, preventing a previous
## call to this macro from leaking...
#set ($avatarAttachment = $NULL)
#end
#if ($avatarAttachment && $avatarAttachment.isImage())
#set ($queryString = '')
#if ($size > 0)
#set ($queryString = "width=$size&height=$size&keepAspectRatio=true")
#end
#set ($url = $profileDoc.getAttachmentURL($avatarAttachment.filename, 'download', $queryString))
#set ($specified = true)
#end
#end
#set ($return = $NULL)
#setVariable ("$return" {'url': $url, 'specified': $specified})
#end
#macro(resizedUserAvatar $username $size)
#if(!$picturelist)
#set($picturelist = {})
#end
#if(!$picturelist.containsKey("${username}--${size}"))
#getUserAvatarURL($username $avatarURL $size)
#if ($avatarURL.specified)
#set ($picture = "<img class='avatar avatar_${escapetool.xml(${size})}' src='")
#set ($picture = $picture.concat($escapetool.xml($avatarURL.url)))
#set ($picture = $picture.concat("' alt='"))
#set ($picture = $picture.concat(${xwiki.getUserName($username, false)}))
#set ($picture = $picture.concat("' title='"))
#set ($picture = $picture.concat(${xwiki.getUserName($username, false)}))
#set ($picture = $picture.concat("'/>"))
#else
#set ($picture = "<img class='avatar avatar_${escapetool.xml(${size})}' src='")
#set ($picture = $picture.concat($avatarURL.url))
#set ($picture = $picture.concat("' alt='${xwiki.getUserName($username, false)}' title='${xwiki.getUserName($username, false)}'/>"))
#end
#set ($discard = $!picturelist.put("${username}--${size}", $picture))
#end
$picturelist.get("${username}--${size}")##
#end
#macro(largeUserAvatar $username)
#resizedUserAvatar($username 120)
#end
#macro(mediumUserAvatar $username)
#resizedUserAvatar($username 50)
#end
#macro(smallUserAvatar $username)
#resizedUserAvatar($username 30)
#end
###
### useravatar
###
### Display the avatar of a user (HTML is returned), or a standard image if the user has no avatar
###
### @param username The name of the user whose avatar will be displayed
###
#macro(useravatar $username)
#resizedUserAvatar($username 0)
#end
###
### mimetypeimg
###
### Display an icon according to the mimetype
###
### @param mime The reported mimetype of the file
### @param fname The name of the file
###
#macro(mimetypeimg $mime $fname)
#set($idx = $fname.lastIndexOf('.'))
#set($idx = $idx + 1)
#if(($idx != 0) && ($idx != -1))
#set($ext = $fname.substring($idx))
#else
#set($ext = '')
#end
## Map mimetypes to their corresponding icons
#if(!$mimetypeMap)
#set($mimetypeMap = {})
## images
#set($discard = $mimetypeMap.put('image/svg+xml', ['vector', 'svg']))
#set($discard = $mimetypeMap.put('application/svg+xml', ['vector', 'svg']))
#set($discard = $mimetypeMap.put('image/svg', ['vector', 'svg']))
#set($discard = $mimetypeMap.put('image/svg+xml', ['vector', 'svg']))
#set($discard = $mimetypeMap.put('image/', ['image', 'image']))
## text
#set($discard = $mimetypeMap.put('text/html', ['file-code', 'html']))
#set($discard = $mimetypeMap.put('text/css', ['file-code', 'css']))
#set($discard = $mimetypeMap.put('text/', ['file-text', 'text']))
## documents
#set($discard = $mimetypeMap.put('application/xml', ['file-code', 'xml']))
#set($discard = $mimetypeMap.put('application/pdf', ['file-pdf', 'pdf']))
#set($discard = $mimetypeMap.put('application/postscript', ['file-pdf', 'ps']))
#set($discard = $mimetypeMap.put('application/msword', ['file-word', 'document']))
#set($discard = $mimetypeMap.put('application/powerpoint', ['file-powerpoint', 'presentation']))
#set($discard = $mimetypeMap.put('application/vnd.ms-powerpoint', ['file-powerpoint', 'presentation']))
#set($discard = $mimetypeMap.put('application/vnd.oasis.opendocument', ['file', 'office']))
#set($discard = $mimetypeMap.put('application/x-shockwave-flash', ['film', 'flash']))
## archives
#set($discard = $mimetypeMap.put('application/x-tar', ['file-archive', 'tar']))
#set($discard = $mimetypeMap.put('application/x-gzip', ['file-archive', 'gz']))
#set($discard = $mimetypeMap.put('application/x-gtar', ['file-archive', 'gz']))
#set($discard = $mimetypeMap.put('application/zip', ['file-archive', 'zip']))
#set($discard = $mimetypeMap.put('application/java-archive', ['coffee', 'jar']))
#set($discard = $mimetypeMap.put('audio/', ['music', 'audio']))
#set($discard = $mimetypeMap.put('video/', ['film', 'video']))
#end
#if(!$extensionMap)
## Map extensions to their corresponding icons
#set($extensionMap = {})
## media
#set($discard = $extensionMap.put('ogg', ['music', 'audio']))
#set($discard = $extensionMap.put('flac', ['music', 'audio']))
#set($discard = $extensionMap.put('ogv', ['film', 'video']))
#set($discard = $extensionMap.put('mk', ['film', 'video']))
#set($discard = $extensionMap.put('avi', ['film', 'video']))
#set($discard = $extensionMap.put('divx', ['film', 'video']))
#set($discard = $extensionMap.put('mov', ['film', 'video']))
#set($discard = $extensionMap.put('flv', ['film', 'flash']))
#set($discard = $extensionMap.put('fla', ['film', 'flash']))
#set($discard = $extensionMap.put('swf', ['film', 'flash']))
## office
#set($discard = $extensionMap.put('ppt', ['file-powerpoint', 'presentation']))
#set($discard = $extensionMap.put('odp', ['file-powerpoint', 'presentation']))
#set($discard = $extensionMap.put('doc', ['file-word', 'document']))
#set($discard = $extensionMap.put('odf', ['file', 'document']))
#set($discard = $extensionMap.put('ods', ['file-excel', 'spreadsheet']))
#set($discard = $extensionMap.put('xls', ['file-excel', 'spreadsheet']))
#set($discard = $extensionMap.put('odt', ['file-word', 'odt']))
#set($discard = $extensionMap.put('sxw', ['file-word', 'office']))
#set($discard = $extensionMap.put('stw', ['file-word', 'office']))
## archives
#set($discard = $extensionMap.put('bz', ['file-archive', 'bz']))
#set($discard = $extensionMap.put('bz2', ['file-archive', 'bz']))
#set($discard = $extensionMap.put('tbz', ['file-archive', 'bz']))
#set($discard = $extensionMap.put('gz', ['file-archive', 'gz']))
#set($discard = $extensionMap.put('tgz', ['file-archive', 'gz']))
#set($discard = $extensionMap.put('rar', ['file-archive', 'rar']))
#set($discard = $extensionMap.put('7z', ['file-archive', 'zip']))
## development
#set($discard = $extensionMap.put('sql', ['database', 'sql']))
#set($discard = $extensionMap.put('php', ['file-code', 'php']))
#set($discard = $extensionMap.put('c', ['file-code', 'c']))
#set($discard = $extensionMap.put('cpp', ['file-code', 'cpp']))
#set($discard = $extensionMap.put('c++', ['file-code', 'cpp']))
#set($discard = $extensionMap.put('cs', ['file-code', 'cs']))
#set($discard = $extensionMap.put('h', ['file-code', 'h']))
#set($discard = $extensionMap.put('ruby', ['file-code', 'ruby']))
#set($discard = $extensionMap.put('java', ['coffee', 'java']))
#set($discard = $extensionMap.put('js', ['file-code', 'js']))
#set($discard = $extensionMap.put('csproj', ['file-code', 'vs']))
#set($discard = $extensionMap.put('sln', ['file-code', 'vs']))
#set($discard = $extensionMap.put('res', ['file-code', 'vs']))
## data
#set($discard = $extensionMap.put('ics', ['calendar', 'calendar']))
#set($discard = $extensionMap.put('eml', ['email', 'email']))
#set($discard = $extensionMap.put('vcf', ['vcard', 'vcard']))
#set($discard = $extensionMap.put('vcard', ['vcard', 'vcard']))
## executables
#set($discard = $extensionMap.put('exe', ['cog', 'exe']))
#set($discard = $extensionMap.put('bat', ['terminal', 'script']))
#set($discard = $extensionMap.put('sh', ['terminal', 'script']))
#end
#if($mimetypeMap.containsKey($mime))
#set ($image = $mimetypeMap.get($mime).get(0))
#set ($text = $mimetypeMap.get($mime).get(1))
#elseif ($extensionMap.containsKey($ext))
#set ($image = $extensionMap.get($ext).get(0))
#set ($text = $extensionMap.get($ext).get(1))
#else
#set ($mimetypePrefix = $mime.indexOf('/'))
#set ($mimetypePrefix = $mimetypePrefix + 1)
#set ($mimetypePrefix = $mime.substring(0, $mimetypePrefix))
#if ($mimetypeMap.containsKey($mimetypePrefix))
#set ($image = $mimetypeMap.get($mimetypePrefix).get(0))
#set ($text = $mimetypeMap.get($mimetypePrefix).get(1))
#else
#set ($image = 'attach')
#set ($text = 'attachment')
#end
#end
<span title="${services.localization.render("core.viewers.attachments.mime.${text}")}">$!services.icon.renderHTML($image)</span>
#end
###
### packName
###
### Display a shorter version of a string
###
### @param name The processed string
###
#macro(packName $name)
#if(!$maxnamelength)
#set($maxnamelength = 25)
#end
#set($idx = $name.lastIndexOf("."))
#if(($idx != 0) && ($idx != -1))
#set($ext = $name.substring($idx))
#else
#set($ext = "")
#set($idx = $name.length())
#end
#set($fname = $name.substring(0, $idx))
#if($fname.length() > $maxnamelength)$fname.substring(0, $maxnamelength)~$ext#else$name#end
#end
#macro(xwikiobjectfield $fielddoc $fieldname $fieldtext $action)
<div class="xmblabel">$fieldtext</div>
<div class="xmbfield">
#if($fieldname!="")
$fielddoc.display($fieldname, $action)
#end
</div>
#end
##
## Formats a date according to the ISO8601 standard
##
#macro(formatdateISO $date)
#set($tz = $xwiki.formatDate($date, "Z"))
#set($tz = "${tz.substring(0, 3)}:${tz.substring(3)}")
$xwiki.formatDate($date, "yyyy-MM-dd")T$xwiki.formatDate($date, "HH:mm:ss")$tz#end
##
## Formats a username like a fn (hCard microformat)
##
#macro(userfn $username)
#set($fn = $xwiki.getUserName($username))
#if($fn.indexOf("<a") >= 0)
#set($fn = $fn.replaceAll("<a", '<a class="url fn"'))
#else
#set($fn = "<span class='fn'>$fn</span>")
#end
$fn
#end
###
###
### Macros for "foot notes"
###
### TODO:
### Make Radeox macros
### Support in wysiwyg
###
###
#macro(footnote $text)
#if(!$page_footnotes)
#set($page_footnotes = [])
#set($footnote_group_id = 1)
#end
#set($discard = $page_footnotes.add($text))
#set($processedText = $text.replaceAll('[*~<>_-]', ''))
#set($footnote_id = $page_footnotes.size())
<sup class="footnoteRef" id="footnoteref_${footnote_group_id}_${footnote_id}"><a href="#footnote_${footnote_group_id}_${footnote_id}" title="$services.localization.render('core.footnotes.gotofootnote', [${footnote_id}]): {pre}$processedText{/pre}">$footnote_id</a></sup>#end
##
##
##
#macro(putFootnotes)
#if($page_footnotes && ($page_footnotes.size() > 0))
<ol class="footnotes">
#foreach($footnote in $page_footnotes)
<li id="footnote_${footnote_group_id}_${foreach.count}">
<a class="footnoteBackRef" title="$services.localization.render('core.footnotes.backtoref')" href="#footnoteref_${footnote_group_id}_${foreach.count}">^</a>
$footnote</li>
#end
</ol>
#set($discard = $page_footnotes.clear())
#set($footnote_group_id = $footnote_group_id + 1)
#end
#end
##
## Generate navigation links for paged documents. It will use the URL parameters "ipp" to forward
## the number of items per page, and "page" to indicate a certain page. The actual range (in items,
## not in pages) can be computer using #preparePagedViewParams. The macro does not print anything
## if only one page exists and $alwaysDisplay is not set to true. Does not alter any variables.
##
## @param itemsPerPage The number of items per page, will be forwarded in the links to other pages.
## @param totalPages The total number of pages, starting at 1.
## @param currentPageNumber The currently displayed page, starting at 1.
## @param additionalQueryParams Query string fragment that should be put in the links. Should not
## start or end with ? or &
## @param alwaysDisplay Force display of the links, even if there is only one page in total.
##
#macro(printPagedViewLinks $itemsPerPage $totalPages $currentPageNumber $additionalQueryParams $alwaysDisplay)
## Only display if there are more than 1 pages or we explicitely require it.
#if(($totalPages > 1) || $alwaysDisplay)
<div class="pagedNavigation">
#if($currentPageNumber > 1)
#set($currentPageNumber = $currentPageNumber - 1)
<span class="pagedLink"><a href="$doc.getURL($xcontext.action, "page=1&ipp=${itemsPerPage}")#if("$!additionalQueryParams" != "")&$additionalQueryParams#end">$services.localization.render('web.paging.firstPage')</a></span>
<span class="pagedLink"><a href="$doc.getURL($xcontext.action, "page=${currentPageNumber}&ipp=${itemsPerPage}")#if("$!additionalQueryParams" != "")&$additionalQueryParams#end">$services.localization.render('web.paging.previousPage')</a></span>
#set($currentPageNumber = $currentPageNumber + 1)
#else
<span class="pagedLink inactive">$services.localization.render('web.paging.firstPage')</span>
<span class="pagedLink inactive">$services.localization.render('web.paging.previousPage')</span>
#end
<span class="pagedStatus">$services.localization.render('web.paging.pageNumberOf', [$currentPageNumber, $totalPages])</span>
#if($currentPageNumber < $totalPages)
#set($currentPageNumber = $currentPageNumber + 1)
<span class="pagedLink"><a href="$doc.getURL($xcontext.action, "page=${currentPageNumber}&ipp=${itemsPerPage}")#if("$!additionalQueryParams" != "")&$additionalQueryParams#end">$services.localization.render('web.paging.nextPage')</a></span>
<span class="pagedLink"><a href="$doc.getURL($xcontext.action, "page=${totalPages}&ipp=${itemsPerPage}")#if("$!additionalQueryParams" != "")&$additionalQueryParams#end">$services.localization.render('web.paging.lastPage')</a></span>
#set($currentPageNumber = $currentPageNumber - 1)
#else
<span class="pagedLink inactive">$services.localization.render('web.paging.nextPage')</span>
<span class="pagedLink inactive">$services.localization.render('web.paging.lastPage')</span>
#end
</div>
#end
#end
##
##
## Used together with #printPagedViewLinks, computes the range of items to show and the
## variables used by #printPagedViewLinks, $currentPageNumber, $itemsPerPage, $totalPages.
##
## @param totalItems The total number of items that need to be displayed.
## @param defaultItemsPerPage The default number of items per page, if no override is found in the
## URL. If 0, then display all items.
## @sets startAt The first item to display (inclusive).
## @sets endAt The last item to display (exclusive).
## @sets itemsPerPage The requested number of items per page.
## @sets totalPages The total number of pages according to the requested number of items per page
## and total items. Starts at 1.
## @sets currentPageNumber The current page displayed. If the requested page is not available (out
## of range), then it will be corrected to a valid number. Starts at 1.
##
#macro(preparePagedViewParams $totalItems $defaultItemsPerPage)
## Reuse existing variable, in case it is manually overriden somewhere else
#if(!$itemsPerPage)
#if($request.ipp)
#set($itemsPerPage = $numbertool.toNumber($request.ipp).intValue())
#else
#set($itemsPerPage = $defaultItemsPerPage)
#end
#end
## Page numbers start at 1 outside this macro, but for internal computations we use 0-indexed values.
#set($currentPageNumber = $numbertool.toNumber($request.page).intValue() - 1)
#if(!$currentPageNumber || $currentPageNumber < 0)
#set($currentPageNumber = 0)
#end
## The first item to show. Must be >= 0.
#set($startAt = $itemsPerPage * $currentPageNumber)
#if($startAt < 0)
#set($startAt = 0)
#end
## The last item to show (exclusive). Must be <= total number of items.
#set($endAt = $itemsPerPage * ($currentPageNumber + 1))
#if(($endAt > $totalItems) || ($itemsPerPage == 0))
#set($endAt = $totalItems)
#end
## Never show the items after the last one... They don't exist!
#if($startAt >= $endAt)
#set($startAt = $endAt - 1)
#end
## Compute the total number of pages.
#if($itemsPerPage == 0)
#set($totalPages = 1)
#else
#set($totalPages = ($totalItems - 1) / $itemsPerPage + 1)
#end
## The requested page might not be available, so correct it to correspond to the displayed items.
#set($currentPageNumber = $startAt / $itemsPerPage + 1)
#end
##
##
## Macro to set a page break used in print, pdf and rtf mode
##
#macro(pagebreak)
<p style="page-break-before: always;" />
#end
##
##
## Macro to include children of a page
##
#set($clevel = 1)
#**
* Macro to include children at multiple levels. The children are rendered in the generated output. The number of nested levels to
* render is defined in a global variable called "$clevel".
*
* @param $page the document whose children should be rendered; preferably a Document object, but a document name works as well
* @param $withPageBreaks a boolean indicating whether a page break should be generated before each new child document
*###
#macro(includeChildren $page $withPageBreaks)
#if ($clevel && $clevel > 0)
#if ("$!page.fullName" == '')
## Not a Document, probably a String (document name)
## Make it backwards compatible with older versions of the macro
#set ($page = $xwiki.getDocument($page))
#end
#foreach ($childDocName in $page.children)
#set ($childDoc = $xwiki.getDocument($childDocName))
#if ($childDoc && ($services.user.properties.displayHiddenDocuments() || !$childDoc.isHidden()))
#if ($withPageBreaks)
#pagebreak()
#end
$childDoc.getRenderedContent()
#set ($clevel = $clevel - 1)
#includeChildren($childDoc $withPageBreaks)
#set ($clevel = $clevel + 1)
#end
#end
#end
#end
##
## Macro to include linked pages at multiple levels
#macro(includeLinks $page $withPageBreaks)
#if($clevel && $clevel!=0)
#set($pageDoc = $xwiki.getDocument($page))
#foreach($child in $pageDoc.getLinks())
#set($childDocName = $child.getLink())
#set($childDoc = $xwiki.getDocument($childDocName))
#if(($childDoc)&&($childDoc.getSpace()!="Panels")&&($childDoc.getSpace()!="XWiki"))
#if($withPageBreaks)
#pagebreak()
#end
$childDoc.getRenderedContent()
#set($clevel = $xwiki.add($clevel,-1))
#includeLinks($childDocName $withPageBreaks)
#set($clevel = $xwiki.add($clevel,1))
#end
#end
#end
#end
###
### Panel header
###
### Generate the starting html code for a panel
###
### @param title The panel caption title
### @param isLarge True if the panel should be larger (default: false)
### @param isHeaderHidden True if the header should be hidden (default: false)
###
#macro(panelheader $title $isLarge $isHeaderHidden $isNavigation)
## Note: We pass the Panel name as an HTML class attribute so that it's possible to style the Panels selectively using
## CSS.
## We want to avoid showing the "WebHome" suffix in the generated class since we're working to remove it from the UI
## and from the APIs. In addition it generates class names longer than they are needed. Thus for nested pages we strip
## it. We also strip the wiki prefix to have a shorter generated class name and because they're not needed to provide
## per-wiki styling of Panels.
#set ($defaultDocumentName = $services.model.getEntityReference('DOCUMENT', 'default').name)
#if ($paneldoc.documentReference.name == $defaultDocumentName)
#set ($serializedDocument = $services.model.serialize($paneldoc.documentReference.parent, 'compactwiki'))
#else
#set ($serializedDocument = $services.model.serialize($paneldoc.documentReference, 'compactwiki'))
#end
## We keep only alphanumeric characters so it can be used as a CSS class.
## For instance: "xwiki:A.B.WebHome" will become "AB"
#set ($specialClassAttribute = $stringtool.toAlphaNumeric("$!serializedDocument"))
## We keep this class for compatibility purpose but the previous one should be used instead.
#set ($deprecatedClassAttribute = $stringtool.toAlphaNumeric("$!paneldoc.documentReference.name"))
#if ($paneldoc.syntax.toIdString() == 'xwiki/1.0')
<div role="#if ($isNavigation)navigation#{else}complementary#{end}" class="#if ($isLarge)large #{end}panel
expanded $!specialClassAttribute $!deprecatedClassAttribute"
aria-label="$escapetool.xml($title)">
<h2 class="xwikipaneltitle#if ($isHeaderHidden) hidden#end">$title</h2>
<div class="xwikipanelcontents">
#else
(% role="#if ($isNavigation)navigation#{else}complementary#{end}" class="#if ($isLarge)large#{end}panel
expanded $!specialClassAttribute $!deprecatedClassAttribute"
aria-label="$escapetool.xml($title)"
%)(((
{{html}}<h2 class="xwikipaneltitle#if ($isHeaderHidden) hidden#end">$title</h2>{{/html}}
(% class="xwikipanelcontents" %)(((
#end
#end
#macro(largepanelheader $title)
#panelheader($title, true, false, false)
#end
#macro(panelhiddenheader $title)
#panelheader($title, false, true, false)
#end
## Changes the semantic role of the panel.
#macro(navigationPanelHeader $title)
#panelheader($title, false, false, true)
#end
#macro(largeNavigationPanelHeader $title)
#panelheader($title, true, false, true)
#end
###
### Panel footer
###
### Generate the ending html code for a panel
###
#macro(panelfooter)
#if ($paneldoc.syntax.toIdString() == 'xwiki/1.0')
</div>
</div>
#else
)))
)))
#end
#end
###
### Display Panel
###
### Extract and display the panel code from the panel object
###
### @Deprecated
#macro(displaypanel $name)
#set ($paneldoc = $xwiki.getDocument($name))
#if ($paneldoc)
#set ($pobj = $paneldoc.getObject('Panels.PanelClass'))
#if ($pobj)
$!doc.display('content', 'view', $pobj)
#end
#end
#end
#macro(displayPropName $prop)
#if($services.localization.render("${class.getName()}_${prop.name}") == "${class.getName()}_${prop.name}")
$prop.prettyName#else
$services.localization.render($prop.name)#end
#end
###
### Display Panel content
###
###
#macro(displaypanelcontent $doc $obj)
$doc.display("content", $obj)
#end
###
### Message box
###
#macro(xwikimessageboxstart $title $message)
<div class="centered">
<fieldset class="xwikimessage">
<legend><span>$title</span></legend>
#if ("$!message" != '')
<p class="xwikimessage">$message</p>
#end
#end
#macro(xwikimessageboxend)
</fieldset>
</div>
#end
#macro(xwikimessagebox $title $message $urlyes $urlno $msgyes $msgno)
#xwikimessageboxstart($title $message)
<div class="buttons"><a href="$urlyes" class="buttonwrapper"><input type="button" class="button" value="$msgyes" onclick="location='$urlyes'; return false;"/></a><a href="$urlno" class="buttonwrapper"><input type="button" class="button" value="$msgno" onclick="location='$urlno'; return false;"/></a></div>
#xwikimessageboxend()
#end
#macro(xwikimessageboxfield $fielddoc $fieldname $fieldtext $html)
<div class="xmblabel">$fieldtext</div>
<div class="xmbfield">
#if($fieldname!="")
$fielddoc.display($fieldname, "edit")
#end
#if($html!="")
$html
#end
</div>
#end
#macro(xwikimessageboxsubmit $submittext)
<div class="xmbbutton">
<input type="submit" value="$submittext" />
</div>
#end
###
### message
###
#macro(warning $text)
<div class="warningmessage"><span class="messagetype">$services.localization.render('warning'): </span>$text</div>
#end
#macro(error $text)
<div class="errormessage"><span class="messagetype">$services.localization.render('error'): </span>$text</div>
#end
#macro(info $text)
<div class="infomessage">$text</div>
#end
#macro(message $text)
<div class="plainmessage">$text</div>
#end
#macro (floatingbox $text)
<div class="floatinginfobox">$text</div>
#end
#macro (startfloatingbox)
<div class="floatinginfobox">
#end
#macro (endfloatingbox)
</div>
#end
###
### Display in page panels layout
###
###
#macro(displayPanelLayout $nbcolumns $panelNameList)
<div class="panellayoutcontainer-${nbcolumns}col">
#set($lastColumnId = ($nbcolumns - 1))
#foreach($colId in [0..$lastColumnId])
<div class="panellayoutcol">
#foreach($panelName in $panelNameList)
#if($panelName && ($panelName != "") && (((($foreach.count - 1) + $nbcolumns) % $nbcolumns) == $colId))
#displaypanel($panelName)
#end
#end
</div>
#end
</div>
#end