summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--inc/html.php30
-rw-r--r--inc/parser/handler.php10
-rw-r--r--inc/parser/renderer.php2
-rw-r--r--inc/parser/xhtml.php38
4 files changed, 44 insertions, 36 deletions
diff --git a/inc/html.php b/inc/html.php
index d31c97724..09e871b67 100644
--- a/inc/html.php
+++ b/inc/html.php
@@ -130,23 +130,21 @@ function html_editbutton(){
/**
* prints a section editing button
+ * used as a callback in html_secedit
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
-function html_secedit_button($section,$p){
+function html_secedit_button($matches){
global $ID;
global $lang;
- global $INFO;
$secedit = '';
-# if($p) $secedit .= "</p>\n";
$secedit .= '<div class="secedit">';
$secedit .= html_btn('secedit',$ID,'',
array('do' => 'edit',
'lines' => "$section",
'rev' => $INFO['lastmod']),
- 'post');
+ 'post', $name);
$secedit .= '</div>';
-# if($p) $secedit .= "\n<p>";
return $secedit;
}
@@ -157,16 +155,14 @@ function html_secedit_button($section,$p){
*/
function html_secedit($text,$show=true){
global $INFO;
+
if($INFO['writable'] && $show && !$INFO['rev']){
- $text = preg_replace('#<!-- SECTION \[(\d+-\d+)\] -->#e',
- "html_secedit_button('\\1',true)",
- $text);
- $text = preg_replace('#<!-- SECTION \[(\d+-)\] -->#e',
- "html_secedit_button('\\1',false)",
- $text);
+ $text = preg_replace_callback('#<!-- SECTION "(.*?)" \[(\d+-\d*)\] -->#',
+ 'html_secedit_button', $text);
}else{
- $text = preg_replace('#<!-- SECTION \[(\d*-\d*)\] -->#e','',$text);
+ $text = preg_replace('#<!-- SECTION "(.*?)" \[(\d+-\d*)\] -->#','',$text);
}
+
return $text;
}
@@ -214,16 +210,18 @@ function html_backtomedia_button($params,$akey=''){
/**
* Displays a button (using its own form)
+ * If tooltip exists, the access key tooltip is replaced.
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
-function html_btn($name,$id,$akey,$params,$method='get'){
+function html_btn($name,$id,$akey,$params,$method='get',$tooltip=''){
global $conf;
global $lang;
$label = $lang['btn_'.$name];
$ret = '';
+ $tip = '';
//filter id (without urlencoding)
$id = idfilter($id,false);
@@ -250,9 +248,13 @@ function html_btn($name,$id,$akey,$params,$method='get'){
$ret .= '<input type="submit" value="'.htmlspecialchars($label).'" class="button" ';
if($akey){
- $ret .= 'title="[ALT+'.strtoupper($akey).']" ';
+ $tip = '[ALT+'.strtoupper($akey).']';
$ret .= 'accesskey="'.$akey.'" ';
}
+ if ($tooltip!='') {
+ $tip = htmlspecialchars($tooltip);
+ }
+ $ret .= 'title="'.$tip.'" ';
$ret .= '/>';
$ret .= '</div></form>';
diff --git a/inc/parser/handler.php b/inc/parser/handler.php
index fde538515..58eed0c34 100644
--- a/inc/parser/handler.php
+++ b/inc/parser/handler.php
@@ -11,6 +11,9 @@ class Doku_Handler {
var $status = array(
'section' => FALSE,
+ 'section_edit_start' => -1,
+ 'section_edit_level' => 1,
+ 'section_edit_title' => ''
);
var $rewriteBlocks = TRUE;
@@ -29,6 +32,8 @@ class Doku_Handler {
if ( $this->status['section'] ) {
$last_call = end($this->calls);
array_push($this->calls,array('section_close',array(), $last_call[2]));
+ array_push($this->calls,array('section_edit',array($this->status['section_edit_start'], 0,
+ $this->status['section_edit_level'], $this->status['section_edit_title']), $last_call[2]));
}
if ( $this->rewriteBlocks ) {
@@ -90,6 +95,11 @@ class Doku_Handler {
if ($this->status['section']) $this->_addCall('section_close',array(),$pos);
+ $this->_addCall('section_edit',array($this->status['section_edit_start'], $pos-1, $this->status['section_edit_level'], $this->status['section_edit_title']), $pos);
+ $this->status['section_edit_start'] = $pos;
+ $this->status['section_edit_level'] = $level;
+ $this->status['section_edit_title'] = $title;
+
$this->_addCall('header',array($title,$level,$pos), $pos);
$this->_addCall('section_open',array($level),$pos);
diff --git a/inc/parser/renderer.php b/inc/parser/renderer.php
index 238abdeff..931be6ceb 100644
--- a/inc/parser/renderer.php
+++ b/inc/parser/renderer.php
@@ -43,6 +43,8 @@ class Doku_Renderer {
function header($text, $level, $pos) {}
+ function section_edit($start, $end, $level, $name) {}
+
function section_open($level) {}
function section_close() {}
diff --git a/inc/parser/xhtml.php b/inc/parser/xhtml.php
index dc28423f9..ad981df35 100644
--- a/inc/parser/xhtml.php
+++ b/inc/parser/xhtml.php
@@ -52,9 +52,6 @@ class Doku_Renderer_xhtml extends Doku_Renderer {
}
function document_end() {
- // add button for last section if any and more than one
- if($this->lastsec > 1) $this->_secedit($this->lastsec,'');
-
if ( count ($this->footnotes) > 0 ) {
$this->doc .= '<div class="footnotes">'.DOKU_LF;
@@ -126,13 +123,6 @@ class Doku_Renderer_xhtml extends Doku_Renderer {
function header($text, $level, $pos) {
global $conf;
- //handle section editing
- if($level <= $conf['maxseclevel']){
- // add button for last section if any
- if($this->lastsec) $this->_secedit($this->lastsec,$pos-1);
- // remember current position
- $this->lastsec = $pos;
- }
// create a unique header id
$hid = $this->_headerToLink($text,'true');
@@ -152,6 +142,22 @@ class Doku_Renderer_xhtml extends Doku_Renderer {
$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).'] -->';
+ }
+ }
+
function section_open($level) {
$this->doc .= "<div class=\"level$level\">".DOKU_LF;
}
@@ -1040,18 +1046,6 @@ class Doku_Renderer_xhtml extends Doku_Renderer {
}
/**
- * Adds code for section editing button
- *
- * This is just aplaceholder and gets replace by the button if
- * section editing is allowed
- *
- * @author Andreas Gohr <andi@splitbrain.org>
- */
- function _secedit($f, $t){
- $this->doc .= '<!-- SECTION ['.$f.'-'.$t.'] -->';
- }
-
- /**
* Construct a title and handle images in titles
*
* @author Harry Fuecks <hfuecks@gmail.com>