Allgemeine Aktionen:
Anmelden
Registrieren
Start
▼
:
Wiki Verzeichnis
»
Bereich:
XWiki
»
Seite:
ConfigurableClass
default
Aktionen:
Exportieren
▼
:
Als PDF exportieren
Als RTF exportieren
Als HTML exportieren
Weitere Aktionen
▼
:
Druckvorschau
Zeige den Quellcode
Willkommen bei bytebang
»
XWiki Bereich
»
Benutzerspezifisch konfigurierbare Bereiche
Wiki-Quellcode von
Benutzerspezifisch konfigurierbare Bereiche
Zuletzt geändert von
Administrator
am 2014/06/29 19:28
Inhalt
·
Anhänge
(1)
·
Information
Zeilennummern verstecken
1: {{include reference="XWiki.ConfigurableClassMacros" /}} 2: 3: {{velocity}} 4: #* 5: * This part takes the configuration from any documents containing XWiki.ConfigurableClass objects and creates a form 6: * for each. To includeForm this document, you may specify: 7: * 8: * $section - String - The section which we are administrating eg: "Registration", "Users", or "Import". 9: * If none is specified then it checks for a request parameter called "section" and uses that, 10: * if no parameter, then this code assumes that it is part of the admin icons sheet and adds icons 11: * for any section which is not in $sections, in that event, this code assumes it is being run 12: * inside of a <ul> block. 13: * 14: * $sections - List<String> - If section is not specified, any sections on this list will not have icons made for them, 15: * the assumption being that the icons are already there. If section is specified then this 16: * is not taken into account and may safely be undefined. 17: * 18: * $currentDoc - String (document.fullName) - The administration document, users who don't have permission to edit 19: * it will not be able to include applications (possibly injecting 20: * arbitrary code.) if none specified then $doc.getFullName() is used. 21: * 22: * $globaladmin - boolean - If set true then we will assume we are administrationg the entire wiki. 23: * If not set then we look for a request parameter called "editor" if that exists and equals 24: * "globaladmin" then $globaladmin is true, if it doesn't exist then we check to see if 25: * $currentDoc.getFullName() equals "XWiki.XWikiPreferences". 26: *### 27: ## 28: ## Form submission depends on this. 29: $xwiki.jsfx.use('js/xwiki/actionbuttons/actionButtons.js', true) 30: ## 31: #if(!$section) 32: #set($section = $request.getParameter('section')) 33: #end 34: #if(!$currentDoc) 35: #set($currentDoc = $doc.getFullName()) 36: #end 37: ## Get value of $globaladmin if not specified. 38: #if("$!globaladmin" == '') 39: #if($editor != 'globaladmin' 40: && $request.getParameter('editor') != 'globaladmin' 41: && $currentDoc != 'XWiki.XWikiPreferences') 42: ## 43: #set($globaladmin = false) 44: #else 45: #set($globaladmin = true) 46: #end 47: #end 48: #set($currentSpace = $xwiki.getDocument($currentDoc).getSpace()) 49: ## 50: ## This application should not run with programming rights because it evaluates code which may not be trustworthy. 51: ## Removing the next line will open a security hole. 52: $doc.dropPermissions()## 53: ## 54: ##------------------------------------------------------------------------------------------------------------ 55: ## If $section exists then we are viewing the admin page for a particular section. 56: ## eg: 'Registration', 'Presentation', 'Import' etc. 57: ##------------------------------------------------------------------------------------------------------------ 58: ## 59: #if($section && $section != '') 60: ## 61: ## This is for keeping track of whether we have shown the heading yet or not. 62: ## If the heading doesn't need to be shown, but an error occurs in processing, then we show the heading 63: ## so that the user knows what the error relates to. 64: #set($headingShowing = false) 65: ## 66: ## Searches the database for names of apps to be configured 67: #set($outputList = []) 68: #findNamesOfAppsToConfigure($section, $globaladmin, $xwiki.getDocument($currentDoc).getSpace(), $outputList) 69: ## 70: #foreach($appName in $outputList) 71: ## 72: ## Make sure the current user has permission to edit the configurable application. 73: #set($userHasAccessToDocument = $xcontext.hasAccessLevel('edit', $appName)) 74: ## 75: ## If the document was not last saved by a user with edit privilege on this page 76: ## then we can't safely display the page but we should warn the viewer. 77: #if($userHasAccessToDocument) 78: ## Get the configurable application 79: #set($app = $xwiki.getDocument($appName)) 80: ## 81: #set($documentSavedByAuthorizedUser = false) 82: #checkDocumentSavedByAuthorizedUser($app, $currentDoc, $documentSavedByAuthorizedUser) 83: #end 84: ## 85: ## There is no need to display a heading unless: 86: ## 1. There was already a section before this document. 87: ## 2. This is not the first document in this section. 88: ## 89: ## If we are displaying the heading and there is an error to be shown Javascript will not strip the heading. 90: #if(!$appName.equals($outputList.get(0)) || $sections.contains($section)) 91: ## Create a document heading. 92: #showHeading($appName, $headingShowing) 93: #end 94: ## 95: #if(!$userHasAccessToDocument) 96: #showHeading($appName, $headingShowing) 97: 98: {{error}}{{translation key="xe.admin.configurable.noPermissionThisApplication"/}}{{/error}} 99: 100: #elseif(!$documentSavedByAuthorizedUser) 101: #showHeading($appName, $headingShowing) 102: 103: {{error}}{{translation key="xe.admin.configurable.applicationAuthorNoAdmin" parameters="$app.Author"/}}{{/error}} 104: 105: ## 106: ##------------------------------------------------------------------------------------------------------------ 107: ## If the document is locked and not by the current user and forceEdit is not set true, 108: #elseif($app.getLocked() && $app.getLockingUser() != $xcontext.getUser() && !$request.getParameter('forceEdit')) 109: #set($requestURL = "$request.getRequestURL()") 110: #if($requestURL.indexOf('?') == -1) 111: #set($requestURL = "${requestURL}?") 112: #end 113: #showHeading($appName, $headingShowing) 114: 115: {{error}}{{translation key="doclockedby"/}} $app.getLockingUser() [[{{translation key="forcelock"/}}>>${requestURL}&forceEdit=1]]{{/error}} 116: 117: #else 118: ## If the document is not already locked, attempt to acquire the lock. 119: #if(!$app.getLocked()) 120: 121: {{html wiki=true}} 122: <noscript> 123: 124: {{warning}}{{translation key="xe.admin.configurable.cannotLockNoJavascript"/}}{{/warning}} 125: 126: </noscript> 127: <script type="text/javascript"> 128: document.observe("xwiki:dom:loaded", function() { 129: new XWiki.DocumentLock('$escapetool.javascript($app.fullName)').lock(); 130: }); 131: </script> 132: {{/html}} 133: #end 134: ##------------------------------------------------------------------------------------------------------------ 135: ## Done Locking. 136: ## 137: ## Get all objects of the "ConfigurableClass" from this document. 138: #set($allConfigurableObjs = $app.getObjects($nameOfThisDocument)) 139: ## Separate out the objects which are for this section. 140: #set($configurableObjs = []) 141: #foreach($configurableObj in $allConfigurableObjs) 142: #if($app.getValue('displayInSection', $configurableObj) == $section) 143: ## If this is space admin, then don't display global, if global don't display space. 144: #if($globaladmin == ($app.getValue('configureGlobally', $configurableObj) == 1)) 145: #set($discard = $configurableObjs.add($configurableObj)) 146: #end 147: #end 148: #end 149: #if($configurableObjs.size() == 0) 150: ## Internal error, not translated. 151: #showHeading($appName, $headingShowing) 152: 153: {{error}}Internal error: All objects were filtered out for application: $appName.{{/error}} 154: 155: #else 156: #set($formAction = $xwiki.getURL($app.getFullName(), 'save')) 157: #set($formId = "${section.toLowerCase()}_${app.getFullName()}") 158: #set($escapedAppName = $escapetool.xml($app.getFullName())) 159: #foreach($configurableObj in $configurableObjs) 160: ## Display the header if one exists. 161: #set($heading = $app.getValue('heading', $configurableObj)) 162: #if($heading && $heading != '') 163: == #evaluate($heading) == 164: #end 165: ## 166: #set($codeToExecute = "$!app.getValue('codeToExecute', $configurableObj)") 167: #if($codeToExecute != '') 168: (%class="codeToExecute"%)(((## 169: #evaluate($codeToExecute)## 170: ))) 171: #end 172: ## 173: ## If propertiesToShow is set, then we will only show the properties contained therein. 174: #set($propertiesToShow = $app.getValue('propertiesToShow', $configurableObj)) 175: #if(!$propertiesToShow || $propertiesToShow.getClass().getName().indexOf('List') == -1) 176: #set($propertiesToShow = []) 177: #end 178: ## 179: ## If linkPrefix is set, then we will make each property label a link which starts with that prefix. 180: #set($linkPrefix = "$!app.getValue('linkPrefix', $configurableObj)") 181: ## 182: ## If the Configurable object specifies a configuration class, use it, 183: ## otherwise assume custom forms are used instead. 184: #set($configClassName = "$!app.getValue('configurationClass', $configurableObj)") 185: #if($configClassName != '') 186: #set($objClass = $xwiki.getDocument($configClassName).getxWikiClass()) 187: #if(!$objClass || $objClass.getClass().getName().indexOf('.Class') == -1) 188: #showHeading($appName, $headingShowing) 189: 190: {{error}}{{translation key="xe.admin.configurable.configurationClassNonexistant"/}}{{/error}} 191: 192: #else 193: ## Use the first object from the document which is of the configuration class. 194: #set($obj = $app.getObject($objClass.getName())) 195: ## 196: #if(!$obj || $obj.getClass().getName().indexOf('.Object') == -1) 197: #showHeading($appName, $headingShowing) 198: 199: {{error}} 200: {{translation key="xe.admin.configurable.noObjectOfConfigurationClassFound" parameters="$objClass.getName(), $app.getFullName()"/}} 201: {{/error}} 202: 203: #else 204: ## 205: ## Merge save buttons, remove headings from subsections, and make information links into popups. 206: ## This is not done if there is only a custom defined form. 207: $xwiki.jsx.use($nameOfThisDocument)## 208: ## 209: ## We don't begin the form until we have content for it so that a configurable can specify a 210: ## custom form in codeToExecute and if that configurable object is the first of it's kind in that 211: ## document, the custom form will not be put inside of our form. 212: #if(!$insideForm) 213: ## We are opening a form and fieldset without closing it, thus we cannot clean this html. 214: 215: {{html clean=false}} 216: <form id="$formId" method="post" action="$formAction" class="xform half"> 217: <fieldset> 218: {{/html}} 219: #set($insideForm = true) 220: #end 221: 222: {{html}} 223: $formHtml.toString() 224: {{/html}} 225: #end## If object exists 226: #end## If class exists 227: #end## If class name is specified. 228: #end## Foreach configurable object found in this document 229: ## If a form was started then we end it. 230: #if($insideForm) 231: 232: ## This is closing an open form which was opened above, we cannot clean this html. 233: {{html clean=false}} 234: ## We add in a redirect field to prevent the user from being carried away when they save 235: ## if they don't have javascript. 236: #set($thisURL = $request.getRequestURL()) 237: #if($request.getQueryString() && $request.getQueryString().length() > 0) 238: #set($thisURL = "${thisURL}?$request.getQueryString()") 239: #end 240: <input type="hidden" id="${escapedAppName}_redirect" name="$redirectParameter" value="$escapetool.xml($thisURL)" /> 241: <input type="hidden" name="form_token" value="$!{services.csrf.getToken()}" /> 242: </fieldset> 243: <div class="bottombuttons"> 244: <p class="admin-buttons"> 245: <span class="buttonwrapper"> 246: ## Text to display on the button. If there is a heading then this button should be labeled 247: ## that it is for saving this section. Otherwise it should be a generic "save" button. 248: #if($headingShowing) 249: #set($buttonText = "$services.localization.render('admin.save') $escapedAppName") 250: #else 251: #set($buttonText = "$services.localization.render('admin.save')") 252: #end 253: <input class="button" type="submit" name="action_saveandcontinue" value="$buttonText" /> 254: </span> 255: </p> 256: </div> ## bottombuttons 257: </form> 258: #set($insideForm = false) 259: {{/html}} 260: #end 261: #end## If there are configurable objects 262: #end## If document is not locked or forceEdit is enabled 263: #end## Foreach document name in names to configure 264: 265: {{html}} 266: <script type="text/javascript"> 267: /* <![CDATA[ */ 268: ## Alt+Shift+S presses the first saveAndContinue button it finds, not what we want so we will disable edit shortcuts. 269: document.observe('xwiki:dom:loaded', function() { 270: XWiki.actionButtons.EditActions = Object.extend(XWiki.actionButtons.EditActions, {addShortcuts : function() { }}); 271: }); 272: //]]> 273: </script> 274: {{/html}}## 275: ## 276: #else 277: ## 278: ##------------------------------------------------------------------------------------------------------------ 279: ## If section is not set then we are viewing the main administration page. 280: ##------------------------------------------------------------------------------------------------------------ 281: ## 282: ## If there is no list called sections then we set sections to an empty list. 283: #if(!$sections || $sections.getClass().getName().indexOf('List') == -1) 284: #set($sections = []) 285: #end 286: ## 287: ## We have to create a list of documents which the current user doesn't have permission to view. 288: ## So we can add an error message to the bottom of the page if there are any. 289: #set($appsUserCannotView = []) 290: ## 291: ## A list of sections (to be added) which the user is not allowed to edit, icons will be displayed with a message 292: #set($sectionsUserCannotEdit = []) 293: ## List of sections to be added, in order by creationDate of oldest contained application. 294: #set($sectionsToAdd = []) 295: ## Map of URL of icon to use by the name of the section to use that icon on. 296: #set($iconBySection = {}) 297: ## 298: #set($outputList = []) 299: #findNamesOfAppsToConfigure("", $globaladmin, $currentSpace, $outputList) 300: ## 301: #foreach($appName in $outputList) 302: ## 303: ## Get the configurable application 304: #set($app = $xwiki.getDocument($appName)) 305: ## 306: ## If getDocument returns null, then warn the user that they don't have view access to that application. 307: #if(!$app) 308: #set($discard = $appsUserCannotView.add($appName)) 309: #end 310: ## 311: #set($configurableObjects = $app.getObjects($nameOfThisDocument)) 312: #foreach($configurableObject in $configurableObjects) 313: #set($displayInSection = $app.getValue('displayInSection', $configurableObject)) 314: ## 315: ## If there is no section for this configurable or if the section cannot be edited, then check if the 316: ## application can be edited by the current user, if so then we display the icon from the current app and 317: ## don't display any message to tell the user they can't edit that section. 318: #if(!$sections.contains($displayInSection) || $sectionsUserCannotEdit.contains($displayInSection)) 319: ## 320: ## If there is no section for this configurable, then we will have to add one. 321: #if(!$sections.contains($displayInSection) && !$sectionsToAdd.contains($displayInSection)) 322: #set($discard = $sectionsToAdd.add($displayInSection)) 323: #end 324: ## 325: ## If an attachment by the filename iconAttachment exists and is an image 326: #set($attachment = $app.getAttachment("$app.getValue('iconAttachment', $configurableObject)")) 327: #if($attachment && $attachment.isImage()) 328: ## Set the icon for this section as the attachment URL. 329: #set($discard = $iconBySection.put($displayInSection, $app.getAttachmentURL($attachment.getFilename()))) 330: #end 331: ## 332: ## If the user doesn't have edit access to the application, we want to show a message on the icon 333: #if(!$xcontext.hasAccessLevel("edit", $app.getFullName())) 334: #if(!$sectionsUserCannotEdit.contains($displayInSection)) 335: #set($discard = $sectionsUserCannotEdit.add($displayInSection)) 336: #end 337: #elseif($sectionsUserCannotEdit.contains($displayInSection)) 338: ## If the user didn't have access to the section before but does have access to _this_ app which is 339: ## configured in the section, then the section becomes accessible. 340: #set($discard = $sectionsUserCannotEdit.remove($displayInSection)) 341: #end 342: #end## If section doesn't exist or user doesn't have access. 343: #end## Foreach configurable object in this app. 344: #end## Foreach application which is configurable. 345: ## 346: ## Now we go through sectionsToAdd and generate icons for them 347: #set($defaultIcon = $xwiki.getAttachmentURL($nameOfThisDocument, 'DefaultAdminSectionIcon.png')) 348: #if($globaladmin) 349: #set($queryString = "editor=globaladmin&section=") 350: #else 351: #set($queryString = "space=${currentSpace}&section=") 352: #if($request.getParameter('editor')) 353: #set($queryString = "editor=$escapetool.url($request.getParameter('editor'))&$queryString") 354: #end 355: #end 356: 357: ## This is an html fragment and thus cannot be cleaned 358: {{html clean=false}} 359: #foreach($sectionToAdd in $sectionsToAdd) 360: #set($icon = $iconBySection.get($sectionToAdd)) 361: #if(!$icon) 362: #set($icon = $defaultIcon) 363: #end 364: <li class="$escapetool.xml($sectionToAdd).replaceAll(' ', '_')"> 365: #set($hasAccess = !$sectionsUserCannotEdit.contains($sectionToAdd)) 366: #if($hasAccess) 367: <a href="$xwiki.getURL($currentDoc, $xcontext.getAction(), "$queryString$escapetool.url($sectionToAdd)")"> 368: #else 369: <a title="$services.localization.render('xe.admin.configurable.sectionIconNoAccessTooltip')"> 370: #end 371: <span> 372: <img src="$icon" alt="$escapetool.xml($sectionToAdd) icon"/> 373: ## Try to translate the names of the sections, build the key by adding an "admin." in front. 374: ## Not the best way to translate, but very inline with the way the translations are done in XWiki.AdminSheet for individual administration page titles. 375: ## If there is no translation (translated message is equals to key), don't display the message key, but the section name instead. 376: #if($services.localization.get("admin.${sectionToAdd.toLowerCase()}")) 377: #set($sectionDisplayName = $services.localization.render("admin.${sectionToAdd.toLowerCase()}")) 378: #else 379: #set($sectionDisplayName = $sectionToAdd) 380: #end 381: $escapetool.xml($sectionDisplayName) 382: </span> 383: #if(!$hasAccess) 384: <br/><span class="errormessage">$services.localization.render('xe.admin.configurable.sectionIconNoAccess')</span> 385: #end 386: </a> 387: </li> 388: #end 389: {{/html}} 390: 391: ## Finally we display an error message if there are any applications which we were unable to view. 392: #if($appsUserCannotView.size() > 0) 393: 394: {{error}}$services.localization.render('xe.admin.configurable.noViewAccessSomeApplications', [$appsUserCannotView]){{/error}} 395: 396: #end 397: #end## If we should be looking at the main administration page. 398: {{/velocity}}