Permalink
Browse files

Make the edit page button use section edits, fixes #65

This means that now the edit buttons for included pages only appear
where it makes sense (i.e. not in the preview and not in the RSS feed).
This also means that the cache no longer depends on the edit permissions
as there is nothing in the rendering process anymore that depends on
them because the edit buttons are generated after the rendering.
  • Loading branch information...
1 parent 4679e92 commit d2cd3b4cb3f0685be0cc20e19c989b5f441a0ab2 @michitux michitux committed Aug 19, 2011
Showing with 25 additions and 25 deletions.
  1. +16 −2 action.php
  2. +6 −7 helper.php
  3. +3 −16 syntax/editbtn.php
View
@@ -173,21 +173,35 @@ function handle_secedit_button(&$event, $params) {
// stack of included pages in the form ('id' => page, 'rev' => modification time, 'writable' => bool)
static $page_stack = array();
- global $ID;
+ global $ID, $lang;
$data = $event->data;
if ($data['target'] == 'plugin_include_start' || $data['target'] == 'plugin_include_start_noredirect') {
// handle the "section edits" added by the include plugin
$fn = wikiFN($data['name']);
+ $perm = auth_quickaclcheck($data['name']);
array_unshift($page_stack, array(
'id' => $data['name'],
'rev' => @filemtime($fn),
- 'writable' => (is_writable($fn) && auth_quickaclcheck($data['name']) >= AUTH_EDIT),
+ 'writable' => (page_exists($data['name']) ? (is_writable($fn) && $perm >= AUTH_EDIT) : $perm >= AUTH_CREATE),
'redirect' => ($data['target'] == 'plugin_include_start'),
));
} elseif ($data['target'] == 'plugin_include_end') {
array_shift($page_stack);
+ } elseif ($data['target'] == 'plugin_include_editbtn') {
+ if ($page_stack[0]['writable']) {
+ $params = array('do' => 'edit',
+ 'id' => $page_stack[0]['id']);
+ if ($page_stack[0]['redirect'])
+ $params['redirect_id'] = $ID;
+ $event->result = '<div class="secedit">' . DOKU_LF .
+ html_btn('incledit', $page_stack[0]['id'], '',
+ $params, 'post',
+ $data['name'],
+ $lang['btn_secedit'].' ('.$page_stack[0]['id'].')') .
+ '</div>' . DOKU_LF;
+ }
} elseif (!empty($page_stack)) {
// Special handling for the edittable plugin
View
@@ -405,10 +405,7 @@ function _convert_instructions(&$ins, $lvl, $page, $sect, $flags, $root_id) {
// add edit button
if($flags['editbtn']) {
- $perm = auth_quickaclcheck($page);
- $can_edit = page_exists($page) ? $perm >= AUTH_EDIT : $perm >= AUTH_CREATE;
- if ($can_edit)
- $this->_editbtn($ins, $page, $sect, $sect_title, ($flags['redirect'] ? $root_id : false));
+ $this->_editbtn($ins, $page, $sect, $sect_title, ($flags['redirect'] ? $root_id : false));
}
// add footer
@@ -461,9 +458,10 @@ function _footer($page, $sect, $sect_title, $flags, $footer_lvl, $root_id) {
* @author Michael Klier <chi@chimeric.de>
*/
function _editbtn(&$ins, $page, $sect, $sect_title, $root_id) {
+ $title = ($sect) ? $sect_title : $page;
$editbtn = array();
$editbtn[0] = 'plugin';
- $editbtn[1] = array('include_editbtn', array($page, $sect, $sect_title, $root_id));
+ $editbtn[1] = array('include_editbtn', array($title));
$ins[] = $editbtn;
}
@@ -522,6 +520,8 @@ function _get_firstsec(&$ins, $page) {
if($ins[$i][0] == 'section_close') {
$first_sect = $i;
}
+ // only truncate the content and add the read more link when there is really
+ // more than that first section
if(($first_sect) && ($ins[$i][0] == 'section_open')) {
$ins = array_slice($ins, 0, $first_sect);
$ins[] = array('p_open', array());
@@ -576,9 +576,8 @@ function _get_included_pages($mode, $page, $sect, $parent_id) {
$result = array();
foreach ($pages as $page) {
- $perm = auth_quickaclcheck($page);
$exists = page_exists($page);
- $result[] = array('id' => $page, 'exists' => $exists, 'can_edit' => ($perm >= AUTH_EDIT), 'parent_id' => $parent_id);
+ $result[] = array('id' => $page, 'exists' => $exists, 'parent_id' => $parent_id);
}
return $result;
}
View
@@ -33,23 +33,10 @@ function handle($match, $state, $pos, &$handler) {
*/
function render($mode, &$renderer, $data) {
global $lang;
- list($page, $sect, $sect_title, $redirect_id) = $data;
+ list($title) = $data;
if ($mode == 'xhtml') {
- $title = ($sect) ? $sect_title : $page;
- $params = array('do' => 'edit',
- 'id' => $page);
- if ($redirect_id !== false)
- $params['redirect_id'] = $redirect_id;
- $xhtml .= '<div class="secedit">' . DOKU_LF;
- $xhtml .= '<form class="button btn_incledit" method="post" action="' . DOKU_SCRIPT . '"><div class="no">' . DOKU_LF;
- foreach($params as $key => $val) {
- $xhtml .= '<input type="hidden" name="'.$key.'" ';
- $xhtml .= 'value="'.htmlspecialchars($val).'" />';
- }
- $xhtml .= '<input type="submit" value="'.htmlspecialchars($lang['btn_secedit']).' (' . $page . ')" class="button" title="'.$title.'"/>' . DOKU_LF;
- $xhtml .= '</div></form>' . DOKU_LF;
- $xhtml .= '</div>' . DOKU_LF;
- $renderer->doc .= $xhtml;
+ $renderer->startSectionEdit(0, 'plugin_include_editbtn', $title);
+ $renderer->finishSectionEdit();
return true;
}
return false;

0 comments on commit d2cd3b4

Please sign in to comment.