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
Show line numbers
{{velocity}} #set ($needsAdminRights = false) ## ## 1. Register translations ## #set ($xwikiPreferencesDocumentReference = $services.model.createDocumentReference($xcontext.database, 'XWiki', 'XWikiPreferences')) #set ($xwikiPreferencesDocument = $xwiki.getDocument($xwikiPreferencesDocumentReference)) #set ($xwikiPreferencesObject = $xwikiPreferencesDocument.getObject('XWiki.XWikiPreferences')) #set ($documentBundles = "$!xwikiPreferencesObject.getProperty('documentBundles').value") #if (!$documentBundles.contains('WorkspaceManager.Translations')) #if ($hasGlobalAdmin) #set ($discard = $xwikiPreferencesObject.set('documentBundles', "$documentBundles, WorkspaceManager.Translations")) #set ($discard = $xwikiPreferencesDocument.save('Automatically registered Workspace Manager translations.', true)) {{success}}$msg.get('workspacemanager.translations.install.success'){{/success}} #else #set ($needsAdminRights = true) #end #else ## ## Don't display this information if the code is included from somewhere else. ## #if ($context.doc == $context.tdoc) {{success}}$msg.get('workspacemanager.translations.install.success'){{/success}} #end #end ## ## 2. Register workspace search suggestions ## #macro (registerWorkspaceSearchSuggestions $wikiName $skipSuccessMessage $skipNeedsAdminRightsCheck) #set ($searchSuggestConfigDocumentReference = $services.model.createDocumentReference($wikiName, 'XWiki', 'SearchSuggestConfig')) #set ($searchSuggestConfigDocument = $xwiki.getDocument($searchSuggestConfigDocumentReference)) #set ($searchSuggestConfigObject = $searchSuggestConfigDocument.getObject('XWiki.SearchSuggestSourceClass', 'name', 'Workspaces')) #if (!$searchSuggestConfigObject) #if ($hasGlobalAdmin) #set ($searchSuggestConfigObject = $searchSuggestConfigDocument.newObject("$wikiName:XWiki.SearchSuggestSourceClass")) #set ($discard = $searchSuggestConfigObject.set('name', 'Workspaces')) #set ($discard = $searchSuggestConfigObject.set('query', 'XWiki.XWikiServerClass.wikiprettyname:__INPUT__* AND object:WorkspaceManager.WorkspaceClass')) #set ($discard = $searchSuggestConfigObject.set('resultsNumber', '3')) #set ($suggestUrl = '$xwiki.getURL(' + $escapetool.quote + '${xcontext.mainWikiName}:WorkspaceManager.WorkspacesSuggestLuceneService' + $escapetool.quote + ', ' + $escapetool.singleQuote + 'get' + $escapetool.singleQuote + ', ' + $escapetool.singleQuote + 'outputSyntax=plain' + $escapetool.singleQuote + ')') #set ($discard = $searchSuggestConfigObject.set('url', $suggestUrl)) #set ($discard = $searchSuggestConfigObject.set('activated', 1)) #set ($discard = $searchSuggestConfigObject.set('highlight', 1)) #set ($suggestIcon = '$xwiki.getSkinFile(' + $escapetool.singleQuote + 'icons/silk/chart_organisation.png' + $escapetool.singleQuote + ')') #set ($discard = $searchSuggestConfigObject.set('icon', $suggestIcon)) ## #set ($discard = $searchSuggestConfigDocument.save('Automatically registered workspace search suggestions.', true)) #if (!$skipSuccessMessage) {{success}}$msg.get('workspacemanager.searchSuggestions.install.success'){{/success}} #end #elseif (!$skipNeedsAdminRightsCheck) #set ($needsAdminRights = true) #end #elseif (!$skipSuccessMessage) ## ## Don't display this information if the code is included from somewhere else. ## #if ($context.doc == $context.tdoc) {{success}}$msg.get('workspacemanager.searchSuggestions.install.success'){{/success}} #end #end #end #registerWorkspaceSearchSuggestions($xcontext.database) ## ## 3. Install template ## #if (!$WikiManager) #set ($WikiManager = $services.wikimanager) #if (!$WikiManager) {{error}}$msg.get('workspacemanager.dependencies.wikimanager.missing'){{/error}} #end #end #if (!$services.applicationmanager) {{error}}$msg.get('workspacemanager.dependencies.applicationmanager.missing'){{/error}} #end ## ## Constants #set ($TEMPLATE_NAME = 'workspacetemplate') #set ($TEMPLATE_PACKAGE = 'workspace-template.xar') ## #set ($Exception = $WikiManager.DefaultException) #set ($template = $WikiManager.getWikiTemplateDocument($TEMPLATE_NAME)) #if ("$!template" == '') #if ($hasGlobalAdmin) #if ($doc.getAttachment($TEMPLATE_PACKAGE)) #if ("$!request.confirmTemplateInstall" == '1') #set ($result = $WikiManager.createWikiTemplate($TEMPLATE_NAME, 'Workspace Template', $TEMPLATE_PACKAGE)) #if ($result == $Exception.ERROR_NOERROR) ## Use a redirect so that the page can be refreshed after the form's POST. #set ($discard = $response.sendRedirect($doc.getURL())) {{success}}$msg.get('workspacemanager.template.install.success'){{/success}} #elseif ($result == $Exception.ERROR_XWIKI_ACCESS_DENIED) #set ($needsAdminRights = true) #else {{error}}$msg.get('workspacemanager.template.install.error', [$xcontext.lastexception]){{/error}} #end #else {{warning}} Workspace template is not yet installed. Install the workspace template now? {{html}} <form method='post' action="$doc.getURL()"> <div> <input type='hidden' name='form_token' value="$!{services.csrf.getToken()}" /> <input type='hidden' name='confirmTemplateInstall' value='1' /> <span class='buttonwrapper'> <input type='submit' value='Install' class='button' /> </span> </div> </form> {{/html}} {{/warning}} #end #else {{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}} #end #else #set ($needsAdminRights = true) #end #else ## ## Don't display this information if the code is included from somewhere else. ## #if ($context.doc == $context.tdoc) {{success}}$msg.get('workspacemanager.template.install.success'){{/success}} #end #end ## ## 4. Install template features (workspace related pages + settings) ## #set ($TEMPLATE_FEATURES_PACKAGE = 'workspace-template-features.xar') ## ## Install template features only if not already done so. #set ($template = $WikiManager.getWikiTemplateDocument($TEMPLATE_NAME)) #set ($manageWorkspaceDocumentReference = $services.model.createDocumentReference("$TEMPLATE_NAME", 'XWiki', 'ManageWorkspace')) #if (!$template) #if (!$hasGlobalAdmin) #set ($needsAdminRights = true) #else {{error}}Workspace template features can not be installed without the workspace base template being installed first.{{/error}} #end #elseif (!$xwiki.exists($manageWorkspaceDocumentReference)) #set ($templateFeaturesAttachment = $doc.getAttachment($TEMPLATE_FEATURES_PACKAGE)) #if (!$hasGlobalAdmin) #set ($needsAdminRights = true) #elseif ($templateFeaturesAttachment) ## Change the database to the target wiki due to the Packager plugin limitation. #set ($currentDatabase = $xcontext.database) #set ($discard = $xcontext.setDatabase($TEMPLATE_NAME)) #set ($packager = $xwiki.package) #set ($templateFeaturesAttachmentLoadResultOk = $packager.importPackageFromByteArray($templateFeaturesAttachment.content)) #set ($templateFeaturesAttachmentInstallResult = $packager.install()) ## Change back to the current wiki. #set ($discard = $xcontext.setDatabase($currentDatabase)) #set ($PACKAGE_INSTALL_OK = 2) #if (!$templateFeaturesAttachmentLoadResultOk || $templateFeaturesAttachmentInstallResult != $PACKAGE_INSTALL_OK) {{error}}The template features package contains invalid entries. $!xcontext.import_error{{/error}} #else ## The workspace pages are now imported. Making final changes. #set ($xwikiPreferencesDocumentReference = $services.model.createDocumentReference("$TEMPLATE_NAME", 'XWiki', 'XWikiPreferences')) #set ($xwikiPreferencesDocument = $xwiki.getDocument($xwikiPreferencesDocumentReference)) #set ($xwikiPreferencesClassName = $services.model.serialize($xwikiPreferencesDocumentReference)) #set ($xwikiPreferencesObject = $xwikiPreferencesDocument.getObject($xwikiPreferencesClassName)) #set ($xwikiPreferencesNeedsSaving = false) ## ## 1. Register workspace translations ## #set ($workspaceManagerTranslations = "${xcontext.mainWikiName}:WorkspaceManager.Translations") #set ($currentTranslations = $xwikiPreferencesObject.getProperty('documentBundles').value) #if (!$currentTranslations.contains($workspaceManagerTranslations)) #set ($currentTranslations = "$workspaceManagerTranslations,$!currentTranslations") #set ($xwikiPreferencesNeedsSaving = true) #end #set ($templateTranslations = "${xcontext.mainWikiName}:WorkspaceManager.TemplateTranslations") #if (!$currentTranslations.contains($templateTranslations)) #set ($currentTranslations = "$templateTranslations,$!currentTranslations") #set ($xwikiPreferencesNeedsSaving = true) #end #set ($discard = $xwikiPreferencesObject.set('documentBundles', "$!currentTranslations")) ## ## 2. Register the Workspace Information Panel ## #set ($workspaceInformationPanel = 'Panels.WorkspaceInformationPanel') #set ($currentRightPanels = $xwikiPreferencesObject.getProperty('rightPanels').value) #if (!$currentRightPanels.contains($workspaceInformationPanel)) #set ($discard = $xwikiPreferencesObject.set('rightPanels', "$workspaceInformationPanel,$!currentRightPanels")) #set ($xwikiPreferencesNeedsSaving = true) #end ## ## Save XWikiPreferences with the new changes. #if ($xwikiPreferencesNeedsSaving) #set ($discard = $xwikiPreferencesDocument.save('Automatically registered workspace translations and panel', true)) #end ## ## 3. Extend XWiki.SearchSuggestConfig to show Workspaces as search suggestions. ## #registerWorkspaceSearchSuggestions($TEMPLATE_NAME, true, true) ## ## 4. Remove the local admin from XWikiAllGroup and XWikiAdminGroup. ## #set ($templateXwikiAllGroupDocumentReference = $services.model.createDocumentReference($TEMPLATE_NAME, 'XWiki', 'XWikiAllGroup')) #set ($templateXwikiAdminGroupDocumentReference = $services.model.createDocumentReference($TEMPLATE_NAME, 'XWiki', 'XWikiAdminGroup')) #set ($templateGroupClass = $services.model.createDocumentReference($TEMPLATE_NAME, 'XWiki', 'XWikiGroups')) #set ($groupReferencesToClean = [$templateXwikiAllGroupDocumentReference, $templateXwikiAdminGroupDocumentReference]) ## #foreach ($groupReferenceToClean in $groupReferencesToClean) #set ($groupDocumentToClean = $xwiki.getDocument($groupReferenceToClean)) #set ($serializedTemplateGroupClass = $services.model.serialize($templateGroupClass)) #set ($groupAllMembers = $groupDocumentToClean.getObjects($serializedTemplateGroupClass)) #set ($templateAdminMember = $groupDocumentToClean.getObject($serializedTemplateGroupClass, 'member', 'XWiki.Admin')) #if ($templateAdminMember) #if ($groupAllMembers.size() == 1) ## Just one member, we must not delete the object or the group will be disolved. #set ($discard = $templateAdminMember.set('member', '')) #else ## More than 1 member, we can sefely delete this object and the group will not be affected. #set ($discard = $groupDocumentToClean.removeObject($templateAdminMember)) #end #set ($discard = $groupDocumentToClean.save('Automatically removed local admin.', true)) #end #end ## ## Some tools used below, for steps 5, 6, 7 and 8. ## #set ($templateXWikiRightsDocumentReference = $services.model.createDocumentReference($TEMPLATE_NAME, 'XWiki', 'XWikiRights')) #set ($templateXWikiGlobalRightsDocumentReference = $services.model.createDocumentReference($TEMPLATE_NAME, 'XWiki', 'XWikiGlobalRights')) #macro (setRights $documentReference $rightsClassDocumentReference $entity $comment $isGroup) #set ($document = $xwiki.getDocument($documentReference)) #set ($serializedRightsClass = $services.model.serialize($rightsClassDocumentReference)) #set ($entityType = "#if($isGroup)groups#{else}users#end") #set ($existingRight = $document.getObject($serializedRightsClass, $entityType, $entity)) #if (!$existingRight) #set ($newRightsObject = $document.newObject($serializedRightsClass)) #set ($discard = $newRightsObject.set($entityType, "$!entity")) #set ($discard = $newRightsObject.set('levels', 'view')) #set ($discard = $newRightsObject.set('allow', 1)) ## #set ($discard = $document.save("$!comment", true)) #end #end ## #set ($allGlobalUsersGroup = "${xcontext.mainWikiName}:XWiki.XWikiAllGroup") #set ($guestUser = 'XWiki.XWikiGuest') ## ## 5. Set initial rights for the entire workspace to registered users. ## #setRights($xwikiPreferencesDocumentReference, $templateXWikiGlobalRightsDocumentReference, $allGlobalUsersGroup, 'Automatically set default rights for global users to allow view.', true) ## ## 6. Set initial rights for displaying panels properly to guests/registered users. ## #set ($panelsSpacePreferencesDocumentReference = $services.model.createDocumentReference($TEMPLATE_NAME, 'Panels', 'WebPreferences')) #setRights($panelsSpacePreferencesDocumentReference, $templateXWikiGlobalRightsDocumentReference, $guestUser, 'Automatically set default rights to panels for guests to allow view.') #setRights($panelsSpacePreferencesDocumentReference, $templateXWikiGlobalRightsDocumentReference, $allGlobalUsersGroup, 'Automatically set default rights to panels for global users to allow view.', true) ## ## 7. Set initial rights for displaying color themes properly to guests/registered users. ## #set ($colorThemesSpacePreferencesDocumentReference = $services.model.createDocumentReference($TEMPLATE_NAME, 'ColorThemes', 'WebPreferences')) #setRights($colorThemesSpacePreferencesDocumentReference, $templateXWikiGlobalRightsDocumentReference, $guestUser, 'Automatically set default rights to color themes for guests to allow view.') #setRights($colorThemesSpacePreferencesDocumentReference, $templateXWikiGlobalRightsDocumentReference, $allGlobalUsersGroup, 'Automatically set default rights to color themes for global users to allow view.', true) ## ## 8. Set initial rights for displaying the skin properly to guests/registered users. ## #set ($skinDocumentName = $xwikiPreferencesObject.getProperty('skin').value) #set ($discard = $xcontext.setDatabase($TEMPLATE_NAME)) #set ($skinDocumentReference = $services.model.resolveDocument($skinDocumentName)) #set ($discard = $xcontext.setDatabase($currentDatabase)) #setRights($skinDocumentReference, $templateXWikiRightsDocumentReference, $guestUser, 'Automatically set default rights to skin for guests to allow view.') #setRights($skinDocumentReference, $templateXWikiRightsDocumentReference, $allGlobalUsersGroup, 'Automatically set default rights to skin for global users to allow view.') ## ## 9. Disable local user registration ## #macro (permanentlyDeleteDocument $documentReferenceToRemove) #if ($xwiki.exists($documentReferenceToRemove)) #set ($documentToRemove = $xwiki.getDocument($documentReferenceToRemove)) #set ($discard = $xcontext.setDatabase($TEMPLATE_NAME)) ## Make sure not to leave anything in the recycle bin so don`t send to trash. #set ($discard = $xwiki.xWiki.deleteDocument($documentToRemove.document, false, $xcontext.context)) #set ($discard = $xcontext.setDatabase($currentDatabase)) #end #end ## #set ($templateAdminRegistrationSheetDocumentReference = $services.model.createDocumentReference($TEMPLATE_NAME, 'XWiki', 'AdminRegistrationSheet')) #set ($templateRegistrationConfigDocumentReference = $services.model.createDocumentReference($TEMPLATE_NAME, 'XWiki', 'RegistrationConfig')) #set ($templateRegistrationHelpDocumentReference = $services.model.createDocumentReference($TEMPLATE_NAME, 'XWiki', 'RegistrationHelp')) #permanentlyDeleteDocument($templateAdminRegistrationSheetDocumentReference) #permanentlyDeleteDocument($templateRegistrationConfigDocumentReference) #permanentlyDeleteDocument($templateRegistrationHelpDocumentReference) ## ## 10. Disable local user management ## #set ($templateAdminRegistrationSheetDocumentReference = $services.model.createDocumentReference($TEMPLATE_NAME, 'XWiki', 'AdminUsersSheet')) #permanentlyDeleteDocument($templateAdminRegistrationSheetDocumentReference) ## ## 11. Disable the local admin. ## #set ($templateLocalAdminDocumentReference = $services.model.createDocumentReference($TEMPLATE_NAME, 'XWiki', 'Admin')) #permanentlyDeleteDocument($templateLocalAdminDocumentReference) ## ## Macro to be used for setting the document author of documents requiring an existing user as author or a user with admin/programming rights. ## #set ($documentNamesAlreadyFixed = []) #macro(fixDocumentAuthor $className $comment $documentNamesAlreadyFixed) #set ($currentDatabase = $xcontext.database) #set ($discard = $xcontext.setDatabase($TEMPLATE_NAME)) #set ($documentNamesToFix = $services.query.xwql("from doc.object($className) as theObject").execute()) #foreach ($documentNameToFix in $documentNamesToFix) #if (!$documentNamesAlreadyFixed.contains($documentNameToFix)) #set ($documentReferencetoFix = $services.model.resolveDocument($documentNameToFix)) #set ($documentToFix = $xwiki.getDocument($documentReferencetoFix)) #set ($discard = $documentToFix.save($comment, true)) #set ($discard = $documentNamesAlreadyFixed.add($documentNameToFix)) #end #end #set ($discard = $xcontext.setDatabase($currentDatabase)) #end ## ## 12. Fix the author of wiki macro documents (use the current admin user) so that they are correctly registered. ## #fixDocumentAuthor('XWiki.WikiMacroClass', 'Fixed macro registration.', $documentNamesAlreadyFixed) ## ## 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. ## #fixDocumentAuthor('XWiki.ConfigurableClass', 'Fixed Configurable Class registration issues.', $documentNamesAlreadyFixed) ## ## 14. Fix the author of SSX and JSX extensions. ## #fixDocumentAuthor('XWiki.StyleSheetExtension', 'Fixed SSX registration issues.', $documentNamesAlreadyFixed) #fixDocumentAuthor('XWiki.JavaScriptExtension', 'Fixed JSX registration issues.', $documentNamesAlreadyFixed) ## ## 15. Fix the author of documents with RequiredRightClass declarations. ## #fixDocumentAuthor('XWiki.RequiredRightClass', 'Fixed RequiredRightClass requests.', $documentNamesAlreadyFixed) {{success}}Workspace template features successfully installed.{{/success}} #end #else {{error}}$msg.get('workspacemanager.template.install.error.missingattachment', [$TEMPLATE_FEATURES_PACKAGE, $doc.fullName]){{/error}} #end #else ## ## Don't display this information if the code is included from somewhere else. ## #if ($context.doc == $context.tdoc) {{success}}Workspace template features successfully installed.{{/success}} #end #end ## #if ($needsAdminRights) ## It might be possible that admin rights are required to register the translations themselves. Use this as backup message. #if ($msg.get('workspacemanager.install.notallowed') == 'workspacemanager.install.notallowed') {{error}}Admin rights are required to complete the Workspace Manager installation. Please login as Admin to complete the installation.{{/error}} #else {{error}}$msg.get('workspacemanager.install.notallowed'){{/error}} #end #end {{/velocity}}