General Actions:
Log-in
Register
Wiki:
Main wiki
▼
:
Document Index
»
Space:
WorkspaceManager
▼
:
Document Index
»
Page:
Install
Search
en
Page Actions:
Export
▼
:
Export as PDF
Export as RTF
Export as HTML
More actions
▼
:
Print preview
View Source
Main wiki
»
Browse Workspaces
»
Install
Wiki source code of
Install
Last modified by
Administrator
on 2012/03/21 17:40
Content
·
Comments
(0)
·
Annotations
(0)
·
Attachments
(2)
·
History
·
Information
Hide line numbers
1: {{velocity}} 2: #set ($needsAdminRights = false) 3: ## 4: ## 1. Register translations 5: ## 6: #set ($xwikiPreferencesDocumentReference = $services.model.createDocumentReference($xcontext.database, 'XWiki', 'XWikiPreferences')) 7: #set ($xwikiPreferencesDocument = $xwiki.getDocument($xwikiPreferencesDocumentReference)) 8: #set ($xwikiPreferencesObject = $xwikiPreferencesDocument.getObject('XWiki.XWikiPreferences')) 9: #set ($documentBundles = "$!xwikiPreferencesObject.getProperty('documentBundles').value") 10: #if (!$documentBundles.contains('WorkspaceManager.Translations')) 11: #if ($hasGlobalAdmin) 12: #set ($discard = $xwikiPreferencesObject.set('documentBundles', "$documentBundles, WorkspaceManager.Translations")) 13: #set ($discard = $xwikiPreferencesDocument.save('Automatically registered Workspace Manager translations.', true)) 14: {{success}}$msg.get('workspacemanager.translations.install.success'){{/success}} 15: #else 16: #set ($needsAdminRights = true) 17: #end 18: #else 19: ## 20: ## Don't display this information if the code is included from somewhere else. 21: ## 22: #if ($context.doc == $context.tdoc) 23: {{success}}$msg.get('workspacemanager.translations.install.success'){{/success}} 24: #end 25: #end 26: ## 27: ## 2. Register workspace search suggestions 28: ## 29: #macro (registerWorkspaceSearchSuggestions $wikiName $skipSuccessMessage $skipNeedsAdminRightsCheck) 30: #set ($searchSuggestConfigDocumentReference = $services.model.createDocumentReference($wikiName, 'XWiki', 'SearchSuggestConfig')) 31: #set ($searchSuggestConfigDocument = $xwiki.getDocument($searchSuggestConfigDocumentReference)) 32: #set ($searchSuggestConfigObject = $searchSuggestConfigDocument.getObject('XWiki.SearchSuggestSourceClass', 'name', 'Workspaces')) 33: #if (!$searchSuggestConfigObject) 34: #if ($hasGlobalAdmin) 35: #set ($searchSuggestConfigObject = $searchSuggestConfigDocument.newObject("$wikiName:XWiki.SearchSuggestSourceClass")) 36: #set ($discard = $searchSuggestConfigObject.set('name', 'Workspaces')) 37: #set ($discard = $searchSuggestConfigObject.set('query', 'XWiki.XWikiServerClass.wikiprettyname:__INPUT__* AND object:WorkspaceManager.WorkspaceClass')) 38: #set ($discard = $searchSuggestConfigObject.set('resultsNumber', '3')) 39: #set ($suggestUrl = '$xwiki.getURL(' + $escapetool.quote + '${xcontext.mainWikiName}:WorkspaceManager.WorkspacesSuggestLuceneService' + $escapetool.quote + ', ' + $escapetool.singleQuote + 'get' + $escapetool.singleQuote + ', ' + $escapetool.singleQuote + 'outputSyntax=plain' + $escapetool.singleQuote + ')') 40: #set ($discard = $searchSuggestConfigObject.set('url', $suggestUrl)) 41: #set ($discard = $searchSuggestConfigObject.set('activated', 1)) 42: #set ($discard = $searchSuggestConfigObject.set('highlight', 1)) 43: #set ($suggestIcon = '$xwiki.getSkinFile(' + $escapetool.singleQuote + 'icons/silk/chart_organisation.png' + $escapetool.singleQuote + ')') 44: #set ($discard = $searchSuggestConfigObject.set('icon', $suggestIcon)) 45: ## 46: #set ($discard = $searchSuggestConfigDocument.save('Automatically registered workspace search suggestions.', true)) 47: #if (!$skipSuccessMessage) 48: 49: {{success}}$msg.get('workspacemanager.searchSuggestions.install.success'){{/success}} 50: #end 51: #elseif (!$skipNeedsAdminRightsCheck) 52: #set ($needsAdminRights = true) 53: #end 54: #elseif (!$skipSuccessMessage) 55: ## 56: ## Don't display this information if the code is included from somewhere else. 57: ## 58: #if ($context.doc == $context.tdoc) 59: 60: {{success}}$msg.get('workspacemanager.searchSuggestions.install.success'){{/success}} 61: #end 62: #end 63: #end 64: #registerWorkspaceSearchSuggestions($xcontext.database) 65: ## 66: ## 3. Install template 67: ## 68: #if (!$WikiManager) 69: #set ($WikiManager = $services.wikimanager) 70: #if (!$WikiManager) 71: 72: {{error}}$msg.get('workspacemanager.dependencies.wikimanager.missing'){{/error}} 73: #end 74: #end 75: #if (!$services.applicationmanager) 76: 77: {{error}}$msg.get('workspacemanager.dependencies.applicationmanager.missing'){{/error}} 78: #end 79: ## 80: ## Constants 81: #set ($TEMPLATE_NAME = 'workspacetemplate') 82: #set ($TEMPLATE_PACKAGE = 'workspace-template.xar') 83: ## 84: #set ($Exception = $WikiManager.DefaultException) 85: #set ($template = $WikiManager.getWikiTemplateDocument($TEMPLATE_NAME)) 86: #if ("$!template" == '') 87: #if ($hasGlobalAdmin) 88: #if ($doc.getAttachment($TEMPLATE_PACKAGE)) 89: #if ("$!request.confirmTemplateInstall" == '1') 90: #set ($result = $WikiManager.createWikiTemplate($TEMPLATE_NAME, 'Workspace Template', $TEMPLATE_PACKAGE)) 91: #if ($result == $Exception.ERROR_NOERROR) 92: ## Use a redirect so that the page can be refreshed after the form's POST. 93: #set ($discard = $response.sendRedirect($doc.getURL())) 94: 95: {{success}}$msg.get('workspacemanager.template.install.success'){{/success}} 96: #elseif ($result == $Exception.ERROR_XWIKI_ACCESS_DENIED) 97: #set ($needsAdminRights = true) 98: #else 99: 100: {{error}}$msg.get('workspacemanager.template.install.error', [$xcontext.lastexception]){{/error}} 101: #end 102: #else 103: 104: {{warning}} 105: Workspace template is not yet installed. Install the workspace template now? 106: 107: {{html}} 108: <form method='post' action="$doc.getURL()"> 109: <div> 110: <input type='hidden' name='form_token' value="$!{services.csrf.getToken()}" /> 111: <input type='hidden' name='confirmTemplateInstall' value='1' /> 112: <span class='buttonwrapper'> 113: <input type='submit' value='Install' class='button' /> 114: </span> 115: </div> 116: </form> 117: {{/html}} 118: {{/warning}} 119: #end 120: #else 121: 122: {{error}}$msg.get('workspacemanager.template.install.error.missingtemplateattachment', [$TEMPLATE_PACKAGE, $doc.fullName, "http://nexus.xwiki.org/nexus/content/groups/public/org/xwiki/enterprise/xwiki-enterprise-ui-all/${xwiki.version}/xwiki-enterprise-ui-all-${xwiki.version}.xar"]){{/error}} 123: #end 124: #else 125: #set ($needsAdminRights = true) 126: #end 127: #else 128: ## 129: ## Don't display this information if the code is included from somewhere else. 130: ## 131: #if ($context.doc == $context.tdoc) 132: 133: {{success}}$msg.get('workspacemanager.template.install.success'){{/success}} 134: #end 135: #end 136: ## 137: ## 4. Install template features (workspace related pages + settings) 138: ## 139: #set ($TEMPLATE_FEATURES_PACKAGE = 'workspace-template-features.xar') 140: ## 141: ## Install template features only if not already done so. 142: #set ($template = $WikiManager.getWikiTemplateDocument($TEMPLATE_NAME)) 143: #set ($manageWorkspaceDocumentReference = $services.model.createDocumentReference("$TEMPLATE_NAME", 'XWiki', 'ManageWorkspace')) 144: #if (!$template) 145: #if (!$hasGlobalAdmin) 146: #set ($needsAdminRights = true) 147: #else 148: 149: {{error}}Workspace template features can not be installed without the workspace base template being installed first.{{/error}} 150: #end 151: #elseif (!$xwiki.exists($manageWorkspaceDocumentReference)) 152: #set ($templateFeaturesAttachment = $doc.getAttachment($TEMPLATE_FEATURES_PACKAGE)) 153: #if (!$hasGlobalAdmin) 154: #set ($needsAdminRights = true) 155: #elseif ($templateFeaturesAttachment) 156: ## Change the database to the target wiki due to the Packager plugin limitation. 157: #set ($currentDatabase = $xcontext.database) 158: #set ($discard = $xcontext.setDatabase($TEMPLATE_NAME)) 159: #set ($packager = $xwiki.package) 160: #set ($templateFeaturesAttachmentLoadResultOk = $packager.importPackageFromByteArray($templateFeaturesAttachment.content)) 161: #set ($templateFeaturesAttachmentInstallResult = $packager.install()) 162: ## Change back to the current wiki. 163: #set ($discard = $xcontext.setDatabase($currentDatabase)) 164: #set ($PACKAGE_INSTALL_OK = 2) 165: #if (!$templateFeaturesAttachmentLoadResultOk || $templateFeaturesAttachmentInstallResult != $PACKAGE_INSTALL_OK) 166: 167: {{error}}The template features package contains invalid entries. $!xcontext.import_error{{/error}} 168: #else 169: ## The workspace pages are now imported. Making final changes. 170: #set ($xwikiPreferencesDocumentReference = $services.model.createDocumentReference("$TEMPLATE_NAME", 'XWiki', 'XWikiPreferences')) 171: #set ($xwikiPreferencesDocument = $xwiki.getDocument($xwikiPreferencesDocumentReference)) 172: #set ($xwikiPreferencesClassName = $services.model.serialize($xwikiPreferencesDocumentReference)) 173: #set ($xwikiPreferencesObject = $xwikiPreferencesDocument.getObject($xwikiPreferencesClassName)) 174: #set ($xwikiPreferencesNeedsSaving = false) 175: ## 176: ## 1. Register workspace translations 177: ## 178: #set ($workspaceManagerTranslations = "${xcontext.mainWikiName}:WorkspaceManager.Translations") 179: #set ($currentTranslations = $xwikiPreferencesObject.getProperty('documentBundles').value) 180: #if (!$currentTranslations.contains($workspaceManagerTranslations)) 181: #set ($currentTranslations = "$workspaceManagerTranslations,$!currentTranslations") 182: #set ($xwikiPreferencesNeedsSaving = true) 183: #end 184: #set ($templateTranslations = "${xcontext.mainWikiName}:WorkspaceManager.TemplateTranslations") 185: #if (!$currentTranslations.contains($templateTranslations)) 186: #set ($currentTranslations = "$templateTranslations,$!currentTranslations") 187: #set ($xwikiPreferencesNeedsSaving = true) 188: #end 189: #set ($discard = $xwikiPreferencesObject.set('documentBundles', "$!currentTranslations")) 190: ## 191: ## 2. Register the Workspace Information Panel 192: ## 193: #set ($workspaceInformationPanel = 'Panels.WorkspaceInformationPanel') 194: #set ($currentRightPanels = $xwikiPreferencesObject.getProperty('rightPanels').value) 195: #if (!$currentRightPanels.contains($workspaceInformationPanel)) 196: #set ($discard = $xwikiPreferencesObject.set('rightPanels', "$workspaceInformationPanel,$!currentRightPanels")) 197: #set ($xwikiPreferencesNeedsSaving = true) 198: #end 199: ## 200: ## Save XWikiPreferences with the new changes. 201: #if ($xwikiPreferencesNeedsSaving) 202: #set ($discard = $xwikiPreferencesDocument.save('Automatically registered workspace translations and panel', true)) 203: #end 204: ## 205: ## 3. Extend XWiki.SearchSuggestConfig to show Workspaces as search suggestions. 206: ## 207: #registerWorkspaceSearchSuggestions($TEMPLATE_NAME, true, true) 208: ## 209: ## 4. Remove the local admin from XWikiAllGroup and XWikiAdminGroup. 210: ## 211: #set ($templateXwikiAllGroupDocumentReference = $services.model.createDocumentReference($TEMPLATE_NAME, 'XWiki', 'XWikiAllGroup')) 212: #set ($templateXwikiAdminGroupDocumentReference = $services.model.createDocumentReference($TEMPLATE_NAME, 'XWiki', 'XWikiAdminGroup')) 213: #set ($templateGroupClass = $services.model.createDocumentReference($TEMPLATE_NAME, 'XWiki', 'XWikiGroups')) 214: #set ($groupReferencesToClean = [$templateXwikiAllGroupDocumentReference, $templateXwikiAdminGroupDocumentReference]) 215: ## 216: #foreach ($groupReferenceToClean in $groupReferencesToClean) 217: #set ($groupDocumentToClean = $xwiki.getDocument($groupReferenceToClean)) 218: #set ($serializedTemplateGroupClass = $services.model.serialize($templateGroupClass)) 219: #set ($groupAllMembers = $groupDocumentToClean.getObjects($serializedTemplateGroupClass)) 220: #set ($templateAdminMember = $groupDocumentToClean.getObject($serializedTemplateGroupClass, 'member', 'XWiki.Admin')) 221: #if ($templateAdminMember) 222: #if ($groupAllMembers.size() == 1) 223: ## Just one member, we must not delete the object or the group will be disolved. 224: #set ($discard = $templateAdminMember.set('member', '')) 225: #else 226: ## More than 1 member, we can sefely delete this object and the group will not be affected. 227: #set ($discard = $groupDocumentToClean.removeObject($templateAdminMember)) 228: #end 229: #set ($discard = $groupDocumentToClean.save('Automatically removed local admin.', true)) 230: #end 231: #end 232: ## 233: ## Some tools used below, for steps 5, 6, 7 and 8. 234: ## 235: #set ($templateXWikiRightsDocumentReference = $services.model.createDocumentReference($TEMPLATE_NAME, 'XWiki', 'XWikiRights')) 236: #set ($templateXWikiGlobalRightsDocumentReference = $services.model.createDocumentReference($TEMPLATE_NAME, 'XWiki', 'XWikiGlobalRights')) 237: #macro (setRights $documentReference $rightsClassDocumentReference $entity $comment $isGroup) 238: #set ($document = $xwiki.getDocument($documentReference)) 239: #set ($serializedRightsClass = $services.model.serialize($rightsClassDocumentReference)) 240: #set ($entityType = "#if($isGroup)groups#{else}users#end") 241: #set ($existingRight = $document.getObject($serializedRightsClass, $entityType, $entity)) 242: #if (!$existingRight) 243: #set ($newRightsObject = $document.newObject($serializedRightsClass)) 244: #set ($discard = $newRightsObject.set($entityType, "$!entity")) 245: #set ($discard = $newRightsObject.set('levels', 'view')) 246: #set ($discard = $newRightsObject.set('allow', 1)) 247: ## 248: #set ($discard = $document.save("$!comment", true)) 249: #end 250: #end 251: ## 252: #set ($allGlobalUsersGroup = "${xcontext.mainWikiName}:XWiki.XWikiAllGroup") 253: #set ($guestUser = 'XWiki.XWikiGuest') 254: ## 255: ## 5. Set initial rights for the entire workspace to registered users. 256: ## 257: #setRights($xwikiPreferencesDocumentReference, $templateXWikiGlobalRightsDocumentReference, $allGlobalUsersGroup, 'Automatically set default rights for global users to allow view.', true) 258: ## 259: ## 6. Set initial rights for displaying panels properly to guests/registered users. 260: ## 261: #set ($panelsSpacePreferencesDocumentReference = $services.model.createDocumentReference($TEMPLATE_NAME, 'Panels', 'WebPreferences')) 262: #setRights($panelsSpacePreferencesDocumentReference, $templateXWikiGlobalRightsDocumentReference, $guestUser, 'Automatically set default rights to panels for guests to allow view.') 263: #setRights($panelsSpacePreferencesDocumentReference, $templateXWikiGlobalRightsDocumentReference, $allGlobalUsersGroup, 'Automatically set default rights to panels for global users to allow view.', true) 264: ## 265: ## 7. Set initial rights for displaying color themes properly to guests/registered users. 266: ## 267: #set ($colorThemesSpacePreferencesDocumentReference = $services.model.createDocumentReference($TEMPLATE_NAME, 'ColorThemes', 'WebPreferences')) 268: #setRights($colorThemesSpacePreferencesDocumentReference, $templateXWikiGlobalRightsDocumentReference, $guestUser, 'Automatically set default rights to color themes for guests to allow view.') 269: #setRights($colorThemesSpacePreferencesDocumentReference, $templateXWikiGlobalRightsDocumentReference, $allGlobalUsersGroup, 'Automatically set default rights to color themes for global users to allow view.', true) 270: ## 271: ## 8. Set initial rights for displaying the skin properly to guests/registered users. 272: ## 273: #set ($skinDocumentName = $xwikiPreferencesObject.getProperty('skin').value) 274: #set ($discard = $xcontext.setDatabase($TEMPLATE_NAME)) 275: #set ($skinDocumentReference = $services.model.resolveDocument($skinDocumentName)) 276: #set ($discard = $xcontext.setDatabase($currentDatabase)) 277: #setRights($skinDocumentReference, $templateXWikiRightsDocumentReference, $guestUser, 'Automatically set default rights to skin for guests to allow view.') 278: #setRights($skinDocumentReference, $templateXWikiRightsDocumentReference, $allGlobalUsersGroup, 'Automatically set default rights to skin for global users to allow view.') 279: ## 280: ## 9. Disable local user registration 281: ## 282: #macro (permanentlyDeleteDocument $documentReferenceToRemove) 283: #if ($xwiki.exists($documentReferenceToRemove)) 284: #set ($documentToRemove = $xwiki.getDocument($documentReferenceToRemove)) 285: #set ($discard = $xcontext.setDatabase($TEMPLATE_NAME)) 286: ## Make sure not to leave anything in the recycle bin so don`t send to trash. 287: #set ($discard = $xwiki.xWiki.deleteDocument($documentToRemove.document, false, $xcontext.context)) 288: #set ($discard = $xcontext.setDatabase($currentDatabase)) 289: #end 290: #end 291: ## 292: #set ($templateAdminRegistrationSheetDocumentReference = $services.model.createDocumentReference($TEMPLATE_NAME, 'XWiki', 'AdminRegistrationSheet')) 293: #set ($templateRegistrationConfigDocumentReference = $services.model.createDocumentReference($TEMPLATE_NAME, 'XWiki', 'RegistrationConfig')) 294: #set ($templateRegistrationHelpDocumentReference = $services.model.createDocumentReference($TEMPLATE_NAME, 'XWiki', 'RegistrationHelp')) 295: #permanentlyDeleteDocument($templateAdminRegistrationSheetDocumentReference) 296: #permanentlyDeleteDocument($templateRegistrationConfigDocumentReference) 297: #permanentlyDeleteDocument($templateRegistrationHelpDocumentReference) 298: ## 299: ## 10. Disable local user management 300: ## 301: #set ($templateAdminRegistrationSheetDocumentReference = $services.model.createDocumentReference($TEMPLATE_NAME, 'XWiki', 'AdminUsersSheet')) 302: #permanentlyDeleteDocument($templateAdminRegistrationSheetDocumentReference) 303: ## 304: ## 11. Disable the local admin. 305: ## 306: #set ($templateLocalAdminDocumentReference = $services.model.createDocumentReference($TEMPLATE_NAME, 'XWiki', 'Admin')) 307: #permanentlyDeleteDocument($templateLocalAdminDocumentReference) 308: ## 309: ## Macro to be used for setting the document author of documents requiring an existing user as author or a user with admin/programming rights. 310: ## 311: #set ($documentNamesAlreadyFixed = []) 312: #macro(fixDocumentAuthor $className $comment $documentNamesAlreadyFixed) 313: #set ($currentDatabase = $xcontext.database) 314: #set ($discard = $xcontext.setDatabase($TEMPLATE_NAME)) 315: #set ($documentNamesToFix = $services.query.xwql("from doc.object($className) as theObject").execute()) 316: #foreach ($documentNameToFix in $documentNamesToFix) 317: #if (!$documentNamesAlreadyFixed.contains($documentNameToFix)) 318: #set ($documentReferencetoFix = $services.model.resolveDocument($documentNameToFix)) 319: #set ($documentToFix = $xwiki.getDocument($documentReferencetoFix)) 320: #set ($discard = $documentToFix.save($comment, true)) 321: #set ($discard = $documentNamesAlreadyFixed.add($documentNameToFix)) 322: #end 323: #end 324: #set ($discard = $xcontext.setDatabase($currentDatabase)) 325: #end 326: ## 327: ## 12. Fix the author of wiki macro documents (use the current admin user) so that they are correctly registered. 328: ## 329: #fixDocumentAuthor('XWiki.WikiMacroClass', 'Fixed macro registration.', $documentNamesAlreadyFixed) 330: ## 331: ## 13. Fix the author of configuration pages for each application (use the current admin user) so that they are correctly registered and accessible in the workspace Administration section. 332: ## 333: #fixDocumentAuthor('XWiki.ConfigurableClass', 'Fixed Configurable Class registration issues.', $documentNamesAlreadyFixed) 334: ## 335: ## 14. Fix the author of SSX and JSX extensions. 336: ## 337: #fixDocumentAuthor('XWiki.StyleSheetExtension', 'Fixed SSX registration issues.', $documentNamesAlreadyFixed) 338: #fixDocumentAuthor('XWiki.JavaScriptExtension', 'Fixed JSX registration issues.', $documentNamesAlreadyFixed) 339: ## 340: ## 15. Fix the author of documents with RequiredRightClass declarations. 341: ## 342: #fixDocumentAuthor('XWiki.RequiredRightClass', 'Fixed RequiredRightClass requests.', $documentNamesAlreadyFixed) 343: 344: {{success}}Workspace template features successfully installed.{{/success}} 345: #end 346: #else 347: 348: {{error}}$msg.get('workspacemanager.template.install.error.missingattachment', [$TEMPLATE_FEATURES_PACKAGE, $doc.fullName]){{/error}} 349: #end 350: #else 351: ## 352: ## Don't display this information if the code is included from somewhere else. 353: ## 354: #if ($context.doc == $context.tdoc) 355: 356: {{success}}Workspace template features successfully installed.{{/success}} 357: #end 358: #end 359: ## 360: #if ($needsAdminRights) 361: ## It might be possible that admin rights are required to register the translations themselves. Use this as backup message. 362: #if ($msg.get('workspacemanager.install.notallowed') == 'workspacemanager.install.notallowed') 363: 364: {{error}}Admin rights are required to complete the Workspace Manager installation. Please login as Admin to complete the installation.{{/error}} 365: #else 366: 367: {{error}}$msg.get('workspacemanager.install.notallowed'){{/error}} 368: #end 369: #end 370: {{/velocity}}