-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.php
123 lines (96 loc) · 2.81 KB
/
utils.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
<?php
/**
* DokuWiki Plugin dokutranslate (Misc functions)
*
* @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
* @author Martin Doucha <[email protected]>
*/
// must be run within Dokuwiki
if (!defined('DOKU_INC')) die();
if (!defined('DOKU_LF')) define('DOKU_LF', "\n");
if (!defined('DOKU_TAB')) define('DOKU_TAB', "\t");
if (!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
define('DOKUTRANSLATE_MODLIST', DOKU_INC . 'conf/dokutranslate.modlist.conf');
$DOKUTRANSLATE_EDITFORM = '';
# Read cleaned instructions for file and group them by paragraphs
function getCleanInstructions($file) {
$instructions = p_cached_instructions($file);
$ret = array();
$i = 0;
foreach ($instructions as $ins) {
switch ($ins[0]) {
# Filter out sections and document start/end instructions
case 'document_start':
case 'document_end':
case 'section_open':
case 'section_close':
break;
# Start new block of instructions on paragraph end
case 'p_close':
$ret[$i++][] = $ins;
break;
# Add the instruction to current block
default:
$ret[$i][] = $ins;
break;
}
}
return $ret;
}
function dataPath($id) {
return dirname(wikiFN($id)) . '/_' . noNS($id);
}
function getParID() {
return isset($_REQUEST['parid']) ? intval($_REQUEST['parid']) : 0;
}
# Read the modlist file and return array of lines
function loadModlist() {
$ret = @file(DOKUTRANSLATE_MODLIST);
return $ret === false ? array() : $ret;
}
# Parse array of modlist lines and return array(ns => modgroup)
function parseModlist($lines) {
$ret = array();
foreach ($lines as $line) {
$line = trim(preg_replace('/#.*$/', '', $line)); //ignore comments
if (!$line) {
continue;
}
$entry = preg_split('/\s+/', $line);
$entry[1] = rawurldecode($entry[1]);
$ret[$entry[0]] = $entry[1];
}
return $ret;
}
# Check if current user has moderator privileges for given page ID
function isModerator($id) {
global $USERINFO;
static $modlist = NULL;
# Not logged in
if (empty($_SERVER['REMOTE_USER'])) {
return false;
}
if (is_null($modlist)) {
$modlist = parseModlist(loadModlist());
}
# Check nearest non-root parent namespace
for ($ns = getNS($id); $ns; $ns = getNS($ns)) {
$wildcard = $ns . ':*';
if (!empty($modlist[$wildcard])) {
return in_array($modlist[$wildcard], $USERINFO['grps']);
}
}
# Check root namespace
if (!empty($modlist['*'])) {
return in_array($modlist['*'], $USERINFO['grps']);
}
# No moderator group set for any of parent namespaces
return false;
}
function canReview($id, $meta, $parid) {
return isModerator($id) && $meta[$parid]['user'] != $_SERVER['REMOTE_USER'] && $meta[$parid]['ip'] != clientIP(true);
}
function needsReview($id, $meta, $parid) {
return canReview($id, $meta, $parid) && !isset($meta[$parid]['reviews'][$_SERVER['REMOTE_USER']]);
}
// vim:ts=4:sw=4:et: