Revision history for WikiTemplate


Revision [22941]

Last edited on 2016-05-20 07:38:42 by JavaWoman [Replaces old-style internal links with new pipe-split links.]
Additions:
echo "[[ | ".$to." has been created from ".$from." and note was: ".$note." ]]"; // confirms what has been done
~~~~2. Wikka for studies - maybe this helps? [[http://shirky.com/writings/group_user.html | Group as User: Flaming and the Design of Social Software]] - by Clay Shirky; I guess you're doing a field study? ;-) --JavaWoman''
~~~-Pointing to the 'clone' handler for the current page can then be easily done by adding a footer link, much as the current "Edit page". I'm more and more convinced that these kinds of operations on pages (which are coherent with the definition of a [[Docs:HandlerInfo | handler]]) should one day be all added in the footer menu: different footer links pointing to different handlers will then allow the user to //edit the current page//, //show source of current page//, //modify the ACLs for the current page//, //display the referrers of the current page//, //**clone the current page**//, //delete the current page//, //send the current page by email//, //create a PDF of the current page// etc.
Deletions:
echo "[[ ".$to." has been created from ".$from." and note was: ".$note." ]]"; // confirms what has been done
~~~~2. Wikka for studies - maybe this helps? [[http://shirky.com/writings/group_user.html Group as User: Flaming and the Design of Social Software]] - by Clay Shirky; I guess you're doing a field study? ;-) --JavaWoman''
~~~-Pointing to the 'clone' handler for the current page can then be easily done by adding a footer link, much as the current "Edit page". I'm more and more convinced that these kinds of operations on pages (which are coherent with the definition of a [[Docs:HandlerInfo handler]]) should one day be all added in the footer menu: different footer links pointing to different handlers will then allow the user to //edit the current page//, //show source of current page//, //modify the ACLs for the current page//, //display the referrers of the current page//, //**clone the current page**//, //delete the current page//, //send the current page by email//, //create a PDF of the current page// etc.


Revision [18285]

Edited on 2008-01-28 00:10:57 by JavaWoman [Modified links pointing to docs server]
Additions:
~~~-Pointing to the 'clone' handler for the current page can then be easily done by adding a footer link, much as the current "Edit page". I'm more and more convinced that these kinds of operations on pages (which are coherent with the definition of a [[Docs:HandlerInfo handler]]) should one day be all added in the footer menu: different footer links pointing to different handlers will then allow the user to //edit the current page//, //show source of current page//, //modify the ACLs for the current page//, //display the referrers of the current page//, //**clone the current page**//, //delete the current page//, //send the current page by email//, //create a PDF of the current page// etc.
Deletions:
~~~-Pointing to the 'clone' handler for the current page can then be easily done by adding a footer link, much as the current "Edit page". I'm more and more convinced that these kinds of operations on pages (which are coherent with the definition of a [[HandlerInfo handler]]) should one day be all added in the footer menu: different footer links pointing to different handlers will then allow the user to //edit the current page//, //show source of current page//, //modify the ACLs for the current page//, //display the referrers of the current page//, //**clone the current page**//, //delete the current page//, //send the current page by email//, //create a PDF of the current page// etc.


Revision [5856]

Edited on 2005-02-10 06:22:24 by JavaWoman [ref. to CloneHandlerInfo]
Additions:
=====Templates=====
//This **idea** is now implemented (as a handler, not as an action) as of version 1.1.6.0; see CloneHandlerInfo.//
{{lastedit}}

I like to re-use and hate to redesign the wheel... Surely I'm not alone ;-)

===My solution===
I would like to build an action ""{{template from="OldPage" to="NewPage" editoption="true"}}"" that would duplicate the template page to a new page .
It would first check the existence of the template page, the non existence of the page to be created, the user right to read the template and the user right to create a page.
The editoption when true will create the new page and then open it for edition.

===The code===
Copy this code into an action named: template.php - place it in the actions folder.
%%(php)
<?php
/**
* Duplicate a "template" page to a new named page
*
* Usage: {{template from="OldPage" to="NewPage" editoption="true"}}
*
* This action checks the existence of the template page, the non existence of the page to be created, the user
* right to read the template and the user right to create a page.
* The editoption when true will create the new page and then open it for edition.
*
*
* @package Actions
* @subpackage
* @name template
*
* @author {@link http://wikka.jsnx.com/ChristianBarthelemy Christian Barthelemy}
* @version 0.2
* @since Wikka 1.1.5.3
*
* @input string $from optional: the template page to be duplicated
* must be an existing page and must be authorized for reading to the current user
* defaulted to the current WikiPage
*
* @input string $to mandatory: the page to be created
* must be a non existing page and current user must be authorized to create
*
* @input string $note optional: the note to be added to the page when created
* default is "Templated from " followed by the name of the template page
*
* @input boolean $editoption optional: if true, the newly created page will be opened for edition
* default is false
*/

// ***** CONSTANTS *****
define ('USER_NAME',$this->GetUserName());
define ('BASE_URL',$this->config['base_url']);
// ***** END CONSTANTS *****

// ***** INPUT FORM *****

echo $this->FormOpen();
?>
<table class="template" border="1">
<tr>
<th align="left">WikiPage to be templated (empty means this page):</th>
<td><input type="text" name="from" size="37" value="<?php echo $from ?>" /></td>
</tr>
<tr>
<th align="left">WikiPage to be created:</th>
<td><input type="text" name="to" size="37" value="<?php echo $to ?>" /></td>
</tr>
<tr>
<th align="left">Added note to your edit:</th>
<td><input type="text" name="note" size="37" value="<?php echo $note ?>" /></td>
</tr>
<tr>
<th align="left">Do you want to edit the new page when created?</th>
<td>
<table border="1">
<tr>
<td><input type="checkbox" name="editoption" value="Y" <?php echo $editoption == "true" ? "checked=\"checked\"" : "" ?> />Edit after creation</td>
<td><input type="submit" name="create" value="Template it now"></td>
</tr>
</table>
</td>
</tr>
</table>
<?php
echo $this->FormClose();
// ***** END INPUT FORM *****

// ***** GET PARAMETERS *****
$from = $_POST["from"];
$to = $_POST["to"];
$note = $_POST["note"];
$editoption = $_POST["editoption"];
// ***** END PARAMETERS *****

// ***** TEMPLATING PROCESS *****
If ($to<>"") {
// The user must provide a WikiPage name to be created...
if ($this->ExistsPage($to))
{
// and it should be a new one...
$errormessage = "The destination page must not exist.";
echo $errormessage;
return;
}
// also the user has to be allowed to create this page...
elseif ($this->HasAccess("write", $to)) {
// The user should provide a WikiPage name to be duplicated...
if (!$from)
{
// by default the system will duplicate the current page...
$from = $this->GetPageTag();
}
else
{
// otherwise, the page to be dublicated must of course exit...
if ($this->ExistsPage($from))
{
// and the user has to be allowed to read it...
if (!$this->HasAccess("read", $from))
{
$errormessage = "You are not authorized to use the template page.";
echo $errormessage;
return;
}
}
else
{
// this is what happens if the user tries to duplicate a non existing page...
$errormessage = "The template page does not exist.";
echo $errormessage;
return;
}
}
// the user may provide a creation note otherwise...
if (!$note)
{
// the system will create one by default...
$note = "Templated from ".$from;
}

// ***** DERIVED VARIABLES *****
$thepage=$this->LoadPage($from); // load the page that has to be duplicated...
if ($thepage) $pagecontent = $thepage["body"]; // and get its content.
// ***** END DERIVED VARIABLES *****

// ***** OUTPUT SECTION *****
$this->SavePage($to, $pagecontent, $note); // creates the page...
echo "[[ ".$to." has been created from ".$from." and note was: ".$note." ]]"; // confirms what has been done
if ($editoption) $this->redirect(BASE_URL.$to."/edit"); // drops the user to the new page for edition if he choosed so
// ***** END OUTPUT SECTION *****

} else
{
// this is what happens if you try to create a page when you are not authorized.
$errormessage = "You are not authorized to create the destination page.";
echo $errormessage;
return;
}
}
// ***** END TEMPLATING PROCESS *****
?>
%%

===How to use it?===
Once you have (re)designed a page that fits to be replicated many times (Task Lists, User Pages, Bug Description, Developement Description...) you just have to use the ""{{template}}"" action from any page: you may want to have a dedicated TemplatePage with the action and the instructions on it (I will propose one if this action can be installed on the Wikka server).
Then you must fill the name of the new WikiPage to be created, if you do not fill the name of the page that has to be duplicated the system will duplicate the current page, you may want to add a note, finally you decide if you just want to create the page or if you want to jump and edit it as soon as it has been copied.

===To Do===
My code needs probably to be reviewed by expert coder as I am not at all a developper.
Any ideas around this action more than welcome.

==Solved error & minor code changes==
''I get the following error (just copied the code to template.php and tried the syntax you gave):

Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /.../actions/template.php on line 2

Parse error: parse error, unexpected T_STRING in /.../actions/template.php on line 2"
--NilsLindenberg''

''Nils, I don't have a clue how you can get that error; did you grab the code from the page source? --JavaWoman.''
''Yepp, I always copy from the source. --NilsLindenberg''
~Do you still have the same error with the new code? --ChristianBarthelemy
~~~''I have to try later, they don't trust me that much in the university, to allow ftp access to pages. And I haven't worked out how I should explain wikka as an essentail part of my studies ;-). I'll check later. --NilsLindenberg''
~~~~''1. Are you **entering** something in the form or as an action attribute that contains a ""\""? There's not even a ""\"" in the code that I can see. If so, try ""/"" as a path separator instead.
~~~~2. Wikka for studies - maybe this helps? [[http://shirky.com/writings/group_user.html Group as User: Flaming and the Design of Social Software]] - by Clay Shirky; I guess you're doing a field study? ;-) --JavaWoman''
~~~''Ok, I tried the new code, but it hasn't changed anything. I tried simple opage names like NewPage, ""NewerPage"" etc. even adding ""{{template}}"" gives that error. --NilsLindenberg''
~~~~Which Wikka version are you using? I do not see any reason for such an error. I replaced the template.php version from my server with a copy from this page to a new txt notepad file, renamed into template.php placed it in the action folder and it worked.

Update: Ok, I finally found out what I made wrong. My mistake: the txt files on this pc are connected with wordpad, not with notepad. I hadn't looked after that and so saved the files with useless renderings *bangs head against wall*. But after that, I found some points in your script:
1) There was an ?> missing at the end
1) The length for a page can be 75 chars, ++I changed your value to that++ just keep that in mind, cuase it means scrolling now for names >37
1) if you have much output, more simple than putting out all with echo is to leave php. I replaced the input form above. You now get the variables shown in the fields.
--NilsLindenberg
2ndUpdate: works fine, thanx. --NilsLindenberg

Any one else tried it? --ChristianBarthelemy
~''I've been tweaking the code a bit but haven't actually tested anything yet; I'm afraid I have a few more urgent things on my list right now (such as finishing WikkaGeSHiIntegration with install/update). I **will** get back to this though, promise, since I think it's very useful! --JavaWoman''

~''I like the idea too. A couple of general remarks'' --''DarTar''

==Difference action/handler==
''Should this really be an //action//? Why not a handler?'' --''DarTar''

~This action (usefully) accepts a number of parameters, either predefined in the action or via the form; as far as I can tell you can not easily do that with a handler: URL parameters are possible but are much harder to handle for an end user (requiring knowledge of how to build a query via a URL). Also, such a handler would either have to operate on the source page or on the target page while an action like this can be embedded in any page. User input really is required: an action with a form is more flexible and more user-frienldy. --JavaWoman

~I thought about this when I first defined what I expected, and concluded that an action was more appropriate for the reasons explained by JavaWoman. --ChristianBarthelemy

~~''To me 'cloning a page' is really something that should be taken care of by a handler. Here's why:
~~~-I don't see the difficulty of creating handlers containing forms. See for instance the /acls handler: you can have user-input and URL parameters (both GET and POST) easily dealt with a handler.
~~~-Moreover, the reason why I see this functionality better implemented as a handler than as an action is that it really looks like an operation that users are likely to perform on //any page//. Instead of: 1) opening the page, 2) adding an action, 3) save the page, and start cloning the page, you just need to point to the 'clone' handler for this page. The clone handler will then print a form asking you the name of the target page (the source being by default the current page - as the default selected item of a form menu).
~~~-Pointing to the 'clone' handler for the current page can then be easily done by adding a footer link, much as the current "Edit page". I'm more and more convinced that these kinds of operations on pages (which are coherent with the definition of a [[HandlerInfo handler]]) should one day be all added in the footer menu: different footer links pointing to different handlers will then allow the user to //edit the current page//, //show source of current page//, //modify the ACLs for the current page//, //display the referrers of the current page//, //**clone the current page**//, //delete the current page//, //send the current page by email//, //create a PDF of the current page// etc.
~~~-As a general rule, what handlers are displayed in the footer menu should be a configurable option (either system-wide or a user preference).
~~Doesn't this sound more reasonable than using an action? -- DarTar''

~~~Got your point and the logic behind. I do not know enough about the handlers and did not realized that you can use forms within. I am far from being a coder, anyway I will try to figure out how to make it a handler. I think that an expert advice explaining when to use handler or action would be nice to be found at ActionOrHandler--ChristianBarthelemy

~~~~''Christian, take a look at HandlerInfo to see the distinction between actions and handlers. Actions are meant in general to 'produce automatically generated content //within// a page'. Handlers perform operations on a page as a whole -- DarTar''.

~~~~~''I knew about the general distinction between actions and (page) handlers, but like Christian I hadn't realised that a handler can display a form, too. I thought of action because a form is obvously needed, and that would need to be displayed "on" a page. Given that a handler can display a form to request parameter input, I agree this would be better implemented as a handler.---[Note to self: learn more about handlers!] --JavaWoman''

~~~~~My distinction between handler and action is the following:an action can be included in a page. It adds code, it is a plugin. A handler is not put on a page, nor does it add code to it, but it does something with the page. --NilsLindenberg

==Dropdown-list with page-names==
''What about adding a menu to allow the user to choose the source page from one of the existing pages? This might avoid checking for page existence'' --''DarTar''

~Sounds nice but would be workable only in a small Wiki. OTH, if you limit the action to special-purpose Template pages this could be workable; or one could have an extra option to choose a template **or** any page with a dropdown only for templates and a text field for any other page. --JavaWoman

~~''Is there any problem with long drop-down menus? In any case the source won't be longer than the source of PageIndex. I find interesting on the other hand the idea of having some preferred pages listed at the top of the menu (maybe just checking a Category will do the job)-- DarTar''

~"Another idea would be to predefine the pages that may be duplicated by tagging them somehow. The system would then only provide in a dropdown list such pages. --ChristianBarthelemy"



==better name then template?==
''I think that the concept of **template** is associated in general to something quite different from what you are proposing here. What about using a name suggesting page //exporting//,//duplicating// or //cloning//?'' --''DarTar''

~First, it would be possible to create a number of (read-only) templates (e.g., a Doumentation template). In general, though //clone// (but not //export//) might be a better term if you (can) use the action to copy any page and not just special-purpose template. --JavaWoman

~"I agree, the name of template only fits my personnal purpose and "clone" is a more appropriate naming for this action. Hence a new page: CloneAction. --ChristianBarthelemy"


==Development==
''(After code change) Christian, OK, I see the intention now. And I like it a lot! Unfortunately, the code isn't quite correct - mind if I take a stab at clearing it up? --JavaWoman''

You of course have my blessing - This code surely needs some revamping and I will be more than happy that we get something cleaner --ChristianBarthelemy

==Contribution==
I dont know if this is proper , (putting up ChristianBarthelemy 's code with my edits but here it is ...
this is has a drop-down menu to select the page you want to copy ...
( also removed the amazing documentation/comments so that it wont be heavy in the eye when posting on this page.
Edit/Remove at will
// code removed I stayed behind and didnt look at the development train ...//
~''Well, do add a bit to show what your idea for the dropdown was... --JavaWoman''
%%(php)$res = $this->LoadAll("select tag from ".$this->config['table_prefix']."pages where latest='Y'");

foreach($res as $i => $arr){
if (!($arr['tag'] == $this->GetPageTag()))
$select_input .= '<option value="'.$arr['tag'].'">'.$arr['tag'].'</option>\n\t';
}

$select_input = $this->ReturnSafeHTML(
"<select name=\"from\">".
"\n\t<option value=\"".$this->GetPageTag()."\">".$this->GetPageTag()."</option>".
"\t\n$select_input</select>"
);
%% This is the way I created the dropdown formfield ... maybe it will be usefull at some point .. --GeorgePetsagourakis

Pardon me if this is not a proper way to do things.. I am a bit new in here --GeorgePetsagourakis
~"This is a wiki so it has to be a collaborative environment, as I pointed out, my original code surely needs to be improved. --ChristianBarthelemy."

''George, nothing in principle against including alternative code - but your code seems to be based on Christian's original code which was already much improved (by Nils) as can be seen earlier on this page. Consequently your code has the same problems Christian's original had. Why not just show how the code above could be changed with your extension? (And note my remark above: "Sounds nice but would be workable only in a small Wiki.") --JavaWoman''

----
Deletions:
====Templates====
{{lastedit}}

I like to re-use and hate to redesign the wheel... Surely I'm not alone ;-)

===My solution===
I would like to build an action ""{{template from="OldPage" to="NewPage" editoption="true"}}"" that would duplicate the template page to a new page .
It would first check the existence of the template page, the non existence of the page to be created, the user right to read the template and the user right to create a page.
The editoption when true will create the new page and then open it for edition.

===The code===
Copy this code into an action named: template.php - place it in the actions folder.
%%(php)
<?php
/**
* Duplicate a "template" page to a new named page
*
* Usage: {{template from="OldPage" to="NewPage" editoption="true"}}
*
* This action checks the existence of the template page, the non existence of the page to be created, the user
* right to read the template and the user right to create a page.
* The editoption when true will create the new page and then open it for edition.
*
*
* @package Actions
* @subpackage
* @name template
*
* @author {@link http://wikka.jsnx.com/ChristianBarthelemy Christian Barthelemy}
* @version 0.2
* @since Wikka 1.1.5.3
*
* @input string $from optional: the template page to be duplicated
* must be an existing page and must be authorized for reading to the current user
* defaulted to the current WikiPage
*
* @input string $to mandatory: the page to be created
* must be a non existing page and current user must be authorized to create
*
* @input string $note optional: the note to be added to the page when created
* default is "Templated from " followed by the name of the template page
*
* @input boolean $editoption optional: if true, the newly created page will be opened for edition
* default is false
*/

// ***** CONSTANTS *****
define ('USER_NAME',$this->GetUserName());
define ('BASE_URL',$this->config['base_url']);
// ***** END CONSTANTS *****

// ***** INPUT FORM *****

echo $this->FormOpen();
?>
<table class="template" border="1">
<tr>
<th align="left">WikiPage to be templated (empty means this page):</th>
<td><input type="text" name="from" size="37" value="<?php echo $from ?>" /></td>
</tr>
<tr>
<th align="left">WikiPage to be created:</th>
<td><input type="text" name="to" size="37" value="<?php echo $to ?>" /></td>
</tr>
<tr>
<th align="left">Added note to your edit:</th>
<td><input type="text" name="note" size="37" value="<?php echo $note ?>" /></td>
</tr>
<tr>
<th align="left">Do you want to edit the new page when created?</th>
<td>
<table border="1">
<tr>
<td><input type="checkbox" name="editoption" value="Y" <?php echo $editoption == "true" ? "checked=\"checked\"" : "" ?> />Edit after creation</td>
<td><input type="submit" name="create" value="Template it now"></td>
</tr>
</table>
</td>
</tr>
</table>
<?php
echo $this->FormClose();
// ***** END INPUT FORM *****

// ***** GET PARAMETERS *****
$from = $_POST["from"];
$to = $_POST["to"];
$note = $_POST["note"];
$editoption = $_POST["editoption"];
// ***** END PARAMETERS *****

// ***** TEMPLATING PROCESS *****
If ($to<>"") {
// The user must provide a WikiPage name to be created...
if ($this->ExistsPage($to))
{
// and it should be a new one...
$errormessage = "The destination page must not exist.";
echo $errormessage;
return;
}
// also the user has to be allowed to create this page...
elseif ($this->HasAccess("write", $to)) {
// The user should provide a WikiPage name to be duplicated...
if (!$from)
{
// by default the system will duplicate the current page...
$from = $this->GetPageTag();
}
else
{
// otherwise, the page to be dublicated must of course exit...
if ($this->ExistsPage($from))
{
// and the user has to be allowed to read it...
if (!$this->HasAccess("read", $from))
{
$errormessage = "You are not authorized to use the template page.";
echo $errormessage;
return;
}
}
else
{
// this is what happens if the user tries to duplicate a non existing page...
$errormessage = "The template page does not exist.";
echo $errormessage;
return;
}
}
// the user may provide a creation note otherwise...
if (!$note)
{
// the system will create one by default...
$note = "Templated from ".$from;
}

// ***** DERIVED VARIABLES *****
$thepage=$this->LoadPage($from); // load the page that has to be duplicated...
if ($thepage) $pagecontent = $thepage["body"]; // and get its content.
// ***** END DERIVED VARIABLES *****

// ***** OUTPUT SECTION *****
$this->SavePage($to, $pagecontent, $note); // creates the page...
echo "[[ ".$to." has been created from ".$from." and note was: ".$note." ]]"; // confirms what has been done
if ($editoption) $this->redirect(BASE_URL.$to."/edit"); // drops the user to the new page for edition if he choosed so
// ***** END OUTPUT SECTION *****

} else
{
// this is what happens if you try to create a page when you are not authorized.
$errormessage = "You are not authorized to create the destination page.";
echo $errormessage;
return;
}
}
// ***** END TEMPLATING PROCESS *****
?>
%%

===How to use it?===
Once you have (re)designed a page that fits to be replicated many times (Task Lists, User Pages, Bug Description, Developement Description...) you just have to use the ""{{template}}"" action from any page: you may want to have a dedicated TemplatePage with the action and the instructions on it (I will propose one if this action can be installed on the Wikka server).
Then you must fill the name of the new WikiPage to be created, if you do not fill the name of the page that has to be duplicated the system will duplicate the current page, you may want to add a note, finally you decide if you just want to create the page or if you want to jump and edit it as soon as it has been copied.

===To Do===
My code needs probably to be reviewed by expert coder as I am not at all a developper.
Any ideas around this action more than welcome.

==Solved error & minor code changes==
''I get the following error (just copied the code to template.php and tried the syntax you gave):

Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /.../actions/template.php on line 2

Parse error: parse error, unexpected T_STRING in /.../actions/template.php on line 2"
--NilsLindenberg''

''Nils, I don't have a clue how you can get that error; did you grab the code from the page source? --JavaWoman.''
''Yepp, I always copy from the source. --NilsLindenberg''
~Do you still have the same error with the new code? --ChristianBarthelemy
~~~''I have to try later, they don't trust me that much in the university, to allow ftp access to pages. And I haven't worked out how I should explain wikka as an essentail part of my studies ;-). I'll check later. --NilsLindenberg''
~~~~''1. Are you **entering** something in the form or as an action attribute that contains a ""\""? There's not even a ""\"" in the code that I can see. If so, try ""/"" as a path separator instead.
~~~~2. Wikka for studies - maybe this helps? [[http://shirky.com/writings/group_user.html Group as User: Flaming and the Design of Social Software]] - by Clay Shirky; I guess you're doing a field study? ;-) --JavaWoman''
~~~''Ok, I tried the new code, but it hasn't changed anything. I tried simple opage names like NewPage, ""NewerPage"" etc. even adding ""{{template}}"" gives that error. --NilsLindenberg''
~~~~Which Wikka version are you using? I do not see any reason for such an error. I replaced the template.php version from my server with a copy from this page to a new txt notepad file, renamed into template.php placed it in the action folder and it worked.

Update: Ok, I finally found out what I made wrong. My mistake: the txt files on this pc are connected with wordpad, not with notepad. I hadn't looked after that and so saved the files with useless renderings *bangs head against wall*. But after that, I found some points in your script:
1) There was an ?> missing at the end
1) The length for a page can be 75 chars, ++I changed your value to that++ just keep that in mind, cuase it means scrolling now for names >37
1) if you have much output, more simple than putting out all with echo is to leave php. I replaced the input form above. You now get the variables shown in the fields.
--NilsLindenberg
2ndUpdate: works fine, thanx. --NilsLindenberg

Any one else tried it? --ChristianBarthelemy
~''I've been tweaking the code a bit but haven't actually tested anything yet; I'm afraid I have a few more urgent things on my list right now (such as finishing WikkaGeSHiIntegration with install/update). I **will** get back to this though, promise, since I think it's very useful! --JavaWoman''

~''I like the idea too. A couple of general remarks'' --''DarTar''

==Difference action/handler==
''Should this really be an //action//? Why not a handler?'' --''DarTar''

~This action (usefully) accepts a number of parameters, either predefined in the action or via the form; as far as I can tell you can not easily do that with a handler: URL parameters are possible but are much harder to handle for an end user (requiring knowledge of how to build a query via a URL). Also, such a handler would either have to operate on the source page or on the target page while an action like this can be embedded in any page. User input really is required: an action with a form is more flexible and more user-frienldy. --JavaWoman

~I thought about this when I first defined what I expected, and concluded that an action was more appropriate for the reasons explained by JavaWoman. --ChristianBarthelemy

~~''To me 'cloning a page' is really something that should be taken care of by a handler. Here's why:
~~~-I don't see the difficulty of creating handlers containing forms. See for instance the /acls handler: you can have user-input and URL parameters (both GET and POST) easily dealt with a handler.
~~~-Moreover, the reason why I see this functionality better implemented as a handler than as an action is that it really looks like an operation that users are likely to perform on //any page//. Instead of: 1) opening the page, 2) adding an action, 3) save the page, and start cloning the page, you just need to point to the 'clone' handler for this page. The clone handler will then print a form asking you the name of the target page (the source being by default the current page - as the default selected item of a form menu).
~~~-Pointing to the 'clone' handler for the current page can then be easily done by adding a footer link, much as the current "Edit page". I'm more and more convinced that these kinds of operations on pages (which are coherent with the definition of a [[HandlerInfo handler]]) should one day be all added in the footer menu: different footer links pointing to different handlers will then allow the user to //edit the current page//, //show source of current page//, //modify the ACLs for the current page//, //display the referrers of the current page//, //**clone the current page**//, //delete the current page//, //send the current page by email//, //create a PDF of the current page// etc.
~~~-As a general rule, what handlers are displayed in the footer menu should be a configurable option (either system-wide or a user preference).
~~Doesn't this sound more reasonable than using an action? -- DarTar''

~~~Got your point and the logic behind. I do not know enough about the handlers and did not realized that you can use forms within. I am far from being a coder, anyway I will try to figure out how to make it a handler. I think that an expert advice explaining when to use handler or action would be nice to be found at ActionOrHandler--ChristianBarthelemy

~~~~''Christian, take a look at HandlerInfo to see the distinction between actions and handlers. Actions are meant in general to 'produce automatically generated content //within// a page'. Handlers perform operations on a page as a whole -- DarTar''.

~~~~~''I knew about the general distinction between actions and (page) handlers, but like Christian I hadn't realised that a handler can display a form, too. I thought of action because a form is obvously needed, and that would need to be displayed "on" a page. Given that a handler can display a form to request parameter input, I agree this would be better implemented as a handler.---[Note to self: learn more about handlers!] --JavaWoman''

~~~~~My distinction between handler and action is the following:an action can be included in a page. It adds code, it is a plugin. A handler is not put on a page, nor does it add code to it, but it does something with the page. --NilsLindenberg

==Dropdown-list with page-names==
''What about adding a menu to allow the user to choose the source page from one of the existing pages? This might avoid checking for page existence'' --''DarTar''

~Sounds nice but would be workable only in a small Wiki. OTH, if you limit the action to special-purpose Template pages this could be workable; or one could have an extra option to choose a template **or** any page with a dropdown only for templates and a text field for any other page. --JavaWoman

~~''Is there any problem with long drop-down menus? In any case the source won't be longer than the source of PageIndex. I find interesting on the other hand the idea of having some preferred pages listed at the top of the menu (maybe just checking a Category will do the job)-- DarTar''

~"Another idea would be to predefine the pages that may be duplicated by tagging them somehow. The system would then only provide in a dropdown list such pages. --ChristianBarthelemy"



==better name then template?==
''I think that the concept of **template** is associated in general to something quite different from what you are proposing here. What about using a name suggesting page //exporting//,//duplicating// or //cloning//?'' --''DarTar''

~First, it would be possible to create a number of (read-only) templates (e.g., a Doumentation template). In general, though //clone// (but not //export//) might be a better term if you (can) use the action to copy any page and not just special-purpose template. --JavaWoman

~"I agree, the name of template only fits my personnal purpose and "clone" is a more appropriate naming for this action. Hence a new page: CloneAction. --ChristianBarthelemy"


==Development==
''(After code change) Christian, OK, I see the intention now. And I like it a lot! Unfortunately, the code isn't quite correct - mind if I take a stab at clearing it up? --JavaWoman''

You of course have my blessing - This code surely needs some revamping and I will be more than happy that we get something cleaner --ChristianBarthelemy

==Contribution==
I dont know if this is proper , (putting up ChristianBarthelemy 's code with my edits but here it is ...
this is has a drop-down menu to select the page you want to copy ...
( also removed the amazing documentation/comments so that it wont be heavy in the eye when posting on this page.
Edit/Remove at will
// code removed I stayed behind and didnt look at the development train ...//
~''Well, do add a bit to show what your idea for the dropdown was... --JavaWoman''
%%(php)$res = $this->LoadAll("select tag from ".$this->config['table_prefix']."pages where latest='Y'");

foreach($res as $i => $arr){
if (!($arr['tag'] == $this->GetPageTag()))
$select_input .= '<option value="'.$arr['tag'].'">'.$arr['tag'].'</option>\n\t';
}

$select_input = $this->ReturnSafeHTML(
"<select name=\"from\">".
"\n\t<option value=\"".$this->GetPageTag()."\">".$this->GetPageTag()."</option>".
"\t\n$select_input</select>"
);
%% This is the way I created the dropdown formfield ... maybe it will be usefull at some point .. --GeorgePetsagourakis

Pardon me if this is not a proper way to do things.. I am a bit new in here --GeorgePetsagourakis
~"This is a wiki so it has to be a collaborative environment, as I pointed out, my original code surely needs to be improved. --ChristianBarthelemy."

''George, nothing in principle against including alternative code - but your code seems to be based on Christian's original code which was already much improved (by Nils) as can be seen earlier on this page. Consequently your code has the same problems Christian's original had. Why not just show how the code above could be changed with your extension? (And note my remark above: "Sounds nice but would be workable only in a small Wiki.") --JavaWoman''

----


Revision [3506]

Edited on 2004-12-19 23:18:21 by ChristianBarthelemy [Thank you Georges]
Additions:
~"This is a wiki so it has to be a collaborative environment, as I pointed out, my original code surely needs to be improved. --ChristianBarthelemy."


Revision [3500]

Edited on 2004-12-19 22:43:39 by GeorgePetsagourakis [george encouraged ;)]
Additions:
%% This is the way I created the dropdown formfield ... maybe it will be usefull at some point .. --GeorgePetsagourakis
Deletions:
%% This is the way I created the dropdown formfield ... maybe it will be usefull at some point ..


Revision [3499]

Edited on 2004-12-19 22:42:50 by GeorgePetsagourakis [george encouraged ;)]
Additions:
%%(php)$res = $this->LoadAll("select tag from ".$this->config['table_prefix']."pages where latest='Y'");
foreach($res as $i => $arr){
if (!($arr['tag'] == $this->GetPageTag()))
$select_input .= '<option value="'.$arr['tag'].'">'.$arr['tag'].'</option>\n\t';
$select_input = $this->ReturnSafeHTML(
"<select name=\"from\">".
"\n\t<option value=\"".$this->GetPageTag()."\">".$this->GetPageTag()."</option>".
"\t\n$select_input</select>"
);
%% This is the way I created the dropdown formfield ... maybe it will be usefull at some point ..


Revision [3498]

Edited on 2004-12-19 22:35:31 by JavaWoman [encourage George :)]
Additions:
~''Well, do add a bit to show what your idea for the dropdown was... --JavaWoman''


Revision [3497]

Edited on 2004-12-19 22:32:17 by GeorgePetsagourakis [removed "slow" code piece ...]
Additions:
// code removed I stayed behind and didnt look at the development train ...//
Pardon me if this is not a proper way to do things.. I am a bit new in here --GeorgePetsagourakis
Deletions:
%%(php)<?php
/*
Duplicate a "template" page to a new named page
Usage: {{template from="OldPage" to="NewPage" editoption="true"}}
or simply {{template}} to be able to choose any page ...
This action checks the existence of the template page, the non existence of the page to be created, the user
right to read the template and the user right to create a page.
The editoption when true will create the new page and then open it for edition.
@package: Actions
@name: template
@author: Christian Barthelemy: original code
GeorgePetsagourakis: added a drop-down that allows you to choose the originating page.
@version: 0.2
@since: Wikka 1.1.5.3
@input: string $from optional: the template page to be duplicated
must be an existing page and must be authorized for reading to the current user
defaulted to the current WikiPage
@input: string $to mandatory: the page to be created
must be a non existing page and current user must be authorized to create
@input: string $note optional: the note to be added to the page when created
default is "Templated from " followed by the name of the template page
@input: boolean $editoption optional: if true, the newly created page will be opened for edition
default is false
*/
// creating the drop down box for the 'from' field..
$select_input = '';
$res = $this->LoadAll("select tag from ".$this->config['table_prefix']."pages where latest='Y'");
foreach($res as $i => $arr){
if (!($arr['tag'] == $this->GetPageTag())) $select_input .= '<option value="'.$arr['tag'].'">'.$arr['tag'].'</option>\n\t';
$select_input = $this->ReturnSafeHTML("<select name=\"from\">\n\t<option value=\"".$this->GetPageTag()."\">".$this->GetPageTag()."</option>\t\n$select_input</select>");
echo $this->ReturnSafeHTML('
<table align="center" class="template" border="0">
<tr>
<td align="right">Select the originating page:</td>
<td>'.$select_input.'</td>
</tr>
<tr>
<td align="right">WikiPage to be created:</td>
<td><input type="text" name="to" size="25">'.$to.'</td>
</tr>
<tr>
<td align="right"><em>Add a note to your edit:</em></td>
<td><input type="text" name="note" size="25">'.$note.'</td>
</tr>
<tr><td align="right"><input type="checkbox" name="editoption" value="false">Edit after creation'.$editoption.'</td></tr>
<tr><td align="center" colspan="2"><input type="submit" name="create" value="Template it now"></td></tr>
</table>');
function page_exists($arr, $tag){
$ret = false;
foreach($arr as $i => $r){
if ($tag==$r['tag']) {
$ret = true;
return $ret;
if ($to<>"") {
if (page_exists($res, $to)) {
echo "The destination page must not exist.";
if (!$from){
else {
if (page_exists($res, $from)){
if (!$this->HasAccess("read", $from)) {
echo "You are not authorized to use the template page.";
else {
echo "The template page does not exist.";
if (!$note) $note = "Templated from ".$from;
$thepage=$this->LoadPage($from);
if ($thepage) $pagecontent = $thepage["body"];
$this->SavePage($to, $pagecontent, $note);
echo "[[ ".$to." has been created from ".$from." and note was: ".$note." ]]";
if ($editoption) $this->redirect($this->config['base_url'].$to."/edit");
else {
echo "You are not authorized to create the destination page.";
?>%%Pardon me if this is not a proper way to do things.. I am a bit new in here --GeorgePetsagourakis


Revision [3496]

Edited on 2004-12-19 22:26:06 by JavaWoman [comment to George]
Additions:
''George, nothing in principle against including alternative code - but your code seems to be based on Christian's original code which was already much improved (by Nils) as can be seen earlier on this page. Consequently your code has the same problems Christian's original had. Why not just show how the code above could be changed with your extension? (And note my remark above: "Sounds nice but would be workable only in a small Wiki.") --JavaWoman''


Revision [3495]

Edited on 2004-12-19 22:12:28 by GeorgePetsagourakis [addded code contribution]
Additions:
==Contribution==
I dont know if this is proper , (putting up ChristianBarthelemy 's code with my edits but here it is ...
this is has a drop-down menu to select the page you want to copy ...
( also removed the amazing documentation/comments so that it wont be heavy in the eye when posting on this page.
Edit/Remove at will
%%(php)<?php
/*
Duplicate a "template" page to a new named page
Usage: {{template from="OldPage" to="NewPage" editoption="true"}}
or simply {{template}} to be able to choose any page ...
This action checks the existence of the template page, the non existence of the page to be created, the user
right to read the template and the user right to create a page.
The editoption when true will create the new page and then open it for edition.
@package: Actions
@name: template
@author: Christian Barthelemy: original code
GeorgePetsagourakis: added a drop-down that allows you to choose the originating page.
@version: 0.2
@since: Wikka 1.1.5.3
@input: string $from optional: the template page to be duplicated
must be an existing page and must be authorized for reading to the current user
defaulted to the current WikiPage
@input: string $to mandatory: the page to be created
must be a non existing page and current user must be authorized to create
@input: string $note optional: the note to be added to the page when created
default is "Templated from " followed by the name of the template page
@input: boolean $editoption optional: if true, the newly created page will be opened for edition
default is false
*/
// creating the drop down box for the 'from' field..
$select_input = '';
$res = $this->LoadAll("select tag from ".$this->config['table_prefix']."pages where latest='Y'");
foreach($res as $i => $arr){
if (!($arr['tag'] == $this->GetPageTag())) $select_input .= '<option value="'.$arr['tag'].'">'.$arr['tag'].'</option>\n\t';
$select_input = $this->ReturnSafeHTML("<select name=\"from\">\n\t<option value=\"".$this->GetPageTag()."\">".$this->GetPageTag()."</option>\t\n$select_input</select>");
echo $this->ReturnSafeHTML('
<table align="center" class="template" border="0">
<tr>
<td align="right">Select the originating page:</td>
<td>'.$select_input.'</td>
</tr>
<tr>
<td align="right">WikiPage to be created:</td>
<td><input type="text" name="to" size="25">'.$to.'</td>
</tr>
<tr>
<td align="right"><em>Add a note to your edit:</em></td>
<td><input type="text" name="note" size="25">'.$note.'</td>
</tr>
<tr><td align="right"><input type="checkbox" name="editoption" value="false">Edit after creation'.$editoption.'</td></tr>
<tr><td align="center" colspan="2"><input type="submit" name="create" value="Template it now"></td></tr>
</table>');
function page_exists($arr, $tag){
$ret = false;
foreach($arr as $i => $r){
if ($tag==$r['tag']) {
$ret = true;
return $ret;
if ($to<>"") {
if (page_exists($res, $to)) {
echo "The destination page must not exist.";
if (!$from){
else {
if (page_exists($res, $from)){
if (!$this->HasAccess("read", $from)) {
echo "You are not authorized to use the template page.";
else {
echo "The template page does not exist.";
if (!$note) $note = "Templated from ".$from;
$thepage=$this->LoadPage($from);
if ($thepage) $pagecontent = $thepage["body"];
$this->SavePage($to, $pagecontent, $note);
echo "[[ ".$to." has been created from ".$from." and note was: ".$note." ]]";
if ($editoption) $this->redirect($this->config['base_url'].$to."/edit");
else {
echo "You are not authorized to create the destination page.";
?>%%Pardon me if this is not a proper way to do things.. I am a bit new in here --GeorgePetsagourakis


Revision [3489]

Edited on 2004-12-19 21:43:09 by JavaWoman [nother layout change (repairing thread)]
Additions:
''Nils, I don't have a clue how you can get that error; did you grab the code from the page source? --JavaWoman.''
''(After code change) Christian, OK, I see the intention now. And I like it a lot! Unfortunately, the code isn't quite correct - mind if I take a stab at clearing it up? --JavaWoman''
Deletions:
''(After code change) Christian, OK, I see the intention now. And I like it a lot! Unfortunately, the code isn't quite correct - mind if I take a stab at clearing it up?
Nils, I don't have a clue how you can get that error; did you grab the code from the page source? --JavaWoman.''


Revision [3488]

Edited on 2004-12-19 20:53:32 by NilsLindenberg [layout changes]
Additions:
==Solved error & minor code changes==
~''I like the idea too. A couple of general remarks'' --''DarTar''
==Difference action/handler==
''Should this really be an //action//? Why not a handler?'' --''DarTar''
~This action (usefully) accepts a number of parameters, either predefined in the action or via the form; as far as I can tell you can not easily do that with a handler: URL parameters are possible but are much harder to handle for an end user (requiring knowledge of how to build a query via a URL). Also, such a handler would either have to operate on the source page or on the target page while an action like this can be embedded in any page. User input really is required: an action with a form is more flexible and more user-frienldy. --JavaWoman
~I thought about this when I first defined what I expected, and concluded that an action was more appropriate for the reasons explained by JavaWoman. --ChristianBarthelemy
~~''To me 'cloning a page' is really something that should be taken care of by a handler. Here's why:
~~~-I don't see the difficulty of creating handlers containing forms. See for instance the /acls handler: you can have user-input and URL parameters (both GET and POST) easily dealt with a handler.
~~~-Moreover, the reason why I see this functionality better implemented as a handler than as an action is that it really looks like an operation that users are likely to perform on //any page//. Instead of: 1) opening the page, 2) adding an action, 3) save the page, and start cloning the page, you just need to point to the 'clone' handler for this page. The clone handler will then print a form asking you the name of the target page (the source being by default the current page - as the default selected item of a form menu).
~~~-Pointing to the 'clone' handler for the current page can then be easily done by adding a footer link, much as the current "Edit page". I'm more and more convinced that these kinds of operations on pages (which are coherent with the definition of a [[HandlerInfo handler]]) should one day be all added in the footer menu: different footer links pointing to different handlers will then allow the user to //edit the current page//, //show source of current page//, //modify the ACLs for the current page//, //display the referrers of the current page//, //**clone the current page**//, //delete the current page//, //send the current page by email//, //create a PDF of the current page// etc.
~~~-As a general rule, what handlers are displayed in the footer menu should be a configurable option (either system-wide or a user preference).
~~Doesn't this sound more reasonable than using an action? -- DarTar''
~~~Got your point and the logic behind. I do not know enough about the handlers and did not realized that you can use forms within. I am far from being a coder, anyway I will try to figure out how to make it a handler. I think that an expert advice explaining when to use handler or action would be nice to be found at ActionOrHandler--ChristianBarthelemy
~~~~''Christian, take a look at HandlerInfo to see the distinction between actions and handlers. Actions are meant in general to 'produce automatically generated content //within// a page'. Handlers perform operations on a page as a whole -- DarTar''.
~~~~~My distinction between handler and action is the following:an action can be included in a page. It adds code, it is a plugin. A handler is not put on a page, nor does it add code to it, but it does something with the page. --NilsLindenberg
==Dropdown-list with page-names==
''What about adding a menu to allow the user to choose the source page from one of the existing pages? This might avoid checking for page existence'' --''DarTar''
~Sounds nice but would be workable only in a small Wiki. OTH, if you limit the action to special-purpose Template pages this could be workable; or one could have an extra option to choose a template **or** any page with a dropdown only for templates and a text field for any other page. --JavaWoman
~~''Is there any problem with long drop-down menus? In any case the source won't be longer than the source of PageIndex. I find interesting on the other hand the idea of having some preferred pages listed at the top of the menu (maybe just checking a Category will do the job)-- DarTar''
~"Another idea would be to predefine the pages that may be duplicated by tagging them somehow. The system would then only provide in a dropdown list such pages. --ChristianBarthelemy"
==better name then template?==
''I think that the concept of **template** is associated in general to something quite different from what you are proposing here. What about using a name suggesting page //exporting//,//duplicating// or //cloning//?'' --''DarTar''
~First, it would be possible to create a number of (read-only) templates (e.g., a Doumentation template). In general, though //clone// (but not //export//) might be a better term if you (can) use the action to copy any page and not just special-purpose template. --JavaWoman
~"I agree, the name of template only fits my personnal purpose and "clone" is a more appropriate naming for this action. Hence a new page: CloneAction. --ChristianBarthelemy"
==Development==
Deletions:
~''I like the idea too. A couple of general remarks:''
~~-''Should this really be an //action//? Why not a handler?''
~~~This action (usefully) accepts a number of parameters, either predefined in the action or via the form; as far as I can tell you can not easily do that with a handler: URL parameters are possible but are much harder to handle for an end user (requiring knowledge of how to build a query via a URL). Also, such a handler would either have to operate on the source page or on the target page while an action like this can be embedded in any page. User input really is required: an action with a form is more flexible and more user-frienldy. --JavaWoman
~~~
~~~I thought about this when I first defined what I expected, and concluded that an action was more appropriate for the reasons explained by JavaWoman. --ChristianBarthelemy
~~~
~~~''To me 'cloning a page' is really something that should be taken care of by a handler. Here's why:
~~~~-I don't see the difficulty of creating handlers containing forms. See for instance the /acls handler: you can have user-input and URL parameters (both GET and POST) easily dealt with a handler.
~~~~-Moreover, the reason why I see this functionality better implemented as a handler than as an action is that it really looks like an operation that users are likely to perform on //any page//. Instead of: 1) opening the page, 2) adding an action, 3) save the page, and start cloning the page, you just need to point to the 'clone' handler for this page. The clone handler will then print a form asking you the name of the target page (the source being by default the current page - as the default selected item of a form menu).
~~~~-Pointing to the 'clone' handler for the current page can then be easily done by adding a footer link, much as the current "Edit page". I'm more and more convinced that these kinds of operations on pages (which are coherent with the definition of a [[HandlerInfo handler]]) should one day be all added in the footer menu: different footer links pointing to different handlers will then allow the user to //edit the current page//, //show source of current page//, //modify the ACLs for the current page//, //display the referrers of the current page//, //**clone the current page**//, //delete the current page//, //send the current page by email//, //create a PDF of the current page// etc.
~~~~-As a general rule, what handlers are displayed in the footer menu should be a configurable option (either system-wide or a user preference).
~~~Doesn't this sound more reasonable than using an action? -- DarTar''
~~~~~Got your point and the logic behind. I do not know enough about the handlers and did not realized that you can use forms within. I am far from being a coder, anyway I will try to figure out how to make it a handler. I think that an expert advice explaining when to use handler or action would be nice to be found at ActionOrHandler--ChristianBarthelemy
~~~~~''Christian, take a look at HandlerInfo to see the distinction between actions and handlers. Actions are meant in general to 'produce automatically generated content //within// a page'. Handlers perform operations on a page as a whole -- DarTar''.
~~-''What about adding a menu to allow the user to choose the source page from one of the existing pages? This might avoid checking for page existence''
~~~Sounds nice but would be workable only in a small Wiki. OTH, if you limit the action to special-purpose Template pages this could be workable; or one could have an extra option to choose a template **or** any page with a dropdown only for templates and a text field for any other page. --JavaWoman
~~~"Another idea would be to predefine the pages that may be duplicated by tagging them somehow. The system would then only provide in a dropdown list such pages. --ChristianBarthelemy"
~~~''Is there any problem with long drop-down menus? In any case the source won't be longer than the source of PageIndex. I find interesting on the other hand the idea of having some preferred pages listed at the top of the menu (maybe just checking a Category will do the job)-- DarTar''
~~-''I think that the concept of **template** is associated in general to something quite different from what you are proposing here. What about using a name suggesting page //exporting//,//duplicating// or //cloning//?''
~~~First, it would be possible to create a number of (read-only) templates (e.g., a Doumentation template). In general, though //clone// (but not //export//) might be a better term if you (can) use the action to copy any page and not just special-purpose template. --JavaWoman
~~~"I agree, the name of template only fits my personnal purpose and "clone" is a more appropriate naming for this action. Hence a new page: CloneAction. --ChristianBarthelemy"
~''DarTar''


Revision [3473]

Edited on 2004-12-19 15:59:03 by JavaWoman [reply to DarTar (and Christian)]
Additions:
~~~~~Got your point and the logic behind. I do not know enough about the handlers and did not realized that you can use forms within. I am far from being a coder, anyway I will try to figure out how to make it a handler. I think that an expert advice explaining when to use handler or action would be nice to be found at ActionOrHandler--ChristianBarthelemy
~~~~~''I knew about the general distinction between actions and (page) handlers, but like Christian I hadn't realised that a handler can display a form, too. I thought of action because a form is obvously needed, and that would need to be displayed "on" a page. Given that a handler can display a form to request parameter input, I agree this would be better implemented as a handler.---[Note to self: learn more about handlers!] --JavaWoman''
Deletions:
~~~~~"Got your point and the logic behind. I do not know enough about the handlers and did not realized that you can use forms within. I am far from being a coder, anyway I will try to figure out how to make it a handler. I think that an expert advice explaining when to use handler or action would be nice to be found at ActionOrHandler--ChristianBarthelemy"


Revision [3471]

Edited on 2004-12-19 15:27:30 by DarTar [Replying to Christian]
Additions:
~~~~-Pointing to the 'clone' handler for the current page can then be easily done by adding a footer link, much as the current "Edit page". I'm more and more convinced that these kinds of operations on pages (which are coherent with the definition of a [[HandlerInfo handler]]) should one day be all added in the footer menu: different footer links pointing to different handlers will then allow the user to //edit the current page//, //show source of current page//, //modify the ACLs for the current page//, //display the referrers of the current page//, //**clone the current page**//, //delete the current page//, //send the current page by email//, //create a PDF of the current page// etc.
~~~~-As a general rule, what handlers are displayed in the footer menu should be a configurable option (either system-wide or a user preference).
~~~Doesn't this sound more reasonable than using an action? -- DarTar''
~~~~~''Christian, take a look at HandlerInfo to see the distinction between actions and handlers. Actions are meant in general to 'produce automatically generated content //within// a page'. Handlers perform operations on a page as a whole -- DarTar''.
Deletions:
~~~~-Pointing to the 'clone' handler for the current page can then be easily done by adding a footer link, much as the current "Edit page". I'm more and more convinced that these kinds of operations on pages (which are coherent with the definition of a [[HandlerInfo handler]]) should one day be all added in the footer menu: different footer links pointing to different handlers will then allow the user to //edit the current page//, //modify the ACLs for the current page//, //display the referrers of the current page//, //clone the current page//, //delete the current page//, //send the current page by email//, //create a PDF of the current page// etc. Doesn't this sound more reasonable than using an action? -- DarTar''


Revision [3469]

Edited on 2004-12-19 15:22:30 by ChristianBarthelemy [Action or Handler: this will deserve a dedicated page...]
Additions:
~~~~~"Got your point and the logic behind. I do not know enough about the handlers and did not realized that you can use forms within. I am far from being a coder, anyway I will try to figure out how to make it a handler. I think that an expert advice explaining when to use handler or action would be nice to be found at ActionOrHandler--ChristianBarthelemy"


Revision [3467]

Edited on 2004-12-19 15:02:39 by DarTar [Why a handler is better than an action]
Additions:
~~~~-Pointing to the 'clone' handler for the current page can then be easily done by adding a footer link, much as the current "Edit page". I'm more and more convinced that these kinds of operations on pages (which are coherent with the definition of a [[HandlerInfo handler]]) should one day be all added in the footer menu: different footer links pointing to different handlers will then allow the user to //edit the current page//, //modify the ACLs for the current page//, //display the referrers of the current page//, //clone the current page//, //delete the current page//, //send the current page by email//, //create a PDF of the current page// etc. Doesn't this sound more reasonable than using an action? -- DarTar''
Deletions:
~~~~-Pointing to the 'clone' handler for the current page can then be easily done by adding a footer link, much as the current "Edit page". I'm more and more convinced that these kinds of operations on pages (which are coherent with the definition of a [[HandlersInfo handler]]) should one day be all added in the footer menu: different footer links pointing to different handlers will then allow the user to //edit the current page//, //modify the ACLs for the current page//, //display the referrers of the current page//, //clone the current page//, //delete the current page//, //send the current page by email//, //create a PDF of the current page// etc. Doesn't this sound more reasonable than using an action? -- DarTar''


Revision [3466]

Edited on 2004-12-19 15:02:01 by DarTar [Why a handler is better than an action]
Additions:
{{lastedit}}
~~~
~~~I thought about this when I first defined what I expected, and concluded that an action was more appropriate for the reasons explained by JavaWoman. --ChristianBarthelemy
~~~
~~~''To me 'cloning a page' is really something that should be taken care of by a handler. Here's why:
~~~~-I don't see the difficulty of creating handlers containing forms. See for instance the /acls handler: you can have user-input and URL parameters (both GET and POST) easily dealt with a handler.
~~~~-Moreover, the reason why I see this functionality better implemented as a handler than as an action is that it really looks like an operation that users are likely to perform on //any page//. Instead of: 1) opening the page, 2) adding an action, 3) save the page, and start cloning the page, you just need to point to the 'clone' handler for this page. The clone handler will then print a form asking you the name of the target page (the source being by default the current page - as the default selected item of a form menu).
~~~~-Pointing to the 'clone' handler for the current page can then be easily done by adding a footer link, much as the current "Edit page". I'm more and more convinced that these kinds of operations on pages (which are coherent with the definition of a [[HandlersInfo handler]]) should one day be all added in the footer menu: different footer links pointing to different handlers will then allow the user to //edit the current page//, //modify the ACLs for the current page//, //display the referrers of the current page//, //clone the current page//, //delete the current page//, //send the current page by email//, //create a PDF of the current page// etc. Doesn't this sound more reasonable than using an action? -- DarTar''
~~~
~~~''Is there any problem with long drop-down menus? In any case the source won't be longer than the source of PageIndex. I find interesting on the other hand the idea of having some preferred pages listed at the top of the menu (maybe just checking a Category will do the job)-- DarTar''
Deletions:
~~~"I thought about this when I first defined what I expected, and concluded that an action was more appropriate for the reasons explained by JavaWoman. --ChristianBarthelemy"


Revision [3464]

Edited on 2004-12-19 14:39:03 by ChristianBarthelemy [Answer to DarTar]
Additions:
~~~"I thought about this when I first defined what I expected, and concluded that an action was more appropriate for the reasons explained by JavaWoman. --ChristianBarthelemy"
~~~"Another idea would be to predefine the pages that may be duplicated by tagging them somehow. The system would then only provide in a dropdown list such pages. --ChristianBarthelemy"
~~~"I agree, the name of template only fits my personnal purpose and "clone" is a more appropriate naming for this action. Hence a new page: CloneAction. --ChristianBarthelemy"


Revision [3444]

Edited on 2004-12-18 16:07:42 by JavaWoman [Replies to DarTar]
Additions:
~''I like the idea too. A couple of general remarks:''
~~-''Should this really be an //action//? Why not a handler?''
~~~This action (usefully) accepts a number of parameters, either predefined in the action or via the form; as far as I can tell you can not easily do that with a handler: URL parameters are possible but are much harder to handle for an end user (requiring knowledge of how to build a query via a URL). Also, such a handler would either have to operate on the source page or on the target page while an action like this can be embedded in any page. User input really is required: an action with a form is more flexible and more user-frienldy. --JavaWoman
~~-''What about adding a menu to allow the user to choose the source page from one of the existing pages? This might avoid checking for page existence''
~~~Sounds nice but would be workable only in a small Wiki. OTH, if you limit the action to special-purpose Template pages this could be workable; or one could have an extra option to choose a template **or** any page with a dropdown only for templates and a text field for any other page. --JavaWoman
~~-''I think that the concept of **template** is associated in general to something quite different from what you are proposing here. What about using a name suggesting page //exporting//,//duplicating// or //cloning//?''
~~~First, it would be possible to create a number of (read-only) templates (e.g., a Doumentation template). In general, though //clone// (but not //export//) might be a better term if you (can) use the action to copy any page and not just special-purpose template. --JavaWoman
~''DarTar''
Deletions:
~
~''I like the idea too. A couple of general remarks:
~~-Should this really be an //action//? Why not a handler?
~~-What about adding a menu to allow the user to choose the source page from one of the existing pages? This might avoid checking for page existence''
~~-I think that the concept of **template** is associated in general to something quite different from what you are proposing here. What about using a name suggesting page //exporting//,//duplicating// or //cloning//?
~DarTar''


Revision [3441]

Edited on 2004-12-18 14:44:37 by NilsLindenberg [works fine]
Additions:
1) if you have much output, more simple than putting out all with echo is to leave php. I replaced the input form above. You now get the variables shown in the fields.
2ndUpdate: works fine, thanx. --NilsLindenberg
Deletions:
1) if you have much output, more simple than putting out all with echo is to leave php. I replaced the input form above.


Revision [3440]

Edited on 2004-12-18 14:34:14 by NilsLindenberg [comment]
Additions:
1) if you have much output, more simple than putting out all with echo is to leave php. I replaced the input form above.
Deletions:
1) if you have much output, more simple than putting out all with echo is to leave php.


Revision [3439]

Edited on 2004-12-18 14:31:43 by NilsLindenberg [changed the input form]
Additions:
<table class="template" border="1">
<tr>
<th align="left">WikiPage to be templated (empty means this page):</th>
<td><input type="text" name="from" size="37" value="<?php echo $from ?>" /></td>
</tr>
<tr>
<th align="left">WikiPage to be created:</th>
<td><input type="text" name="to" size="37" value="<?php echo $to ?>" /></td>
</tr>
<tr>
<th align="left">Added note to your edit:</th>
<td><input type="text" name="note" size="37" value="<?php echo $note ?>" /></td>
</tr>
<tr>
<th align="left">Do you want to edit the new page when created?</th>
<td>
<table border="1">
<tr>
<td><input type="checkbox" name="editoption" value="Y" <?php echo $editoption == "true" ? "checked=\"checked\"" : "" ?> />Edit after creation</td>
<td><input type="submit" name="create" value="Template it now"></td>
</tr>
</table>
</td>
</tr>
</table>
Deletions:
echo '<table class="template" border="1">';
echo ' <tr>';
echo ' <th align="left">WikiPage to be templated (empty means this page):</th>';
echo ' <td><input type="text" name="from" size="37">'.$from.'</td>';
echo ' </tr>';
echo ' <tr>';
echo ' <th align="left">WikiPage to be created:</th>';
echo ' <td><input type="text" name="to" size="37">'.$to.'</td>';
echo ' </tr>';
echo ' <tr>';
echo ' <th align="left">Added note to your edit:</th>';
echo ' <td><input type="text" name="note" size="37">'.$note.'</td>';
echo ' </tr>';
echo ' <tr>';
echo ' <th align="left">Do you want to edit the new page when created?</th>';
echo ' <td>';
echo ' <table border="1">';
echo ' <tr>';
echo ' <td><input type="checkbox" name="editoption" value="false">Edit after creation'.$editoption.'</td>';
echo ' <td><input type="submit" name="create" value="Template it now"></td>';
echo ' </tr>';
echo ' </table>';
echo ' </td>';
echo ' </tr>';
echo '</table>';


Revision [3438]

Edited on 2004-12-18 14:26:10 by NilsLindenberg [re-changed code length, change to my remarks]
Additions:
echo ' <td><input type="text" name="from" size="37">'.$from.'</td>';
echo ' <td><input type="text" name="to" size="37">'.$to.'</td>';
1) There was an ?> missing at the end
1) The length for a page can be 75 chars, ++I changed your value to that++ just keep that in mind, cuase it means scrolling now for names >37
1) if you have much output, more simple than putting out all with echo is to leave php.
Deletions:
echo ' <td><input type="text" name="from" size="75">'.$from.'</td>';
echo ' <td><input type="text" name="to" size="75">'.$to.'</td>';
1) You had forgotten to close the php, I have fixed that
1) The length for a page can be 75 chars, I changed your value to that
1) The way you wan't to output the params doesn't work.


Revision [3437]

Edited on 2004-12-18 14:16:41 by DarTar [adding some ideas]
Additions:
~~-Should this really be an //action//? Why not a handler?


Revision [3436]

Edited on 2004-12-18 14:13:57 by DarTar [adding some ideas]
Additions:
~
~''I like the idea too. A couple of general remarks:
~~-What about adding a menu to allow the user to choose the source page from one of the existing pages? This might avoid checking for page existence''
~~-I think that the concept of **template** is associated in general to something quite different from what you are proposing here. What about using a name suggesting page //exporting//,//duplicating// or //cloning//?
~DarTar''


Revision [3432]

Edited on 2004-12-18 14:01:31 by NilsLindenberg [adding some ideas]
Additions:
Update: Ok, I finally found out what I made wrong. My mistake: the txt files on this pc are connected with wordpad, not with notepad. I hadn't looked after that and so saved the files with useless renderings *bangs head against wall*. But after that, I found some points in your script:
1) You had forgotten to close the php, I have fixed that
1) The length for a page can be 75 chars, I changed your value to that
1) The way you wan't to output the params doesn't work.
--NilsLindenberg


Revision [3431]

Edited on 2004-12-18 13:54:53 by NilsLindenberg [codechange: closed php, changed pagelength to 75]
Additions:
echo ' <td><input type="text" name="from" size="75">'.$from.'</td>';
echo ' <td><input type="text" name="to" size="75">'.$to.'</td>';
?>
Deletions:
echo ' <td><input type="text" name="from" size="37">'.$from.'</td>';
echo ' <td><input type="text" name="to" size="37">'.$to.'</td>';


Revision [3384]

Edited on 2004-12-17 20:38:20 by JavaWoman [arrgh! ypots in reply to Christian]
Additions:
~''I've been tweaking the code a bit but haven't actually tested anything yet; I'm afraid I have a few more urgent things on my list right now (such as finishing WikkaGeSHiIntegration with install/update). I **will** get back to this though, promise, since I think it's very useful! --JavaWoman''
Deletions:
~''I've been tweaking the code a bit but haven't actually tested anything yet; I'm afraid I have a few more urgent things on my list right now (such as finishing WikkGeSHiIntegration with install/update). I *will* get back to this though, promise, since I think it's very useful! --JavaWoman''


Revision [3383]

Edited on 2004-12-17 20:36:57 by JavaWoman [reply to Christian (& sorting out conversation 'colors')]
Additions:
--NilsLindenberg''
''Yepp, I always copy from the source. --NilsLindenberg''
~Do you still have the same error with the new code? --ChristianBarthelemy
~~~''I have to try later, they don't trust me that much in the university, to allow ftp access to pages. And I haven't worked out how I should explain wikka as an essentail part of my studies ;-). I'll check later. --NilsLindenberg''
~~~''Ok, I tried the new code, but it hasn't changed anything. I tried simple opage names like NewPage, ""NewerPage"" etc. even adding ""{{template}}"" gives that error. --NilsLindenberg''
~~~~Which Wikka version are you using? I do not see any reason for such an error. I replaced the template.php version from my server with a copy from this page to a new txt notepad file, renamed into template.php placed it in the action folder and it worked.
Any one else tried it? --ChristianBarthelemy
~''I've been tweaking the code a bit but haven't actually tested anything yet; I'm afraid I have a few more urgent things on my list right now (such as finishing WikkGeSHiIntegration with install/update). I *will* get back to this though, promise, since I think it's very useful! --JavaWoman''
You of course have my blessing - This code surely needs some revamping and I will be more than happy that we get something cleaner --ChristianBarthelemy
Deletions:
--NilsLindenberg
Yepp, I always copy from the source. --NilsLindenberg
~"Do you still have the same error with the new code? --ChristianBarthelemy"
~~~I have to try later, they don't trust me that much in the university, to allow ftp access to pages. And I haven't worked out how I should explain wikka as an essentail part of my studies ;-). I'll check later. --NilsLindenberg
~~~Ok, I tried the new code, but it hasn't changed anything. I tried simple opage names like NewPage, ""NewerPage"" etc. even adding ""{{template}}"" gives that error. --NilsLindenberg
~~~~"Which Wikka version are you using? I do not see any reason for such an error. I replaced the template.php version from my server with a copy from this page to a new txt notepad file, renamed into template.php placed it in the action folder and it worked.
Any one else tried it? --ChristianBarthelemy"
''You of course have my blessing - This code surely needs some revamping and I will be more than happy that we get something cleaner --ChristianBarthelemy''


Revision [3378]

Edited on 2004-12-17 18:39:48 by ChristianBarthelemy [Anyone else tried it?]
Additions:
~~~~"Which Wikka version are you using? I do not see any reason for such an error. I replaced the template.php version from my server with a copy from this page to a new txt notepad file, renamed into template.php placed it in the action folder and it worked.
Any one else tried it? --ChristianBarthelemy"


Revision [3375]

Edited on 2004-12-17 18:05:20 by NilsLindenberg [error hasn't changed]
Additions:
~~~Ok, I tried the new code, but it hasn't changed anything. I tried simple opage names like NewPage, ""NewerPage"" etc. even adding ""{{template}}"" gives that error. --NilsLindenberg


Revision [3364]

Edited on 2004-12-17 14:34:21 by JavaWoman [reply to Nils]
Additions:
~~~~''1. Are you **entering** something in the form or as an action attribute that contains a ""\""? There's not even a ""\"" in the code that I can see. If so, try ""/"" as a path separator instead.
~~~~2. Wikka for studies - maybe this helps? [[http://shirky.com/writings/group_user.html Group as User: Flaming and the Design of Social Software]] - by Clay Shirky; I guess you're doing a field study? ;-) --JavaWoman''


Revision [3355]

Edited on 2004-12-17 14:04:32 by NilsLindenberg [reply to Christian]
Additions:
~~~I have to try later, they don't trust me that much in the university, to allow ftp access to pages. And I haven't worked out how I should explain wikka as an essentail part of my studies ;-). I'll check later. --NilsLindenberg


Revision [3352]

Edited on 2004-12-17 13:55:06 by ChristianBarthelemy [Question to Nils]
Additions:
~"Do you still have the same error with the new code? --ChristianBarthelemy"


Revision [3351]

Edited on 2004-12-17 13:36:14 by NilsLindenberg [reply to JW]
Additions:
Parse error: parse error, unexpected T_STRING in /.../actions/template.php on line 2"
--NilsLindenberg
Yepp, I always copy from the source. --NilsLindenberg
Deletions:
Parse error: parse error, unexpected T_STRING in /.../actions/template.php on line 2
--NilsLindenberg''


Revision [3331]

Edited on 2004-12-16 19:27:08 by ChristianBarthelemy [Help is welcome]
Additions:
''You of course have my blessing - This code surely needs some revamping and I will be more than happy that we get something cleaner --ChristianBarthelemy''


Revision [3330]

Edited on 2004-12-16 19:22:02 by JavaWoman [New (replaced) comment after code change]
Additions:
''(After code change) Christian, OK, I see the intention now. And I like it a lot! Unfortunately, the code isn't quite correct - mind if I take a stab at clearing it up?
Nils, I don't have a clue how you can get that error; did you grab the code from the page source? --JavaWoman.''
Deletions:
''Poking through the code ... you are (also) grabbing the $to variable from a URL parameter; I don't undertand what the intention of that is or how to use it - can you give an example? --JavaWoman''
''Scratch that - I see you're using method GET in the form (POST is better and more secure); but I **don't** see you picking up the parameters from the action itself, or am I missing something again? --JavaWoman''


Revision [3327]

Edited on 2004-12-16 19:00:17 by ChristianBarthelemy [Shoold be ok now - it worked for me but the new code is clearer...]
Additions:
* @version 0.2
// ***** INPUT FORM *****
echo $this->FormOpen();
echo ' <th align="left">WikiPage to be templated (empty means this page):</th>';
echo ' <td><input type="text" name="from" size="37">'.$from.'</td>';
echo ' <th align="left">WikiPage to be created:</th>';
echo ' <td><input type="text" name="to" size="37">'.$to.'</td>';
echo ' <th align="left">Added note to your edit:</th>';
echo ' <td><input type="text" name="note" size="37">'.$note.'</td>';
echo ' <th align="left">Do you want to edit the new page when created?</th>';
echo ' <td><input type="checkbox" name="editoption" value="false">Edit after creation'.$editoption.'</td>';
echo $this->FormClose();
// ***** END INPUT FORM *****
// ***** GET PARAMETERS *****
$from = $_POST["from"];
$to = $_POST["to"];
$note = $_POST["note"];
$editoption = $_POST["editoption"];
// ***** END PARAMETERS *****
// ***** TEMPLATING PROCESS *****
// The user must provide a WikiPage name to be created...
// and it should be a new one...
// also the user has to be allowed to create this page...
// The user should provide a WikiPage name to be duplicated...
if (!$from)
// by default the system will duplicate the current page...
// otherwise, the page to be dublicated must of course exit...
if ($this->ExistsPage($from))
// and the user has to be allowed to read it...
if (!$this->HasAccess("read", $from))
// this is what happens if the user tries to duplicate a non existing page...
// the user may provide a creation note otherwise...
if (!$note)
// the system will create one by default...

$thepage=$this->LoadPage($from); // load the page that has to be duplicated...
if ($thepage) $pagecontent = $thepage["body"]; // and get its content.
$this->SavePage($to, $pagecontent, $note); // creates the page...
echo "[[ ".$to." has been created from ".$from." and note was: ".$note." ]]"; // confirms what has been done
if ($editoption) $this->redirect(BASE_URL.$to."/edit"); // drops the user to the new page for edition if he choosed so
// this is what happens if you try to create a page when you are not authorized.
// ***** END TEMPLATING PROCESS *****
Deletions:
* @version 0.1
echo '<form action="" method="get">';
$result .= "<input type=\"hidden\" name=\"wakka\" value=\"".$this->MiniHref()."\">\n";
echo $result;
//echo $this->FormClose();
echo ' <th align=left>WikiPage to be templated (empty means this page):</th>';
echo ' <td><input type="text" name="from" size="37"></td>';
echo ' <th align=left>WikiPage to be created:</th>';
echo ' <td><input type="text" name="to" size="37"></td>';
echo ' <th align=left>Added note to your edit:</th>';
echo ' <td><input type="text" name="note" size="37"></td>';
echo ' <th align=left>Do you want to edit the new page when created?</th>';
echo ' <td><input type="radio" name="editoption" value="false" checked>No</td>';
echo ' <td><input type="radio" name="editoption" value="true">Yes</td>';
echo '</form>';
$to = $_GET['to'];
// get and interpret parameters
// overrride defaults with parameters provided (accept only valid values)
$uFrom = $_GET['from'];
if ($uFrom)
if ($this->ExistsPage($uFrom))
if ($this->HasAccess("read", $uFrom))
$from = $uFrom;
else
$uNote = $_GET['note'];
if (uNote) $note = $uNote;
$uEditoption = $_GET['editoption'];
if (uEditoption != "") $editoption = $uEditoption;
// ***** END (ACTION) PARAMETERS *****
$thepage=$this->LoadPage($from);
if ($thepage) $pagecontent = $thepage["body"];
$this->SavePage($to, $pagecontent, $note);
echo "[[".$to." has been created from ".$from." and note was: ".$note." ]]";
if ($editoption) $this->redirect(BASE_URL.$to."/edit");

function IsWikiName($text) { return preg_match("/^[A-Z,ÄÖÜ][a-z,ßäöü]+[A-Z,0-9,ÄÖÜ][A-Z,a-z,0-9,ÄÖÜ,ßäöü]*$/", $text); }


Revision [3324]

Edited on 2004-12-16 16:35:26 by JavaWoman [another question]
Additions:
''Scratch that - I see you're using method GET in the form (POST is better and more secure); but I **don't** see you picking up the parameters from the action itself, or am I missing something again? --JavaWoman''


Revision [3317]

Edited on 2004-12-16 15:48:45 by JavaWoman [question as to usage]
Additions:
''I get the following error (just copied the code to template.php and tried the syntax you gave):
--NilsLindenberg''
''Poking through the code ... you are (also) grabbing the $to variable from a URL parameter; I don't undertand what the intention of that is or how to use it - can you give an example? --JavaWoman''
CategoryDevelopment
Deletions:
I get the following error (just copied the code to template.php and tried the syntax you gave):
--NilsLindenberg
CategoryDevelopment


Revision [3314]

Edited on 2004-12-16 15:10:13 by NilsLindenberg [error or am I to blind to copy?]
Additions:
I get the following error (just copied the code to template.php and tried the syntax you gave):
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /.../actions/template.php on line 2
Parse error: parse error, unexpected T_STRING in /.../actions/template.php on line 2
--NilsLindenberg


Revision [3309]

Edited on 2004-12-16 14:32:30 by ChristianBarthelemy [Template action code]
Additions:
===The code===
Copy this code into an action named: template.php - place it in the actions folder.
%%(php)
<?php
/**
* Duplicate a "template" page to a new named page
*
* Usage: {{template from="OldPage" to="NewPage" editoption="true"}}
*
* This action checks the existence of the template page, the non existence of the page to be created, the user
* right to read the template and the user right to create a page.
* The editoption when true will create the new page and then open it for edition.
*
*
* @package Actions
* @subpackage
* @name template
*
* @author {@link http://wikka.jsnx.com/ChristianBarthelemy Christian Barthelemy}
* @version 0.1
* @since Wikka 1.1.5.3
*
* @input string $from optional: the template page to be duplicated
* must be an existing page and must be authorized for reading to the current user
* defaulted to the current WikiPage
*
* @input string $to mandatory: the page to be created
* must be a non existing page and current user must be authorized to create
*
* @input string $note optional: the note to be added to the page when created
* default is "Templated from " followed by the name of the template page
*
* @input boolean $editoption optional: if true, the newly created page will be opened for edition
* default is false
*/
// ***** CONSTANTS *****
define ('USER_NAME',$this->GetUserName());
define ('BASE_URL',$this->config['base_url']);
// ***** END CONSTANTS *****
echo '<form action="" method="get">';
$result .= "<input type=\"hidden\" name=\"wakka\" value=\"".$this->MiniHref()."\">\n";
echo $result;
//echo $this->FormClose();
echo '<table class="template" border="1">';
echo ' <tr>';
echo ' <th align=left>WikiPage to be templated (empty means this page):</th>';
echo ' <td><input type="text" name="from" size="37"></td>';
echo ' </tr>';
echo ' <tr>';
echo ' <th align=left>WikiPage to be created:</th>';
echo ' <td><input type="text" name="to" size="37"></td>';
echo ' </tr>';
echo ' <tr>';
echo ' <th align=left>Added note to your edit:</th>';
echo ' <td><input type="text" name="note" size="37"></td>';
echo ' </tr>';
echo ' <tr>';
echo ' <th align=left>Do you want to edit the new page when created?</th>';
echo ' <td>';
echo ' <table border="1">';
echo ' <tr>';
echo ' <td><input type="radio" name="editoption" value="false" checked>No</td>';
echo ' <td><input type="radio" name="editoption" value="true">Yes</td>';
echo ' <td><input type="submit" name="create" value="Template it now"></td>';
echo ' </tr>';
echo ' </table>';
echo ' </td>';
echo ' </tr>';
echo '</table>';
echo '</form>';
$to = $_GET['to'];
If ($to<>"") {
if ($this->ExistsPage($to))
{
$errormessage = "The destination page must not exist.";
echo $errormessage;
return;
}
elseif ($this->HasAccess("write", $to)) {
// get and interpret parameters
// overrride defaults with parameters provided (accept only valid values)
$uFrom = $_GET['from'];
if ($uFrom)
{
if ($this->ExistsPage($uFrom))
{
if ($this->HasAccess("read", $uFrom))
{
$from = $uFrom;
}
else
{
$errormessage = "You are not authorized to use the template page.";
echo $errormessage;
return;
}
}
else
{
$errormessage = "The template page does not exist.";
echo $errormessage;
return;
}
}
else
{
$from = $this->GetPageTag();
}
$uNote = $_GET['note'];
if (uNote) $note = $uNote;
else
{
$note = "Templated from ".$from;
}
$uEditoption = $_GET['editoption'];
if (uEditoption != "") $editoption = $uEditoption;
// ***** END (ACTION) PARAMETERS *****
// ***** DERIVED VARIABLES *****
$thepage=$this->LoadPage($from);
if ($thepage) $pagecontent = $thepage["body"];
// ***** END DERIVED VARIABLES *****

// ***** OUTPUT SECTION *****
$this->SavePage($to, $pagecontent, $note);
echo "[[".$to." has been created from ".$from." and note was: ".$note." ]]";
if ($editoption) $this->redirect(BASE_URL.$to."/edit");

// ***** END OUTPUT SECTION *****
} else
{
$errormessage = "You are not authorized to create the destination page.";
echo $errormessage;
return;
}
}

/**
function IsWikiName($text) { return preg_match("/^[A-Z,ÄÖÜ][a-z,ßäöü]+[A-Z,0-9,ÄÖÜ][A-Z,a-z,0-9,ÄÖÜ,ßäöü]*$/", $text); }
*/
%%
===How to use it?===
Once you have (re)designed a page that fits to be replicated many times (Task Lists, User Pages, Bug Description, Developement Description...) you just have to use the ""{{template}}"" action from any page: you may want to have a dedicated TemplatePage with the action and the instructions on it (I will propose one if this action can be installed on the Wikka server).
Then you must fill the name of the new WikiPage to be created, if you do not fill the name of the page that has to be duplicated the system will duplicate the current page, you may want to add a note, finally you decide if you just want to create the page or if you want to jump and edit it as soon as it has been copied.
===To Do===
My code needs probably to be reviewed by expert coder as I am not at all a developper.
Any ideas around this action more than welcome.
Deletions:
===So what?===
I am currently testing the action, and will post it there tomorrow.


Revision [3300]

Edited on 2004-12-16 11:11:13 by ChristianBarthelemy [WikiTemplate soon available]
Additions:
I am currently testing the action, and will post it there tomorrow.
Deletions:
I don't know anything about php and mysql but it doesn't look difficult so I will certainly build this soon.. except if some expert one provides some suitable code here.


Revision [2838]

Edited on 2004-12-04 14:42:06 by NilsLindenberg [header changed, cat. added]
Additions:
====Templates====
===My solution===
===So what?===
I don't know anything about php and mysql but it doesn't look difficult so I will certainly build this soon.. except if some expert one provides some suitable code here.
----
CategoryDevelopment
Deletions:
====The problem====
====My solution====
====So what?====
I don't know anything about php and mysql but it doesn't look difficult so I will certainly build this soon.. except if some expert one provides some suitable code here.


Revision [2808]

The oldest known version of this page was created on 2004-12-03 19:01:56 by ChristianBarthelemy [header changed, cat. added]
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki