Clone ACLs

Currently in trunk: Will be included in 1.1.7
Working for 1.1.6.0 to 1.1.6.4. See comments for possible bug.
 


A patch you can apply to handlers/page/clone.php that will optionally copy the ACLs from the source page to the new page while cloning a page.

A note about patches
The patch utility is included in most *nix systems and allows all changes to files to be packaged into one convenient
'patch file' for distribution. I've found that in the process of transferring files with embedded tabs from the development machine to the wiki environment, the tabs are lost when using copy-and-paste. Consequently, the patch command will sometimes fail, since the tabs have been munged up. I've found that patch -p0 -l < some.patch (note the "dash el" option -- not "dash one") seems to handle munged-up whitespace quite nicely.

 


Clone ACLs Patch (1.1.6.1)

--- clone.php   2006/03/11 05:26:01 1.1
+++ clone.php   2006/03/11 06:03:04
@@ -29,6 +29,8 @@
  *
  * @input             boolean $editoption optional: if true, the new page will be opened for edition on creation
  *                            default is false (to allow multiple cloning of the same source)
+ * @input             boolean $cloneaclsoption optional: if true, ACLs will be copied from the source page to the new page
+ *                            default is false
  *
  * @todo              Use central library for valid pagenames.
  *        
@@ -39,6 +41,7 @@
 $to = $this->tag;
 $note = 'Cloned from '.$from; #i18n
$editoption = '';
+$cloneaclsoption = '';
 $box = 'Please fill in a valid target ""PageName"" and an (optional) edit note.'; #i18n

 // print header
@@ -65,6 +68,8 @@
            $to = ($_POST['to'])? $_POST['to'] : $to;
            $note = ($_POST['note'])? $_POST['note'] : $note;
            $editoption = (isset($_POST['editoption']))? 'checked="checked"' : '';
+           $cloneaclsoption = (isset($_POST['cloneaclsoption']))? 'checked="checked"' : '';
+
       
            // 3. check target pagename validity
            if (!preg_match("/^[A-Z&#402;÷&#8249;]+[a-z&#64258;&#8240;&#710;¸]+[A-Z0-9&#402;÷&#8249;][A-Za-z0-9&#402;÷&#8249;&#64258;&#8240;&#710;¸]*$/s", $to))
@@ -90,6 +95,17 @@
                        $thepage=$this->LoadPage($from); # load the source page
                        if ($thepage) $pagecontent = $thepage['body']; # get its content
                        $this->SavePage($to, $pagecontent, $note); #create target page
+                        // Clone ACLs if requested
+                        if($cloneaclsoption == 'checked="checked"')
+                        {
+                            $read_acl = $this->LoadACL($from, "read", 0);
+                            $write_acl = $this->LoadACL($from, "write", 0);
+                            $comment_acl = $this->LoadACL($from, "comment", 0);
+                            $this->SaveACL($to, "read", $this->TrimACLs($read_acl["read_acl"]));
+                            $this->SaveACL($to, "write", $this->TrimACLs($write_acl["write_acl"]));
+                            $this->SaveACL($to, "comment", $this->TrimACLs($comment_acl["comment_acl"]));
+                        }
+                        // Open editor if requested
                        if ($editoption == 'checked="checked"')
                        {
                            // quick edit
@@ -118,6 +134,11 @@
            '<td></td>'.
            '<td>'.
            '<input type="checkbox" name="editoption" '.$editoption.' /> Edit after creation '.
+            '<input type="checkbox" name="cloneaclsoption" '.$cloneaclsoption.' /> Clone ACLs '.
+            '</tr>'.
+            '<tr>'.
+            '<td></td>'.
+            '<td>'.
            '<input type="submit" name="create" value="Clone" />'.
            '</td>'.
            '</tr>'.


Clone ACLs Patch (1.1.6.2)

--- clone.php.orig  Tue Aug 22 18:05:01 2006
+++ clone.php   Tue Aug 22 18:07:58 2006
@@ -29,6 +29,8 @@
  *
  * @input             boolean $editoption optional: if true, the new page will be opened for edition on creation
  *                            default is false (to allow multiple cloning of the same source)
+ * @input             boolean $cloneaclsoption optional: if true, ACLs will be copied from the source page to the new page
+ *                            default is false
  *
  * @todo              Use central library for valid pagenames.
  *
@@ -56,6 +58,7 @@
 $to = $this->tag;
 $note = sprintf(CLONED_FROM, $from);
 $editoption = '';
+$cloneaclsoption = '';
 $box = PLEASE_FILL_VALID_TARGET;

 // print header
@@ -82,7 +85,9 @@
            $to = isset($_POST['to']) && $_POST['to'] ? $_POST['to'] : $to;
            $note = isset($_POST['note']) && $_POST['note'] ? $_POST['note'] : $note;
            $editoption = (isset($_POST['editoption']))? 'checked="checked"' : '';
+           $cloneaclsoption = (isset($_POST['cloneaclsoption']))? 'checked="checked"' : '';

+      
            // 3. check target pagename validity
            if (!preg_match(VALID_PAGENAME_PATTERN, $to))  //TODO use central regex library
            {
@@ -107,6 +112,17 @@
                        $thepage=$this->LoadPage($from); # load the source page
                        if ($thepage) $pagecontent = $thepage['body']; # get its content
                        $this->SavePage($to, $pagecontent, $note); #create target page
+                        // Clone ACLs if requested
+                        if($cloneaclsoption == 'checked="checked"')
+                        {
+                            $read_acl = $this->LoadACL($from, "read", 0);
+                            $write_acl = $this->LoadACL($from, "write", 0);
+                            $comment_acl = $this->LoadACL($from, "comment", 0);
+                            $this->SaveACL($to, "read", $this->TrimACLs($read_acl["read_acl"]));
+                            $this->SaveACL($to, "write", $this->TrimACLs($write_acl["write_acl"]));
+                            $this->SaveACL($to, "comment", $this->TrimACLs($comment_acl["comment_acl"]));
+                        }
+                        // Open editor if requested
                        if ($editoption == 'checked="checked"')
                        {
                            // quick edit
@@ -135,6 +151,12 @@
            '<td></td>'."\n".
            '<td>'."\n".
            '<input type="checkbox" name="editoption" '.$editoption.' id="editoption" /><label for="editoption">'.LABEL_EDIT_OPTION.'</label>'."\n".
+            '<input type="checkbox" name="cloneaclsoption" '.$cloneaclsoption.' /> Clone ACLs '.
+            '</tr>'.
+            '<tr>'.
+            '<td></td>'.
+            '<td>'.
+
            '<input type="submit" name="create" value="'.LABEL_CLONE.'" />'."\n".
            '</td>'."\n".
            '</tr>'."\n".



Categories
CategoryUserContributions
Comments
Comment by DarTar
2006-05-26 04:54:12
nice hack, brian - why don't you post a ticket and upload the patch at http://tracker.wikkawiki.org ?
Comment by BrianKoontz
2006-05-27 02:57:44
Done!
Comment by WazoO
2006-05-27 20:29:34
The other issue with he 'patch' utility is that the file being modified has to be reasonably close to the one you make the 'diff' file from .... In the case of this application, time has gone on since the last release ... you modified your files, Joe modified his differently, I went in a whole 'nother direction ... increasing the 'fuzzify' value only gets one so far at times ...
Comment by AndreasHeintze
2007-01-05 04:04:26
Oh I did the same and posted it on the CloneHandler page, didn't see this until now.
Comment by AndreasHeintze
2007-01-05 04:09:07
I'll concentrate on making clone copy uploaded files too then... =)
Comment by DarTar
2007-01-10 06:28:42
Andreas, this is already included in the dev code to be released with 1.1.7
Please make sure you check out the latest SVN version if you want to suggest any improvement on top of the existing code.
Comment by AndreasHeintze
2007-01-10 09:54:03
Great! I'll look a little closer at SVN next time. Thanks!
Comment by MasinAlDujaili
2008-06-04 04:50:35
Possible bug: If a page without any ACLs is cloned with 'Clone ACLs' checked, it gets empty entries in the _acls table. A page having no entries should default to the ACLs in the config, a page with empty entries is exactly this: a page without any restrictions.

BTW: There's seemingly no way of resetting ACLs to the default values beside deleting the appropriate row in _acls in the database. Maybe the acls.php handler should be extended by a 'Reset to default ACLs' button, deleting the ACLs entry in the database. As I've found no way at the moment to do this, I report this to you. ... maybe I should take a look at delete.php -- deletion of ACLs should be in there.
Comment by NilsLindenberg
2008-06-04 05:34:43
Masin:
resetting acls: http://wush.net/trac/wikka/ticket/211 milestone set for 1.1.7.1 at the moment
Comment by NilsLindenberg
2008-06-04 05:37:21
As for "empty acls": I don't know if this could be considered as a bug in the clone handler, since it does exactly what you would expect: it clones the ACLs. If empty ACLs are allowed, this is a bug of the ACL handler (note to self: test).
Comment by NilsLindenberg
2008-06-04 05:52:06
empty acls: #771
Comment by MasinAlDujaili
2008-06-04 06:14:38
Thanks for the information. The clone handler should act accordingly, nonetheless. As should my InheritACL extension which does otherwise at the moment: Not storing ACLs, if they equal the default, but should check if ACLs exist and clone them, even if they equal the default.

Most simple solution would be to allow the entry 'default' in the ACL boxes, meaning to not store any ACLs, not even empty one. This could also be used to show that the current page uses the default values which is missing currently. Or a checkbox labelled 'Default value' for each ACL box. Might be more elegant and not restricting having a group or user called 'default' (whyever). The default values should be displayed somewhere, maybe beneath the ACL box together with the checkbox.
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki