WikkaModifications ---- ==== Wikka Mod 043 - Clone Page Handler ==== Type: Feature Addition Wikka version: 1.1.6.0 <<==See also:== Documentation: CloneHandlerInfo Development: CloneHandler<<::c:: ---- ===Credit=== **ChristianBarthelemy** (initial idea and code) **DarTar** (bugfixes, error messages and modifications) ---- === Description === This modification adds a page handler that allows to duplicate the current page, provided a valid new name for the target page is specified. Usage: Add ##/clone## to the end of any page URL. For example: http://wikkawiki.org/HomePage/clone handlers/page/clone.php %%(php)
tag; $to = $this->tag; $note = 'Cloned from '.$from; #i18n $editoption = ''; $box = 'Please fill in a valid target ""PageName"" and an (optional) edit note.'; #i18n // print header echo $this->Format('==== Clone current page ===='); // 1. check source page existence if (!$this->ExistsPage($from)) { // source page does not exist! $box = ' Sorry, page '.$from.' does not exist.'; #i18n } else { // 2. page exists - now check user's read-access to the source page if (!$this->HasAccess('read', $from)) { // user can't read source page! $box = ' //You are not allowed to read the source of this page.//'; #i18n } else { // page exists and user has read-access to the source - proceed if ($_POST) { // get parameters $to = ($_POST['to'])? $_POST['to'] : $to; $note = ($_POST['note'])? $_POST['note'] : $note; $editoption = (isset($_POST['editoption']))? 'checked="checked"' : ''; // 3. check target pagename validity if (!preg_match("/^[A-ZÄÖÜ]+[a-zßäöü]+[A-Z0-9ÄÖÜ][A-Za-z0-9ÄÖÜßäöü]*$/s", $to)) { // invalid pagename! $box = '""
You must specify a valid PageName
""'; #i18n } else { // 4. target page name is valid - now check user's write-access if (!$this->HasAccess('write', $to)) { $box = '""
Sorry! You don\'t have write-access to '.$to.'
""'; #i18n } else { // 5. check target page existence if ($this->ExistsPage($to)) { // page already exists! $box = '""
Sorry, the destination page already exists
""'; #i18n } else { // 6. Valid request - proceed to page cloning $thepage=$this->LoadPage($from); # load the source page if ($thepage) $pagecontent = $thepage['body']; # get its content $this->SavePage($to, $pagecontent, $note); #create target page if ($editoption == 'checked="checked"') { // quick edit $this->Redirect($this->href('edit',$to)); } else { // show confirmation message $box = '""'.$this->MiniHref('',$to).'"" was succesfully created!'; #i18n } } } } } // build form $form = $this->FormOpen('clone'); $form .= ''. ''. ''. ''. ''. ''. ''. ''. ''. ''. ''. ''. ''. '
Clone '.$this->Link($this->GetPageTag()).' to:
Edit note:
'. ' Edit after creation '. ''. '
'; $form .= $this->FormClose(); } } // display messages if (isset($box)) echo $this->Format(' --- '.$box.' --- --- '); // print form if (isset($form)) print $form; ?>
%%