Changeset 162

Show
Ignore:
Timestamp:
07/18/2006 06:10:19 AM (4 years ago)
Author:
DarTar
Message:

Adding support for Clone ACL option (Credits: BrianKoontz) #189

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/handlers/page/clone.php

    r161 r162  
    88 * name of the target page to be created, the user's read-access to the source  
    99 * page and write-access to the target page. 
    10  * If the edit option is selected, the user is redirected to the target page for 
     10 * If the "Edit after creation" option is selected, the user is redirected to the target page for 
    1111 * edition immediately after its creation. 
     12 * If the "Clone ACL" option is selected, ACL settings are copied to the target page,  
     13 * otherwise default ACL are applied to the new page. 
    1214 * 
    1315 * @package         Handlers 
    1416 * @subpackage        Page 
     17 * @version           $Id$ 
     18 * @since             Wikka 1.1.6.0 
    1519 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 
    1620 * @filesource 
    1721 * 
    18  * @author            {@link http://wikkawiki.org/ChristianBarthelemy Christian Barthelemy} - original idea and code. 
    19  * @author            {@link http://wikkawiki.org/DarTar Dario Taraborelli} - bugs fixed, code improved, removed popup alerts.   
    20  * @version           $Id$ 
    21  * @since             Wikka 1.1.6.0 
    22  *                       
     22 * @author              {@link http://wikkawiki.org/ChristianBarthelemy Christian Barthelemy} - original idea and code. 
     23 * @author              {@link http://wikkawiki.org/DarTar Dario Taraborelli} - bugs fixed, code improved, removed popup alerts. 
     24 * @author              {@link http://wikkawiki.org/BrianKoontz Brian Koontz} - clone ACL option 
     25 *  
    2326 * @input             string  $to  required: the page to be created 
    24  *                            must be a non existing page and current user must be authorized to create it 
     27 *                            must be a non-existing page and current user must have privs to create it 
    2528 *                            default is source page name                                
    2629 *  
     
    3033 * @input             boolean $editoption optional: if true, the new page will be opened for edition on creation 
    3134 *                            default is false (to allow multiple cloning of the same source) 
     35 * 
     36 * @input             boolean $cloneaclsoption optional: if true, ACLs are copied from the source page to the new page 
     37 *                            default is false 
    3238 * 
    3339 * @uses                          Wakka::ExistsPage() 
     
    5359 * i18n 
    5460 */ 
    55 define('CLONE_HEADER', '==== Clone current page ===='); 
    56 define('CLONE_SUCCESSFUL', '%s was succesfully created!'); 
    57 define('CLONE_X_TO', 'Clone %s to:'); 
    58 define('CLONED_FROM', 'Cloned from %s'); 
    59 define('EDIT_NOTE', 'Edit note:'); 
    60 define('ERROR_ACL_READ', 'You are not allowed to read the source of this page.'); 
    61 define('ERROR_ACL_WRITE', 'Sorry! You don\'t have write-access to %s'); 
    62 define('ERROR_INVALID_PAGENAME', 'This page name is invalid. Valid page names must start with a letter and contain only letters and numbers.'); 
    63 define('ERROR_PAGE_ALREADY_EXIST', 'Sorry, the destination page already exists'); 
    64 define('ERROR_PAGE_NOT_EXIST', ' Sorry, page %s does not exist.'); 
    65 define('LABEL_CLONE', 'Clone'); 
    66 define('LABEL_EDIT_OPTION', ' Edit after creation '); 
    67 define('PLEASE_FILL_VALID_TARGET', 'Please fill in a valid target ""PageName"" and an (optional) edit note.'); 
     61if (!defined('CLONE_HEADER')) define('CLONE_HEADER', '==== Clone current page ===='); 
     62if (!defined('CLONE_SUCCESSFUL')) define('CLONE_SUCCESSFUL', '%s was succesfully created!'); 
     63if (!defined('CLONE_X_TO')) define('CLONE_X_TO', 'Clone %s to:'); 
     64if (!defined('CLONED_FROM')) define('CLONED_FROM', 'Cloned from %s'); 
     65if (!defined('EDIT_NOTE')) define('EDIT_NOTE', 'Edit note:'); 
     66if (!defined('ERROR_ACL_READ')) define('ERROR_ACL_READ', 'You are not allowed to read the source of this page.'); 
     67if (!defined('ERROR_ACL_WRITE')) define('ERROR_ACL_WRITE', 'Sorry! You don\'t have write-access to %s'); 
     68if (!defined('ERROR_INVALID_PAGENAME')) define('ERROR_INVALID_PAGENAME', 'This page name is invalid. Valid page names must start with a letter and contain only letters and numbers.'); 
     69if (!defined('ERROR_PAGE_ALREADY_EXIST')) define('ERROR_PAGE_ALREADY_EXIST', 'Sorry, the destination page already exists'); 
     70if (!defined('ERROR_PAGE_NOT_EXIST')) define('ERROR_PAGE_NOT_EXIST', ' Sorry, page %s does not exist.'); 
     71if (!defined('LABEL_CLONE')) define('LABEL_CLONE', 'Clone'); 
     72if (!defined('LABEL_EDIT_OPTION')) define('LABEL_EDIT_OPTION', ' Edit after creation'); 
     73if (!defined('LABEL_ACL_OPTION')) define('LABEL_ACL_OPTION', ' Clone ACL'); 
     74if (!defined('PLEASE_FILL_VALID_TARGET')) define('PLEASE_FILL_VALID_TARGET', 'Please fill in a valid target ""PageName"" and an (optional) edit note.'); 
    6875 
    6976// initialization 
     
    7279$note = sprintf(CLONED_FROM, $from); 
    7380$editoption = '';  
     81$cloneaclsoption = ''; 
    7482$box = PLEASE_FILL_VALID_TARGET; 
    7583 
     
    100108                        $note = isset($_POST['note']) && $_POST['note'] ? $_POST['note'] : $note; 
    101109                        $editoption = (isset($_POST['editoption']))? 'checked="checked"' : ''; 
     110                        $cloneaclsoption = (isset($_POST['cloneaclsoption']))? 'checked="checked"' : ''; 
    102111                 
    103112                        // 3. check target pagename validity 
     
    122131                                        { 
    123132                                                // 6. Valid request - proceed to page cloning 
    124                                                 $thepage=$this->LoadPage($from); # load the source page 
    125                                                 if ($thepage) $pagecontent = $thepage['body']; # get its content 
    126                                                 $this->SavePage($to, $pagecontent, $note); #create target page 
     133                                                $thepage=$this->LoadPage($from); 
     134                                                if ($thepage) $pagecontent = $thepage['body']; 
     135                                                $this->SavePage($to, $pagecontent, $note); 
     136                                                // Clone ACLs if requested 
     137                                                if ($cloneaclsoption == 'checked="checked"') 
     138                                                { 
     139                                                        $acl = $this->LoadAllACLs($from, 0); 
     140                                                        $this->SaveACL($to, 'read', $this->TrimACLs($acl['read_acl'])); 
     141                                                        $this->SaveACL($to, 'write', $this->TrimACLs($acl['write_acl'])); 
     142                                                        $this->SaveACL($to, 'comment', $this->TrimACLs($acl['comment_acl'])); 
     143                                                } 
     144                                                // Open editor if requested 
    127145                                                if ($editoption == 'checked="checked"') 
    128146                                                { 
     
    153171                        '<td>'."\n". 
    154172                        '<input type="checkbox" name="editoption" '.$editoption.' id="editoption" /><label for="editoption">'.LABEL_EDIT_OPTION.'</label>'."\n". 
     173                        '<input type="checkbox" name="cloneaclsoption" '.$cloneaclsoption.' id="cloneaclsoption" /><label for="cloneaclsoption">'.LABEL_ACL_OPTION.'</label>'."\n". 
     174                        '</tr>'."\n". 
     175                        '<tr>'."\n". 
     176                        '<td></td>'."\n". 
     177                        '<td>'."\n". 
    155178                        '<input type="submit" name="create" value="'.LABEL_CLONE.'" />'."\n". 
    156179                        '</td>'."\n".