Skip to content
Snippets Groups Projects
Commit 7421c3cc authored by Andreas Gohr's avatar Andreas Gohr
Browse files

more info is gathered on metaupdate in background indexer

The background indexer now gathers info on contributors and modification
dates from the changelog when adding the missing meta info.

A new io_grep function was added which might be useful for other parts in
the Wiki as well.

darcs-hash:20060511191450-7ad00-baba1b48ea03b823c88a480862c612316f159b5a.gz
parent 4fa2dffc
No related branches found
No related tags found
No related merge requests found
...@@ -366,4 +366,45 @@ function io_runcmd($cmd){ ...@@ -366,4 +366,45 @@ function io_runcmd($cmd){
return $ret; return $ret;
} }
/**
* Search a file for matching lines
*
* This is probably not faster than file()+preg_grep() but less
* memory intensive because not the whole file needs to be loaded
* at once.
*
* @author Andreas Gohr <andi@splitbrain.org>
* @param string $file The file to search
* @param string $pattern PCRE pattern
* @param int $max How many lines to return (0 for all)
* @param bool $baxkref When true returns array with backreferences instead of lines
* @return matching lines or backref, false on error
*/
function io_grep($file,$pattern,$max=0,$backref=false){
$fh = @fopen($file,'r');
if(!$fh) return false;
$matches = array();
$cnt = 0;
$line = '';
while (!feof($fh)) {
$line .= fgets($fh, 4096); // read full line
if(substr($line,-1) != "\n") continue;
// check if line matches
if(preg_match($pattern,$line,$match)){
if($backref){
$matches[] = $match;
}else{
$matches[] = $line;
}
$cnt++;
}
if($max && $max == $cnt) break;
$line = '';
}
fclose($fh);
return $matches;
}
//Setup VIM: ex: et ts=2 enc=utf-8 : //Setup VIM: ex: et ts=2 enc=utf-8 :
...@@ -91,10 +91,31 @@ function metaUpdate(){ ...@@ -91,10 +91,31 @@ function metaUpdate(){
// rendering needed? // rendering needed?
if (@file_exists($file)) return false; if (@file_exists($file)) return false;
if (!@file_exists(wikiFN($ID))) return false;
require_once(DOKU_INC.'inc/common.php');
require_once(DOKU_INC.'inc/parserutils.php'); require_once(DOKU_INC.'inc/parserutils.php');
global $conf;
// gather some additional info from changelog
$info = io_grep($conf['changelog'],
'/^(\d+)\t(\d+\.\d+\.\d+\.\d+)\t'.preg_quote($ID,'/').'\t([^\t]+)\t([^\t\n]+)/',
0,true);
$meta = array(); $meta = array();
if(count($info)){
$meta['date']['created'] = $info[0][1];
foreach($info as $item){
if($item[4] != '*'){
$meta['date']['modified'] = $item[1];
if($item[3]){
$meta['contributor'][$item[3]] = $item[3];
}
}
}
}
$meta = p_render_metadata($ID, $meta); $meta = p_render_metadata($ID, $meta);
io_saveFile($file, serialize($meta)); io_saveFile($file, serialize($meta));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment