-
Notifications
You must be signed in to change notification settings - Fork 5
/
helper.php
217 lines (182 loc) · 5.88 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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
<?php
/**
* Linkback helper plugin
*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Gina Haeussge <[email protected]>
*/
class helper_plugin_linkback extends DokuWiki_Plugin {
function getMethods() {
$result = array ();
$result[] = array (
'name' => 'th',
'desc' => 'returns the header of the linkback column for pagelist',
'return' => array (
'header' => 'string'
),
);
$result[] = array (
'name' => 'td',
'desc' => 'returns the link to the linkback section with number of comments',
'params' => array (
'id' => 'string',
'number of linkbacks (optional)' => 'integer'
),
'return' => array (
'link' => 'string'
),
);
$result[] = array (
'name' => 'getLinkbacks',
'desc' => 'returns recently added linkbacks individually',
'params' => array (
'namespace' => 'string',
'number (optional)' => 'integer'
),
'return' => array (
'pages' => 'array'
),
);
return $result;
}
/**
* Returns the header of the linkback column for the pagelist
*/
function th() {
return $this->getLang('linkbacks');
}
/**
* Returns the link to the linkback section with number of comments
*/
function td($ID, $number = NULL) {
$section = '#linkback__section';
if (!isset ($number)) {
$lfile = metaFN($ID, '.linkbacks');
$linkbacks = unserialize(io_readFile($lfile, false));
if ($linkbacks){
$number = $linkbacks['number'];
if (!$linkbacks['display']) {
return '';
}
} else {
return '';
}
}
if ($number == 0) {
$linkback = '0 ' . $this->getLang('linkback_plural');
} elseif ($number == 1) {
$linkback = '1 ' . $this->getLang('linkback_singular');
} else {
$linkback = $number . ' ' . $this->getLang('linkback_plural');
}
return '<a href="' . wl($ID) . $section . '" class="wikilink1" title="' . $ID . $section . '">' .
$linkback . '</a>';
}
/**
* Returns recently added linkbacks individually
*/
function getLinkbacks($ns, $num = NULL) {
global $conf;
$first = $_REQUEST['first'];
if (!is_numeric($first)) {
$first = 0;
}
if ((!$num) || (!is_numeric($num))) {
$num = $conf['recent'];
}
$result = array ();
$count = 0;
if (!@ file_exists($conf['metadir'] . '/_linkbacks.changes')) {
return $result;
}
// read all recent changes. (kept short)
$lines = file($conf['metadir'] . '/_linkbacks.changes');
// handle lines
for ($i = count($lines) - 1; $i >= 0; $i--) {
$rec = $this->_handleRecentLinkback($lines[$i], $ns);
if ($rec !== false) {
if (-- $first >= 0) {
continue;
} // skip first entries
$result[$rec['date']] = $rec;
$count++;
// break when we have enough entries
if ($count >= $num) {
break;
}
}
}
// finally sort by time of last comment
krsort($result);
return $result;
}
/**
* Internal function used by $this->getLinkbacks()
*
* don't call directly
*
* @see getRecentComments()
* @author Andreas Gohr <[email protected]>
* @author Ben Coburn <[email protected]>
* @author Esther Brunner <[email protected]>
* @author Gina Haeussge <[email protected]>
*/
function _handleRecentLinkback($line, $ns) {
static $seen = array (); //caches seen pages and skip them
if (empty ($line)) {
return false; //skip empty lines
}
// split the line into parts
$recent = parseChangelogLine($line);
if ($recent === false) {
return false;
}
$lid = $recent['extra'];
$fulllid = $recent['id'] . '#' . $recent['extra'];
// skip seen ones
if (isset ($seen[$fulllid])) {
return false;
}
// skip 'show comment' log entries
if ($recent['type'] === 'sc') {
return false;
}
// remember in seen to skip additional sights
$seen[$fulllid] = 1;
// check if it's a hidden page or comment
if (isHiddenPage($recent['id'])) {
return false;
}
if ($recent['type'] === 'hl') {
return false;
}
// filter namespace or id
if (($ns) && (strpos($recent['id'] . ':', $ns . ':') !== 0)) {
return false;
}
// check ACL
$recent['perm'] = auth_quickaclcheck($recent['id']);
if ($recent['perm'] < AUTH_READ) {
return false;
}
// check existance
$recent['file'] = wikiFN($recent['id']);
$recent['exists'] = @ file_exists($recent['file']);
if (!$recent['exists']) {
return false;
}
if ($recent['type'] === 'dc') {
return false;
}
// get linkback meta file name
$data = unserialize(io_readFile(metaFN($recent['id'], '.linkbacks'), false));
// check if discussion is turned off
if (!$data['display']) {
return false;
}
// okay, then add some additional info
$recent['name'] = $data['receivedpings'][$lid]['url'];
$recent['desc'] = $data['receivedpings'][$lid]['excerpt'];
return $recent;
}
}