Revision history for Mod043fCloneHandler


Revision [19294]

Last edited on 2008-01-28 00:14:45 by JavaWoman [Modified links pointing to docs server]

No Differences

Revision [17221]

Edited on 2007-07-07 15:07:43 by JavaWoman [fixed example URL]
Additions:
http://wikkawiki.org/HomePage/clone
Deletions:
http://wikka.jsnx.com/HomePage/clone


Revision [17220]

Edited on 2007-07-07 15:07:21 by JavaWoman [standardized credit links]
Additions:
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://wikka.jsnx.com/HomePage/clone


handlers/page/clone.php
%%(php)
<div class="page">
<?php
/**
* Clone the current page and save a copy of it as a new page.
*
* Usage: append /clone to the URL of the page you want to clone
*
* This handler checks the existence of the source page, the validity of the
* name of the target page to be created, the user's read-access to the source
* page and write-access to the target page.
* If the edit option is selected, the user is redirected to the target page for
* edition immediately after its creation.
*
* @package Handlers
* @subpackage
* @name clone
*
* @author {@link http://wikka.jsnx.com/ChristianBarthelemy Christian Barthelemy} - original idea and code.
* @author {@link http://wikka.jsnx.com/DarTar Dario Taraborelli} - bugs fixed, code improved, removed popup alerts.
* @version 0.4
* @since Wikka 1.1.6.0
*
* @input string $to required: the page to be created
* must be a non existing page and current user must be authorized to create it
* default is source page name
*
* @input string $note optional: the note to be added to the page when created
* default is "Cloned from " followed by the name of the source page
*
* @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)
*
* @todo Use central library for valid pagenames.
*
*/

// set defaults
$from = $this->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 = '""<div class="error">You must specify a valid PageName</div>""'; #i18n
} else
{
// 4. target page name is valid - now check user's write-access
if (!$this->HasAccess('write', $to))
{
$box = '""<div class="error">Sorry! You don\'t have write-access to '.$to.'</div>""'; #i18n
} else
{
// 5. check target page existence
if ($this->ExistsPage($to))
{
// page already exists!
$box = '""<div class="error">Sorry, the destination page already exists</div>""'; #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 .= '<table class="clone">'.
'<tr>'.
'<td><strong>Clone '.$this->Link($this->GetPageTag()).' to:</strong></td>'.
'<td><input type="text" name="to" value="'.$to.'" size="37" /></td>'.
'</tr>'.
'<tr>'.
'<td><strong>Edit note:</strong></td>'.
'<td><input type="text" name="note" value="'.$note.'" size="37" /></td>'.
'</tr>'.
'<tr>'.
'<td></td>'.
'<td>'.
'<input type="checkbox" name="editoption" '.$editoption.' /> Edit after creation '.
'<input type="submit" name="create" value="Clone" />'.
'</td>'.
'</tr>'.
'</table>';
$form .= $this->FormClose();
}
}

// display messages
if (isset($box)) echo $this->Format(' --- '.$box.' --- --- ');
// print form
if (isset($form)) print $form;
?>
</div>
Deletions:
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://wikka.jsnx.com/HomePage/clone


handlers/page/clone.php
%%(php)
<div class="page">
<?php
/**
* Clone the current page and save a copy of it as a new page.
*
* Usage: append /clone to the URL of the page you want to clone
*
* This handler checks the existence of the source page, the validity of the
* name of the target page to be created, the user's read-access to the source
* page and write-access to the target page.
* If the edit option is selected, the user is redirected to the target page for
* edition immediately after its creation.
*
* @package Handlers
* @subpackage
* @name clone
*
* @author {@link http://wikka.jsnx.com/ChristianBarthelemy Christian Barthelemy} - original idea and code.
* @author {@link http://wikka.jsnx.com/DarTar Dario Taraborelli} - bugs fixed, code improved, removed popup alerts.
* @version 0.4
* @since Wikka 1.1.6.0
*
* @input string $to required: the page to be created
* must be a non existing page and current user must be authorized to create it
* default is source page name
*
* @input string $note optional: the note to be added to the page when created
* default is "Cloned from " followed by the name of the source page
*
* @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)
*
* @todo Use central library for valid pagenames.
*
*/

// set defaults
$from = $this->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 = '""<div class="error">You must specify a valid PageName</div>""'; #i18n
} else
{
// 4. target page name is valid - now check user's write-access
if (!$this->HasAccess('write', $to))
{
$box = '""<div class="error">Sorry! You don\'t have write-access to '.$to.'</div>""'; #i18n
} else
{
// 5. check target page existence
if ($this->ExistsPage($to))
{
// page already exists!
$box = '""<div class="error">Sorry, the destination page already exists</div>""'; #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 .= '<table class="clone">'.
'<tr>'.
'<td><strong>Clone '.$this->Link($this->GetPageTag()).' to:</strong></td>'.
'<td><input type="text" name="to" value="'.$to.'" size="37" /></td>'.
'</tr>'.
'<tr>'.
'<td><strong>Edit note:</strong></td>'.
'<td><input type="text" name="note" value="'.$note.'" size="37" /></td>'.
'</tr>'.
'<tr>'.
'<td></td>'.
'<td>'.
'<input type="checkbox" name="editoption" '.$editoption.' /> Edit after creation '.
'<input type="submit" name="create" value="Clone" />'.
'</td>'.
'</tr>'.
'</table>';
$form .= $this->FormClose();
}
}

// display messages
if (isset($box)) echo $this->Format(' --- '.$box.' --- --- ');
// print form
if (isset($form)) print $form;
?>
</div>


Revision [4420]

Edited on 2005-01-11 09:26:10 by DarTar [See also links]

No Differences

Revision [4419]

Edited on 2005-01-11 09:25:43 by DarTar [See also links]
Additions:
<<==See also:==
Documentation: CloneHandlerInfo
Development: CloneHandler<<::c::


Revision [4417]

Edited on 2005-01-11 09:21:51 by DarTar [Title]
Additions:
==== Wikka Mod 043 - Clone Page Handler ====
Deletions:
==== Wikka Mod 043 ====


Revision [4415]

Edited on 2005-01-11 09:19:41 by DarTar [New page]
Additions:
==== Wikka Mod 043 ====
Deletions:
==== Wikka Mod 042 ====


Revision [4414]

Edited on 2005-01-11 09:19:18 by DarTar [New page]
Additions:
WikkaModifications


Revision [4411]

Edited on 2005-01-11 09:18:30 by DarTar [New page]
Additions:
Wikka version: 1.1.6.0
- ChristianBarthelemy (initial idea and code)
- DarTar (bugfixes, error messages and modifications)
This modification adds a page handler that allows to duplicate the current page, provided a valid new name for the target page is specified.
Add ##/clone## to the end of any page URL.
http://wikka.jsnx.com/HomePage/clone
handlers/page/clone.php
%%(php)
<div class="page">
<?php
/**
* Clone the current page and save a copy of it as a new page.
*
* Usage: append /clone to the URL of the page you want to clone
*
* This handler checks the existence of the source page, the validity of the
* name of the target page to be created, the user's read-access to the source
* page and write-access to the target page.
* If the edit option is selected, the user is redirected to the target page for
* edition immediately after its creation.
*
* @package Handlers
* @subpackage
* @name clone
*
* @author {@link http://wikka.jsnx.com/ChristianBarthelemy Christian Barthelemy} - original idea and code.
* @author {@link http://wikka.jsnx.com/DarTar Dario Taraborelli} - bugs fixed, code improved, removed popup alerts.
* @version 0.4
* @since Wikka 1.1.6.0
*
* @input string $to required: the page to be created
* must be a non existing page and current user must be authorized to create it
* default is source page name
*
* @input string $note optional: the note to be added to the page when created
* default is "Cloned from " followed by the name of the source page
*
* @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)
*
* @todo Use central library for valid pagenames.
*
*/
// set defaults
$from = $this->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 = '""<div class="error">You must specify a valid PageName</div>""'; #i18n
} else
{
// 4. target page name is valid - now check user's write-access
if (!$this->HasAccess('write', $to))
{
$box = '""<div class="error">Sorry! You don\'t have write-access to '.$to.'</div>""'; #i18n
} else
{
// 5. check target page existence
if ($this->ExistsPage($to))
{
// page already exists!
$box = '""<div class="error">Sorry, the destination page already exists</div>""'; #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 .= '<table class="clone">'.
'<tr>'.
'<td><strong>Clone '.$this->Link($this->GetPageTag()).' to:</strong></td>'.
'<td><input type="text" name="to" value="'.$to.'" size="37" /></td>'.
'</tr>'.
'<tr>'.
'<td><strong>Edit note:</strong></td>'.
'<td><input type="text" name="note" value="'.$note.'" size="37" /></td>'.
'</tr>'.
'<tr>'.
'<td></td>'.
'<td>'.
'<input type="checkbox" name="editoption" '.$editoption.' /> Edit after creation '.
'<input type="submit" name="create" value="Clone" />'.
'</td>'.
'</tr>'.
'</table>';
$form .= $this->FormClose();
}
// display messages
if (isset($box)) echo $this->Format(' --- '.$box.' --- --- ');
// print form
if (isset($form)) print $form;
</div>
Deletions:
- The author of WakkaWiki handlers/page/raw.php (assuming Hendrik Mans)
- JsnX (slimmed it down, and added passing the output through nl2br and htmlspecialchars)
- GmBowen, for prompting the development
This modification adds a page handler that shows the raw code of a page, formatted somewhat for viewing.
Add /showcode to the end of any page URL.
http://wikka.jsnx.com/HomePage/showcode
handlers/page/showcode.php
%%(php) <?php
if ($this->HasAccess("read") && $this->page) {
// display raw page, slightly formatted for viewing
print(nl2br(htmlspecialchars($this->page["body"], ENT_QUOTES)));


Revision [4410]

The oldest known version of this page was created on 2005-01-11 09:12:38 by DarTar [New page]
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki