Comparing revisions for CloneHandler

Additions:
This relies of the ExistsPage function developed by JavaWoman and part of release 1.1.6.0. You can find this version at WikkaDevelopment.
$box = '""<div class="error">Sorry! The destination page already exists</div>""'; #i18n
Deletions:
This relies on the ""ExistsPage()"" function developed by JavaWoman and part of release 1.1.6.0. You can find this version at WikkaDevelopment.
$box = '""<div class="error">Sorry! The destination page already exists</div>""'; #i18n
I've added the feature of letting the user clone the ACLs in this version:
(I also fixed what I thought was a bug, it's now possible to have a blank note for the cloned page.)
Comments are welcome.
/AndreasHeintze
* @author {@link http://wikkawiki.org/ChristianBarthelemy Christian Barthelemy} - original idea and code.
* @author {@link http://wikkawiki.org/DarTar Dario Taraborelli} - bugs fixed, code improved, removed popup alerts.
* @since Wikka 1.1.6.0
// defaults
if(!defined('VALID_PAGENAME_PATTERN')) define ('VALID_PAGENAME_PATTERN', '/^[A-Za-zÄÖÜßäöü]+[A-Za-z0-9ÄÖÜßäöü]*$/s');
// i18n
define('CLONE_HEADER', '==== Clone current page ====');
define('CLONE_SUCCESSFUL', '%s was succesfully created!');
define('CLONE_X_TO', 'Clone %s to:');
define('CLONED_FROM', 'Cloned from %s');
define('EDIT_NOTE', 'Edit note:');
define('ERROR_ACL_READ', 'You are not allowed to read the source of this page.');
define('ERROR_ACL_WRITE', 'Sorry! You don\'t have write-access to %s');
define('ERROR_INVALID_PAGENAME', 'This page name is invalid. Valid page names must start with a letter and contain only letters and numbers.');
define('ERROR_PAGE_ALREADY_EXIST', 'Sorry, the destination page already exists');
define('ERROR_PAGE_NOT_EXIST', ' Sorry, page %s does not exist.');
define('LABEL_CLONE', 'Clone');
define('LABEL_EDIT_OPTION', ' Edit after creation ');
define('LABEL_CLONEACLS_OPTION', ' Clone ACLs ');
define('PLEASE_FILL_VALID_TARGET', 'Please fill in a valid target ""PageName"" and an (optional) edit note.');
// initialization
$note = sprintf(CLONED_FROM, $from);
$cloneacls = '';
$box = PLEASE_FILL_VALID_TARGET;
echo $this->Format(CLONE_HEADER);
$box = sprintf(ERROR_PAGE_NOT_EXIST, $from);
$box = ERROR_ACL_READ;
if (isset($_POST) && $_POST)
$to = isset($_POST['to']) && $_POST['to'] ? $_POST['to'] : $to;
$note = isset($_POST['note']) ? $_POST['note'] : $note;
$cloneacls = (isset($_POST['cloneacls']))? 'checked="checked"' : '';
if (!preg_match(VALID_PAGENAME_PATTERN, $to)) //TODO use central regex library
$box = '""<em class="error">'.ERROR_INVALID_PAGENAME.'</em>""';
$box = '""<em class="error">'.sprintf(ERROR_ACL_WRITE, $to).'</em>""';
$box = '""<em class="error">'.ERROR_PAGE_ALREADY_EXIST.'</em>""';
if ($cloneacls == 'checked="checked"')
// Clone ACLs too
$acls = $this->LoadAllACLs($from);
$this->SaveACL($to, 'read', $acls['read_acl']);
$this->SaveACL($to, 'write', $acls['write_acl']);
$this->SaveACL($to, 'comment', $acls['comment_acl']);
$this->Redirect($this->href('edit', $to));
$box = '""<em class="success">'.sprintf(CLONE_SUCCESSFUL, $to).'</em>""';
$form .= '<table class="clone">'."\n".
'<tr>'."\n".
'<td>'.sprintf(CLONE_X_TO, $this->Link($this->GetPageTag())).'</td>'."\n".
'<td><input type="text" name="to" value="'.$to.'" size="37" maxlength="75" /></td>'."\n".
'</tr>'."\n".
'<tr>'."\n".
'<td>'.EDIT_NOTE.'</strong></td>'.
'<td><input type="text" name="note" value="'.$note.'" size="37" maxlength="75" /></td>'."\n".
'</tr>'."\n".
'<tr>'."\n".
'<td></td>'."\n".
'<td>'."\n".
'<input type="checkbox" name="editoption" '.$editoption.' id="editoption" /><label for="editoption">'.LABEL_EDIT_OPTION.'</label><br />'."\n".
'<input type="checkbox" name="cloneacls" '.$cloneacls.' id="cloneacls" checked /><label for="cloneacls">'.LABEL_CLONEACLS_OPTION.'</label><br /><br />'."\n".
'<input type="submit" name="create" value="'.LABEL_CLONE.'" />'."\n".
'</td>'."\n".
'</tr>'."\n".
'</table>'."\n";
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki