Toggle navigation
Log-in
Register
Home
Page Index
User Index
Application Index
Global
Languages
Default Language
Wiki Index
XWiki
XWiki Syntax Guide
Wiki source code of
XWiki Syntax Guide
Last modified by
Marcel Heckel
on 2017/01/25 10:29
Show line numbers
{{velocity output="false"}} #set($SUPPORTED_SYNTAXES = {}) #set($void = $SUPPORTED_SYNTAXES.put('1.0', 'XWiki Syntax 1.0')) #set($void = $SUPPORTED_SYNTAXES.put('2.0', 'XWiki Syntax 2.0')) #set($void = $SUPPORTED_SYNTAXES.put('2.1', 'XWiki Syntax 2.1')) ## ## needed for sections that contain descriptions valid for several syntaxes ## basically it is hack to reuse the 2.0 descriptions for 2.1 #set($SUPPORTED_SYNTAX_ORDER = ['1.0', '2.0', '2.1']) ## ## filter all syntaxes that are not installed/configured #set($configuredSyntaxes = $services.rendering.getConfiguredSyntaxes()) #set($enabledSyntaxIds = []) #foreach($syntax in $configuredSyntaxes) #set($discard = $enabledSyntaxIds.add($syntax.toIdString())) #end #set($unavailableSyntaxes=[]) #foreach($supportedSyntax in $SUPPORTED_SYNTAX_ORDER) #set($fullSyntaxId = "xwiki/$supportedSyntax") #if(!$enabledSyntaxIds.contains($fullSyntaxId)) #set($discard = $unavailableSyntaxes.add($supportedSyntax)) #end #end #foreach($unavailableSyntax in $unavailableSyntaxes) #set($discard = $SUPPORTED_SYNTAX_ORDER.remove($unavailableSyntax)) #set($discard = $SUPPORTED_SYNTAXES.removeKey($unavailableSyntax)) #end #if ($request.xaction == 'switchContext') $response.sendRedirect($request.target) #stop #end #set ($crtCategoryId = "$!{request.category}") #if ($crtCategoryId != '') #set ($crtCategoryId = $mathtool.toInteger($crtCategoryId)) #end #set ($crtSectionId = "$!{request.section}") #set ($crtSyntaxVer = "$!{request.syntax}") #if (!$SUPPORTED_SYNTAXES.containsKey($crtSyntaxVer)) ## Default to the most current one (if we have any) #if(!$SUPPORTED_SYNTAX_ORDER.isEmpty()) #set ($crtSyntaxVer = $SUPPORTED_SYNTAX_ORDER.get($mathtool.sub($SUPPORTED_SYNTAX_ORDER.size(),1))) #end #end #set($crtSyntaxPos = $SUPPORTED_SYNTAX_ORDER.indexOf($crtSyntaxVer)) #set ($extraParamList = []) #if ($request.language) #set ($discard = $extraParamList.add("language=$escapetool.url($request.language)")) #end #if ($request.xpage) #set ($discard = $extraParamList.add("xpage=$escapetool.url($request.xpage)")) #end #if ($extraParamList.isEmpty()) #set ($extraParams = '') #else #set ($extraParams = '&'+$stringtool.join($extraParamList,'&')) #end ## ## Syntax menu map ## #set($syntaxMenu = []) #set($catCount = -1) #set($catName = "") #set($catChildren = []) #set($results = $services.query.xwql('from doc.object(XWiki.XWikiSyntaxClass) as syntax order by syntax.category, syntax.section').addFilter('currentlanguage').addFilter('unique').execute()) #if($results.empty) No syntax sections found! #else #foreach ($item in $results) #set($sectionDoc = $xwiki.getDocument($item)) #set($obj = $sectionDoc.getObject("XWiki.XWikiSyntaxClass")) ## detect if we entered a new category #if($catCount < $obj.getProperty("category").value) ## Put previous category into map (if existing), and reset children map #if($catId) #set($cat = { 'id' : $catId, 'name' : $catName, 'children' : $catChildren }) $syntaxMenu.add($cat) #set($catChildren = []) #end ## extract new catId and catName values, and sectionTitle as we are already traveling the DOM #foreach($headerBlock in $sectionDoc.getDocument().getXDOM().getBlocks('class:HeaderBlock', 'DESCENDANT')) #if($headerBlock.getLevel().getAsInt() == 1) #set($catId = $headerBlock.getId().substring(1)) #set($catName = $services.rendering.render($headerBlock, 'plain/1.0')) #elseif($headerBlock.getLevel().getAsInt() == 2) #set($sectionTitle = $services.rendering.render($headerBlock, 'plain/1.0')) #break #end #end #foreach($headerBlock in $sectionDoc.getTranslatedDocument().getDocument().getXDOM().getBlocks('class:HeaderBlock', 'DESCENDANT')) #if($headerBlock.getLevel().getAsInt() == 1) #set($catName = $services.rendering.render($headerBlock, 'plain/1.0')) #elseif($headerBlock.getLevel().getAsInt() == 2) #set($sectionTitle = $services.rendering.render($headerBlock, 'plain/1.0')) #break ## otherwise finds nested example headlines #end #end #set($catCount = $obj.getProperty("category").value) #else ## still in same category, only need new section title #foreach($headerBlock in $sectionDoc.getTranslatedDocument().getDocument().getXDOM().getBlocks('class:HeaderBlock', 'DESCENDANT')) #if($headerBlock.getLevel().getAsInt() == 2) #set($sectionTitle = $services.rendering.render($headerBlock, 'plain/1.0')) #break #end #end #end ## Add new sections to category children map #set($child = {'id' : $sectionDoc.getName().substring(11), 'minSyntax' : $obj.getProperty("minSyntaxId").value, 'maxSyntax' : $obj.getProperty("maxSyntaxId").value, 'name' : $sectionTitle}) $catChildren.add($child) #end #end #set($cat = { 'id' : $catId, 'name' : $catName, 'children' : $catChildren }) $syntaxMenu.add($cat) ## ## Filter only the sections that are valid for a Syntax ## #set ($categoriesToRemove = []) #foreach ($category in $syntaxMenu) #set ($sectionsToRemove = []) #foreach ($section on $category.children) #set($minSyntaxPos = $SUPPORTED_SYNTAX_ORDER.indexOf($section.minSyntax)) #if ($minSyntaxPos > $crtSyntaxPos) #set ($discard = $sectionsToRemove.add($section)) #if ($section.id == $crtSectionId) #set ($crtSectionId = '') ## clear section if it doesn't exist (can happen when switching from 2.x to 1.0 syntax) #end #end #end #set ($discard = $category.children.removeAll($sectionsToRemove)) #if ($category.children.size() == 0) #set ($discard = $categoriesToRemove.add($category)) #end #end #set ($discard = $syntaxMenu.removeAll($categoriesToRemove)) #if ("$!crtCategoryId" != '' && $crtCategoryId >= $syntaxMenu.size()) #set ($crtCategoryId = '') #end #if ($crtSectionId != '') #set ($crtItemId = $crtSectionId) #elseif ($crtCategoryId != '') #set ($crtItemId = $syntaxMenu.get($crtCategoryId).id) #end #set ($crtSection = $util.null) #set ($crtCategory = $util.null) ## ## Prepare the Syntax menu map for processing ## #foreach ($category in $syntaxMenu) ## "Standard" URLs and icons for categories #set ($category.url = "?syntax=$escapetool.url(${crtSyntaxVer})&category=${mathtool.sub($velocityCount, 1)}${extraParams}") #set ($category.cssClass = "${category.id}Icon") #if ("$!{crtCategoryId}" != '' && $velocityCount == $mathtool.add($crtCategoryId, 1)) #set ($crtCategory = $category) #end ## ## Process each syntax section #foreach ($section in $category.children) #if ($xwiki.exists("XWiki.XWikiSyntax${section.id}")) #if ($crtSectionId == $section.id) #set ($crtSection = $section) #set ($crtCategory = $category) #end #set ($section.url = "?syntax=$escapetool.url(${crtSyntaxVer})§ion=$escapetool.url(${section.id})${extraParams}") #end #end #end #** * Displays the sections from a syntax category * * Expected format: * sections = vector of items * item = map with the following fields: * 'id' : mandatory * 'name' : the text displayed for the corresponding menu item; * optional, defaults to * $services.localization.render("$!{translationPrefix}${item.id}") * * @param $sections the sections list, in the format described above * @param $translationPrefix the translation prefix added to the id of each * item, in order to generate the name and description; ignored when * name or description are specified * @param $heading the heading syntax *# #macro(syntax_displayCategory $sections $translationPrefix $heading) #foreach ($section in $sections) #syntax_displaySection($section $translationPrefix $heading) #end #end #macro(syntax_displaySection $section $translationPrefix $heading) #set ($displayVersion = $crtSyntaxVer) ## here is the hack to display the description for 2.0 if we have no description for 2.x ## this likely needs more work if e.g. there is a 3.x which is not compatible with 2.x #set($maxSyntaxPos = $SUPPORTED_SYNTAX_ORDER.indexOf($section.maxSyntax)) #if ($crtSyntaxPos > $maxSyntaxPos) #set ($displayVersion = $section.maxSyntax) #end #if($heading) (% class="sectionheader" %) $heading $section.name $heading #end {{include reference="XWiki.XWikiSyntax${section.id}" section="H${displayVersion}${section.id}"/}} #end #** * Displays the syntax categories * * Expected format: * sections = vector of items * item = map with the following fields: * 'id' : mandatory * 'name' : the text displayed for the corresponding menu item; * optional, defaults to * $services.localization.render("$!{translationPrefix}${item.id}") * * @param $sections the sections list, in the format described above * @param $translationPrefix the translation prefix added to the id of each * item, in order to generate the name and description; ignored when * name or description are specified *# #macro(syntax_displayCategories $syntaxMenu $translationPrefix) #set ($subHeading = '====') #foreach ($category in $syntaxMenu) == $category.name == #syntax_displayCategory($category.children 'syntax.' '===') #end #end #** * Displays the drop down allowing to switch the syntax. *# #macro (syntaxSwitch) #set ($crtSelection = "") #if ("$!{crtCategoryId}" != '') #set ($crtSelection = "category=$escapetool.url($!{crtCategoryId})") #elseif ($crtSectionId != '') #set ($crtSelection = "section=$escapetool.url($!{crtSectionId})") #end #if ($crtSelection != "") #set ($crtSelection = "${crtSelection}${extraParams}") #else #set ($crtSelection = "$extraParams") #end {{html}} <form id="change-context" class="xformInline" action="$doc.getURL()"> <div> <input type="hidden" name="xaction" value="switchContext" /> #if ($request.language) <input type="hidden" name="language" value="$escapetool.xml($request.language)" /> #end #if ($request.xpage) <input type="hidden" name="xpage" value="$escapetool.xml($request.xpage)" /> #end <select id="goto-select" name="target" title="$escapetool.xml($services.localization.render("help.changesyntax"))"> <optgroup label="$services.localization.render('help.choose_syntax')"> #foreach($syntaxId in $SUPPORTED_SYNTAX_ORDER) #set ($query = "syntax=${escapetool.url($syntaxId)}&${crtSelection}") <option value="$escapetool.xml($doc.getURL('view', $query))"#if($crtSyntaxVer == $syntaxId) selected="selected"#end>$escapetool.html($SUPPORTED_SYNTAXES.get($syntaxId))</option> #end </optgroup> </select> <span class="buttonwrapper"><input type="submit" value="$escapetool.xml($services.localization.render('admin.switchContext'))" class="button" /></span> </div> </form> {{/html}} #end {{/velocity}} {{velocity}} ##************************************************************************************************** ## From the Administration Sheet, used to display a common UI for some wiki features ## here used to display all categories / sections of the syntax guide ##************************************************************************************************** $xwiki.get('jsx').use($doc.getFullName())## $xwiki.get('ssx').use($doc.getFullName())## #if ($crtSectionId != '') #set ($sectionName = ${crtSection.name}) #elseif ($crtCategoryId != '') #set ($sectionName = ${crtCategory.name}) #else #set ($sectionName = $services.localization.render("help.syntaxall")) #end #set ($syntaxTitle = $services.localization.render("help.syntaxtitle", ["${crtSyntaxVer}"])) #syntaxSwitch() ((( #set ($query = "syntax=$escapetool.url(${crtSyntaxVer})${extraParams}") #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 ))) == $syntaxTitle: $sectionName == #verticalNavigation($syntaxMenu {'translationPrefix' : 'syntax.', 'crtItemId' : "$!crtItemId", 'cssClass' : 'syntax-menu'}) ##----------------------------------------- ## syntax-page display ##----------------------------------------- #set ($subHeading = '===') (% id="syntax-page-content" %)((( #if(!$crtSection && !$crtCategory) #syntax_displayCategories($syntaxMenu 'syntax.') #elseif (!$crtSection) #syntax_displayCategory($crtCategory.children 'syntax.' '==') #else #syntax_displaySection($crtSection 'syntax.' false) #end ))) ## syntax-page-content {{/velocity}}