Wiki source code of XWiki Syntax Guide

Last modified by blackpoint GmbH on 2026/10/21 13:03

Hide last authors
blackpoint GmbH 1.1 1 {{velocity output="false"}}
2 #set($SUPPORTED_SYNTAXES = {})
3 #set($void = $SUPPORTED_SYNTAXES.put('1.0', 'XWiki Syntax 1.0'))
4 #set($void = $SUPPORTED_SYNTAXES.put('2.0', 'XWiki Syntax 2.0'))
5 #set($void = $SUPPORTED_SYNTAXES.put('2.1', 'XWiki Syntax 2.1'))
6 ##
7 ## needed for sections that contain descriptions valid for several syntaxes
8 ## basically it is hack to reuse the 2.0 descriptions for 2.1
9 #set($SUPPORTED_SYNTAX_ORDER = ['1.0', '2.0', '2.1'])
10 ##
11 ## filter all syntaxes that are not installed/configured
12 #set($configuredSyntaxes = $services.rendering.getConfiguredSyntaxes())
13 #set($enabledSyntaxIds = [])
14 #foreach($syntax in $configuredSyntaxes)
15 #set($discard = $enabledSyntaxIds.add($syntax.toIdString()))
16 #end
17 #set($unavailableSyntaxes=[])
18 #foreach($supportedSyntax in $SUPPORTED_SYNTAX_ORDER)
19 #set($fullSyntaxId = "xwiki/$supportedSyntax")
20 #if(!$enabledSyntaxIds.contains($fullSyntaxId))
21 #set($discard = $unavailableSyntaxes.add($supportedSyntax))
22 #end
23 #end
24 #foreach($unavailableSyntax in $unavailableSyntaxes)
25 #set($discard = $SUPPORTED_SYNTAX_ORDER.remove($unavailableSyntax))
26 #set($discard = $SUPPORTED_SYNTAXES.removeKey($unavailableSyntax))
27 #end
28
29 #if ($request.xaction == 'switchContext')
30 $response.sendRedirect($request.target)
31 #stop
32 #end
33
34 #set ($crtCategoryId = "$!{request.category}")
35 #if ($crtCategoryId != '')
36 #set ($crtCategoryId = $numbertool.toNumber($crtCategoryId).intValue())
37 #end
38 #set ($crtSectionId = "$!{request.section}")
39 #set ($crtSyntaxVer = "$!{request.syntax}")
40 #if (!$SUPPORTED_SYNTAXES.containsKey($crtSyntaxVer))
41 ## Default to the most current one (if we have any)
42 #if(!$SUPPORTED_SYNTAX_ORDER.isEmpty())
43 #set ($crtSyntaxVer = $SUPPORTED_SYNTAX_ORDER.get($mathtool.sub($SUPPORTED_SYNTAX_ORDER.size(),1)))
44 #end
45 #end
46 #set($crtSyntaxPos = $SUPPORTED_SYNTAX_ORDER.indexOf($crtSyntaxVer))
47
48 #set ($extraParamList = [])
49 #if ($request.language)
50 #set ($discard = $extraParamList.add("language=$escapetool.url($request.language)"))
51 #end
52 #if ($request.xpage)
53 #set ($discard = $extraParamList.add("xpage=$escapetool.url($request.xpage)"))
54 #end
55 #if ($extraParamList.isEmpty())
56 #set ($extraParams = '')
57 #else
58 #set ($extraParams = '&'+$stringtool.join($extraParamList,'&'))
59 #end
60
61 ##
62 ## Syntax menu map
63 ##
64 #set($syntaxMenu = [])
65 #set($catCount = -1)
66 #set($catName = "")
67 #set($catChildren = [])
68 #set($results = $services.query.xwql('from doc.object(XWiki.XWikiSyntaxClass) as syntax order by syntax.category, syntax.section').addFilter('currentlanguage').addFilter('unique').execute())
69
70 #if($results.empty)
71 No syntax sections found!
72 #else
73 #foreach ($item in $results)
74 #set($sectionDoc = $xwiki.getDocument($item))
75 #set($obj = $sectionDoc.getObject("XWiki.XWikiSyntaxClass"))
76
77 ## detect if we entered a new category
78 #if($catCount < $obj.getProperty("category").value)
79 ## Put previous category into map (if existing), and reset children map
80 #if($catId)
81 #set($cat = { 'id' : $catId, 'name' : $catName, 'children' : $catChildren })
82 $syntaxMenu.add($cat)
83 #set($catChildren = [])
84 #end
85 ## extract new catId and catName values, and sectionTitle as we are already traveling the DOM
86 #foreach($headerBlock in $sectionDoc.getDocument().getXDOM().getBlocks('class:HeaderBlock', 'DESCENDANT'))
87 #if($headerBlock.getLevel().getAsInt() == 1)
88 #set($catId = $headerBlock.getId().substring(1))
89 #set($catName = $services.rendering.render($headerBlock, 'plain/1.0'))
90 #elseif($headerBlock.getLevel().getAsInt() == 2)
91 #set($sectionTitle = $services.rendering.render($headerBlock, 'plain/1.0'))
92 #break
93 #end
94 #end
95 #foreach($headerBlock in $sectionDoc.getTranslatedDocument().getDocument().getXDOM().getBlocks('class:HeaderBlock', 'DESCENDANT'))
96 #if($headerBlock.getLevel().getAsInt() == 1)
97 #set($catName = $services.rendering.render($headerBlock, 'plain/1.0'))
98 #elseif($headerBlock.getLevel().getAsInt() == 2)
99 #set($sectionTitle = $services.rendering.render($headerBlock, 'plain/1.0'))
100 #break ## otherwise finds nested example headlines
101 #end
102 #end
103 #set($catCount = $obj.getProperty("category").value)
104 #else
105 ## still in same category, only need new section title
106 #foreach($headerBlock in $sectionDoc.getTranslatedDocument().getDocument().getXDOM().getBlocks('class:HeaderBlock', 'DESCENDANT'))
107 #if($headerBlock.getLevel().getAsInt() == 2)
108 #set($sectionTitle = $services.rendering.render($headerBlock, 'plain/1.0'))
109 #break
110 #end
111 #end
112 #end
113
114 ## Add new sections to category children map
115 #set($child = {'id' : $sectionDoc.documentReference.name.substring(11), 'minSyntax' : $obj.getProperty("minSyntaxId").value, 'maxSyntax' : $obj.getProperty("maxSyntaxId").value, 'name' : $sectionTitle})
116 $catChildren.add($child)
117 #end
118 #end
119 #set($cat = { 'id' : $catId, 'name' : $catName, 'children' : $catChildren })
120 $syntaxMenu.add($cat)
121
122
123 ##
124 ## Filter only the sections that are valid for a Syntax
125 ##
126 #set ($categoriesToRemove = [])
127 #foreach ($category in $syntaxMenu)
128 #set ($sectionsToRemove = [])
129 #foreach ($section on $category.children)
130 #set($minSyntaxPos = $SUPPORTED_SYNTAX_ORDER.indexOf($section.minSyntax))
131 #if ($minSyntaxPos > $crtSyntaxPos)
132 #set ($discard = $sectionsToRemove.add($section))
133 #if ($section.id == $crtSectionId)
134 #set ($crtSectionId = '') ## clear section if it doesn't exist (can happen when switching from 2.x to 1.0 syntax)
135 #end
136 #end
137 #end
138 #set ($discard = $category.children.removeAll($sectionsToRemove))
139 #if ($category.children.size() == 0)
140 #set ($discard = $categoriesToRemove.add($category))
141 #end
142 #end
143 #set ($discard = $syntaxMenu.removeAll($categoriesToRemove))
144 #if ("$!crtCategoryId" != '' && $crtCategoryId >= $syntaxMenu.size())
145 #set ($crtCategoryId = '')
146 #end
147
148 #if ($crtSectionId != '')
149 #set ($crtItemId = $crtSectionId)
150 #elseif ($crtCategoryId != '')
151 #set ($crtItemId = $syntaxMenu.get($crtCategoryId).id)
152 #end
153 #set ($crtSection = $util.null)
154 #set ($crtCategory = $util.null)
155
156
157 ##
158 ## Prepare the Syntax menu map for processing
159 ##
160 #foreach ($category in $syntaxMenu)
161 ## "Standard" URLs and icons for categories
162 #set ($category.url = "?syntax=$escapetool.url(${crtSyntaxVer})&category=${mathtool.sub($foreach.count, 1)}${extraParams}")
163 #set ($category.cssClass = "${category.id}Icon")
164 #if ("$!{crtCategoryId}" != '' && $foreach.count == $mathtool.add($crtCategoryId, 1))
165 #set ($crtCategory = $category)
166 #end
167 ##
168 ## Process each syntax section
169 #foreach ($section in $category.children)
170 #if ($xwiki.exists("XWiki.XWikiSyntax${section.id}"))
171 #if ($crtSectionId == $section.id)
172 #set ($crtSection = $section)
173 #set ($crtCategory = $category)
174 #end
175 #set ($section.url = "?syntax=$escapetool.url(${crtSyntaxVer})&section=$escapetool.url(${section.id})${extraParams}")
176 #end
177 #end
178 #end
179
180 #**
181 * Displays the sections from a syntax category
182 *
183 * Expected format:
184 * sections = vector of items
185 * item = map with the following fields:
186 * 'id' : mandatory
187 * 'name' : the text displayed for the corresponding menu item;
188 * optional, defaults to
189 * $services.localization.render("$!{translationPrefix}${item.id}")
190 *
191 * @param $sections the sections list, in the format described above
192 * @param $translationPrefix the translation prefix added to the id of each
193 * item, in order to generate the name and description; ignored when
194 * name or description are specified
195 * @param $heading the heading syntax
196 *#
197 #macro(syntax_displayCategory $sections $translationPrefix $heading)
198 #foreach ($section in $sections)
199 #syntax_displaySection($section $translationPrefix $heading)
200 #end
201 #end
202
203 #macro(syntax_displaySection $section $translationPrefix $heading)
204 #set ($displayVersion = $crtSyntaxVer)
205 ## here is the hack to display the description for 2.0 if we have no description for 2.x
206 ## this likely needs more work if e.g. there is a 3.x which is not compatible with 2.x
207 #set($maxSyntaxPos = $SUPPORTED_SYNTAX_ORDER.indexOf($section.maxSyntax))
208 #if ($crtSyntaxPos > $maxSyntaxPos)
209 #set ($displayVersion = $section.maxSyntax)
210 #end
211 #if($heading)
212 (% class="sectionheader" %)
213 $heading $services.rendering.escape($section.name, 'xwiki/2.1') $heading
214
215 #end
216 ## Escape the values used as macro parameters.
217 #set ($includeReference = $services.rendering.escape("XWiki.XWikiSyntax${section.id}", 'xwiki/2.1'))
218 #set ($includeSection = $services.rendering.escape("H${displayVersion}${section.id}", 'xwiki/2.1'))
219 {{include reference="$includeReference" section="$includeSection"/}}
220 #end
221
222
223 #**
224 * Displays the syntax categories
225 *
226 * Expected format:
227 * sections = vector of items
228 * item = map with the following fields:
229 * 'id' : mandatory
230 * 'name' : the text displayed for the corresponding menu item;
231 * optional, defaults to
232 * $services.localization.render("$!{translationPrefix}${item.id}")
233 *
234 * @param $sections the sections list, in the format described above
235 * @param $translationPrefix the translation prefix added to the id of each
236 * item, in order to generate the name and description; ignored when
237 * name or description are specified
238 *#
239 #macro(syntax_displayCategories $syntaxMenu $translationPrefix)
240 #set ($subHeading = '====')
241 #foreach ($category in $syntaxMenu)
242 == $services.rendering.escape($category.name, 'xwiki/2.1') ==
243
244 #syntax_displayCategory($category.children 'syntax.' '===')
245 #end
246 #end
247
248 #**
249 * Displays the drop down allowing to switch the syntax.
250 *#
251 #macro (syntaxSwitch)
252 #set ($crtSelection = "")
253 #if ("$!{crtCategoryId}" != '')
254 #set ($crtSelection = "category=$escapetool.url($!{crtCategoryId})")
255 #elseif ($crtSectionId != '')
256 #set ($crtSelection = "section=$escapetool.url($!{crtSectionId})")
257 #end
258 #if ($crtSelection != "")
259 #set ($crtSelection = "${crtSelection}${extraParams}")
260 #else
261 #set ($crtSelection = "$extraParams")
262 #end
263 {{html}}
264 <form id="change-context" class="xformInline" action="$doc.getURL()">
265 <div>
266 <input type="hidden" name="xaction" value="switchContext" />
267 #if ($request.language)
268 <input type="hidden" name="language" value="$escapetool.xml($request.language)" />
269 #end
270 #if ($request.xpage)
271 <input type="hidden" name="xpage" value="$escapetool.xml($request.xpage)" />
272 #end
273 <select id="goto-select" name="target" title="$escapetool.xml($services.localization.render("help.changesyntax"))">
274 <optgroup label="$services.localization.render('help.choose_syntax')">
275 #foreach($syntaxId in $SUPPORTED_SYNTAX_ORDER)
276 #set ($query = "syntax=${escapetool.url($syntaxId)}&${crtSelection}")
277 <option value="$escapetool.xml($doc.getURL('view', $query))"#if($crtSyntaxVer == $syntaxId) selected="selected"#end>$escapetool.html($SUPPORTED_SYNTAXES.get($syntaxId))</option>
278 #end
279 </optgroup>
280 </select>
281 <span class="buttonwrapper"><input type="submit" value="$escapetool.xml($services.localization.render('admin.switchContext'))" class="button" /></span>
282 </div>
283 </form>
284 {{/html}}
285 #end
286 {{/velocity}}
287
288 {{velocity}}
289 ##**************************************************************************************************
290 ## From the Administration Sheet, used to display a common UI for some wiki features
291 ## here used to display all categories / sections of the syntax guide
292 ##**************************************************************************************************
293 $xwiki.get('jsx').use($doc.getFullName())##
294 $xwiki.get('ssx').use($doc.getFullName())##
295 #if ($crtSectionId != '')
296 #set ($sectionName = ${crtSection.name})
297 #elseif ($crtCategoryId != '')
298 #set ($sectionName = ${crtCategory.name})
299 #else
300 #set ($sectionName = $services.localization.render("help.syntaxall"))
301 #end
302 #set ($syntaxTitle = $services.localization.render("help.syntaxtitle", ["${crtSyntaxVer}"]))
303 #syntaxSwitch()
304 (((
305 #set ($query = "syntax=$escapetool.url(${crtSyntaxVer})${extraParams}")
306 #if ($crtCategory)
307 {{html}}<a href="${doc.getURL('view', ${query})}">$syntaxTitle</a>{{/html}} » ##
308 #if ($crtSection)
309 {{html}}<a href="${crtCategory.url}">$escapetool.xml($crtCategory.name)</a>{{/html}} » ##
310 (% class="current" %)$services.rendering.escape($crtSection.name, 'xwiki/2.1')
311 #else
312 (% class="current" %)$services.rendering.escape($crtCategory.name, 'xwiki/2.1')
313 #end
314 #else
315 (% class="current" %)$syntaxTitle
316 #end
317 )))
318 == $syntaxTitle: $services.rendering.escape($sectionName, 'xwiki/2.1') ==
319
320 #verticalNavigation($syntaxMenu {'translationPrefix' : 'syntax.', 'crtItemId' : "$!crtItemId", 'cssClass' : 'syntax-menu'})
321 ##-----------------------------------------
322 ## syntax-page display
323 ##-----------------------------------------
324 #set ($subHeading = '===')
325 (% id="syntax-page-content" %)(((
326 #if(!$crtSection && !$crtCategory)
327 #syntax_displayCategories($syntaxMenu 'syntax.')
328 #elseif (!$crtSection)
329 #syntax_displayCategory($crtCategory.children 'syntax.' '==')
330 #else
331 #syntax_displaySection($crtSection 'syntax.' false)
332 #end
333 ))) ## syntax-page-content
334 {{/velocity}}