-
Notifications
You must be signed in to change notification settings - Fork 2
/
action.php
90 lines (74 loc) · 2.4 KB
/
action.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php
/**
* DokuWiki Plugin ajaxedit (Action Component)
*
* adds lastmod and sectok variable to JSINFO
*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author lisps
*/
class action_plugin_ajaxedit extends DokuWiki_Action_Plugin {
/**
* Register the eventhandlers
*/
function register(Doku_Event_Handler $controller) {
$controller->register_hook('DOKUWIKI_STARTED', 'AFTER', $this, '_addlastmod');
$controller->register_hook('DOKUWIKI_STARTED', 'AFTER', $this, 'fixsecedit');
}
function _addlastmod(&$event, $param) {
global $ID;
global $JSINFO;
$info = pageinfo();
$JSINFO['lastmod'] = $info["lastmod"];
$JSINFO['sectok'] = getSecurityToken();
$perm = auth_quickaclcheck($ID);
if ($perm > AUTH_READ)
$JSINFO['acl_write'] = '1';
}
/**
* try to fix sectioninfo for section edit buttons.
*
* @param Doku_Event $event
* @param unknown $param
*/
function fixsecedit(Doku_Event $event, $param) {
global $INPUT;
global $RANGE;
global $REV;
global $INFO;
global $ID;
global $ACT;
if($ACT !== 'edit') return;
if(!$this->getConf('fix_section_edit')) return;
if($INPUT->str('target') !== 'section') return;
$range = $INPUT->str('range');
$rev = $INPUT->str('rev');
if($rev && $range && (!$REV && !$RANGE)) { //$_POST has range and rev but pageinfo() cleared it -> action
list($r_start,$r_end) = explode('-',$range);
$instructions = p_cached_instructions($INFO['filepath']); //get instructions
$new_section_open = null;
$new_section_close = '';
$found = null;
foreach($instructions as $key => $instruction) {
if($new_section_open && $instruction[0] === 'section_close') { //moved section found, now find closing section
$new_section_close = $instruction[2];
break; //end
} elseif ($new_section_open) {
continue;
}
if($instruction[0] === 'section_open') {
if($r_start == $instruction[2]) {
$new_section_open = $instruction[2];
msg(sprintf($this->getLang('section_found'),wl($ID,array('do'=>'edit'))));
} else if( abs($r_start-$instruction[2]) < $this->getConf('section_edit_range') ) {
$new_section_open = $instruction[2];
msg(sprintf($this->getLang('moved_section_found'),wl($ID,array('do'=>'edit'))));
}
}
}
if($new_section_open !== null) {
$RANGE = implode('-', array($new_section_open,$new_section_close));
}
}
}
}