--- TWiki-4-04.pm	2006-10-27 13:41:04.160265539 +0200
+++ TWiki.pm	2006-10-27 23:56:32.974488416 +0200
@@ -185,6 +185,7 @@
         ICONURLPATH       => \&_ICONURLPATH,
         IF                => \&_IF,
         INCLUDE           => \&_INCLUDE,
+        INCLUDEPARAMS     => \&_INCLUDEPARAMS,     # Niels Oct 2006
         INTURLENCODE      => \&_INTURLENCODE,
         LANGUAGES         => \&_LANGUAGES,
         MAKETEXT          => \&_MAKETEXT,
@@ -2645,6 +2646,38 @@
     return '';
 }
 
+
+# NielsKolso Oct 2006: Handle default paramters
+sub _INCLUDEPARAMS
+{
+    my ( $this, $defaultParams, $includingTopic, $includingWeb ) = @_;
+
+    return qq(<div style='border: dashed red 1pt; padding: 6pt;'><span style='color: red'>Error in =%<nop>INCLUDEPARAM{...}%!= </span> $defaultParams->{_ERROR} </div>) if($defaultParams->{_ERROR});
+
+    my $paramtable = "\n<div class='twikiDefaultIncludeParamTable'>\n".
+                     "|   *%<nop>INCLUDE{...}% paramters*   |||\n".
+                     "| *Name* | *Default value* | *Documentation* |\n";
+
+    foreach (sort keys %$defaultParams)
+    {
+	next if($_ eq '_RAW');
+
+	if($defaultParams->{$_} =~ m/^\s*(.*?)\s*::doc[a-z]*::\s*(.*)$/)
+	{
+	    $paramtable.= '| '.join(' | ', "=$_=", (length($1)?'<verbatim>'.$1.'</verbatim>':'<i style="color: gray">empty</i>') , "$2")." |\n";
+	}
+	else
+	{
+	    $paramtable.= '| '.join(' | ', "=$_=", (length($defaultParams->{$_})?$defaultParams->{$_}:'<i style="color: gray">empty</i>') , "<i style='color:gray'>N/A</i>")." |\n";
+	}
+    }
+
+    $paramtable.="</div>\n";
+
+    return $paramtable;
+}
+
+
 # Processes a specific instance %<nop>INCLUDE{...}% syntax.
 # Returns the text to be inserted in place of the INCLUDE command.
 # $topic and $web should be for the immediate parent topic in the
@@ -2721,15 +2754,58 @@
     $this->{SESSION_TAGS}{INCLUDINGWEB} = $includingWeb;
     $this->{SESSION_TAGS}{INCLUDINGTOPIC} = $includingTopic;
 
+    ( $meta, $text ) =
+      $this->{store}->readTopic( undef, $includedWeb, $includedTopic,
+                                 $rev );
+
+    # NielsKoldso Oct 2006
+    # Handle default argument definition - pad actual parameter list
+    if($text =~ m/%INCLUDEPARAMS{(.*?)}%/s)
+    {
+        my %defaultParamsAndDoc;
+	my $defaultParams = new TWiki::Attrs($1);
+	foreach (keys %$defaultParams)
+	{
+	    if($defaultParams->{$_} =~ m/^\s*(.*?)\s*::doc[a-z]*::\s*(.*)$/)
+	    {
+		$defaultParamsAndDoc{$_}= { value => $1 , documentation => $2 };
+	    }
+	    else
+	    {
+		$defaultParamsAndDoc{$_}= { value => $defaultParams->{$_} , documentation => '' };
+	    }
+            
+	    # Use default attr unless one specified in %INCLDUE{...}%
+            $params->{$_} = $defaultParamsAndDoc{$_}->{'value'} unless(defined $params->{$_});
+	}
+
+        # Now dump parameter table back
+
+        my $paramtable = "\n<div class='twikiDefaultIncludeParamTable'>\n";
+
+	$paramtable.="<div style='border: dashed red 1pt; padding: 6pt;'>\n".
+                     "<span style='color: red'>Error in =%<nop>INCLUDEPARAM{...}%= </span> $defaultParams->{_ERROR}\n".
+                     "</div>\n" if($defaultParams->{_ERROR});
+
+        $paramtable.= "|   *%<nop>INCLUDE{...}% paramters*   ||||\n".
+                      "| *Name* | *Default value* | *Actual value* | *Documentation* |\n";
+        foreach (sort keys %$params) 
+	{   
+	    next if($_ eq '_RAW');
+	    $paramtable.= '| '.join(' | ', "=$_="
+                                        , (length($defaultParamsAndDoc{$_}->{'value'}) ? '<verbatim>'.$defaultParamsAndDoc{$_}->{'value'}.'</verbatim>' :'<i style=\'color: gray\'>empty</i>')  
+                                        , '&raquo;'.$params->{$_}.'&laquo;' 
+                                        , ($defaultParamsAndDoc{$_}->{'documentation'}? $defaultParamsAndDoc{$_}->{'documentation'}                    :'<i style=\'color: gray\'>N/A</i>')) . " |\n";
+	}
+        $paramtable.="</div>\n";
+        $text =~ s/\s*%INCLUDEPARAMS{(.*?)}%\s*\n?/$paramtable/s;
+    }
+
     # copy params into session tags
     foreach my $k ( keys %$params ) {
         $this->{SESSION_TAGS}{$k} = $params->{$k};
     }
 
-    ( $meta, $text ) =
-      $this->{store}->readTopic( undef, $includedWeb, $includedTopic,
-                                 $rev );
-
     unless( $this->{security}->checkAccessPermission(
         'VIEW', $this->{user}, $text, $includedTopic, $includedWeb )) {
         if( isTrue( $warn )) {
