This repository has been archived by the owner on Dec 28, 2024. It is now read-only.
forked from cosmocode/sqlite
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhelper.php
778 lines (676 loc) · 23.8 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
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
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
<?php
/**
* DokuWiki Plugin sqlite (Helper Component)
*
* @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
* @author Andreas Gohr <[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/');
if (!defined('DOKU_EXT_SQLITE')) define('DOKU_EXT_SQLITE', 'sqlite');
if (!defined('DOKU_EXT_PDO')) define('DOKU_EXT_PDO', 'pdo');
class helper_plugin_sqlite extends DokuWiki_Plugin {
var $db = null;
var $dbname = '';
var $extension = null;
function getInfo() {
return confToHash(dirname(__FILE__).'plugin.info.txt');
}
/**
* constructor
*/
function helper_plugin_sqlite(){
if(!$this->extension)
{
if (!extension_loaded('pdo_sqlite')) {
$prefix = (PHP_SHLIB_SUFFIX === 'dll') ? 'php_' : '';
if(function_exists('dl')) @dl($prefix . 'pdo_sqlite.' . PHP_SHLIB_SUFFIX);
}
if(class_exists('pdo')){
$this->extension = DOKU_EXT_PDO;
}
}
if(!$this->extension)
{
if (!extension_loaded('sqlite')) {
$prefix = (PHP_SHLIB_SUFFIX === 'dll') ? 'php_' : '';
if(function_exists('dl')) @dl($prefix . 'sqlite.' . PHP_SHLIB_SUFFIX);
}
if(function_exists('sqlite_open')){
$this->extension = DOKU_EXT_SQLITE;
}
}
if(!$this->extension)
{
msg('SQLite & PDO SQLite support missing in this PHP install - plugin will not work',-1);
}
}
/**
* Initializes and opens the database
*
* Needs to be called right after loading this helper plugin
*/
function init($dbname,$updatedir){
global $conf;
// check for already open DB
if($this->db){
if($this->dbname == $dbname){
// db already open
return true;
}
// close other db
if($this->extension == DOKU_EXT_SQLITE)
{
sqlite_close($this->db);
}
else
{
$this->db->close();
}
$this->db = null;
$this->dbname = '';
}
$this->dbname = $dbname;
// Separate the database files to prevent not-requested autoupgrades.
if($this->extension == DOKU_EXT_SQLITE){
$fileextension = '.sqlite';
}else{
$fileextension = '.sqlite3';
}
$this->dbfile = $conf['metadir'].'/'.$dbname.$fileextension;
$init = (!@file_exists($this->dbfile) || ((int) @filesize($this->dbfile)) < 3);
//first line tell the format of db file http://marc.info/?l=sqlite-users&m=109383875408202
$firstline=@file_get_contents($this->dbfile,false,null,0,15);
if($this->extension == DOKU_EXT_SQLITE)
{
if($firstline=='SQLite format 3'){
msg("SQLite: failed to open SQLite '".$this->dbname."' database (DB has a sqlite3 format instead of sqlite2 format.)",-1);
return false;
}
$error='';
$this->db = sqlite_open($this->dbfile, 0666, $error);
if(!$this->db){
msg("SQLite: failed to open SQLite '".$this->dbname."' database ($error)",-1);
return false;
}
// register our custom aggregate function
sqlite_create_aggregate($this->db,'group_concat',
array($this,'_sqlite_group_concat_step'),
array($this,'_sqlite_group_concat_finalize'), 2);
}
else
{
if($init){
$oldDbfile = substr($this->dbfile,0,-1);
if(@file_exists($oldDbfile)){
$notfound_msg="SQLite: '".$this->dbname.$fileextension."' database not found. In the meta directory is '".$this->dbname.substr($fileextension,0,-1)."' available. ";
$firstline=@file_get_contents($oldDbfile,false,null,0,15);
if($firstline=='SQLite format 3'){
msg($notfound_msg."PDO sqlite needs you rename manual the file extension to '.sqlite3' .",-1);
return false;
}else{
msg($notfound_msg."PDO sqlite needs you upgrade manual this sqlite2 db to sqlite3 format.",-1);
return false;
}
}
}else{
if($firstline!='SQLite format 3'){
msg("SQLite: failed to open SQLite '".$this->dbname."' database (DB has not a sqlite3 format.)",-1);
return false;
}
}
$dsn = 'sqlite:'.$this->dbfile;
try {
$this->db = new PDO($dsn);
} catch (PDOException $e) {
msg("SQLite: failed to open SQLite '".$this->dbname."' database (".$e->getMessage().")",-1);
return false;
}
$this->db->sqliteCreateAggregate('group_concat',
array($this,'_pdo_group_concat_step'),
array($this,'_pdo_group_concat_finalize'));
}
$this->_updatedb($init,$updatedir);
return true;
}
/**
* Return the current Database Version
*/
function _currentDBversion(){
$sql = "SELECT val FROM opts WHERE opt = 'dbversion';";
$res = $this->query($sql);
if(!$res) return false;
$row = $this->res2row($res,0);
return (int) $row['val'];
}
/**
* Update the database if needed
*
* @param bool $init - true if this is a new database to initialize
* @param string $updatedir - Database update infos
*/
function _updatedb($init,$updatedir)
{
if($init){
$current = 0;
}else{
$current = $this->_currentDBversion();
if(!$current){
msg("SQLite: no DB version found. '".$this->dbname."' DB probably broken.",-1);
return false;
}
}
// in case of init, add versioning table
if($init){
if(!$this->_runupdatefile(dirname(__FILE__).'/db.sql',0)){
msg("SQLite: '".$this->dbname."' database upgrade failed for version ", -1);
return false;
}
}
$latest = (int) trim(io_readFile($updatedir.'/latest.version'));
// all up to date?
if($current >= $latest) return true;
for($i=$current+1; $i<=$latest; $i++){
$file = sprintf($updatedir.'/update%04d.sql',$i);
if(file_exists($file)){
if(!$this->_runupdatefile($file,$i)){
msg("SQLite: '".$this->dbname."' database upgrade failed for version ".$i, -1);
return false;
}
}
}
return true;
}
/**
* Updates the database structure using the given file to
* the given version.
*/
function _runupdatefile($file,$version){
$sql = io_readFile($file,false);
$sql = explode(";",$sql);
array_unshift($sql,'BEGIN TRANSACTION');
array_push($sql,"INSERT OR REPLACE INTO opts (val,opt) VALUES ($version,'dbversion')");
array_push($sql,"COMMIT TRANSACTION");
foreach($sql as $s){
$s = preg_replace('!^\s*--.*$!m', '', $s);
$s = trim($s);
if(!$s) continue;
$res = $this->query("$s;");
if ($res === false) {
if($this->extension == DOKU_EXT_SQLITE)
{
sqlite_query($this->db, 'ROLLBACK TRANSACTION');
return false;
}
else
{
return false;
}
}
}
return ($version == $this->_currentDBversion());
}
/**
* Emulate ALTER TABLE
*
* The ALTER TABLE syntax is parsed and then emulated using a
* temporary table
*
* @author <[email protected]>
* @link http://code.jenseng.com/db/
* @author Andreas Gohr <[email protected]>
*/
function _altertable($table,$alterdefs){
// load original table definition SQL
$result = $this->query("SELECT sql,name,type
FROM sqlite_master
WHERE tbl_name = '$table'
AND type = 'table'");
if(($result === false) || ($this->extension == DOKU_EXT_SQLITE && sqlite_num_rows($result)<=0)){
msg("ALTER TABLE failed, no such table '".hsc($table)."'",-1);
return false;
}
if($this->extension == DOKU_EXT_SQLITE )
{
$row = sqlite_fetch_array($result);
}
else
{
$row = $result->fetch(PDO::FETCH_ASSOC);
}
if($row === false){
msg("ALTER TABLE failed, table '".hsc($table)."' had no master data",-1);
return false;
}
// prepare temporary table SQL
$tmpname = 't'.time();
$origsql = trim(preg_replace("/[\s]+/"," ",
str_replace(",",", ",
preg_replace('/\)$/',' )',
preg_replace("/[\(]/","( ",$row['sql'],1)))));
$createtemptableSQL = 'CREATE TEMPORARY '.substr(trim(preg_replace("'".$table."'",$tmpname,$origsql,1)),6);
$createindexsql = array();
// load indexes to reapply later
$result = $this->query("SELECT sql,name,type
FROM sqlite_master
WHERE tbl_name = '$table'
AND type = 'index'");
if(!$result){
$indexes = array();
}else{
$indexes = $this->res2arr($result);
}
$i = 0;
$defs = preg_split("/[,]+/",$alterdefs,-1,PREG_SPLIT_NO_EMPTY);
$prevword = $table;
$oldcols = preg_split("/[,]+/",substr(trim($createtemptableSQL),strpos(trim($createtemptableSQL),'(')+1),-1,PREG_SPLIT_NO_EMPTY);
$newcols = array();
for($i=0;$i<count($oldcols);$i++){
$colparts = preg_split("/[\s]+/",$oldcols[$i],-1,PREG_SPLIT_NO_EMPTY);
$oldcols[$i] = $colparts[0];
$newcols[$colparts[0]] = $colparts[0];
}
$newcolumns = '';
$oldcolumns = '';
reset($newcols);
while(list($key,$val) = each($newcols)){
$newcolumns .= ($newcolumns?', ':'').$val;
$oldcolumns .= ($oldcolumns?', ':'').$key;
}
$copytotempsql = 'INSERT INTO '.$tmpname.'('.$newcolumns.') SELECT '.$oldcolumns.' FROM '.$table;
$dropoldsql = 'DROP TABLE '.$table;
$createtesttableSQL = $createtemptableSQL;
foreach($defs as $def){
$defparts = preg_split("/[\s]+/",$def,-1,PREG_SPLIT_NO_EMPTY);
$action = strtolower($defparts[0]);
switch($action){
case 'add':
if(count($defparts) < 2){
msg('ALTER TABLE: not enough arguments for ADD statement',-1);
return false;
}
$createtesttableSQL = substr($createtesttableSQL,0,strlen($createtesttableSQL)-1).',';
for($i=1;$i<count($defparts);$i++)
$createtesttableSQL.=' '.$defparts[$i];
$createtesttableSQL.=')';
break;
case 'change':
if(count($defparts) <= 3){
msg('ALTER TABLE: near "'.$defparts[0].($defparts[1]?' '.$defparts[1]:'').($defparts[2]?' '.$defparts[2]:'').'": syntax error',-1);
return false;
}
if($severpos = strpos($createtesttableSQL,' '.$defparts[1].' ')){
if($newcols[$defparts[1]] != $defparts[1]){
msg('ALTER TABLE: unknown column "'.$defparts[1].'" in "'.$table.'"',-1);
return false;
}
$newcols[$defparts[1]] = $defparts[2];
$nextcommapos = strpos($createtesttableSQL,',',$severpos);
$insertval = '';
for($i=2;$i<count($defparts);$i++)
$insertval.=' '.$defparts[$i];
if($nextcommapos)
$createtesttableSQL = substr($createtesttableSQL,0,$severpos).$insertval.substr($createtesttableSQL,$nextcommapos);
else
$createtesttableSQL = substr($createtesttableSQL,0,$severpos-(strpos($createtesttableSQL,',')?0:1)).$insertval.')';
} else {
msg('ALTER TABLE: unknown column "'.$defparts[1].'" in "'.$table.'"',-1);
return false;
}
break;
case 'drop':
if(count($defparts) < 2){
msg('ALTER TABLE: near "'.$defparts[0].($defparts[1]?' '.$defparts[1]:'').'": syntax error',-1);
return false;
}
if($severpos = strpos($createtesttableSQL,' '.$defparts[1].' ')){
$nextcommapos = strpos($createtesttableSQL,',',$severpos);
if($nextcommapos)
$createtesttableSQL = substr($createtesttableSQL,0,$severpos).substr($createtesttableSQL,$nextcommapos + 1);
else
$createtesttableSQL = substr($createtesttableSQL,0,$severpos-(strpos($createtesttableSQL,',')?0:1) - 1).')';
unset($newcols[$defparts[1]]);
}else{
msg('ALTER TABLE: unknown column "'.$defparts[1].'" in "'.$table.'"',-1);
return false;
}
break;
default:
msg('ALTER TABLE: near "'.$prevword.'": syntax error',-1);
return false;
}
$prevword = $defparts[count($defparts)-1];
}
// this block of code generates a test table simply to verify that the
// columns specifed are valid in an sql statement
// this ensures that no reserved words are used as columns, for example
$res = $this->query($createtesttableSQL);
if($res === false) return false;
$droptempsql = 'DROP TABLE '.$tmpname;
$res = $this->query($droptempsql);
if($res === false) return false;
$createnewtableSQL = 'CREATE '.substr(trim(preg_replace("'".$tmpname."'",$table,$createtesttableSQL,1)),17);
$newcolumns = '';
$oldcolumns = '';
reset($newcols);
while(list($key,$val) = each($newcols)){
$newcolumns .= ($newcolumns?', ':'').$val;
$oldcolumns .= ($oldcolumns?', ':'').$key;
}
$copytonewsql = 'INSERT INTO '.$table.'('.$newcolumns.') SELECT '.$oldcolumns.' FROM '.$tmpname;
$res = $this->query($createtemptableSQL); //create temp table
if($res === false) return false;
$res = $this->query($copytotempsql); //copy to table
if($res === false) return false;
$res = $this->query($dropoldsql); //drop old table
if($res === false) return false;
$res = $this->query($createnewtableSQL); //recreate original table
if($res === false) return false;
$res = $this->query($copytonewsql); //copy back to original table
if($res === false) return false;
foreach($indexes as $index){ // readd indexes
$res = $this->query($index['sql']);
if($res === false) return false;
}
$res = $this->query($droptempsql); //drop temp table
if($res === false) return false;
return $res; // return a valid resource
}
/**
* Registers a User Defined Function for use in SQL statements
*/
function create_function($function_name,$callback,$num_args){
if($this->extension == DOKU_EXT_SQLITE )
{
sqlite_create_function($this->db,$function_name,$callback,$num_args);
}
else
{
$this->db->sqliteCreateFunction($function_name,$callback,$num_args);
}
}
/**
* Execute a query with the given parameters.
*
* Takes care of escaping
*
* @param string $sql - the statement
* @param arguments...
*/
function query(){
if(!$this->db)
{
msg("SQLite: $this->dbname missing at query ",-1);
return false;
}
// get function arguments
$args = func_get_args();
$sql = trim(array_shift($args));
$sql = rtrim($sql,';');
if(!$sql){
msg('No SQL statement given',-1);
return false;
}
$argc = count($args);
if($argc > 0 && is_array($args[0])) {
$args = $args[0];
$argc = count($args);
}
// check number of arguments
if($argc < substr_count($sql,'?')){
msg('Not enough arguments passed for statement. '.
'Expected '.substr_count($sql,'?').' got '.
$argc.' - '.hsc($sql),-1);
return false;
}
// explode at wildcard, then join again
$parts = explode('?',$sql,$argc+1);
$args = array_map(array($this,'quote_string'),$args);
$sql = '';
while( ($part = array_shift($parts)) !== null ){
$sql .= $part;
$sql .= array_shift($args);
}
// intercept ALTER TABLE statements
$match = null;
if(preg_match('/^ALTER\s+TABLE\s+([\w\.]+)\s+(.*)/i',$sql,$match)){
return $this->_altertable($match[1],$match[2]);
}
// execute query
$err = '';
if($this->extension == DOKU_EXT_SQLITE )
{
$res = @sqlite_query($this->db,$sql,SQLITE_ASSOC,$err);
if($err){
msg($err.':<br /><pre>'.hsc($sql).'</pre>',-1);
return false;
}elseif(!$res){
msg(sqlite_error_string(sqlite_last_error($this->db)).
':<br /><pre>'.hsc($sql).'</pre>',-1);
return false;
}
}
else
{
$res = $this->db->query($sql);
if(!$res){
$err = $this->db->errorInfo();
msg($err[2].':<br /><pre>'.hsc($sql).'</pre>',-1);
return false;
}
}
return $res;
}
/**
* Returns a complete result set as array
*/
function res2arr($res){
$data = array();
if($this->extension == DOKU_EXT_SQLITE )
{
if(!sqlite_num_rows($res)) return $data;
sqlite_rewind($res);
while(($row = sqlite_fetch_array($res, SQLITE_ASSOC)) !== false){
$data[] = $row;
}
}
else
{
if(!$res) return $data;
$data = $res->fetchAll(PDO::FETCH_ASSOC);
}
return $data;
}
/**
* Return the wanted row from a given result set as
* associative array
*/
function res2row($res,$rownum=0){
if($this->extension == DOKU_EXT_SQLITE )
{
if(!@sqlite_seek($res,$rownum)){
return false;
}
return sqlite_fetch_array($res, SQLITE_ASSOC);
}
else
{
if(!$res) return false;
return $res->fetch(PDO::FETCH_ASSOC,PDO::FETCH_ORI_ABS,$rownum);
}
}
/**
* Return the first value from the first row.
*/
function res2single($res)
{
if($this->extension == DOKU_EXT_SQLITE )
{
return sqlite_fetch_single($res);
}
else
{
if(!$res) return false;
$data = $res->fetch(PDO::FETCH_NUM,PDO::FETCH_ORI_ABS,0);
if(!count($data))
{
return false;
}
return $data[0];
}
}
/**
* Join the given values and quote them for SQL insertion
*/
function quote_and_join($vals,$sep=',') {
$vals = array_map(array('helper_plugin_sqlite','quote_string'),$vals);
return join($sep,$vals);
}
/**
* Run sqlite_escape_string() on the given string and surround it
* with quotes
*/
function quote_string($string){
if($this->extension == DOKU_EXT_SQLITE )
{
return "'".sqlite_escape_string($string)."'";
}
else
{
return $this->db->quote($string);
}
}
/**
* Escape string for sql
*/
function escape_string($str)
{
if($this->extension == DOKU_EXT_SQLITE )
{
return sqlite_escape_string($str);
}
else
{
return trim($this->db->quote($str), "'");
}
}
/**
* Aggregation function for SQLite
*
* @link http://devzone.zend.com/article/863-SQLite-Lean-Mean-DB-Machine
*/
function _sqlite_group_concat_step(&$context, $string, $separator = ',') {
$context['sep'] = $separator;
$context['data'][] = $string;
}
/**
* Aggregation function for SQLite
*
* @link http://devzone.zend.com/article/863-SQLite-Lean-Mean-DB-Machine
*/
function _sqlite_group_concat_finalize(&$context) {
$context['data'] = array_unique($context['data']);
return join($context['sep'],$context['data']);
}
/**
* Aggregation function for SQLite via PDO
*
* @link http://devzone.zend.com/article/863-SQLite-Lean-Mean-DB-Machine
*/
function _pdo_group_concat_step(&$context, $rownumber, $string, $separator = ',') {
if(is_null($context))
{
$context = array(
'sep' => $separator,
'data' => array()
);
}
$context['data'][] = $string;
return $context;
}
/**
* Aggregation function for SQLite via PDO
*
* @link http://devzone.zend.com/article/863-SQLite-Lean-Mean-DB-Machine
*/
function _pdo_group_concat_finalize(&$context, $rownumber)
{
if(!is_array($context))
{
return null;
}
$context['data'] = array_unique($context['data']);
return join($context['sep'],$context['data']);
}
/**
* Keep separate instances for every call to keep database connections
*/
function isSingleton() {
return false;
}
/**
* fetch the next row as zero indexed array
*/
function res_fetch_array($res)
{
if($this->extension == DOKU_EXT_SQLITE )
{
return sqlite_fetch_array($res, SQLITE_NUM);
}
else
{
if(!$res) return false;
return $res->fetch(PDO::FETCH_NUM);
}
}
/**
* fetch the next row as assocative array
*/
function res_fetch_assoc($res)
{
if($this->extension == DOKU_EXT_SQLITE )
{
return sqlite_fetch_array($res, SQLITE_ASSOC);
}
else
{
if(!$res) return false;
return $res->fetch(PDO::FETCH_ASSOC);
}
}
/**
* Count the number of records in result
*
* This function is really inperformant in PDO and should be avoided!
*/
function res2count($res) {
if($this->extension == DOKU_EXT_SQLITE )
{
return sqlite_num_rows($res);
}
else
{
if(!$res) return false;
return count($res->fetch(PDO::FETCH_NUM));
}
}
/**
* Count the number of records changed last time
*/
function countChanges($db, $res)
{
if($this->extension == DOKU_EXT_SQLITE )
{
return sqlite_changes($db);
}
else
{
if(!$res) return false;
return $res->rowCount();
}
}
}
// vim:ts=4:sw=4:et:enc=utf-8: