DokuWiki

It's better when it's simple

User Tools

Site Tools


plugin:editsections

Edit Section Reorganizer Plugin

Compatible with DokuWiki

2006-05-23+, 2006-11-06, 2009-12-25 2010-11-07

plugin Move section edit buttons to the start of the section, support hierarchical sections on edit

Last updated on
2010-11-28
Provides
Action
Repository
Source

This extension has not been updated in over 2 years. It may no longer be maintained or supported and may have compatibility issues.

Similar to editsections2

Tagged with !discontinued, editing, section

Obsolete

This plugin is now obsolete and won't be maintained as I don't use it anymore (at least by me, Christophe Drevet 14-10-2012). This other plugin can be used (didn't try it, though) plugin Editsections2, developed on https://github.com/kazmiya/dokuwiki-plugin-editsections2

See plugin Editsections2

Plugin

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.

Since 2010-11-07 dokuwiki release, this plugin can't store useful things in the cache. So, there is an option to disable cache (only for writers) in order to use all features :

  • nested editing
  • names in the summary

The Edit Section Reorganizer Plugin is identified as “editsections” in the Plugin Manager.

Installing

Plugin Manager

Use the Plugin Manager to install this plugin from the following link:
https://github.com/dr4Ke/editsections/tarball/master

Manually

It also can be downloaded manually from the same URL.

Unpack and place the “editsections” folder into the /lib/plugins/ directory of your DokuWiki installation.

Technical Notes

This plugin uses action events to do some clever things with the 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 references. Note that $edits is an array of references to the subset of instructions that need to be changed. The small CSS adjustment is used to clearly associate the edit section buttons with their headings. A JS script is used to adjust hightlighting accordingly.

Source

New sources are now freely available at github

Old source :

action.php
<?php
 
// must be run within DokuWiki
if(!defined('DOKU_INC')) die();
 
if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
require_once(DOKU_PLUGIN.'action.php');
 
class action_plugin_editsections extends DokuWiki_Action_Plugin {
 
	function getInfo(){
		return array(
			'author' => '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(Doku_Event_Handler $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 <H?>…</H?> 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 interested 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, so 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.'<h'.$level.'><a name="'.$hid.'" id="'.$hid.'">';
        $this->doc .= $this->_xmlEntities($text);
        $this->doc .= "</a></h$level>".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 <andi@splitbrain.org>
     * @author Ben Coburn   <btcoburn@silicodon.net>
     */
    function section_edit($start, $end, $level, $name) {
        global $conf;
 
        if ($start!=-1 && $level<=$conf['maxseclevel']) {
            $name = str_replace('"', '', $name);
            $this->doc .= '<!-- SECTION "'.$name.'" ['.$start.'-'.(($end===0)?'':$end).'] -->';
        }
    }
/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.'<h'.$level.'><a name="'.$hid.'" id="'.$hid.'">';
        $this->doc .= $this->_xmlEntities($text);
if($conf['editsectionreplace']) { // +++ New
        if ($start!=-1 && $level<=$conf['maxseclevel']) {
            //$this->doc .= '<!-- +!SECTION!+ -->'."</a>"."</h$level>".DOKU_LF;
            $this->doc .= "</a>".'<!-- +!SECTION!+ -->'."</h$level>".DOKU_LF;
            //$this->doc .= "</a>"."</h$level>".'<!-- +!SECTION!+ -->'.DOKU_LF;
        }else{
            $this->doc .= "</a></h$level>".DOKU_LF;
        }
}else{ // +++ original
        $this->doc .= "</a></h$level>".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 <andi@splitbrain.org>
     * @author Ben Coburn   <btcoburn@silicodon.net>
     */
    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('<!-- +!SECTION!+ -->', '<!-- SECTION "'.$name.'" ['.$start.'-'.(($end===0)?'':$end).'] -->', $this->doc);
        }else{
            $this->doc = str_replace('<!-- +!SECTION!+ -->', '', $this->doc);
        }
}else{ // +++ original
        if ($start!=-1 && $level<=$conf['maxseclevel']) {
            $name = str_replace('"', '', $name);
            $this->doc .= '<!-- SECTION "'.$name.'" ['.$start.'-'.(($end===0)?'':$end).'] -->';
        }
}
 
    }
/conf/local.php: Option-Add

insert this:
(=1 On, =0 Off)

$conf['editsectionreplace'] = 1;

dokuwiki-rc2007-05-24

I just upgraded my DokuWiki site and found that this plug in seems to work, with the same problems as 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. — 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 .= '<!-- +!SECTION!+ -->'."</a>"."</h$level>".DOKU_LF;
        $this->doc .= "</a>".'<!-- +!SECTION!+ -->'."</h$level>".DOKU_LF;
        //$this->doc .= "</a>"."</h$level>".'<!-- +!SECTION!+ -->'.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.'<h'.$level.'><a name="'.$hid.'" id="'.$hid.'">';
        $this->doc .= $this->_xmlEntities($text);
        $this->doc .= "</a></h$level>".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 <andi@splitbrain.org>
     * @author Ben Coburn   <btcoburn@silicodon.net>
     */
    function section_edit($start, $end, $level, $name) {
        global $conf;
 
        if ($start!=-1 && $level<=$conf['maxseclevel']) {
            $name = str_replace('"', '', $name);
            $this->doc .= '<!-- SECTION "'.$name.'" ['.$start.'-'.(($end===0)?'':$end).'] -->';
 
        }
    }
/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.'<!-- +!SECTION!+ -->'.'<h'.$level.'><a name="'.$hid.'" id="'.$hid.'">';
        else
	  $this->doc .= DOKU_LF.'<h'.$level.'><a name="'.$hid.'" id="'.$hid.'">';
	/* /NEW */
        $this->doc .= $this->_xmlEntities($text);
        $this->doc .= "</a></h$level>".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 <andi@splitbrain.org>
     * @author Ben Coburn   <btcoburn@silicodon.net>
     */
    function section_edit($start, $end, $level, $name) {
        global $conf;
 
	/* NEW */
	if ($start!=-1 && $level<=$conf['maxseclevel']) {
            $name = str_replace('"', '', $name);
            $this->doc = str_replace('<!-- +!SECTION!+ -->', '<!-- SECTION "'.$name.'" ['.$start.'-'.(($end===0)?'':$end).'] -->', $this->doc);
        } else {
            $this->doc = str_replace('<!-- +!SECTION!+ -->', '', $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? :-)

Jedamzik, Marc

DokuWiki-2009-12-25

The plugin installs and seems to work fine. But DokuWiki has a nice new feature: section highlighting. Section highlighting is built so it highlights the section above the button, this also needs a change after installing this plugin: the section below needs highlighting now. How could I fix this? — Klap-in 2010/01/02 01:49

@Klap-in: You can do this by changing the addInitEvent() function in lib/scripts/script.js. Simply replace any instance of previousSibling with nextSibling in that function (there are four places it needs to be changed) – DLO 5-Feb-2010

@DLO: Thanks, it works for the flat usage of this plugin. I added a script.js that works with both settings (flat and nested), a french translation and made a few other modifications and published a new version of this plugin. It can be downloaded at : https://github.com/downloads/dr4Ke/editsections/editsections.tar.gzdr4Ke 11 May 2010

DokuWiki-2010-11-07

The plugin doesn't work as section editing is now managed by the renderer.

That's really a shame. Perhaps this functionality should be included as an option in Dokuwiki? – Lackbeard 12 Nov 2010

Same for me, after editing a page every edit links on the page disappears, It's a shame because this functionality is really useful.
It works now (release 2010-11-28) but can't make use of the cache. Work is in progress to either include the functionality in dokuwiki or add more hooks. – Christophe Drevet 28-11-2010
After updating and enabling the plugin the title in the browser title bar disapear, the <title> markup in the <header> is empty, but now I can edit the section correctly.
After installing “Anteater” and then updating the editsections plug to the code in GitHub, and setting cache=disabled I have the same experience: The highlighting of sections and editing the correct section works, but the page title no longer displays and the breadcrumb is blank. Hopefully there will be a fix soon because I can't figure out why this is happening. – Dan Kirkdorffer 14-Apr-2011
I didn't have time to work on it since a while. When I was asking for help on the dev mailing list, Kazmiya told me he has written another version of this plugin. Maybe it is better than mine, I didn't try it. Anyway, here it is : https://github.com/kazmiya/dokuwiki-plugin-editsections2Christophe Drevet 14-04-2011
Actually I looked through the code and realized that if I set my Display Settings configuration for “Use first heading for pagenames” from “Always” to “Never”, that the page headers and breadcrumb once again work. – Dan Kirkdorffer 14-Apr-2011
I've posted a possible solution here https://github.com/dr4Ke/editsections/commit/f30d5543f8f5d2faa2c830b607b9e054b0c0a03dDan Kirkdorffer 15-Apr-2011
Thank you for the solution. It is now applied on the master branch. Tag 2011-04-17. Christophe Drevet 17-04-2011
editsections2 appears to break the yalist plugin :( — AshtagonAshtagon

2011/08/13 09:03
Well, if you're talking about dokuwiki-plugin-editsections2 from kazmiya, you should probably open an issue on github for that. Christophe Drevet 17-08-2011

H0 tag?

Just checking, I noticed that this plugin inserts some <H0> tags, which the W3C validator complains about. Are these intentional?

They are. It's a dirty trick to display the edit button for the first section. I'm not a Web dev, maybe it can be done otherwise. Christophe Drevet 14-04-2011

DokuWiki-2012-01-25 ("Angua")

It appears that the latest version of Dokuwiki (Angua 2012-01-25) no longer has the addInitEvent() function at lib/scripts/script.js, and has instead replaced it with a JQuery version in page.js. But it isn't clear how to make the same modification here. Please advise. Dan Kirkdorffer 25-Mar-2012

What I've had to do is update the sectionHighlight function in lib/scripts/page.js with the mouseover logic in editsections/script.js. I can't seem to figure out how to have Dokuwiki otherwise ignore the default sectionHighlight function and use the plugins' version. Dan Kirkdorffer 30-Mar-2012
plugin/editsections.txt · Last modified: 2016-01-03 07:19 by Aleksandr