WikiManager
CreateNewWiki
en
0
WikiManager.WebHome
XWiki.Admin
XWiki.superadmin
xwiki:XWiki.Admin
1186676964000
1529283495000
1529283495000
1.1

# CreateNewWiki

Imported from XAR
false
xwiki/1.0
false
XWiki.TagClass
0
0
input
1
tags
1
Tags
1
|
|,
30
0
com.xpn.xwiki.objects.classes.StaticListClass
WikiManager.CreateNewWiki
0
XWiki.TagClass
afccd63d-a604-48bc-84a9-22ac9c9e065c
############################################################################################ ## Create a new wiki with initial minimum informations step by step or in one page. ## ## Can use URL parameters : ## -doc ## 0 : Just show input and properties names ## 1 : Print documentation for each field ## -stepbystep ## 0 : All informations in one page and create button ## 1 : Step by step based on javascript ## ############################################################################################ ## PLUGINS DEPENDANCIES #set ($WikiManager = $xwiki.wikimanager) #if (!$WikiManager) #error($msg.get("wikimanager.pluginnotenabled")) #end #if (!$xwiki.applicationmanager) #error($msg.get("xapp.pluginnotenabled")) #end #if(!$xwiki.isVirtualMode()) #error($msg.get("wikimanager.notinvirtualmode")) #end ############################################################################################ ## MACROS #macro(getRequestList $paramlist $paramname) #set ($paramtable = []) #set ($paramtable = $request.getParameterValues($paramname)) #if ($paramtable) #set ($paramlist = []) #foreach($paramvalue in $paramtable) #set ($ok = $paramlist.add($paramvalue)) #end #end #end ## #macro(printUsersAndGroups $users $groups $rightlevel $userlist $grouplist $hidden) <select #if ($hidden) type="hidden" #end name="${rightlevel}users" id="${rightlevel}users" multiple="multiple"> #foreach ($user in $users) #if ($context.database == $context.mainWikiName) #set ($user = "${context.mainWikiName}:${user}") #end <option value="$user" #if ($userlist && $userlist.contains($user)) selected="selected" #end>$xwiki.getUserName($user, $util.null, false)</option> #end </select> <select #if ($hidden) type="hidden" #end name="${rightlevel}groups" id="${rightlevel}groups" multiple="multiple"> #foreach ($group in $groups) #if ($context.database == $context.mainWikiName) #set ($group = "${context.mainWikiName}:${group}") #end #set ($pointindex = $group.indexOf(".") + 1) <option value="$group" #if ($grouplist && $grouplist.contains($group)) selected="selected" #end>$group.substring($pointindex)</option> #end </select> #end ## #macro(addRights $prefdoc $userlist $grouplist $rights $needsave) #set ($users = "") #foreach($user in $userlist) #if ($users != "") #set ($users = "${users},${user}") #else #set ($users = $user) #end #end #set ($groups = "") #foreach($group in $grouplist) #if ($groups != "") #set ($groups = "${groups},${group}") #else #set ($groups = $group) #end #end ## #if (($users != "") || ($groups != "")) #set ($rightsobj = $prefdoc.newObject("XWiki.XWikiGlobalRights")) ## #set ($ok = $rightsobj.set("users", $users)) #set ($ok = $rightsobj.set("groups", $groups)) #set ($ok = $rightsobj.set("levels", $rights)) #set ($ok = $rightsobj.set("allow", 1)) ## #set ($needsave = true) #end #end ############################################################################################ ## TOOLS #set ($Exception = $WikiManager.DefaultException) #set ($ALIASSUFFIX = ".ng.demospace.ch") #set ($WSTEPID_INTRO = 0) ## Wiki creation introduction #set ($WSTEPNAME_INTRO = "wstep_intro") #set ($WSTEPID_WIKINAME = 1) ## Wiki name #set ($WSTEPNAME_WIKINAME = "wstep_wikiname") #set ($WSTEPID_WIKIDESC = 2) ## Wiki descriptor informations #set ($WSTEPNAME_WIKIDESC = "wstep_wikidesc") #set ($WSTEPID_DATAFROM = 3) ## Initialise wiki data from wiki template or XAR package #set ($WSTEPNAME_DATAFROM = "wstep_datafrom") #set ($WSTEPID_USERS = 4) ## Preregistered users #set ($WSTEPNAME_USERS = "wstep_users") #set ($WSTEPID_SUMMARY = 5) ## Summary be fore create #set ($WSTEPNAME_SUMMARY = "wstep_summary") #set ($WSTEPLIST = [$WSTEPNAME_INTRO, $WSTEPNAME_WIKINAME, $WSTEPNAME_WIKIDESC, $WSTEPNAME_DATAFROM, $WSTEPNAME_USERS, $WSTEPNAME_SUMMARY]) #set ($ISWIKINAMEAVAILABLE = $xwiki.getDocument("WikiCode.IsWikiOrDatabaseAvailableService").URL) #set ($MSG_ERROR_WIKIALREADYEXISTS = "<div class=\"errormessage\"><span class=\"messagetype\">$msg.get('error'): </span>$msg.get('wikimanager.wikiname.error.wikialreadyexists')</div>") #set ($MSG_WARNING_DATABASEALREADYEXISTS = "<div class=\"warningmessage\"><span class=\"messagetype\">$msg.get('warning'): </span>$msg.get('wikimanager.wikiname.error.databasealreadyexists')</div>") #set ($MSG_ERROR_DATABASEALREADYEXISTS = "<div class=\"errormessage\"><span class=\"messagetype\">$msg.get('error'): </span>$msg.get('wikimanager.wikiname.error.databasealreadyexists')</div>") #set ($MSG_ERROR_WIKINAMEALREADYUSED = "<div class=\"errormessage\"><span class=\"messagetype\">$msg.get('error'): </span>$msg.get('wikimanager.wikiname.error.alreadyused')</div>") #set ($MSG_ERROR_WIKINAMEEMPTY = "<div class=\"errormessage\"><span class=\"messagetype\">$msg.get('error'): </span>$msg.get('wikimanager.wikiname.error.empty')</div>") #set ($MSG_INFO_WIKINAMEVALID = "<div class=\"infomessage\"><span class=\"messagetype\">$msg.get('info'): </span>$msg.get('wikimanager.wikiname.info.valid')</div>") ## ############################################################################################ ## REQUEST PARAMETERS #if ($request.stepbystep) #set ($wstepbystep = $request.stepbystep) #end #if ($request.doc && $request.doc == "1") #set ($documentation = 1) #end ## #set ($wikidocument = $WikiManager.createWikiDocument()) #set ($wikidocumentobject = $wikidocument.updateObjectFromRequest("XWiki.XWikiServerClass")) ## #if ($request.actioncreate) #set ($action = "create") #else #set ($action = $request.getParameter("action")) #end ## #set ($wikiname = $request.getParameter("wikiname")) #set ($wikitemplate = $request.getParameter("wikitemplate")) #set ($wikipackage = $request.getParameter("wikipackage")) #if ($wikidocument.owner == "") $wikidocument.set("owner", $context.user) #end #if ($wikidocument.server == "" && $wikiname && $wikiname != "") $wikidocument.set("server", "${wikiname}.${DOMAINNAME}") #end ## #getRequestList($readeruserlist "readersusers") #getRequestList($readergrouplist "readersgroups") #getRequestList($writeruserlist "writersusers") #getRequestList($writergrouplist "writersgroups") #getRequestList($adminuserlist "adminsusers") #getRequestList($admingrouplist "adminsgroups") #if ($request.forcewikiname && $request.forcewikiname == 'on') #set ($failonexist = false) #else #set ($failonexist = true) #end ## ############################################################################# ## 1 $msg.get("wikimanager.createwiki") #if ($wstepbystep) [$msg.get("wikimanager.action.createwiki.nonstepbystep")>CreateNewWiki#if($documentation)?doc=1#end] #else [$msg.get("wikimanager.action.createwiki.stepbystep")>CreateNewWiki?stepbystep=0&amp;#if($documentation)doc=1#end] #end ## #if ($action && $action == "create") #set ($result = $WikiManager.createNewWiki($wikiname, $wikitemplate, $wikipackage, $wikidocument, $failonexist)) ## #if ($result == $Exception.ERROR_NOERROR) ## Init new wiki global rights #set ($currentwiki = $context.database) #set ($ok = $context.setDatabase($wikidocument.wikiName)) ## #set ($prefdoc = $xwiki.getDocument("XWiki.XWikiPreferences")) ## #set ($needsave = false) ## #addRights($prefdoc $readeruserlist $readergrouplist "view, comment" $needsave) #addRights($prefdoc $writeruserlist $writergrouplist "edit, view, comment" $needsave) #addRights($prefdoc $adminuserlist $admingrouplist "admin" $needsave) ## #if ($needsave) $prefdoc.save() #end ## #set ($ok = $context.setDatabase($currentwiki)) ## #info($msg.get("wikimanager.successcreatewiki", [$wikiname, $wikidocument.getHomePageUrl()])) #else #if ($result == $Exception.ERROR_WM_WIKIALREADYEXISTS) #error($msg.get("wikimanager.errorcreatewiki.ERROR_WM_WIKIALREADYEXISTS", [$wikiname, $result])) #else #error($msg.get("wikimanager.errorcreatewiki", [$wikiname, $context.lastexception])) #end #end #end ## ############################################################################# ## {pre} <script type="text/javascript"> // <![CDATA[ var domainnamesetted = false; var prettynamesetted = false; var lastwikiname; #if ($wstepbystep) var steps = new Array(#foreach ($wstep in $WSTEPLIST)#if ($velocityCount > 1), #end"$wstep"#end) var currentstep = $wstepbystep;

function getUsersGroupsValue(users, groups) { var str = "";

if (users.value != "" || users.value != "") { str = "<ul class=\"star\">";

if (users.value != "") str += "<li>Users: " + users.value + "<\/li>" if (groups.value != "") str += "<li>Groups: " + groups.value + "<\/li>"

str += "<\/ul>"; }

return str; }

function refreshSummary() { $("summarywikiname").innerHTML = "<p>" + $("wikiname").value + "<\/p>"; $("summarywikiprettyname").innerHTML = "<p>" + $("XWiki.XWikiServerClass_0_wikiprettyname").value + "<\/p>"; $("summarywikidesc").innerHTML = "<p>" + $("XWiki.XWikiServerClass_0_description").value + "<\/p>"; $("summarywikidomain").innerHTML = "<p>" + $("XWiki.XWikiServerClass_0_server").value + "<\/p>"; $("summarywikiadmin").innerHTML = "<p>" + $("XWiki.XWikiServerClass_0_owner").value + "<\/p>"; $("summarywikitemplate").innerHTML = "<p>" + $("wikitemplate").value + "<\/p>"; $("summarywikipackage").innerHTML = "<p>" + $("wikipackage").value + "<\/p>"; $("summaryreaders").innerHTML = getUsersGroupsValue($("readersusers"), $("readersgroups")); $("summarywriters").innerHTML = getUsersGroupsValue($("writersusers"), $("writersgroups")); $("summaryadmins").innerHTML = getUsersGroupsValue($("adminsusers"), $("adminsgroups")); }

function showStep() { for (var i = 0; i < steps.length; ++i) { if (i != currentstep) addClass($(steps[i]), "hidden"); else rmClass($(steps[i]), "hidden"); }

if (currentstep > 0) rmClass($("actionprevious"), "hidden"); else addClass($("actionprevious"), "hidden");

if (currentstep < steps.length-1) { rmClass($("actionnext"), "hidden"); addClass($("actioncreate"), "hidden"); } else { addClass($("actionnext"), "hidden"); rmClass($("actioncreate"), "hidden");

refreshSummary(); } }

function goNext() { ++currentstep; showStep(); }

function goPrevious() { --currentstep; showStep(); }

#end

function validateWikiName() { $('wikiname').value = noaccent($('wikiname').value).toLowerCase();

var wikiname = $('wikiname').value;

if (lastwikiname == wikiname) { return; }

lastwikiname = wikiname;

if (wikiname && wikiname != "") { $('wikinamevalidation').innerHTML = "$MSG_ERROR_WIKINAMEEMPTY";

var surl = "$ISWIKINAMEAVAILABLE" + "?xpage=plain&ajax=1&wikiname=" + escape(wikiname); new Ajax.Request(surl, { method: 'get', onSuccess: function(transport) { var hideForceWikiName = false;

if (transport.responseText == "true") { $('wikinamevalidation').innerHTML = "$MSG_INFO_WIKINAMEVALID"; $('actioncreatebutton').disabled = false; } else if (transport.responseText == "database") { hideForceWikiName = false;

forceWikiNameChanged(); } else if (transport.responseText == "wiki") { $('wikinamevalidation').innerHTML = "$MSG_ERROR_WIKIALREADYEXISTS"; $('actioncreatebutton').disabled = true; } else { $('wikinamevalidation').innerHTML = "$MSG_ERROR_WIKINAMEALREADYUSED"; $('actioncreatebutton').disabled = true; }

if (hideForceWikiName) { addClass($('forcewikinamediv'), "hidden"); } else { rmClass($('forcewikinamediv'), "hidden"); } } }); } else { $('wikinamevalidation').innerHTML = "$MSG_ERROR_WIKINAMEEMPTY"; $('actioncreatebutton').disabled = true; addClass($('forcewikinamediv'), "hidden"); } }

function forceWikiNameChanged() { if ($('forcewikiname').checked == true) { $('wikinamevalidation').innerHTML = "$MSG_WARNING_DATABASEALREADYEXISTS"; $('actioncreatebutton').disabled = false; } else { $('wikinamevalidation').innerHTML = "$MSG_ERROR_DATABASEALREADYEXISTS"; $('actioncreatebutton').disabled = true; } }

function wikiNameChanged() { validateWikiName();

if (domainnamesetted == false) { $("XWiki.XWikiServerClass_0_server").value = $("wikiname").value + "$ALIASSUFFIX"; }

if (prettynamesetted == false) { $("XWiki.XWikiServerClass_0_wikiprettyname").value = $("wikiname").value.substring(0,1).toUpperCase() + $("wikiname").value.substring(1); } }

function domainNameChanged() { domainnamesetted = true; }

function prettyNameChanged() { prettynamesetted = true; }

function validate() { } // ]]> </script> {/pre} <form method="get" action="" id="wikicreationform"> #if ($wstepbystep) <div id="$WSTEPNAME_INTRO"> ##1.1 $msg.get("wikimanager.title.createwiki.intro") <p>$msg.get("wikimanager.doc.createwiki.intro")</p> </div> #end ## ############################################################################# ## <div id="$WSTEPNAME_WIKINAME"> #if ($wstepbystep) 1.1 $msg.get("wikimanager.title.createwiki.wikiname") #end <table> <tr> <td> <dl> <dt>$msg.get("wikimanager.prop.wiki.wikiname")</dt> <dd> <input size="40" id="wikiname" name="wikiname" type="text" onchange="wikiNameChanged();" onkeyup="wikiNameChanged();" /> <br /> <div id="wikinamevalidation"></div> <div id="forcewikinamediv"><input id="forcewikiname" name="forcewikiname" type="checkbox" #if ($failonexist == false)checked="true"#end onchange="forceWikiNameChanged();"/>$msg.get("wikimanager.wikiname.force")</div> </dd> </dl> </td> #if ($documentation) <td>$msg.get("wikimanager.doc.createwiki.wikiname")</td> #end </tr> </table> </div> ## ############################################################################# ## <div id="$WSTEPNAME_WIKIDESC"> #if ($wstepbystep) 1.1 $msg.get("wikimanager.title.createwiki.desc") #if ($documentation) $msg.get("wikimanager.doc.createwiki.desc") #end #end <table> <tr> <td> <dl> <dt>$msg.get("wikimanager.prop.wiki.wikiprettyname")</dt> <dd><input size="40" id="XWiki.XWikiServerClass_0_wikiprettyname" name="XWiki.XWikiServerClass_0_wikiprettyname" type="text" onchange="prettyNameChanged();" /></dd> </dl> </td> #if ($documentation) <td>$msg.get("wikimanager.doc.createwiki.desc.wikiprettyname")</td> #end </tr> <tr> <td> <dl> <dt>$msg.get("wikimanager.prop.wiki.description")</dt> <dd>$wikidocument.display("description", "edit")</dd> </dl> </td> #if ($documentation) <td>$msg.get("wikimanager.doc.createwiki.desc.description")</td> #end </tr> <tr> <td> <dl> <dt>$msg.get("wikimanager.prop.wiki.server")</dt> <dd><input size="40" id="XWiki.XWikiServerClass_0_server" name="XWiki.XWikiServerClass_0_server" type="text" onchange="domainNameChanged();" /></dd> </dl> </td> #if ($documentation) <td>$msg.get("wikimanager.doc.createwiki.desc.server.creation", [$ALIASSUFFIX])</td> #end </tr> <tr> <td> <dl> <dt>$msg.get("wikimanager.prop.wiki.owner")</dt> <dd>$wikidocument.display("owner", "edit")</dd> </dl> </td> #if ($documentation) <td>$msg.get("wikimanager.doc.createwiki.desc.owner")</td> #end </tr> </table> </div> ## ############################################################################# ## <div id="$WSTEPNAME_DATAFROM"> #if ($wstepbystep) 1.1 $msg.get("wikimanager.title.createwiki.datafrom") #if ($documentation) $msg.get("wikimanager.doc.createwiki.datafrom") #end #end <table> <tr> <td> <dl> <dt><label for="wikitemplate">$msg.get("wikimanager.wikitemplate")</label></dt> <dd> #set ($listtemplate=$WikiManager.getWikiTemplateList()) <select #if($listtemplate.size() == 0)disabled="disabled"#end name="wikitemplate" id="wikitemplate"> <option value="">---</option> #foreach ($template in $listtemplate) <option value="$template.wikiName">#if($template.wikiPrettyName != "")$template.wikiPrettyName#else$template.wikiName#end</option> #end </select> </dd> </dl> </td> #if ($documentation) <td>$msg.get("wikimanager.doc.createwiki.datafrom.template")</td> #end </tr> <tr> <td> <dl> <dt><label for="wikipackage">$msg.get("wikimanager.wikipackage")</label></dt> <dd> #set ($listpackage=$doc.getAttachmentList()) <select #if($listpackage.size() == 0)disabled="disabled"#end name="wikipackage" id="wikipackage"> <option value="">---</option> #foreach ($package in $listpackage) <option value="$package.getFilename()">$package.getFilename()</option> #end </select> </dd> </dl> </td> #if ($documentation) <td>$msg.get("wikimanager.doc.createwiki.datafrom.package")</td> #end </tr> </table> </div> ## ############################################################################# ## #set ($rightsmanager = $xwiki.rightsmanager) #set ($users = $rightsmanager.usersApi.allGlobalUsersNames) #set ($groups = $rightsmanager.groupsApi.allGlobalGroupsNames) <div id="$WSTEPNAME_USERS"> #if ($wstepbystep) 1.1 $msg.get("wikimanager.title.createwiki.members") #if ($documentation) $msg.get("wikimanager.doc.createwiki.members") #end #end <table> <tr> <td> <dl> <dt><label for="readersusers">$msg.get("wikimanager.readers")</label></dt> <dd>#printUsersAndGroups($users $groups "readers" $readeruserlist $readergrouplist false)</dd> </dl> </td> #if ($documentation) <td>$msg.get("wikimanager.doc.createwiki.members.readers")</td> #end </tr> <tr> <td> <dl> <dt><label for="writersusers">$msg.get("wikimanager.writers")</label></dt> <dd>#printUsersAndGroups($users $groups "writers" $writeruserlist $writergrouplist false)</dd> </dl> </td> #if ($documentation) <td>$msg.get("wikimanager.doc.createwiki.members.writers")</td> #end </tr> <tr> <td> <dl> <dt><label for="adminsusers">$msg.get("wikimanager.admins")</label></dt> <dd>#printUsersAndGroups($users $groups "admins" $adminuserlist $admingrouplist false)</dd> </dl> </td> #if ($documentation) <td>$msg.get("wikimanager.doc.createwiki.members.administrators")</td> #end </tr> </table> </div> ## ############################################################################# ## #if ($wstepbystep) <div id="$WSTEPNAME_SUMMARY"> 1.1 $msg.get("wikimanager.title.createwiki.summary") #if ($documentation) $msg.get("wikimanager.doc.createwiki.summary") #end <table class="wiki-table" border="0" cellpadding="0" cellspacing="0"> <tbody> <tr><th>Properties</th><th>Values</th></tr> <tr class="table-odd"><td>*$msg.get("wikimanager.prop.wiki.wikiname")*</td><td id="summarywikiname">---</td></tr> <tr class="table-odd"><td>*$msg.get("wikimanager.prop.wiki.wikiprettyname")*</td><td id="summarywikiprettyname">---</td></tr> <tr class="table-odd"><td>*$msg.get("wikimanager.prop.wiki.description")*</td><td id="summarywikidesc">---</td></tr> <tr class="table-even"><td>*$msg.get("wikimanager.prop.wiki.server")*</td><td id="summarywikidomain">---</td></tr> <tr class="table-odd"><td>*$msg.get("wikimanager.prop.wiki.owner")*</td><td id="summarywikiadmin">---</td></tr> <tr class="table-odd"><td>*$msg.get("wikimanager.wikitemplate")*</td><td id="summarywikitemplate">---</td></tr> <tr class="table-odd"><td>*$msg.get("wikimanager.wikipackage")*</td><td id="summarywikipackage">---</td></tr> <tr class="table-odd"><td>*$msg.get("wikimanager.readers")*</td><td id="summaryreaders">---</td></tr> <tr class="table-odd"><td>*$msg.get("wikimanager.writers")*</td><td id="summarywriters">---</td></tr> <tr class="table-odd"><td>*$msg.get("wikimanager.admins")*</td><td id="summaryadmins">---</td></tr> </tbody> </table> </div> #end ## ############################################################################# ## <div> #if ($wstepbystep) <a href="javascript:void(0)" id="actionprevious" class="button" onclick="goPrevious();">${msg.get("wikimanager.action.previous")}</a> | <a href="javascript:void(0)" id="actionnext" class="button" onclick="goNext();">${msg.get("wikimanager.action.next")}</a> #end <div id="actioncreate"> <br /> #if ($request.stepbystep) <input type="hidden" name="stepbystep" value="$request.stepbystep" /> #end #if ($request.doc) <input type="hidden" name="doc" value="$request.doc" /> #end <input type="submit" id="actioncreatebutton" name="actioncreate" value="${msg.get("create")}" onclick="return validate();" /> </div> </div> </form> {pre} <script type="text/javascript"> // <![CDATA[ validateWikiName()

#if ($wstepbystep) showStep();

if ($("XWiki.XWikiServerClass_0_server").value != "") domainnamesetted = true;

if ($("XWiki.XWikiServerClass_0_wikiprettyname").value != "") prettynamesetted = true; #end // ]]> </script> {/pre}