1<?php 2/** 3 * Functions to create the fulltext search index 4 * 5 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 6 * @author Andreas Gohr <andi@splitbrain.org> 7 */ 8 9if(!defined('DOKU_INC')) die('meh.'); 10 11// set the minimum token length to use in the index (note, this doesn't apply to numeric tokens) 12if (!defined('IDX_MINWORDLENGTH')) define('IDX_MINWORDLENGTH',2); 13 14// Asian characters are handled as words. The following regexp defines the 15// Unicode-Ranges for Asian characters 16// Ranges taken from http://en.wikipedia.org/wiki/Unicode_block 17// I'm no language expert. If you think some ranges are wrongly chosen or 18// a range is missing, please contact me 19define('IDX_ASIAN1','[\x{0E00}-\x{0E7F}]'); // Thai 20define('IDX_ASIAN2','['. 21 '\x{2E80}-\x{3040}'. // CJK -> Hangul 22 '\x{309D}-\x{30A0}'. 23 '\x{30FD}-\x{31EF}\x{3200}-\x{D7AF}'. 24 '\x{F900}-\x{FAFF}'. // CJK Compatibility Ideographs 25 '\x{FE30}-\x{FE4F}'. // CJK Compatibility Forms 26 ']'); 27define('IDX_ASIAN3','['. // Hiragana/Katakana (can be two characters) 28 '\x{3042}\x{3044}\x{3046}\x{3048}'. 29 '\x{304A}-\x{3062}\x{3064}-\x{3082}'. 30 '\x{3084}\x{3086}\x{3088}-\x{308D}'. 31 '\x{308F}-\x{3094}'. 32 '\x{30A2}\x{30A4}\x{30A6}\x{30A8}'. 33 '\x{30AA}-\x{30C2}\x{30C4}-\x{30E2}'. 34 '\x{30E4}\x{30E6}\x{30E8}-\x{30ED}'. 35 '\x{30EF}-\x{30F4}\x{30F7}-\x{30FA}'. 36 ']['. 37 '\x{3041}\x{3043}\x{3045}\x{3047}\x{3049}'. 38 '\x{3063}\x{3083}\x{3085}\x{3087}\x{308E}\x{3095}-\x{309C}'. 39 '\x{30A1}\x{30A3}\x{30A5}\x{30A7}\x{30A9}'. 40 '\x{30C3}\x{30E3}\x{30E5}\x{30E7}\x{30EE}\x{30F5}\x{30F6}\x{30FB}\x{30FC}'. 41 '\x{31F0}-\x{31FF}'. 42 ']?'); 43define('IDX_ASIAN', '(?:'.IDX_ASIAN1.'|'.IDX_ASIAN2.'|'.IDX_ASIAN3.')'); 44 45/** 46 * Measure the length of a string. 47 * Differs from strlen in handling of asian characters. 48 * 49 * @author Tom N Harris <tnharris@whoopdedo.org> 50 */ 51function wordlen($w){ 52 $l = strlen($w); 53 // If left alone, all chinese "words" will get put into w3.idx 54 // So the "length" of a "word" is faked 55 if(preg_match('/'.IDX_ASIAN2.'/u',$w)) 56 $l += ord($w) - 0xE1; // Lead bytes from 0xE2-0xEF 57 return $l; 58} 59 60/** 61 * Write a list of strings to an index file. 62 * 63 * @author Tom N Harris <tnharris@whoopdedo.org> 64 */ 65function idx_saveIndex($pre, $wlen, &$idx){ 66 global $conf; 67 $fn = $conf['indexdir'].'/'.$pre.$wlen; 68 $fh = @fopen($fn.'.tmp','w'); 69 if(!$fh) return false; 70 fwrite($fh,join('', $idx)); 71 fclose($fh); 72 if(isset($conf['fperm'])) chmod($fn.'.tmp', $conf['fperm']); 73 io_rename($fn.'.tmp', $fn.'.idx'); 74 return true; 75} 76 77/** 78 * Append a given line to an index file. 79 * 80 * @author Andreas Gohr <andi@splitbrain.org> 81 */ 82function idx_appendIndex($pre, $wlen, $line){ 83 global $conf; 84 $fn = $conf['indexdir'].'/'.$pre.$wlen; 85 $fh = @fopen($fn.'.idx','a'); 86 if(!$fh) return false; 87 fwrite($fh,$line); 88 fclose($fh); 89 return true; 90} 91 92/** 93 * Read the list of words in an index (if it exists). 94 * 95 * @author Tom N Harris <tnharris@whoopdedo.org> 96 */ 97function idx_getIndex($pre, $wlen){ 98 global $conf; 99 $fn = $conf['indexdir'].'/'.$pre.$wlen.'.idx'; 100 if(!@file_exists($fn)) return array(); 101 return file($fn); 102} 103 104/** 105 * Create an empty index file if it doesn't exist yet. 106 * 107 * FIXME: This function isn't currently used. It will probably be removed soon. 108 * 109 * @author Tom N Harris <tnharris@whoopdedo.org> 110 */ 111function idx_touchIndex($pre, $wlen){ 112 global $conf; 113 $fn = $conf['indexdir'].'/'.$pre.$wlen.'.idx'; 114 if(!@file_exists($fn)){ 115 touch($fn); 116 if($conf['fperm']) chmod($fn, $conf['fperm']); 117 } 118} 119 120/** 121 * Read a line ending with \n. 122 * Returns false on EOF. 123 * 124 * @author Tom N Harris <tnharris@whoopdedo.org> 125 */ 126function _freadline($fh) { 127 if (feof($fh)) return false; 128 $ln = ''; 129 while (($buf = fgets($fh,4096)) !== false) { 130 $ln .= $buf; 131 if (substr($buf,-1) == "\n") break; 132 } 133 if ($ln === '') return false; 134 if (substr($ln,-1) != "\n") $ln .= "\n"; 135 return $ln; 136} 137 138/** 139 * Write a line to an index file. 140 * 141 * @author Tom N Harris <tnharris@whoopdedo.org> 142 */ 143function idx_saveIndexLine($pre, $wlen, $idx, $line){ 144 global $conf; 145 if(substr($line,-1) != "\n") $line .= "\n"; 146 $fn = $conf['indexdir'].'/'.$pre.$wlen; 147 $fh = @fopen($fn.'.tmp','w'); 148 if(!$fh) return false; 149 $ih = @fopen($fn.'.idx','r'); 150 if ($ih) { 151 $ln = -1; 152 while (($curline = fgets($ih)) !== false) { 153 if (++$ln == $idx) { 154 fwrite($fh, $line); 155 } else { 156 fwrite($fh, $curline); 157 } 158 } 159 if ($idx > $ln) { 160 fwrite($fh,$line); 161 } 162 fclose($ih); 163 } else { 164 fwrite($fh,$line); 165 } 166 fclose($fh); 167 if($conf['fperm']) chmod($fn.'.tmp', $conf['fperm']); 168 io_rename($fn.'.tmp', $fn.'.idx'); 169 return true; 170} 171 172/** 173 * Read a single line from an index (if it exists). 174 * 175 * @author Tom N Harris <tnharris@whoopdedo.org> 176 */ 177function idx_getIndexLine($pre, $wlen, $idx){ 178 global $conf; 179 $fn = $conf['indexdir'].'/'.$pre.$wlen.'.idx'; 180 if(!@file_exists($fn)) return ''; 181 $fh = @fopen($fn,'r'); 182 if(!$fh) return ''; 183 $ln = -1; 184 while (($line = fgets($fh)) !== false) { 185 if (++$ln == $idx) break; 186 } 187 fclose($fh); 188 return "$line"; 189} 190 191/** 192 * Split a page into words 193 * 194 * Returns an array of word counts, false if an error occurred. 195 * Array is keyed on the word length, then the word index. 196 * 197 * @author Andreas Gohr <andi@splitbrain.org> 198 * @author Christopher Smith <chris@jalakai.co.uk> 199 */ 200function idx_getPageWords($page){ 201 global $conf; 202 $swfile = DOKU_INC.'inc/lang/'.$conf['lang'].'/stopwords.txt'; 203 if(@file_exists($swfile)){ 204 $stopwords = file($swfile); 205 }else{ 206 $stopwords = array(); 207 } 208 209 $body = ''; 210 $data = array($page, $body); 211 $evt = new Doku_Event('INDEXER_PAGE_ADD', $data); 212 if ($evt->advise_before()) $data[1] .= rawWiki($page); 213 $evt->advise_after(); 214 unset($evt); 215 216 list($page,$body) = $data; 217 218 $body = strtr($body, "\r\n\t", ' '); 219 $tokens = explode(' ', $body); 220 $tokens = array_count_values($tokens); // count the frequency of each token 221 222 // ensure the deaccented or romanised page names of internal links are added to the token array 223 // (this is necessary for the backlink function -- there maybe a better way!) 224 if ($conf['deaccent']) { 225 $links = p_get_metadata($page,'relation references'); 226 227 if (!empty($links)) { 228 $tmp = join(' ',array_keys($links)); // make a single string 229 $tmp = strtr($tmp, ':', ' '); // replace namespace separator with a space 230 $link_tokens = array_unique(explode(' ', $tmp)); // break into tokens 231 232 foreach ($link_tokens as $link_token) { 233 if (isset($tokens[$link_token])) continue; 234 $tokens[$link_token] = 1; 235 } 236 } 237 } 238 239 $words = array(); 240 foreach ($tokens as $word => $count) { 241 $arr = idx_tokenizer($word,$stopwords); 242 $arr = array_count_values($arr); 243 foreach ($arr as $w => $c) { 244 $l = wordlen($w); 245 if(isset($words[$l])){ 246 $words[$l][$w] = $c * $count + (isset($words[$l][$w]) ? $words[$l][$w] : 0); 247 }else{ 248 $words[$l] = array($w => $c * $count); 249 } 250 } 251 } 252 253 // arrive here with $words = array(wordlen => array(word => frequency)) 254 255 $word_idx_modified = false; 256 257 $index = array(); //resulting index 258 foreach (array_keys($words) as $wlen){ 259 $word_idx = idx_getIndex('w',$wlen); 260 foreach ($words[$wlen] as $word => $freq) { 261 $wid = array_search("$word\n",$word_idx); 262 if(!is_int($wid)){ 263 $wid = count($word_idx); 264 $word_idx[] = "$word\n"; 265 $word_idx_modified = true; 266 } 267 if(!isset($index[$wlen])) 268 $index[$wlen] = array(); 269 $index[$wlen][$wid] = $freq; 270 } 271 272 // save back word index 273 if($word_idx_modified && !idx_saveIndex('w',$wlen,$word_idx)){ 274 trigger_error("Failed to write word index", E_USER_ERROR); 275 return false; 276 } 277 } 278 279 return $index; 280} 281 282/** 283 * Adds/updates the search for the given page 284 * 285 * This is the core function of the indexer which does most 286 * of the work. This function needs to be called with proper 287 * locking! 288 * 289 * @author Andreas Gohr <andi@splitbrain.org> 290 */ 291function idx_addPage($page){ 292 global $conf; 293 294 // load known documents 295 $page_idx = idx_getIndex('page',''); 296 297 // get page id (this is the linenumber in page.idx) 298 $pid = array_search("$page\n",$page_idx); 299 if(!is_int($pid)){ 300 $pid = count($page_idx); 301 // page was new - write back 302 if (!idx_appendIndex('page','',"$page\n")){ 303 trigger_error("Failed to write page index", E_USER_ERROR); 304 return false; 305 } 306 } 307 unset($page_idx); // free memory 308 309 idx_saveIndexLine('title', '', $pid, p_get_first_heading($page, false)); 310 311 $pagewords = array(); 312 // get word usage in page 313 $words = idx_getPageWords($page); 314 if($words === false) return false; 315 316 if(!empty($words)) { 317 foreach(array_keys($words) as $wlen){ 318 $index = idx_getIndex('i',$wlen); 319 foreach($words[$wlen] as $wid => $freq){ 320 if($wid<count($index)){ 321 $index[$wid] = idx_updateIndexLine($index[$wid],$pid,$freq); 322 }else{ 323 // New words **should** have been added in increasing order 324 // starting with the first unassigned index. 325 // If someone can show how this isn't true, then I'll need to sort 326 // or do something special. 327 $index[$wid] = idx_updateIndexLine('',$pid,$freq); 328 } 329 $pagewords[] = "$wlen*$wid"; 330 } 331 // save back word index 332 if(!idx_saveIndex('i',$wlen,$index)){ 333 trigger_error("Failed to write index", E_USER_ERROR); 334 return false; 335 } 336 } 337 } 338 339 // Remove obsolete index entries 340 $pageword_idx = trim(idx_getIndexLine('pageword','',$pid)); 341 if ($pageword_idx !== '') { 342 $oldwords = explode(':',$pageword_idx); 343 $delwords = array_diff($oldwords, $pagewords); 344 $upwords = array(); 345 foreach ($delwords as $word) { 346 if($word=='') continue; 347 list($wlen,$wid) = explode('*',$word); 348 $wid = (int)$wid; 349 $upwords[$wlen][] = $wid; 350 } 351 foreach ($upwords as $wlen => $widx) { 352 $index = idx_getIndex('i',$wlen); 353 foreach ($widx as $wid) { 354 $index[$wid] = idx_updateIndexLine($index[$wid],$pid,0); 355 } 356 idx_saveIndex('i',$wlen,$index); 357 } 358 } 359 // Save the reverse index 360 $pageword_idx = join(':',$pagewords)."\n"; 361 if(!idx_saveIndexLine('pageword','',$pid,$pageword_idx)){ 362 trigger_error("Failed to write word index", E_USER_ERROR); 363 return false; 364 } 365 366 return true; 367} 368 369/** 370 * Write a new index line to the filehandle 371 * 372 * This function writes an line for the index file to the 373 * given filehandle. It removes the given document from 374 * the given line and readds it when $count is >0. 375 * 376 * @deprecated - see idx_updateIndexLine 377 * @author Andreas Gohr <andi@splitbrain.org> 378 */ 379function idx_writeIndexLine($fh,$line,$pid,$count){ 380 fwrite($fh,idx_updateIndexLine($line,$pid,$count)); 381} 382 383/** 384 * Modify an index line with new information 385 * 386 * This returns a line of the index. It removes the 387 * given document from the line and readds it if 388 * $count is >0. 389 * 390 * @author Tom N Harris <tnharris@whoopdedo.org> 391 * @author Andreas Gohr <andi@splitbrain.org> 392 */ 393function idx_updateIndexLine($line,$pid,$count){ 394 if ($line == ''){ 395 $newLine = "\n"; 396 }else{ 397 $newLine = preg_replace('/(^|:)'.preg_quote($pid, '/').'\*\d*/', '', $line); 398 } 399 if ($count){ 400 if (strlen($newLine) > 1){ 401 return "$pid*$count:".$newLine; 402 }else{ 403 return "$pid*$count".$newLine; 404 } 405 } 406 return $newLine; 407} 408 409/** 410 * Get the list of lenghts indexed in the wiki 411 * 412 * Read the index directory or a cache file and returns 413 * a sorted array of lengths of the words used in the wiki. 414 * 415 * @author YoBoY <yoboy.leguesh@gmail.com> 416 */ 417function idx_listIndexLengths() { 418 global $conf; 419 // testing what we have to do, create a cache file or not. 420 if ($conf['readdircache'] == 0) { 421 $docache = false; 422 } else { 423 clearstatcache(); 424 if (@file_exists($conf['indexdir'].'/lengths.idx') and (time() < @filemtime($conf['indexdir'].'/lengths.idx') + $conf['readdircache'])) { 425 if (($lengths = @file($conf['indexdir'].'/lengths.idx', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES) ) !== false) { 426 $idx = array(); 427 foreach ( $lengths as $length) { 428 $idx[] = (int)$length; 429 } 430 return $idx; 431 } 432 } 433 $docache = true; 434 } 435 436 if ($conf['readdircache'] == 0 or $docache ) { 437 $dir = @opendir($conf['indexdir']); 438 if($dir===false) 439 return array(); 440 $idx[] = array(); 441 while (($f = readdir($dir)) !== false) { 442 if (substr($f,0,1) == 'i' && substr($f,-4) == '.idx'){ 443 $i = substr($f,1,-4); 444 if (is_numeric($i)) 445 $idx[] = (int)$i; 446 } 447 } 448 closedir($dir); 449 sort($idx); 450 // we save this in a file. 451 if ($docache === true) { 452 $handle = @fopen($conf['indexdir'].'/lengths.idx','w'); 453 @fwrite($handle, implode("\n",$idx)); 454 @fclose($handle); 455 } 456 return $idx; 457 } 458 459 return array(); 460} 461 462/** 463 * Get the word lengths that have been indexed. 464 * 465 * Reads the index directory and returns an array of lengths 466 * that there are indices for. 467 * 468 * @author YoBoY <yoboy.leguesh@gmail.com> 469 */ 470function idx_indexLengths(&$filter){ 471 global $conf; 472 $idx = array(); 473 if (is_array($filter)){ 474 // testing if index files exists only 475 foreach ($filter as $key => $value) { 476 if (@file_exists($conf['indexdir']."/i$key.idx")) { 477 $idx[] = $key; 478 } 479 } 480 } else { 481 $lengths = idx_listIndexLengths(); 482 foreach ( $lengths as $key => $length) { 483 // we keep all the values equal or superior 484 if ((int)$length >= (int)$filter) { 485 $idx[] = $length; 486 } 487 } 488 } 489 return $idx; 490} 491 492/** 493 * Find the the index number of each search term. 494 * 495 * This will group together words that appear in the same index. 496 * So it should perform better, because it only opens each index once. 497 * Actually, it's not that great. (in my experience) Probably because of the disk cache. 498 * And the sorted function does more work, making it slightly slower in some cases. 499 * 500 * @param array $words The query terms. Words should only contain valid characters, 501 * with a '*' at either the beginning or end of the word (or both) 502 * @param arrayref $result Set to word => array("length*id" ...), use this to merge the 503 * index locations with the appropriate query term. 504 * @return array Set to length => array(id ...) 505 * 506 * @author Tom N Harris <tnharris@whoopdedo.org> 507 */ 508function idx_getIndexWordsSorted($words,&$result){ 509 // parse and sort tokens 510 $tokens = array(); 511 $tokenlength = array(); 512 $tokenwild = array(); 513 foreach($words as $word){ 514 $result[$word] = array(); 515 $wild = 0; 516 $xword = $word; 517 $wlen = wordlen($word); 518 519 // check for wildcards 520 if(substr($xword,0,1) == '*'){ 521 $xword = substr($xword,1); 522 $wild |= 1; 523 $wlen -= 1; 524 } 525 if(substr($xword,-1,1) == '*'){ 526 $xword = substr($xword,0,-1); 527 $wild |= 2; 528 $wlen -= 1; 529 } 530 if ($wlen < IDX_MINWORDLENGTH && $wild == 0 && !is_numeric($xword)) continue; 531 if(!isset($tokens[$xword])){ 532 $tokenlength[$wlen][] = $xword; 533 } 534 if($wild){ 535 $ptn = preg_quote($xword,'/'); 536 if(($wild&1) == 0) $ptn = '^'.$ptn; 537 if(($wild&2) == 0) $ptn = $ptn.'$'; 538 $tokens[$xword][] = array($word, '/'.$ptn.'/'); 539 if(!isset($tokenwild[$xword])) $tokenwild[$xword] = $wlen; 540 }else 541 $tokens[$xword][] = array($word, null); 542 } 543 asort($tokenwild); 544 // $tokens = array( base word => array( [ query word , grep pattern ] ... ) ... ) 545 // $tokenlength = array( base word length => base word ... ) 546 // $tokenwild = array( base word => base word length ... ) 547 548 $length_filter = empty($tokenwild) ? $tokenlength : min(array_keys($tokenlength)); 549 $indexes_known = idx_indexLengths($length_filter); 550 if(!empty($tokenwild)) sort($indexes_known); 551 // get word IDs 552 $wids = array(); 553 foreach($indexes_known as $ixlen){ 554 $word_idx = idx_getIndex('w',$ixlen); 555 // handle exact search 556 if(isset($tokenlength[$ixlen])){ 557 foreach($tokenlength[$ixlen] as $xword){ 558 $wid = array_search("$xword\n",$word_idx); 559 if(is_int($wid)){ 560 $wids[$ixlen][] = $wid; 561 foreach($tokens[$xword] as $w) 562 $result[$w[0]][] = "$ixlen*$wid"; 563 } 564 } 565 } 566 // handle wildcard search 567 foreach($tokenwild as $xword => $wlen){ 568 if($wlen >= $ixlen) break; 569 foreach($tokens[$xword] as $w){ 570 if(is_null($w[1])) continue; 571 foreach(array_keys(preg_grep($w[1],$word_idx)) as $wid){ 572 $wids[$ixlen][] = $wid; 573 $result[$w[0]][] = "$ixlen*$wid"; 574 } 575 } 576 } 577 } 578 return $wids; 579} 580 581/** 582 * Lookup words in index 583 * 584 * Takes an array of word and will return a list of matching 585 * documents for each one. 586 * 587 * Important: No ACL checking is done here! All results are 588 * returned, regardless of permissions 589 * 590 * @author Andreas Gohr <andi@splitbrain.org> 591 */ 592function idx_lookup($words){ 593 global $conf; 594 595 $result = array(); 596 597 $wids = idx_getIndexWordsSorted($words, $result); 598 if(empty($wids)) return array(); 599 600 // load known words and documents 601 $page_idx = idx_getIndex('page',''); 602 603 $docs = array(); // hold docs found 604 foreach(array_keys($wids) as $wlen){ 605 $wids[$wlen] = array_unique($wids[$wlen]); 606 $index = idx_getIndex('i',$wlen); 607 foreach($wids[$wlen] as $ixid){ 608 if($ixid < count($index)) 609 $docs["$wlen*$ixid"] = idx_parseIndexLine($page_idx,$index[$ixid]); 610 } 611 } 612 613 // merge found pages into final result array 614 $final = array(); 615 foreach($result as $word => $res){ 616 $final[$word] = array(); 617 foreach($res as $wid){ 618 $hits = &$docs[$wid]; 619 foreach ($hits as $hitkey => $hitcnt) { 620 if (!isset($final[$word][$hitkey])) { 621 $final[$word][$hitkey] = $hitcnt; 622 } else { 623 $final[$word][$hitkey] += $hitcnt; 624 } 625 } 626 } 627 } 628 return $final; 629} 630 631/** 632 * Returns a list of documents and counts from a index line 633 * 634 * It omits docs with a count of 0 and pages that no longer 635 * exist. 636 * 637 * @param array $page_idx The list of known pages 638 * @param string $line A line from the main index 639 * @author Andreas Gohr <andi@splitbrain.org> 640 */ 641function idx_parseIndexLine(&$page_idx,$line){ 642 $result = array(); 643 644 $line = trim($line); 645 if($line == '') return $result; 646 647 $parts = explode(':',$line); 648 foreach($parts as $part){ 649 if($part == '') continue; 650 list($doc,$cnt) = explode('*',$part); 651 if(!$cnt) continue; 652 $doc = trim($page_idx[$doc]); 653 if(!$doc) continue; 654 // make sure the document still exists 655 if(!page_exists($doc,'',false)) continue; 656 657 $result[$doc] = $cnt; 658 } 659 return $result; 660} 661 662/** 663 * Tokenizes a string into an array of search words 664 * 665 * Uses the same algorithm as idx_getPageWords() 666 * 667 * @param string $string the query as given by the user 668 * @param arrayref $stopwords array of stopwords 669 * @param boolean $wc are wildcards allowed? 670 */ 671function idx_tokenizer($string,&$stopwords,$wc=false){ 672 $words = array(); 673 $wc = ($wc) ? '' : $wc = '\*'; 674 675 if(preg_match('/[^0-9A-Za-z]/u', $string)){ 676 // handle asian chars as single words (may fail on older PHP version) 677 $asia = @preg_replace('/('.IDX_ASIAN.')/u',' \1 ',$string); 678 if(!is_null($asia)) $string = $asia; //recover from regexp failure 679 680 $arr = explode(' ', utf8_stripspecials($string,' ','\._\-:'.$wc)); 681 foreach ($arr as $w) { 682 if (!is_numeric($w) && strlen($w) < IDX_MINWORDLENGTH) continue; 683 $w = utf8_strtolower($w); 684 if($stopwords && is_int(array_search("$w\n",$stopwords))) continue; 685 $words[] = $w; 686 } 687 }else{ 688 $w = $string; 689 if (!is_numeric($w) && strlen($w) < IDX_MINWORDLENGTH) return $words; 690 $w = strtolower($w); 691 if(is_int(array_search("$w\n",$stopwords))) return $words; 692 $words[] = $w; 693 } 694 695 return $words; 696} 697 698//Setup VIM: ex: et ts=4 enc=utf-8 : 699