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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
|
<?php
/**
* DokuWiki template functions
*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Andreas Gohr <andi@splitbrain.org>
*/
if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../').'/');
require_once(DOKU_INC.'conf/dokuwiki.php');
/**
* Wrapper around htmlspecialchars()
*
* @author Andreas Gohr <andi@splitbrain.org>
* @see htmlspecialchars()
*/
function hsc($string){
return htmlspecialchars($string);
}
/**
* print a newline terminated string
*
* You can give an indention as optional parameter
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
function ptln($string,$intend=0){
for($i=0; $i<$intend; $i++) print ' ';
print"$string\n";
}
/**
* Print the content
*
* This function is used for printing all the usual content
* (defined by the global $ACT var) by calling the appropriate
* outputfunction(s) from html.php
*
* Everything that doesn't use the default template isn't
* handled by this function. ACL stuff is not done either.
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
function tpl_content(){
global $ACT;
global $TEXT;
global $PRE;
global $SUF;
global $SUM;
global $IDX;
switch($ACT){
case 'show':
html_show();
break;
case 'preview':
html_edit($TEXT);
html_show($TEXT);
break;
case 'edit':
html_edit();
break;
case 'wordblock':
html_edit($TEXT,'wordblock');
break;
case 'search':
html_search();
break;
case 'revisions':
html_revisions();
break;
case 'diff':
html_diff();
break;
case 'recent':
html_recent();
break;
case 'index':
html_index($IDX); #FIXME can this be pulled from globals? is it sanitized correctly?
break;
case 'backlink':
html_backlinks();
break;
case 'conflict':
html_conflict(con($PRE,$TEXT,$SUF),$SUM);
html_diff(con($PRE,$TEXT,$SUF),false);
break;
case 'locked':
html_locked($lockedby);
break;
case 'login':
html_login();
break;
case 'register':
html_register();
break;
case 'denied':
print parsedLocale('denied');
break;
case 'admin':
tpl_admin();
break;
default:
msg("Failed to handle command: ".hsc($ACT),-1);
}
}
/**
* Handle the admin page contents
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
function tpl_admin(){
switch($_REQUEST['page']){
case 'acl':
admin_acl_html();
break;
default:
html_admin();
}
}
/**
* Print the correct HTML meta headers
*
* This has to go into the head section of your template.
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
function tpl_metaheaders(){
global $ID;
global $INFO;
global $ACT;
global $lang;
$it=2;
// the usual stuff
ptln('<meta name="generator" content="DokuWiki '.getVersion().'" />',$it);
ptln('<link rel="start" href="'.DOKU_BASE.'" />',$it);
ptln('<link rel="contents" href="'.wl($ID,'do=index').'" title="'.$lang['index'].'" />',$it);
ptln('<link rel="alternate" type="application/rss+xml" title="Recent Changes" href="'.DOKU_BASE.'feed.php" />',$it);
ptln('<link rel="alternate" type="application/rss+xml" title="Current Namespace" href="'.DOKU_BASE.'feed.php?mode=list&ns='.$INFO['namespace'].'" />',$it);
ptln('<link rel="alternate" type="text/html" title="Plain HTML" href="'.wl($ID,'do=export_html').'" />',$it);
ptln('<link rel="alternate" type="text/plain" title="Wiki Markup" href="'.wl($ID, 'do=export_raw').'" />',$it);
ptln('<link rel="stylesheet" media="screen" type="text/css" href="'.DOKU_BASE.'style.css" />',$it);
// setup robot tags apropriate for different modes
if( ($ACT=='show' || $ACT=='export_html') && !$REV){
if($INFO['exists']){
ptln('<meta name="date" content="'.date('Y-m-d\TH:i:sO',$INFO['lastmod']).'" />',$it);
//delay indexing:
if((time() - $INFO['lastmod']) >= $conf['indexdelay']){
ptln('<meta name="robots" content="index,follow" />',$it);
}else{
ptln('<meta name="robots" content="noindex,nofollow" />',$it);
}
}else{
ptln('<meta name="robots" content="noindex,follow" />',$it);
}
}else{
ptln('<meta name="robots" content="noindex,nofollow" />',$it);
}
// include some JavaScript language strings
ptln('<script language="JavaScript" type="text/javascript">',$it);
ptln(" var alertText = '".$lang['qb_alert']."'",$it);
ptln(" var notSavedYet = '".$lang['notsavedyet']."'",$it);
ptln(" var DOKU_BASE = '".DOKU_BASE."'",$it);
ptln('</script>',$it);
// load the default JavaScript file
ptln('<script language="JavaScript" type="text/javascript" src="'.DOKU_BASE.'script.js"></script>',$it);
//FIXME include some default CSS ? IE FIX?
}
/**
* Print a link
*
* Just builds a link but adds additional JavaScript needed for
* the unsaved data check needed in the edit form.
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
function tpl_link($url,$name,$more=''){
print '<a href="'.$url.'" onclick="return svchk()" onkeypress="return svchk()"';
if ($more) print ' '.$more;
print ">$name</a>";
}
/**
* Print one of the buttons
*
* Available Buttons are
*
* edit - edit/create/show button
* history - old revisions
* recent - recent changes
* login - login/logout button - if ACL enabled
* index - The index
* admin - admin page - if enough rights
* top - a back to top button
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
function tpl_button($type){
global $ID;
global $INFO;
global $conf;
switch($type){
case 'edit':
print html_editbutton();
break;
case 'history':
print html_btn(revs,$ID,'o',array('do' => 'revisions'));
break;
case 'recent':
print html_btn(recent,'','r',array('do' => 'recent'));
break;
case 'index':
print html_btn(index,$ID,'x',array('do' => 'index'));
break;
case 'top':
print html_topbtn();
break;
case 'login':
if($conf['useacl']){
if($_SERVER['REMOTE_USER']){
print html_btn('logout',$ID,'',array('do' => 'logout',));
}else{
print html_btn('login',$ID,'',array('do' => 'login'));
}
}
break;
case 'admin':
if($INFO['perm'] == AUTH_ADMIN)
print html_btn(admin,$ID,'',array('do' => 'admin'));
break;
default:
print '[unknown button type]';
}
}
/**
* Print the search form
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
function tpl_searchform(){
global $lang;
print '<form action="'.wl().'" accept-charset="utf-8" class="search" onsubmit="return svchk()">';
print '<input type="hidden" name="do" value="search" />';
print '<input type="text" accesskey="f" name="id" class="edit" />';
print '<input type="submit" value="'.$lang['btn_search'].'" class="button" />';
print '</form>';
}
/**
* Print the breadcrumbs trace
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
function tpl_breadcrumbs(){
global $lang;
global $conf;
//check if enabled
if(!$conf['breadcrumbs']) return;
$crumbs = breadcrumbs(); //setup crumb trace
print $lang['breadcrumb'].':';
foreach ($crumbs as $id => $name){
print ' » ';
tpl_link(wl($id),$name,'class="breadcrumbs" title="'.$id.'"');
}
}
/**
* Hierarchical breadcrumbs
*
* This code was suggested as replacement for the usual breadcrumbs
* trail in the Wiki and was modified by me.
* It only makes sense with a deep site structure.
*
* @author Andreas Gohr <andi@splitbrain.org>
* @link http://wiki.splitbrain.org/wiki:tipsandtricks:hierarchicalbreadcrumbs
*/
function tpl_youarehere(){
global $conf;
global $ID;
global $lang;
$parts = explode(':', $ID);
print $lang['breadcrumb'].': ';
//always print the startpage
if( $a_part[0] != $conf['start'] )
tpl_link(wl($conf['start']),$conf['start'],'title="'.$conf['start'].'"');
$page = '';
foreach ($parts as $part){
print ' » ';
$page .= $part;
if(file_exists(wikiFN($page))){
tpl_link(wl($page),$part,'title="'.$page.'"');
}else{
print $page;
}
$page .= ':';
}
}
/**
* Print info if the user is logged in
*
* Could be enhanced with a profile link in future?
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
function tpl_userinfo(){
global $lang;
if($_SERVER['REMOTE_USER'])
print $lang['loggedinas'].': '.$_SERVER['REMOTE_USER'];
}
/**
* Print some info about the current page
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
function tpl_pageinfo(){
global $conf;
global $lang;
global $INFO;
global $REV;
// prepare date and path
$fn = $INFO['filepath'];
if(!$conf['fullpath']){
if($REV){
$fn = str_replace(realpath($conf['olddir']).DIRECTORY_SEPARATOR,'',$fn);
}else{
$fn = str_replace(realpath($conf['datadir']).DIRECTORY_SEPARATOR,'',$fn);
}
}
$fn = utf8_decodeFN($fn);
$date = date($conf['dformat'],$INFO['lastmod']);
// print it
if($INFO['exists']){
print $fn;
print ' · ';
print $lang['lastmod'];
print ': ';
print $date;
if($INFO['editor']){
print ' '.$lang['by'].' ';
print $INFO['editor'];
}
if($INFO['locked']){
print ' · ';
print $lang['lockedby'];
print ': ';
print $INFO['locked'];
}
}
}
/**
* Print a list of namespaces containing media files
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
function tpl_medianamespaces(){
global $conf;
$data = array();
search($data,$conf['mediadir'],'search_namespaces',array());
print html_buildlist($data,'idx',media_html_list_namespaces);
}
/**
* Print a list of mediafiles in the current namespace
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
function tpl_mediafilelist(){
global $conf;
global $lang;
global $NS;
$dir = utf8_encodeFN(str_replace(':','/',$NS));
$data = array();
search($data,$conf['mediadir'],'search_media',array(),$dir);
if(!count($data)){
ptln('<div class="nothing">'.$lang['nothingfound'].'<div>');
return;
}
ptln('<ul>',2);
foreach($data as $item){
ptln('<li>',4);
ptln('<a href="javascript:mediaSelect(\''.$item['id'].'\')">'.
utf8_decodeFN($item['file']).
'</a>',6);
if($item['isimg']){
ptln('('.$item['info'][0].'×'.$item['info'][1].
' '.filesize_h($item['size']).')<br />',6);
# build thumbnail
$link=array();
$link['name']=$item['id'];
if($item['info'][0]>120) $link['name'] .= '?120';
$link = format_link_media($link);
ptln($link['name'],6);
}else{
ptln ('('.filesize_h($item['size']).')',6);
}
ptln('</li>',4);
}
ptln('</ul>',2);
}
/**
* Print the media upload form if permissions are correct
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
function tpl_mediauploadform(){
global $NS;
global $UPLOADOK;
global $lang;
if(!$UPLOADOK) return;
ptln('<form action="'.$_SERVER['PHP_SELF'].'" name="upload"'.
' method="post" enctype="multipart/form-data">',2);
ptln($lang['txt_upload'].':<br />',4);
ptln('<input type="file" name="upload" class="edit" onchange="suggestWikiname();" />',4);
ptln('<input type="hidden" name="ns" value="'.hsc($NS).'" /><br />',4);
ptln($lang['txt_filename'].'<br />',4);
ptln('<input type="text" name="id" class="edit" />',4);
ptln('<input type="submit" class="button" value="'.$lang['btn_upload'].'" accesskey="s" />',4);
ptln('</form>',2);
}
?>
|