-
Notifications
You must be signed in to change notification settings - Fork 2
/
helper.php
168 lines (141 loc) · 3.44 KB
/
helper.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
<?php
/**
* DokuWiki Plugin ajaxedit (Helper Component)
*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author lisps
*/
class helper_plugin_ajaxedit extends DokuWiki_Plugin {
const ERROR_LOCK = 1;
const ERROR_SECTOC = 2;
const ERROR_MODIFIED= 4;
const ERROR_ACL = 3;
const ERROR_READ = 5;
const ERROR_OTHER = 99;
public $ID;
public $index;
function __construct(){
global $ID;
$ID=isset($_POST["pageid"])?cleanID($_POST["pageid"]):$ID;
}
/**
* error throw an error and leave
* @param string $msg
* @param integer $type error type
* @param boolean $exit leave or not
**/
function error($msg,$type=self::ERROR_OTHER,$exit = true){
$ret = array(
'error' => $type,
'msg' => $msg,
'lastmod' => intval($_POST["lastmod"]),
);
echo json_encode($ret);
if($exit && !defined('DOKU_UNITTEST')) exit;
}
function _error($type,$exit = true){
$ret = array(
'error' => $type,
'msg' => $this->_getErrorMsg($type),
'lastmod' => intval($_POST["lastmod"]),
);
echo json_encode($ret);
if($exit && !defined('DOKU_UNITTEST')) exit;
}
/**
* getWikiPage returns the raw wiki data
* @return string
*/
function getWikiPage($checkLastmod = true, $min_acl = AUTH_EDIT){
global $ID;
global $INFO;
$this->ID=cleanID(trim($_POST["pageid"]));
$ID = $this->ID;
$this->index = intval($_POST["index"]);
$oldrev = intval($_POST["lastmod"]);
if(!checkSecurityToken()) $this->_error(self::ERROR_SECTOC);
if (auth_quickaclcheck($ID) < $min_acl) {
$this->_error(self::ERROR_ACL);
}
$INFO = pageinfo();
if($checkLastmod && $INFO['lastmod']!=$oldrev ) {
$this->_error(self::ERROR_MODIFIED);
}
if(checklock($ID)){
$this->_error(self::ERROR_LOCK);
}
if (!($data=rawWiki($ID))){
$this->_error(self::ERROR_READ);
}
return $data;
}
/**
* success sends the success message
* automatically sends error,msg,lastmod,index(id counter)
*
* @param array $data additional data
*/
function success($data=array()){
global $ID;
$info = pageinfo();
$ret = array(
'error' => 0,
'msg' => '',
'lastmod'=> $info['lastmod'],
'index' => $this->index,
'pageid' => $ID,
);
$ret = array_merge($ret,$data);
echo json_encode($ret);
exit;
}
/**
* saveWikiPage saves the wiki page
*
* @param string $data wiki page
* @param string $summary
* @param boolean $minor
* @param array $param will go to @see success
* @param boolean $autosubmit if set will call success
*/
function saveWikiPage($data,$summary,$minor = false,$param=array(),$autosubmit=true){
saveWikiText($this->ID,$data,$summary,$minor);
if($autosubmit){
$this->success($param);
}
global $INFO;
$INFO = pageinfo();
}
function _getErrorMsg($error){
global $INFO;
$INFO = pageinfo();
$msg = '';
switch($error){
case self::ERROR_LOCK:
$msg = 'ERROR_LOCK:tbd';
ob_start();
html_locked();
$msg = ob_get_clean();
break;
case self::ERROR_SECTOC :
$msg = 'ERROR_SECTOC:tbd';
break;
case self::ERROR_ACL:
$msg = p_locale_xhtml('denied');
break;
case self::ERROR_READ:
$msg = 'ERROR_READ:tbd';
break;
case self::ERROR_MODIFIED:
$msg = sprintf($this->getLang('e_modified'),hsc(editorinfo($INFO['user'])));
break;
case self::ERROR_OTHER:
$msg = 'tbd';
break;
default:
$msg = 'Undefined Failure';
break;
}
return $msg;
}
}