Changes for page XWiki Syntax Guide

Last modified by Ludovic Dubost on 2020/07/30 11:21

From version 3.1
edited by Thomas Mortagne
on 2014/09/29 12:41
Change comment: Install extension [org.xwiki.platform:xwiki-platform-help-ui-6.2]
To version 7.1
edited by Ludovic Dubost
on 2016/10/24 00:53
Change comment: Install extension [org.xwiki.platform:xwiki-platform-help-ui-8.2.1]

Summary

Details

Page properties
Author
... ... @@ -1,1 +1,1 @@
1 -xwiki:XWiki.ThomasMortagne
1 +xwiki:XWiki.ludovic
Content
... ... @@ -1,8 +1,30 @@
1 1  {{velocity output="false"}}
2 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'))
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
6 6  
7 7  #if ($request.xaction == 'switchContext')
8 8   $response.sendRedirect($request.target)
... ... @@ -14,13 +14,14 @@
14 14   #set ($crtCategoryId = $mathtool.toInteger($crtCategoryId))
15 15  #end
16 16  #set ($crtSectionId = "$!{request.section}")
17 -#set ($crtSyntaxVer = $mathtool.toDouble($request.syntax))
18 -#if ($crtSyntaxVer && $SUPPORTED_SYNTAXES.containsKey($crtSyntaxVer))
19 - #set ($crtSyntaxVer = $mathtool.toDouble($crtSyntaxVer))
20 -
21 -#else
22 - #set ($crtSyntaxVer = 2.1) ## Default to Syntax 2.1
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
23 23  #end
46 +#set($crtSyntaxPos = $SUPPORTED_SYNTAX_ORDER.indexOf($crtSyntaxVer))
24 24  
25 25  #set ($extraParamList = [])
26 26  #if ($request.language)
... ... @@ -52,7 +52,7 @@
52 52   #set($obj = $sectionDoc.getObject("XWiki.XWikiSyntaxClass"))
53 53  
54 54   ## detect if we entered a new category
55 - #if($catCount < $obj.getProperty("category").value))
78 + #if($catCount < $obj.getProperty("category").value)
56 56   ## Put previous category into map (if existing), and reset children map
57 57   #if($catId)
58 58   #set($cat = { 'id' : $catId, 'name' : $catName, 'children' : $catChildren })
... ... @@ -89,7 +89,7 @@
89 89   #end
90 90  
91 91   ## Add new sections to category children map
92 - #set($child = {'id' : $sectionDoc.getName().substring(11), 'minSyntax' : $obj.getProperty("minSyntaxVersion").value, 'maxSyntax' : $obj.getProperty("maxSyntaxVersion").value, 'name' : $sectionTitle})
115 + #set($child = {'id' : $sectionDoc.getName().substring(11), 'minSyntax' : $obj.getProperty("minSyntaxId").value, 'maxSyntax' : $obj.getProperty("maxSyntaxId").value, 'name' : $sectionTitle})
93 93   $catChildren.add($child)
94 94   #end
95 95  #end
... ... @@ -104,10 +104,11 @@
104 104  #foreach ($category in $syntaxMenu)
105 105   #set ($sectionsToRemove = [])
106 106   #foreach ($section on $category.children)
107 - #if ($section.minSyntax > $crtSyntaxVer)
130 + #set($minSyntaxPos = $SUPPORTED_SYNTAX_ORDER.indexOf($section.minSyntax))
131 + #if ($minSyntaxPos > $crtSyntaxPos)
108 108   #set ($discard = $sectionsToRemove.add($section))
109 109   #if ($section.id == $crtSectionId)
110 - #set ($crtSectionId = '') ## clear section if it doesn't exist (can happen when switching from 2.0 to 2.1 syntax)
134 + #set ($crtSectionId = '') ## clear section if it doesn't exist (can happen when switching from 2.x to 1.0 syntax)
111 111   #end
112 112   #end
113 113   #end
... ... @@ -172,15 +172,24 @@
172 172   *#
173 173  #macro(syntax_displayCategory $sections $translationPrefix $heading)
174 174   #foreach ($section in $sections)
199 + #syntax_displaySection($section $translationPrefix $heading)
200 + #end
201 +#end
202 +
203 +#macro(syntax_displaySection $section $translationPrefix $heading)
175 175   #set ($displayVersion = $crtSyntaxVer)
176 - #if ($crtSyntaxVer > $section.maxSyntax)
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)
177 177   #set ($displayVersion = $section.maxSyntax)
178 178   #end
211 + #if($heading)
179 179   (% class="sectionheader" %)
180 180   $heading $section.name $heading
181 181  
215 + #end
182 182   {{include reference="XWiki.XWikiSyntax${section.id}" section="H${displayVersion}${section.id}"/}}
183 - #end
184 184  #end
185 185  
186 186  
... ... @@ -225,7 +225,7 @@
225 225   #set ($crtSelection = "$extraParams")
226 226   #end
227 227  {{html}}
228 - <form id="change-context" class="xformInline" action="">
261 + <form id="change-context" class="xformInline" action="$doc.getURL()">
229 229   <div>
230 230   <input type="hidden" name="xaction" value="switchContext" />
231 231   #if ($request.language)
... ... @@ -236,12 +236,10 @@
236 236   #end
237 237   <select id="goto-select" name="target" title="$escapetool.xml($services.localization.render("help.changesyntax"))">
238 238   <optgroup label="$services.localization.render('help.choose_syntax')">
239 - #set ($query = "syntax=1.0&${crtSelection}")
240 - <option value="$doc.getURL('view', $query)" #if($crtSyntaxVer==1.0)selected="selected"#end>$SUPPORTED_SYNTAXES.get(1.0)</option>
241 - #set ($query = "syntax=2.0&${crtSelection}")
242 - <option value="$doc.getURL('view', $query)" #if($crtSyntaxVer==2.0)selected="selected"#end>$SUPPORTED_SYNTAXES.get(2.0)</option>
243 - #set ($query = "syntax=2.1&${crtSelection}")
244 - <option value="$doc.getURL('view', $query)" #if($crtSyntaxVer==2.1)selected="selected"#end>$SUPPORTED_SYNTAXES.get(2.1)</option>
272 + #foreach($syntaxId in $SUPPORTED_SYNTAX_ORDER)
273 + #set ($query = "syntax=${escapetool.url($syntaxId)}&${crtSelection}")
274 + <option value="$escapetool.xml($doc.getURL('view', $query))"#if($crtSyntaxVer == $syntaxId) selected="selected"#end>$escapetool.html($SUPPORTED_SYNTAXES.get($syntaxId))</option>
275 + #end
245 245   </optgroup>
246 246   </select>
247 247   <span class="buttonwrapper"><input type="submit" value="$escapetool.xml($services.localization.render('admin.switchContext'))" class="button" /></span>
... ... @@ -269,7 +269,7 @@
269 269  #syntaxSwitch()
270 270  (((
271 271  #set ($query = "syntax=$escapetool.url(${crtSyntaxVer})${extraParams}")
272 -#if ($crtCategory){{html}}<a href="${doc.getURL('view', ${query})}">$syntaxTitle</a>{{/html}}#{else}(% class="current" %)$syntaxTitle#{end}#if ($crtCategory) (% class="separator" %)» #if ($crtSection){{html}}<a href="${crtCategory.url}">${crtCategory.name}</a>{{/html}}#{else}(% class="current" %)${crtCategory.name}#{end}#if ($crtSection) (% class="separator" %)» (% class="current" %)${crtSection.name}#end#end
303 +#if ($crtCategory){{html}}<a href="${doc.getURL('view', ${query})}">$syntaxTitle</a>{{/html}}#{else}(% class="current" %)$syntaxTitle#{end}#if ($crtCategory) » #if ($crtSection){{html}}<a href="${crtCategory.url}">${crtCategory.name}</a>{{/html}}#{else}(% class="current" %)${crtCategory.name}#{end}#if ($crtSection) » (% class="current" %)${crtSection.name}#end#end
273 273  )))
274 274  == $syntaxTitle: $sectionName ==
275 275  
... ... @@ -284,12 +284,7 @@
284 284   #set ($subHeading = '===')
285 285   #syntax_displayCategory($crtCategory.children 'syntax.' '==')
286 286   #else
287 - #set ($displayVersion = $crtSyntaxVer)
288 - #if ($crtSyntaxVer > $crtSection.maxSyntax)
289 - #set ($displayVersion = $crtSection.maxSyntax)
290 - #end
291 - #set ($subHeading = '==')
292 - {{include reference="XWiki.XWikiSyntax${crtSection.id}" section="H${displayVersion}${crtSection.id}"/}}
318 + #syntax_displaySection($crtSection 'syntax.' false)
293 293   #end
294 294   ))) ## syntax-page-content
295 295  {{/velocity}}