Show last authors
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 ## We need a way to have a mapping between a string and a number, and we cannot use $mathtool.toDouble() because
8 ## it is locale dependent (see: http://jira.xwiki.org/browse/XWIKI-11343).
9 ## TODO: fix $mathtool or create a script service that handles this english-locale string<->number conversion,
10 ## because this fix is a bit hacky/spaghetti.
11 ## A better fix would be to refactor this application, because the syntax number SHOULD NOT BE USED because a syntax
12 ## is not supposed to be a number (imagine that we switch to 'Markdown', it is impossible to compare).
13 ## Instead, a syntax object should have a list of categories that the syntax supports.
14 #set($NUMBERS_CONVERSION = {})
15 #set($void = $NUMBERS_CONVERSION.put('1.0', 1.0))
16 #set($void = $NUMBERS_CONVERSION.put('2.0', 2.0))
17 #set($void = $NUMBERS_CONVERSION.put('2.1', 2.1))
18
19 #if ($request.xaction == 'switchContext')
20 $response.sendRedirect($request.target)
21 #stop
22 #end
23
24 #set ($crtCategoryId = "$!{request.category}")
25 #if ($crtCategoryId != '')
26 #set ($crtCategoryId = $mathtool.toInteger($crtCategoryId))
27 #end
28 #set ($crtSectionId = "$!{request.section}")
29 #set ($crtSyntaxVer = $NUMBERS_CONVERSION.get($request.syntax))
30 #if ("$!crtSyntaxVer" == '' || !$SUPPORTED_SYNTAXES.containsKey($crtSyntaxVer))
31 #set ($crtSyntaxVer = 2.1) ## Default to Syntax 2.1
32 #end
33
34 #set ($extraParamList = [])
35 #if ($request.language)
36 #set ($discard = $extraParamList.add("language=$escapetool.url($request.language)"))
37 #end
38 #if ($request.xpage)
39 #set ($discard = $extraParamList.add("xpage=$escapetool.url($request.xpage)"))
40 #end
41 #if ($extraParamList.isEmpty())
42 #set ($extraParams = '')
43 #else
44 #set ($extraParams = '&'+$stringtool.join($extraParamList,'&'))
45 #end
46
47 ##
48 ## Syntax menu map
49 ##
50 #set($syntaxMenu = [])
51 #set($catCount = -1)
52 #set($catName = "")
53 #set($catChildren = [])
54 #set($results = $services.query.xwql('from doc.object(XWiki.XWikiSyntaxClass) as syntax order by syntax.category, syntax.section').addFilter('currentlanguage').addFilter('unique').execute())
55
56 #if($results.empty)
57 No syntax sections found!
58 #else
59 #foreach ($item in $results)
60 #set($sectionDoc = $xwiki.getDocument($item))
61 #set($obj = $sectionDoc.getObject("XWiki.XWikiSyntaxClass"))
62
63 ## detect if we entered a new category
64 #if($catCount < $obj.getProperty("category").value))
65 ## Put previous category into map (if existing), and reset children map
66 #if($catId)
67 #set($cat = { 'id' : $catId, 'name' : $catName, 'children' : $catChildren })
68 $syntaxMenu.add($cat)
69 #set($catChildren = [])
70 #end
71 ## extract new catId and catName values, and sectionTitle as we are already traveling the DOM
72 #foreach($headerBlock in $sectionDoc.getDocument().getXDOM().getBlocks('class:HeaderBlock', 'DESCENDANT'))
73 #if($headerBlock.getLevel().getAsInt() == 1)
74 #set($catId = $headerBlock.getId().substring(1))
75 #set($catName = $services.rendering.render($headerBlock, 'plain/1.0'))
76 #elseif($headerBlock.getLevel().getAsInt() == 2)
77 #set($sectionTitle = $services.rendering.render($headerBlock, 'plain/1.0'))
78 #break
79 #end
80 #end
81 #foreach($headerBlock in $sectionDoc.getTranslatedDocument().getDocument().getXDOM().getBlocks('class:HeaderBlock', 'DESCENDANT'))
82 #if($headerBlock.getLevel().getAsInt() == 1)
83 #set($catName = $services.rendering.render($headerBlock, 'plain/1.0'))
84 #elseif($headerBlock.getLevel().getAsInt() == 2)
85 #set($sectionTitle = $services.rendering.render($headerBlock, 'plain/1.0'))
86 #break ## otherwise finds nested example headlines
87 #end
88 #end
89 #set($catCount = $obj.getProperty("category").value)
90 #else
91 ## still in same category, only need new section title
92 #foreach($headerBlock in $sectionDoc.getTranslatedDocument().getDocument().getXDOM().getBlocks('class:HeaderBlock', 'DESCENDANT'))
93 #if($headerBlock.getLevel().getAsInt() == 2)
94 #set($sectionTitle = $services.rendering.render($headerBlock, 'plain/1.0'))
95 #break
96 #end
97 #end
98 #end
99
100 ## Add new sections to category children map
101 #set($child = {'id' : $sectionDoc.getName().substring(11), 'minSyntax' : $obj.getProperty("minSyntaxVersion").value, 'maxSyntax' : $obj.getProperty("maxSyntaxVersion").value, 'name' : $sectionTitle})
102 $catChildren.add($child)
103 #end
104 #end
105 #set($cat = { 'id' : $catId, 'name' : $catName, 'children' : $catChildren })
106 $syntaxMenu.add($cat)
107
108
109 ##
110 ## Filter only the sections that are valid for a Syntax
111 ##
112 #set ($categoriesToRemove = [])
113 #foreach ($category in $syntaxMenu)
114 #set ($sectionsToRemove = [])
115 #foreach ($section on $category.children)
116 ## TODO: This should be refactored (see before): a syntax is not supposed to be a number
117 #if ($section.minSyntax > $crtSyntaxVer)
118 #set ($discard = $sectionsToRemove.add($section))
119 #if ($section.id == $crtSectionId)
120 #set ($crtSectionId = '') ## clear section if it doesn't exist (can happen when switching from 2.0 to 2.1 syntax)
121 #end
122 #end
123 #end
124 #set ($discard = $category.children.removeAll($sectionsToRemove))
125 #if ($category.children.size() == 0)
126 #set ($discard = $categoriesToRemove.add($category))
127 #end
128 #end
129 #set ($discard = $syntaxMenu.removeAll($categoriesToRemove))
130 #if ("$!crtCategoryId" != '' && $crtCategoryId >= $syntaxMenu.size())
131 #set ($crtCategoryId = '')
132 #end
133
134 #if ($crtSectionId != '')
135 #set ($crtItemId = $crtSectionId)
136 #elseif ($crtCategoryId != '')
137 #set ($crtItemId = $syntaxMenu.get($crtCategoryId).id)
138 #end
139 #set ($crtSection = $util.null)
140 #set ($crtCategory = $util.null)
141
142
143 ##
144 ## Prepare the Syntax menu map for processing
145 ##
146 #foreach ($category in $syntaxMenu)
147 ## "Standard" URLs and icons for categories
148 #set ($category.url = "?syntax=$escapetool.url(${crtSyntaxVer})&category=${mathtool.sub($velocityCount, 1)}${extraParams}")
149 #set ($category.cssClass = "${category.id}Icon")
150 #if ("$!{crtCategoryId}" != '' && $velocityCount == $mathtool.add($crtCategoryId, 1))
151 #set ($crtCategory = $category)
152 #end
153 ##
154 ## Process each syntax section
155 #foreach ($section in $category.children)
156 #if ($xwiki.exists("XWiki.XWikiSyntax${section.id}"))
157 #if ($crtSectionId == $section.id)
158 #set ($crtSection = $section)
159 #set ($crtCategory = $category)
160 #end
161 #set ($section.url = "?syntax=$escapetool.url(${crtSyntaxVer})&section=$escapetool.url(${section.id})${extraParams}")
162 #end
163 #end
164 #end
165
166 #**
167 * Displays the sections from a syntax category
168 *
169 * Expected format:
170 * sections = vector of items
171 * item = map with the following fields:
172 * 'id' : mandatory
173 * 'name' : the text displayed for the corresponding menu item;
174 * optional, defaults to
175 * $services.localization.render("$!{translationPrefix}${item.id}")
176 *
177 * @param $sections the sections list, in the format described above
178 * @param $translationPrefix the translation prefix added to the id of each
179 * item, in order to generate the name and description; ignored when
180 * name or description are specified
181 * @param $heading the heading syntax
182 *#
183 #macro(syntax_displayCategory $sections $translationPrefix $heading)
184 #foreach ($section in $sections)
185 #set ($displayVersion = $crtSyntaxVer)
186 ## TODO: This should be refactored (see before): a syntax is not supposed to be a number
187 #if ($crtSyntaxVer > $section.maxSyntax)
188 #set ($displayVersion = $section.maxSyntax)
189 #end
190 (% class="sectionheader" %)
191 $heading $section.name $heading
192
193 {{include reference="XWiki.XWikiSyntax${section.id}" section="H${displayVersion}${section.id}"/}}
194 #end
195 #end
196
197
198 #**
199 * Displays the syntax categories
200 *
201 * Expected format:
202 * sections = vector of items
203 * item = map with the following fields:
204 * 'id' : mandatory
205 * 'name' : the text displayed for the corresponding menu item;
206 * optional, defaults to
207 * $services.localization.render("$!{translationPrefix}${item.id}")
208 *
209 * @param $sections the sections list, in the format described above
210 * @param $translationPrefix the translation prefix added to the id of each
211 * item, in order to generate the name and description; ignored when
212 * name or description are specified
213 *#
214 #macro(syntax_displayCategories $syntaxMenu $translationPrefix)
215 #set ($subHeading = '====')
216 #foreach ($category in $syntaxMenu)
217 == $category.name ==
218
219 #syntax_displayCategory($category.children 'syntax.' '===')
220 #end
221 #end
222
223 #**
224 * Displays the drop down allowing to switch the syntax.
225 *#
226 #macro (syntaxSwitch)
227 #set ($crtSelection = "")
228 #if ("$!{crtCategoryId}" != '')
229 #set ($crtSelection = "category=$escapetool.url($!{crtCategoryId})")
230 #elseif ($crtSectionId != '')
231 #set ($crtSelection = "section=$escapetool.url($!{crtSectionId})")
232 #end
233 #if ($crtSelection != "")
234 #set ($crtSelection = "${crtSelection}${extraParams}")
235 #else
236 #set ($crtSelection = "$extraParams")
237 #end
238 {{html}}
239 <form id="change-context" class="xformInline" action="$doc.getURL()">
240 <div>
241 <input type="hidden" name="xaction" value="switchContext" />
242 #if ($request.language)
243 <input type="hidden" name="language" value="$escapetool.xml($request.language)" />
244 #end
245 #if ($request.xpage)
246 <input type="hidden" name="xpage" value="$escapetool.xml($request.xpage)" />
247 #end
248 <select id="goto-select" name="target" title="$escapetool.xml($services.localization.render("help.changesyntax"))">
249 <optgroup label="$services.localization.render('help.choose_syntax')">
250 #set ($query = "syntax=1.0&${crtSelection}")
251 <option value="$doc.getURL('view', $query)" #if($crtSyntaxVer==1.0)selected="selected"#end>$SUPPORTED_SYNTAXES.get(1.0)</option>
252 #set ($query = "syntax=2.0&${crtSelection}")
253 <option value="$doc.getURL('view', $query)" #if($crtSyntaxVer==2.0)selected="selected"#end>$SUPPORTED_SYNTAXES.get(2.0)</option>
254 #set ($query = "syntax=2.1&${crtSelection}")
255 <option value="$doc.getURL('view', $query)" #if($crtSyntaxVer==2.1)selected="selected"#end>$SUPPORTED_SYNTAXES.get(2.1)</option>
256 </optgroup>
257 </select>
258 <span class="buttonwrapper"><input type="submit" value="$escapetool.xml($services.localization.render('admin.switchContext'))" class="button" /></span>
259 </div>
260 </form>
261 {{/html}}
262 #end
263 {{/velocity}}
264
265 {{velocity}}
266 ##**************************************************************************************************
267 ## From the Administration Sheet, used to display a common UI for some wiki features
268 ## here used to display all categories / sections of the syntax guide
269 ##**************************************************************************************************
270 $xwiki.get('jsx').use($doc.getFullName())##
271 $xwiki.get('ssx').use($doc.getFullName())##
272 #if ($crtSectionId != '')
273 #set ($sectionName = ${crtSection.name})
274 #elseif ($crtCategoryId != '')
275 #set ($sectionName = ${crtCategory.name})
276 #else
277 #set ($sectionName = $services.localization.render("help.syntaxall"))
278 #end
279 #set ($syntaxTitle = $services.localization.render("help.syntaxtitle", ["${crtSyntaxVer}"]))
280 #syntaxSwitch()
281 (((
282 #set ($query = "syntax=$escapetool.url(${crtSyntaxVer})${extraParams}")
283 #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
284 )))
285 == $syntaxTitle: $sectionName ==
286
287 #verticalNavigation($syntaxMenu {'translationPrefix' : 'syntax.', 'crtItemId' : "$!crtItemId", 'cssClass' : 'syntax-menu'})
288 ##-----------------------------------------
289 ## syntax-page display
290 ##-----------------------------------------
291 (% id="syntax-page-content" %)(((
292 #if(!$crtSection && !$crtCategory)
293 #syntax_displayCategories($syntaxMenu 'syntax.')
294 #elseif (!$crtSection)
295 #set ($subHeading = '===')
296 #syntax_displayCategory($crtCategory.children 'syntax.' '==')
297 #else
298 #set ($displayVersion = $crtSyntaxVer)
299 #if ($crtSyntaxVer > $crtSection.maxSyntax)
300 #set ($displayVersion = $crtSection.maxSyntax)
301 #end
302 #set ($subHeading = '==')
303 {{include reference="XWiki.XWikiSyntax${crtSection.id}" section="H${displayVersion}${crtSection.id}"/}}
304 #end
305 ))) ## syntax-page-content
306 {{/velocity}}

Get Connected