<?php if (!defined('PmWiki')) exit();

/*  Copyright 2004 
    
    Version: authorcontribution 1.0.1
    
    *Contributors*
    Patrick Michaud
    Laurent Meister (kt007) (meister at apfelwiki dot de)
    Sebastian Siedentopf (Schlaefer) (schlaefer at macnews dot de)
    
    *Licence*
    You can redistribute this file and/or modify
    it under the terms of the GNU General Public License as published
    by the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.  
    
    *Description*
    Collect all contributions of an author.
    
    If an author has a page in the group "Profiles" it generates a page with authors name in the group "Contributions". Everytime an author saves a wikipage this contribution is collected there in the same way like RecentChanges does.
    
    
        
    *Installation*
    Simply copy this file into the 'cookbook/' subdirectory or some other
    suitable place and then do

        include_once('cookbook/authorcontribution.php');
        
    For your comfort (?) you can use (:include Contributions.AUTHORNAME:) to include this on the profilepage.
     
    *Attention* 
    This script works only with pmwiki2!
    
   
*/

$EditFunctions[] = 'PostAuthorChanges';

function PostAuthorChanges($pagename,&$page,&$new) {
  global $IsPagePosted,$RCDelimPattern;

  $AuthorChangesFmt = array(
  '$Author' => 
    '* [[$Group.$Name]]  . . . $CurrentTime - \'\' [=$ChangeSummary=] \'\' ');

  if (!$IsPagePosted) return;
 
  foreach($AuthorChangesFmt as $rcfmt=>$pgfmt) {
    
    $rcname = FmtPageName("Profiles.".$rcfmt,$pagename);  if (!$rcname) continue;
    if (!PageExists($rcname)) continue;     
    
    $rcname = FmtPageName("Contributions.".$rcfmt,$pagename);  if (!$rcname) continue;
    $pgtext = FmtPageName($pgfmt,$pagename);  if (!$pgtext) continue;
    if (@$seen[$rcname]++) continue;
    
    $rcpage = ReadPage($rcname);
    $rcelim = preg_quote(preg_replace("/$RCDelimPattern.*$/",' ',$pgtext),'/');
    $rcpage['text'] = preg_replace("/[^\n]*$rcelim.*\n/","",@$rcpage['text']);
    if (!preg_match("/$RCDelimPattern/",$rcpage['text'])) 
      $rcpage['text'] .= "$pgtext\n";
    else
      $rcpage['text'] = preg_replace("/([^\n]*$RCDelimPattern.*\n)/",
        "$pgtext\n$1",$rcpage['text'],1);
    WritePage($rcname,$rcpage);
  }
}

?>