====== Edit Section Reorganizer Plugin ======
---- plugin ----
description: Move section edit buttons to the start of the section, support hierarchical sections on edit
author : Ben Coburn
email : btcoburn@silicodon.net
type : action
lastupdate :
compatible : 2006-05-23+, 2006-11-06
depends :
conflicts :
similar :
tags : gui, sectionediting, edit, section
----
The [[:plugin:editsections|Edit Section Reorganizer Plugin]] is identified as "editsections" in the [[:plugin:plugin|Plugin Manager]].
The "editsections" plugin moves edit section buttons up to the heading they originated from. Configurable for nested (hierarchical) or flat edit sections. Nested edit sections cover the same indentation level as their heading. Requires a DokuWiki version from 2006-05-23 or newer. Works with the current((2006-11-06)) release.
===== Installing =====
==== Plugin Manager ====
Use the [[:plugin:plugin|Plugin Manager]] to install this plugin from the following link:
http://source.silicodon.net/releases/dokuwiki-plugins/edit-section-reorganizer/editsections.tgz
==== Manually ====
It also can be downloaded manually from:
http://source.silicodon.net/releases/dokuwiki-plugins/edit-section-reorganizer/
Unpack and place the "editsections" folder into the ''/lib/plugins/'' directory of your DokuWiki installation.
===== Technical Notes =====
This plugin uses an [[:wiki:events_list|action event]] to do some clever things with the [[:wiki:parser|instruction list]] before it gets rendered into XHTML. This also means that the work of this plugin is cached in the stored instructions saved after parsing a wiki page. The work of this plugin is greatly simplified by the use of [[http://www.php.net/references|references]]. Note that ''$edits'' is an array of references to the subset of [[:wiki:parser|instructions]] that need to be changed. The small CSS adjustment is used to clearly associate the edit section buttons with their headings.
==== Source ====
__''action.php''__
'Ben Coburn',
'email' => 'btcoburn@silicodon.net',
'date' => '2006-05-23',
'name' => 'Edit Section Reorganizer',
'desc' => 'Moves edit section buttons up to the heading they originated from. '.
'Configurable for nested (hierarchical) or flat edit sections. '.
'Requires the development version of DokuWiki from 2006-05-23 or a later release.',
'url' => 'http://source.silicodon.net/releases/dokuwiki-plugins/edit-section-reorganizer/editsections.tgz',
);
}
function register(&$controller) {
$controller->register_hook('PARSER_HANDLER_DONE', 'BEFORE', $this, 'rewrite_sections');
}
function rewrite_sections(&$event, $ags) {
// get the instructions list from the handler
$calls =& $event->data->calls;
$edits = array();
$order = $this->getConf('order_type');
// scan instructions for edit sections
$size = count($calls);
for ($i=0; $i<$size; $i++) {
if ($calls[$i][0]=='section_edit') {
$edits[] =& $calls[$i];
}
}
// rewrite edit section instructions
$last = max(count($edits)-1,0);
for ($i=0; $i<=$last; $i++) {
$end = 0;
// get data to move
$start = $edits[min($i+1,$last)][1][0];
$level = $edits[min($i+1,$last)][1][2];
$name = $edits[min($i+1,$last)][1][3];
// find the section end point
if ($order) {
$finger = $i+2;
while (isset($edits[$finger]) && $edits[$finger][1][2]>$level) {
$finger++;
}
if (isset($edits[$finger])) {
$end = $edits[$finger][1][0]-1;
}
} else {
$end = $edits[min($i+1,$last)][1][1];
}
// put the data back where it belongs
$edits[$i][1][0] = $start;
$edits[$i][1][1] = $end;
$edits[$i][1][2] = $level;
$edits[$i][1][3] = $name;
}
$edits[max($last-1,0)][1][1] = 0; // set new last section
$edits[$last][1][0] = -1; // hide old last section
}
}
__''all.css''__
/*
Makes the default template display much better with this plugin.
If using other templates, you may want to make your own adjustments.
This moves the section edit button down onto the same "line" as the header
that it belongs to.
Note: Adding the 'body' selector makes these rules more specific, and so
ensures that they will augment DokuWiki's 'secedit' css rules. You should
be able to override this by adding the 'html' selector to the 'secedit' css
rules in your template.
*/
body div.dokuwiki div.secedit {
overflow: visible;
}
body div.dokuwiki div.secedit input.button {
margin-top: 1.25em;
}
===== Discussion =====
:?: Is it possible to place the edit button exactly under the ... instead of above?
> Try adjusting the CSS styles of your template.... The buttons are rendered above the headers in the XHTML, so there is only so much the CSS styles can do. A float left and increased top margin may help. See http://www.w3.org/TR/REC-CSS2/
>>I tried this. The problem is that i use different margin-top for the headings. That does not look good, if the buttons are always somewhere else. The Plugin himself has to place the button differently. Because margin-bottom is for all headings the same. I tried to change the php-code of ''editsections''..... without success.
> I am also interessted in this. Is there a workaround?
:?: I am using the dokucms template. The edit button is being placed directly on the header line. I have tried editing the design.css file, but I can only move the edit button to left.
==== Replace to Header ====
I found a way, but probably not the best one.
And you must change a Dokuwiki original file.
I am not a good PHP programmer! a Dokuwiki pro should verify it.
== /inc/parser/xhtml.php: ORIGINAL ==
function header($text, $level, $pos) {
global $conf;
// create a unique header id
$hid = $this->_headerToLink($text,'true');
//handle TOC
if($level >= $conf['toptoclevel'] && $level <= $conf['maxtoclevel']){
// the TOC is one of our standard ul list arrays ;-)
$this->toc[] = array( 'hid' => $hid,
'title' => $text,
'type' => 'ul',
'level' => $level-$conf['toptoclevel']+1);
}
// write the header
$this->doc .= DOKU_LF.'';
$this->doc .= $this->_xmlEntities($text);
$this->doc .= "".DOKU_LF;
}
/**
* Section edit marker is replaced by an edit button when
* the page is editable. Replacement done in 'inc/html.php#html_secedit'
*
* @author Andreas Gohr
* @author Ben Coburn
*/
function section_edit($start, $end, $level, $name) {
global $conf;
if ($start!=-1 && $level<=$conf['maxseclevel']) {
$name = str_replace('"', '', $name);
$this->doc .= '';
}
}
== /inc/parser/xhtml.php: NEW ==
function header($text, $level, $pos) {
global $conf;
// create a unique header id
$hid = $this->_headerToLink($text,'true');
//handle TOC
if($level >= $conf['toptoclevel'] && $level <= $conf['maxtoclevel']){
// the TOC is one of our standard ul list arrays ;-)
$this->toc[] = array( 'hid' => $hid,
'title' => $text,
'type' => 'ul',
'level' => $level-$conf['toptoclevel']+1);
}
// write the header
$this->doc .= DOKU_LF.'';
$this->doc .= $this->_xmlEntities($text);
if($conf['editsectionreplace']) { // +++ New
if ($start!=-1 && $level<=$conf['maxseclevel']) {
//$this->doc .= ''.""."".DOKU_LF;
$this->doc .= "".''."".DOKU_LF;
//$this->doc .= ""."".''.DOKU_LF;
}else{
$this->doc .= "".DOKU_LF;
}
}else{ // +++ original
$this->doc .= "".DOKU_LF;
}
}
/**
* Section edit marker is replaced by an edit button when
* the page is editable. Replacement done in 'inc/html.php#html_secedit'
*
* @author Andreas Gohr
* @author Ben Coburn
*/
function section_edit($start, $end, $level, $name) {
global $conf;
if($conf['editsectionreplace']) { // +++ New
if ($start!=-1 && $level<=$conf['maxseclevel']) {
$name = str_replace('"', '', $name);
$this->doc = str_replace('', '', $this->doc);
}else{
$this->doc = str_replace('', '', $this->doc);
}
}else{ // +++ original
if ($start!=-1 && $level<=$conf['maxseclevel']) {
$name = str_replace('"', '', $name);
$this->doc .= '';
}
}
}
== /conf/local.php: Option-Add ==
insert this:\\
(=1 On, =0 Off)
$conf['editsectionreplace'] = 1;
----
====== dokuwiki-rc2007-05-24 ======
I just upgraded my dokuwiki [[http://www.patentblurb.com/ | site]] and found that this plug in seems to work, with the same problemas before, i.e., the edit button is positioned above the header line. I found that the ORIGINAL xhtml.php fix works to place it in-line with the first row of the header (which looks great when the header is only on one line). The modified xhtml.php fix places it **below** the header line. --- //[[lenehey@gmail.com|Lenny]] 2007-05-27 16:07//
>i don't understand exactly what you min, but the position of the edit button can by selected by activating one of this 3 lines.
you can experiment wit this an activate ONE of the lines.
what is the result you want? (rc2007-05-24 no tested)
//$this->doc .= ''.""."".DOKU_LF;
$this->doc .= "".''."".DOKU_LF;
//$this->doc .= ""."".''.DOKU_LF;
====== dokuwiki-2007-06-26 ======
The plugin works without any changes (header). Be sure to touch one of the config files to purge the cache - otherwise you won't see the change instantly.
====== dokuwiki-2008-05-05 ======
I have a new version of the code above, which works with DokuWiki 2008-05-05, and moves the button up so that it is right next to the headers. Note this gets rid of the config option, to make the code a bit simpler. If you're making this mod, I'm going to assume that you want it turned on. :-)
== /inc/parser/xhtml.php: ORIGINAL ==
function header($text, $level, $pos) {
$hid = $this->_headerToLink($text,true);
//only add items within configured levels
$this->toc_additem($hid, $text, $level);
// write the header
$this->doc .= DOKU_LF.'';
$this->doc .= $this->_xmlEntities($text);
$this->doc .= "".DOKU_LF;
}
/**
* Section edit marker is replaced by an edit button when
* the page is editable. Replacement done in 'inc/html.php#html_secedit'
*
* @author Andreas Gohr
* @author Ben Coburn
*/
function section_edit($start, $end, $level, $name) {
global $conf;
if ($start!=-1 && $level<=$conf['maxseclevel']) {
$name = str_replace('"', '', $name);
$this->doc .= '';
}
}
== /inc/parser/xhtml.php: NEW ==
function header($text, $level, $pos) {
global $conf; /* NEW */
$hid = $this->_headerToLink($text,true);
//only add items within configured levels
$this->toc_additem($hid, $text, $level);
// write the header
/* NEW */
if ($level<=$conf['maxseclevel'])
$this->doc .= DOKU_LF.''.'';
else
$this->doc .= DOKU_LF.'';
/* /NEW */
$this->doc .= $this->_xmlEntities($text);
$this->doc .= "".DOKU_LF;
}
/**
* Section edit marker is replaced by an edit button when
* the page is editable. Replacement done in 'inc/html.php#html_secedit'
*
* @author Andreas Gohr
* @author Ben Coburn
*/
function section_edit($start, $end, $level, $name) {
global $conf;
/* NEW */
if ($start!=-1 && $level<=$conf['maxseclevel']) {
$name = str_replace('"', '', $name);
$this->doc = str_replace('', '', $this->doc);
} else {
$this->doc = str_replace('', '', $this->doc);
}
/* /NEW */
}
I actually found that moved the buttons up a bit too high, so you may want to put in some CSS in your template with a ''margin-top''
div.dokuwiki div.secedit input.button {
border-color: __form_border__;
font-size: 100%;
/* NEW */
margin-top:10px;
/* NEW */
}
Using the monobook-template, how could I fix the position of the edit-button? Where would I place a css-file, and what would it be named and what would I type into it? :-)
[[Marc.Jedamzik@hil.interpane.net|Jedamzik, Marc]]