Index: openacs-4/packages/acs-messaging/sql/postgresql/acs-messaging-packages.sql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-messaging/sql/postgresql/acs-messaging-packages.sql,v
diff -u -r1.19 -r1.20
--- openacs-4/packages/acs-messaging/sql/postgresql/acs-messaging-packages.sql	10 Feb 2009 18:31:54 -0000	1.19
+++ openacs-4/packages/acs-messaging/sql/postgresql/acs-messaging-packages.sql	30 Mar 2013 13:22:22 -0000	1.20
@@ -10,21 +10,30 @@
 -- updated for OpenACS by Jon Griffin
 --
 
-create or replace function acs_message__edit (integer,varchar,varchar,varchar,text,integer,timestamptz,integer,varchar,boolean)
-returns integer as '
-declare
-    p_message_id    alias for $1;
-    p_title         alias for $2;    -- default null
-    p_description   alias for $3;    -- default null
-    p_mime_type     alias for $4;    -- default ''text/plain''
-    p_text          alias for $5;    -- default null
-    p_data          alias for $6;    -- default null
-    p_creation_date alias for $7;    -- default sysdate
-    p_creation_user alias for $8;    -- default null
-    p_creation_ip   alias for $9;    -- default null
-    p_is_live       alias for $10;   -- default ''t''
+
+
+-- added
+select define_function_args('acs_message__edit','message_id,title;null,description;null,mime_type;text/plain,text;null,data;null,creation_date;sysdate,creation_user;null,creation_ip;null,is_live;t');
+
+--
+-- procedure acs_message__edit/10
+--
+CREATE OR REPLACE FUNCTION acs_message__edit(
+   p_message_id integer,
+   p_title varchar,             -- default null
+   p_description varchar,       -- default null
+   p_mime_type varchar,         -- default 'text/plain'
+   p_text text,                 -- default null
+   p_data integer,              -- default null
+   p_creation_date timestamptz, -- default sysdate
+   p_creation_user integer,     -- default null
+   p_creation_ip varchar,       -- default null
+   p_is_live boolean            -- default 't'
+
+) RETURNS integer AS $$
+DECLARE
     v_revision_id cr_revisions.revision_id%TYPE;
-begin
+BEGIN
     -- create a new revision using whichever call is appropriate
     if p_data is not null then
 		-- need to take care of blob?
@@ -61,7 +70,8 @@
     end if;
 
     return v_revision_id;
-end;' language 'plpgsql';
+END;
+$$ LANGUAGE plpgsql;
    
 ----------------
 -- MAJOR NOTE OF NON-COMPLIANCE
@@ -73,56 +83,63 @@
 -- Jon Griffin 05-21-2001
 ----------------
 
-create or replace function acs_message__new (integer,integer,timestamptz,integer,
-varchar,varchar,varchar,varchar,text,integer,integer,integer,integer,
-varchar,varchar,boolean,integer)
-returns integer as '
-declare
-        p_message_id    alias for $1;  --default null,
-        p_reply_to      alias for $2;  --default null,
-        p_sent_date     alias for $3;  --default sysdate,
-        p_sender        alias for $4;  --default null,
-        p_rfc822_id     alias for $5;  --default null,
-        p_title         alias for $6;  --default null,
-        p_description   alias for $7;  --default null,
-        p_mime_type     alias for $8;  --default ''text/plain'',
-        p_text          alias for $9;  --default null,
-        p_data          alias for $10; --default null,
-        p_parent_id     alias for $11; --default 0,
-        p_context_id    alias for $12;
+
+
+-- added
+select define_function_args('acs_message__new','message_id,reply_to,sent_date,sender,rfc822_id,title,description,mime_type,text,data,parent_id,context_id,creation_user,creation_ip,object_type,is_live,package_id');
+
+--
+-- procedure acs_message__new/17
+--
+CREATE OR REPLACE FUNCTION acs_message__new(
+   p_message_id integer,    --default null,
+   p_reply_to integer,      --default null,
+   p_sent_date timestamptz, --default sysdate,
+   p_sender integer,        --default null,
+   p_rfc822_id varchar,     --default null,
+   p_title varchar,         --default null,
+   p_description varchar,   --default null,
+   p_mime_type varchar,     --default 'text/plain',
+   p_text text,             --default null,
+   p_data integer,          --default null,
+   p_parent_id integer,     --default 0,
+   p_context_id integer,
+   p_creation_user integer, --default null,
+   p_creation_ip varchar,   --default null,
+   p_object_type varchar,   --default 'acs_message',
+   p_is_live boolean,       --default 't'
+   p_package_id integer
+
+) RETURNS integer AS $$
+DECLARE
         p_creation_date timestamptz := current_timestamp;  -- alias for $13 --default sysdate,
-        p_creation_user alias for $13; --default null,
-        p_creation_ip   alias for $14; --default null,
-        p_object_type   alias for $15; --default ''acs_message'',
-        p_is_live       alias for $16; --default ''t''
-        p_package_id    alias for $17;
         v_message_id   acs_messages.message_id%TYPE;
         v_rfc822_id    acs_messages.rfc822_id%TYPE;
         v_revision_id  cr_revisions.revision_id%TYPE;
 		v_system_url   varchar;
 		v_domain_name  varchar;
 		v_idx		   integer;
-    begin
+    BEGIN
         -- generate a message id now so we can get an rfc822 message-id
         if p_message_id is null then
-            select nextval(''t_acs_object_id_seq'') into v_message_id;
+            select nextval('t_acs_object_id_seq') into v_message_id;
         else
             v_message_id := p_message_id;
         end if;
 
         -- need to make this mandatory also - jg
-        -- this needs to be fixed up, but Oracle doesn''t give us a way
+        -- this needs to be fixed up, but Oracle doesn't give us a way
         -- to get the FQDN
 
 	-- vk: get SystemURL parameter and use it to extract domain name
-         select apm__get_value(package_id, ''SystemURL'') into v_system_url
-          from apm_packages where package_key=''acs-kernel'';
-		v_idx := position(''http://'' in v_system_url);
+         select apm__get_value(package_id, 'SystemURL') into v_system_url
+          from apm_packages where package_key='acs-kernel';
+		v_idx := position('http://' in v_system_url);
 		v_domain_name := trim (substr(v_system_url, v_idx + 7));
 
         if p_rfc822_id is null then
-           v_rfc822_id := current_date || ''.'' || v_message_id || ''@'' ||
-               v_domain_name || ''.hate'';
+           v_rfc822_id := current_date || '.' || v_message_id || '@' ||
+               v_domain_name || '.hate';
         else
             v_rfc822_id := p_rfc822_id;
         end if;
@@ -137,13 +154,13 @@
             p_context_id,			  -- context_id     
             p_creation_ip,			  -- creation_ip    
             p_object_type,			  -- item_subtype   
-            ''acs_message_revision'',		  -- content_type   
+            'acs_message_revision',		  -- content_type   
             null,				  -- title
             null,				  -- description
-            ''text/plain'',			  -- mime_type
+            'text/plain',			  -- mime_type
             null,				  -- nls_language
             null,				  -- text
-            ''text'',				  -- storage_type
+            'text',				  -- storage_type
             p_package_id
         );
 
@@ -167,31 +184,36 @@
         );
 
         return v_message_id;
-end;' language 'plpgsql';
+END;
+$$ LANGUAGE plpgsql;
 
-create or replace function acs_message__new (integer,integer,timestamptz,integer,
-varchar,varchar,varchar,varchar,text,integer,integer,integer,integer,
-varchar,varchar,boolean)
-returns integer as '
-declare
-        p_message_id    alias for $1;  --default null,
-        p_reply_to      alias for $2;  --default null,
-        p_sent_date     alias for $3;  --default sysdate,
-        p_sender        alias for $4;  --default null,
-        p_rfc822_id     alias for $5;  --default null,
-        p_title         alias for $6;  --default null,
-        p_description   alias for $7;  --default null,
-        p_mime_type     alias for $8;  --default ''text/plain'',
-        p_text          alias for $9;  --default null,
-        p_data          alias for $10; --default null,
-        p_parent_id     alias for $11; --default 0,
-        p_context_id    alias for $12;
+
+
+--
+-- procedure acs_message__new/16
+--
+CREATE OR REPLACE FUNCTION acs_message__new(
+   p_message_id integer,    --default null,
+   p_reply_to integer,      --default null,
+   p_sent_date timestamptz, --default sysdate,
+   p_sender integer,        --default null,
+   p_rfc822_id varchar,     --default null,
+   p_title varchar,         --default null,
+   p_description varchar,   --default null,
+   p_mime_type varchar,     --default 'text/plain',
+   p_text text,             --default null,
+   p_data integer,          --default null,
+   p_parent_id integer,     --default 0,
+   p_context_id integer,
+   p_creation_user integer, --default null,
+   p_creation_ip varchar,   --default null,
+   p_object_type varchar,   --default 'acs_message',
+   p_is_live boolean        --default 't'
+
+) RETURNS integer AS $$
+DECLARE
         p_creation_date timestamptz := current_timestamp;  -- alias for $13 --default sysdate,
-        p_creation_user alias for $13; --default null,
-        p_creation_ip   alias for $14; --default null,
-        p_object_type   alias for $15; --default ''acs_message'',
-        p_is_live       alias for $16; --default ''t''
-begin
+BEGIN
     return acs_message__new (p_message_id,
                              p_reply_to,
                              p_sent_date,
@@ -210,79 +232,125 @@
                              p_is_live,
                              null::integer
    );
-end;' language 'plpgsql';
+END;
+$$ LANGUAGE plpgsql;
 
-create or replace function acs_message__delete (integer)
-returns integer as '
-declare
-    p_message_id    alias for $1;
-begin
+
+
+-- added
+select define_function_args('acs_message__delete','message_id');
+
+--
+-- procedure acs_message__delete/1
+--
+CREATE OR REPLACE FUNCTION acs_message__delete(
+   p_message_id integer
+) RETURNS integer AS $$
+DECLARE
+BEGIN
     delete from acs_messages where message_id = p_message_id;
     perform content_item__delete(p_message_id);
     return 1;
-end;' language 'plpgsql';
+END;
+$$ LANGUAGE plpgsql;
 
-create or replace function acs_message__message_p (integer)
-returns boolean as '
-declare
-    p_message_id          alias for $1;
+
+
+-- added
+select define_function_args('acs_message__message_p','message_id');
+
+--
+-- procedure acs_message__message_p/1
+--
+CREATE OR REPLACE FUNCTION acs_message__message_p(
+   p_message_id integer
+) RETURNS boolean AS $$
+DECLARE
     v_check_message_id  integer;
-begin
+BEGIN
     select count(message_id) into v_check_message_id
         from acs_messages where message_id = p_message_id;
 
     if v_check_message_id <> 0 then
-        return ''t'';
+        return 't';
     else
-        return ''f'';
+        return 'f';
     end if;
-end;' language 'plpgsql' stable;
+END;
+$$ LANGUAGE plpgsql stable;
 
-create or replace function acs_message__send (integer,varchar,integer,timestamptz)
-returns integer as '
-declare
-    p_message_id    alias for $1;
-    p_to_address    alias for $2;
-    p_grouping_id   alias for $3;    -- default null
-    p_wait_until    alias for $4;    -- default sysdate
+
+
+-- added
+
+--
+-- procedure acs_message__send/4
+--
+CREATE OR REPLACE FUNCTION acs_message__send(
+   p_message_id integer,
+   p_to_address varchar,
+   p_grouping_id integer,   -- default null
+   p_wait_until timestamptz -- default sysdate
+
+) RETURNS integer AS $$
+DECLARE
     v_wait_until timestamptz;
-begin
+BEGIN
     v_wait_until := coalesce(p_wait_until, current_timestamp);
     insert into acs_messages_outgoing
         (message_id, to_address, grouping_id, wait_until)
     values
         (p_message_id, p_to_address, p_grouping_id, v_wait_until);
     return 1;
-end;' language 'plpgsql';
+END;
+$$ LANGUAGE plpgsql;
 
-create or replace function acs_message__send (integer,integer,integer,timestamptz)
-returns integer as '
-declare
-    p_message_id    alias for $1;
-    p_recipient_id  alias for $2;
-    p_grouping_id   alias for $3;    -- default null
-    p_wait_until    alias for $4;    -- default sysdate
+
+
+-- added
+select define_function_args('acs_message__send','message_id,recipient_id,grouping_id;null,wait_until;sysdate');
+
+--
+-- procedure acs_message__send/4
+--
+CREATE OR REPLACE FUNCTION acs_message__send(
+   p_message_id integer,
+   p_recipient_id integer,
+   p_grouping_id integer,   -- default null
+   p_wait_until timestamptz -- default sysdate
+
+) RETURNS integer AS $$
+DECLARE
     v_wait_until timestamptz;
-begin
+BEGIN
     v_wait_until := coalesce (p_wait_until, current_timestamp);
     insert into acs_messages_outgoing
         (message_id, to_address, grouping_id, wait_until)
     select p_message_id, p.email, p_grouping_id, v_wait_until
         from parties p
         where p.party_id = p_recipient_id;
     return 1;
-end;' language 'plpgsql';
+END;
+$$ LANGUAGE plpgsql;
 
 
 -- Ported to take advantage of tree_sortkey column by DLP
 
-create or replace function acs_message__first_ancestor (integer)
-returns integer as '
-declare
-    p_message_id alias for $1;
+
+
+-- added
+select define_function_args('acs_message__first_ancestor','message_id');
+
+--
+-- procedure acs_message__first_ancestor/1
+--
+CREATE OR REPLACE FUNCTION acs_message__first_ancestor(
+   p_message_id integer
+) RETURNS integer AS $$
+DECLARE
     v_message_id acs_messages.message_id%TYPE;
     v_ancestor_sk varbit;
-begin
+BEGIN
     select tree_ancestor_key(tree_sortkey, 1) into v_ancestor_sk
       from acs_messages
      where message_id = p_message_id;
@@ -292,7 +360,8 @@
      where tree_sortkey = v_ancestor_sk;
 
     return v_message_id;
-end;' language 'plpgsql' stable strict;
+END;
+$$ LANGUAGE plpgsql stable strict;
 
     -- ACHTUNG!  WARNING!  ACHTUNG!  WARNING!  ACHTUNG!  WARNING! --
 
@@ -301,26 +370,34 @@
     -- functions will migrate to another PL/SQL package or be replaced
     -- by direct calls to CR code in the near future.
 
-create or replace function acs_message__new_file (integer,integer,varchar,varchar,
-text,varchar,integer,timestamptz,integer,varchar,boolean,varchar,integer)
-returns integer as '
-declare
-    p_message_id    alias for $1;
-    p_file_id       alias for $2;    -- default null
-    p_file_name     alias for $3;
-    p_title         alias for $4;    -- default null
-    p_description   alias for $5;    -- default null
-    p_mime_type     alias for $6;    -- default ''text/plain''
-    p_data          alias for $7;    -- default null
-    p_creation_date alias for $8;    -- default sysdate
-    p_creation_user alias for $9;    -- default null
-    p_creation_ip   alias for $10;   -- default null
-    p_is_live       alias for $11;   -- default ''t''
-    p_storage_type  alias for $12;   -- default ''file''
-    p_package_id    alias for $13;   -- default null
+
+
+-- added
+select define_function_args('acs_message__new_file','message_id,file_id;null,file_name,title;null,description;null,mime_type;text/plain,data;null,creation_date;sysdate,creation_user;null,creation_ip;null,is_live;t,storage_type;file,package_id;null');
+
+--
+-- procedure acs_message__new_file/13
+--
+CREATE OR REPLACE FUNCTION acs_message__new_file(
+   p_message_id integer,
+   p_file_id integer,           -- default null
+   p_file_name varchar,
+   p_title varchar,             -- default null
+   p_description text,          -- default null
+   p_mime_type varchar,         -- default 'text/plain'
+   p_data integer,              -- default null
+   p_creation_date timestamptz, -- default sysdate
+   p_creation_user integer,     -- default null
+   p_creation_ip varchar,       -- default null
+   p_is_live boolean,           -- default 't'
+   p_storage_type varchar,      -- default 'file'
+   p_package_id integer         -- default null
+
+) RETURNS integer AS $$
+DECLARE
     v_file_id      cr_items.item_id%TYPE;
     v_revision_id  cr_revisions.revision_id%TYPE;
-begin
+BEGIN
     v_file_id := content_item__new (
         p_file_name,			   -- name           
         p_message_id,			   -- parent_id      
@@ -330,11 +407,11 @@
         p_creation_user,		   -- creation_user  
         null,				   -- context_id
         p_creation_ip,			   -- creation_ip    
-        ''content_item'',		   -- item_subtype
-        ''content_revision'',		   -- content_type
+        'content_item',		   -- item_subtype
+        'content_revision',		   -- content_type
         null,				   -- title
         null,				   -- description
-        ''text/plain'',			   -- mime_type
+        'text/plain',			   -- mime_type
         null,				   -- nls_language
         null,				   -- text
 	p_storage_type,			   -- storage_type
@@ -355,25 +432,31 @@
     );
 
     return v_file_id;
-end;' language 'plpgsql';
+END;
+$$ LANGUAGE plpgsql;
 
-create or replace function acs_message__new_file (integer,integer,varchar,varchar,
-text,varchar,integer,timestamptz,integer,varchar,boolean,varchar)
-returns integer as '
-declare
-    p_message_id    alias for $1;
-    p_file_id       alias for $2;    -- default null
-    p_file_name     alias for $3;
-    p_title         alias for $4;    -- default null
-    p_description   alias for $5;    -- default null
-    p_mime_type     alias for $6;    -- default ''text/plain''
-    p_data          alias for $7;    -- default null
-    p_creation_date alias for $8;    -- default sysdate
-    p_creation_user alias for $9;    -- default null
-    p_creation_ip   alias for $10;   -- default null
-    p_is_live       alias for $11;   -- default ''t''
-    p_storage_type  alias for $12;   -- default ''file''
-begin
+
+
+--
+-- procedure acs_message__new_file/12
+--
+CREATE OR REPLACE FUNCTION acs_message__new_file(
+   p_message_id integer,
+   p_file_id integer,           -- default null
+   p_file_name varchar,
+   p_title varchar,             -- default null
+   p_description text,          -- default null
+   p_mime_type varchar,         -- default 'text/plain'
+   p_data integer,              -- default null
+   p_creation_date timestamptz, -- default sysdate
+   p_creation_user integer,     -- default null
+   p_creation_ip varchar,       -- default null
+   p_is_live boolean,           -- default 't'
+   p_storage_type varchar       -- default 'file'
+
+) RETURNS integer AS $$
+DECLARE
+BEGIN
     return acs_message__new_file (p_message_id,
                                   p_file_id,
                                   p_file_name,
@@ -388,23 +471,32 @@
                                   p_storage_type,
                                   null
    );
-end;' language 'plpgsql';
+END;
+$$ LANGUAGE plpgsql;
 
-create or replace function acs_message__edit_file (integer,varchar,text,varchar,
-integer,timestamptz,integer,varchar,boolean)
-returns integer as '
-declare
-    p_file_id       alias for $1;
-    p_title         alias for $2;    -- default null
-    p_description   alias for $3;    -- default null
-    p_mime_type     alias for $4;    -- default ''text/plain''
-    p_data          alias for $5;    -- default null
-    p_creation_date alias for $6;    -- default sysdate
-    p_creation_user alias for $7;    -- default null
-    p_creation_ip   alias for $8;    -- default null
-    p_is_live       alias for $9;    -- default ''t''
+
+
+-- added
+select define_function_args('acs_message__edit_file','file_id,title;null,description;null,mime_type;text/plain,data;null,creation_date;sysdate,creation_user;null,creation_ip;null,is_live;t');
+
+--
+-- procedure acs_message__edit_file/9
+--
+CREATE OR REPLACE FUNCTION acs_message__edit_file(
+   p_file_id integer,
+   p_title varchar,             -- default null
+   p_description text,          -- default null
+   p_mime_type varchar,         -- default 'text/plain'
+   p_data integer,              -- default null
+   p_creation_date timestamptz, -- default sysdate
+   p_creation_user integer,     -- default null
+   p_creation_ip varchar,       -- default null
+   p_is_live boolean            -- default 't'
+
+) RETURNS integer AS $$
+DECLARE
     v_revision_id  cr_revisions.revision_id%TYPE;
-begin
+BEGIN
     v_revision_id := content_revision__new (
         p_title,			-- title         
         p_description,
@@ -425,39 +517,57 @@
     end if;
 
     return v_revision_id;
-end;' language 'plpgsql';
+END;
+$$ LANGUAGE plpgsql;
 
-create or replace function acs_message__delete_file (integer)
-returns integer as '
-declare
-    p_file_id  alias for $1;
-begin
+
+
+-- added
+select define_function_args('acs_message__delete_file','file_id');
+
+--
+-- procedure acs_message__delete_file/1
+--
+CREATE OR REPLACE FUNCTION acs_message__delete_file(
+   p_file_id integer
+) RETURNS integer AS $$
+DECLARE
+BEGIN
     perform content_item__delete(p_file_id);       
     return 1;
-end;' language 'plpgsql';
+END;
+$$ LANGUAGE plpgsql;
 
-create or replace function acs_message__new_image (integer,integer,varchar,varchar,
-text,varchar,integer,integer,integer,timestamptz,integer,varchar,boolean,varchar,integer)
-returns integer as '
-declare
-    p_message_id     alias for $1;
-    p_image_id       alias for $2;    -- default null
-    p_file_name      alias for $3;
-    p_title          alias for $4;    -- default null
-    p_description    alias for $5;    -- default null
-    p_mime_type      alias for $6;    -- default ''text/plain''
-    p_data           alias for $7;    -- default null
-    p_width          alias for $8;    -- default null
-    p_height         alias for $9;    -- default null
-    p_creation_date  alias for $10;   -- default sysdate
-    p_creation_user  alias for $11;   -- default null
-    p_creation_ip    alias for $12;   -- default null
-    p_is_live        alias for $13;   -- default ''t''
-    p_storage_type   alias for $14;   -- default ''file''
-    p_package_id     alias for $15;   -- default null
+
+
+-- added
+select define_function_args('acs_message__new_image','message_id,image_id;null,file_name,title;null,description;null,mime_type;text/plain,data;null,width;null,height;null,creation_date;sysdate,creation_user;null,creation_ip;null,is_live;t,storage_type;file,package_id;null');
+
+--
+-- procedure acs_message__new_image/15
+--
+CREATE OR REPLACE FUNCTION acs_message__new_image(
+   p_message_id integer,
+   p_image_id integer,          -- default null
+   p_file_name varchar,
+   p_title varchar,             -- default null
+   p_description text,          -- default null
+   p_mime_type varchar,         -- default 'text/plain'
+   p_data integer,              -- default null
+   p_width integer,             -- default null
+   p_height integer,            -- default null
+   p_creation_date timestamptz, -- default sysdate
+   p_creation_user integer,     -- default null
+   p_creation_ip varchar,       -- default null
+   p_is_live boolean,           -- default 't'
+   p_storage_type varchar,      -- default 'file'
+   p_package_id integer         -- default null
+
+) RETURNS integer AS $$
+DECLARE
     v_image_id     cr_items.item_id%TYPE;
     v_revision_id  cr_revisions.revision_id%TYPE;
-begin
+BEGIN
     v_image_id := content_item__new (
          p_file_name,				-- name          
          p_message_id,				-- parent_id     
@@ -467,14 +577,14 @@
          p_creation_user,			-- creation_user 
          null,					-- context_id
          p_creation_ip,				-- creation_ip
-	 ''content_item'',			-- item_subtype
-	 ''content_revision'',			-- content_type
+	 'content_item',			-- item_subtype
+	 'content_revision',			-- content_type
 	 null,					-- title
 	 null,					-- description
-	 ''text/plain'',			-- mime_type
+	 'text/plain',			-- mime_type
 	 null,					-- nls_language
 	 null,					-- text
-	 ''file'',				-- storage_type
+	 'file',				-- storage_type
          p_package_id				-- package_id
     );
 
@@ -494,27 +604,33 @@
     );
 
     return v_image_id;
-end;' language 'plpgsql';
+END;
+$$ LANGUAGE plpgsql;
 
-create or replace function acs_message__new_image (integer,integer,varchar,varchar,
-text,varchar,integer,integer,integer,timestamptz,integer,varchar,boolean,varchar)
-returns integer as '
-declare
-    p_message_id     alias for $1;
-    p_image_id       alias for $2;    -- default null
-    p_file_name      alias for $3;
-    p_title          alias for $4;    -- default null
-    p_description    alias for $5;    -- default null
-    p_mime_type      alias for $6;    -- default ''text/plain''
-    p_data           alias for $7;    -- default null
-    p_width          alias for $8;    -- default null
-    p_height         alias for $9;    -- default null
-    p_creation_date  alias for $10;   -- default sysdate
-    p_creation_user  alias for $11;   -- default null
-    p_creation_ip    alias for $12;   -- default null
-    p_is_live        alias for $13;   -- default ''t''
-    p_storage_type   alias for $14;   -- default ''file''
-begin
+
+
+--
+-- procedure acs_message__new_image/14
+--
+CREATE OR REPLACE FUNCTION acs_message__new_image(
+   p_message_id integer,
+   p_image_id integer,          -- default null
+   p_file_name varchar,
+   p_title varchar,             -- default null
+   p_description text,          -- default null
+   p_mime_type varchar,         -- default 'text/plain'
+   p_data integer,              -- default null
+   p_width integer,             -- default null
+   p_height integer,            -- default null
+   p_creation_date timestamptz, -- default sysdate
+   p_creation_user integer,     -- default null
+   p_creation_ip varchar,       -- default null
+   p_is_live boolean,           -- default 't'
+   p_storage_type varchar       -- default 'file'
+
+) RETURNS integer AS $$
+DECLARE
+BEGIN
     return acs_message__new_image (p_message_id,
                                    p_image_id,
                                    p_file_name,
@@ -531,25 +647,34 @@
                                    p_storage_type,
                                    null
    );
-end;' language 'plpgsql';
+END;
+$$ LANGUAGE plpgsql;
 
-create or replace function acs_message__edit_image (integer,varchar,text,varchar,
-integer,integer,integer,timestamptz,integer,varchar,boolean)
-returns integer as '
-declare
-    p_image_id       alias for $1;
-    p_title          alias for $2;    -- default null
-    p_description    alias for $3;    -- default null
-    p_mime_type      alias for $4;    -- default ''text/plain''
-    p_data           alias for $5;    -- default null
-    p_width          alias for $6;    -- default null
-    p_height         alias for $7;    -- default null
-    p_creation_date  alias for $8;    -- default sysdate
-    p_creation_user  alias for $9;    -- default null
-    p_creation_ip    alias for $10;   -- default null
-    p_is_live        alias for $11;   -- default ''t''
+
+
+-- added
+select define_function_args('acs_message__edit_image','image_id,title;null,description;null,mime_type;text/plain,data;null,width;null,height;null,creation_date;sysdate,creation_user;null,creation_ip;null,is_live;t');
+
+--
+-- procedure acs_message__edit_image/11
+--
+CREATE OR REPLACE FUNCTION acs_message__edit_image(
+   p_image_id integer,
+   p_title varchar,             -- default null
+   p_description text,          -- default null
+   p_mime_type varchar,         -- default 'text/plain'
+   p_data integer,              -- default null
+   p_width integer,             -- default null
+   p_height integer,            -- default null
+   p_creation_date timestamptz, -- default sysdate
+   p_creation_user integer,     -- default null
+   p_creation_ip varchar,       -- default null
+   p_is_live boolean            -- default 't'
+
+) RETURNS integer AS $$
+DECLARE
     v_revision_id  cr_revisions.revision_id%TYPE;
-begin
+BEGIN
 		-- not sure which __new to use
     v_revision_id := content_revision__new (
          p_title,             -- title         
@@ -578,35 +703,53 @@
     end if;
 
     return v_revision_id;
-end;' language 'plpgsql';
+END;
+$$ LANGUAGE plpgsql;
 
-create or replace function acs_message__delete_image (integer)
-returns integer as '
-declare
-    p_image_id  alias for $1;
-begin
+
+
+-- added
+select define_function_args('acs_message__delete_image','image_id');
+
+--
+-- procedure acs_message__delete_image/1
+--
+CREATE OR REPLACE FUNCTION acs_message__delete_image(
+   p_image_id integer
+) RETURNS integer AS $$
+DECLARE
+BEGIN
     perform image__delete(p_image_id);
 
     return 0;
-end;' language 'plpgsql';
+END;
+$$ LANGUAGE plpgsql;
 
     -- XXX should just call content_extlink.new
-create or replace function acs_message__new_extlink (varchar,integer,varchar,
-varchar,text,integer,timestamptz,integer,varchar,integer)
-returns integer as '
-declare
-    p_name           alias for $1;    -- default null
-    p_extlink_id     alias for $2;    -- default null
-    p_url            alias for $3;   
-    p_label          alias for $4;    -- default null
-    p_description    alias for $5;    -- default null
-    p_parent_id      alias for $6;
-    p_creation_date  alias for $7;    -- default sysdate
-    p_creation_user  alias for $8;    -- default null
-    p_creation_ip    alias for $9;    -- default null
-    p_package_id     alias for $10;   -- default null
+
+
+-- added
+select define_function_args('acs_message__new_extlink','name;null,extlink_id;null,url,label;null,description;null,parent_id,creation_date;sysdate,creation_user;null,creation_ip;null,package_id;null');
+
+--
+-- procedure acs_message__new_extlink/10
+--
+CREATE OR REPLACE FUNCTION acs_message__new_extlink(
+   p_name varchar,              -- default null
+   p_extlink_id integer,        -- default null
+   p_url varchar,
+   p_label varchar,             -- default null
+   p_description text,          -- default null
+   p_parent_id integer,
+   p_creation_date timestamptz, -- default sysdate
+   p_creation_user integer,     -- default null
+   p_creation_ip varchar,       -- default null
+   p_package_id integer         -- default null
+
+) RETURNS integer AS $$
+DECLARE
     v_extlink_id  cr_extlinks.extlink_id%TYPE;
-begin
+BEGIN
     v_extlink_id := content_extlink__new (
          p_name,			-- name          
          p_url,				-- url           
@@ -621,22 +764,28 @@
     );
 
 	return v_extlink_id;
-end;' language 'plpgsql';
+END;
+$$ LANGUAGE plpgsql;
     
-create or replace function acs_message__new_extlink (varchar,integer,varchar,
-varchar,text,integer,timestamptz,integer,varchar)
-returns integer as '
-declare
-    p_name           alias for $1;    -- default null
-    p_extlink_id     alias for $2;    -- default null
-    p_url            alias for $3;   
-    p_label          alias for $4;    -- default null
-    p_description    alias for $5;    -- default null
-    p_parent_id      alias for $6;
-    p_creation_date  alias for $7;    -- default sysdate
-    p_creation_user  alias for $8;    -- default null
-    p_creation_ip    alias for $9;    -- default null
-begin
+
+
+--
+-- procedure acs_message__new_extlink/9
+--
+CREATE OR REPLACE FUNCTION acs_message__new_extlink(
+   p_name varchar,              -- default null
+   p_extlink_id integer,        -- default null
+   p_url varchar,
+   p_label varchar,             -- default null
+   p_description text,          -- default null
+   p_parent_id integer,
+   p_creation_date timestamptz, -- default sysdate
+   p_creation_user integer,     -- default null
+   p_creation_ip varchar        -- default null
+
+) RETURNS integer AS $$
+DECLARE
+BEGIN
     return acs_message__new_extlink (p_name,
                                      p_extlink_id,
                                      p_url,
@@ -648,48 +797,77 @@
                                      p_creation_ip,
                                      null
    );
-end;' language 'plpgsql';
+END;
+$$ LANGUAGE plpgsql;
 
 -- XXX should just edit extlink
-create or replace function acs_message__edit_extlink (integer,varchar,varchar,text)
-returns integer as '
-declare
-    p_extlink_id   alias for $1;
-    p_url          alias for $2;
-    p_label        alias for $3;    -- default null
-    p_description  alias for $4;    --  default null
+
+
+-- added
+select define_function_args('acs_message__edit_extlink','extlink_id,url,label;null,description');
+
+--
+-- procedure acs_message__edit_extlink/4
+--
+CREATE OR REPLACE FUNCTION acs_message__edit_extlink(
+   p_extlink_id integer,
+   p_url varchar,
+   p_label varchar,   -- default null
+   p_description text --  default null
+
+) RETURNS integer AS $$
+DECLARE
     v_is_extlink   boolean;
-begin
+BEGIN
     v_is_extlink := content_extlink__is_extlink(p_extlink_id);
-    if v_is_extlink = ''t'' then
+    if v_is_extlink = 't' then
         update cr_extlinks
         set url = p_url,
             label = p_label,
             description = p_description
         where extlink_id = p_extlink_id;
     end if;
     return 0;
-end;' language 'plpgsql';
+END;
+$$ LANGUAGE plpgsql;
 
-create or replace function acs_message__delete_extlink (integer)
-returns integer as '
-declare
-    p_extlink_id    alias for $1;
-begin
+
+
+-- added
+select define_function_args('acs_message__delete_extlink','extlink_id');
+
+--
+-- procedure acs_message__delete_extlink/1
+--
+CREATE OR REPLACE FUNCTION acs_message__delete_extlink(
+   p_extlink_id integer
+) RETURNS integer AS $$
+DECLARE
+BEGIN
     perform content_extlink__delete(p_extlink_id);
 
 	return 0;
-end;' language 'plpgsql';
+END;
+$$ LANGUAGE plpgsql;
 
-create or replace function acs_message__name (integer)
-returns varchar as '
-declare
-    p_message_id   alias for $1;
+
+
+-- added
+select define_function_args('acs_message__name','message_id');
+
+--
+-- procedure acs_message__name/1
+--
+CREATE OR REPLACE FUNCTION acs_message__name(
+   p_message_id integer
+) RETURNS varchar AS $$
+DECLARE
     v_message_name   cr_revisions.title%TYPE;
-begin
+BEGIN
     select title into v_message_name
         from acs_messages_all
         where message_id = p_message_id;
     return v_message_name;
-end;' language 'plpgsql' stable strict;
+END;
+$$ LANGUAGE plpgsql stable strict;
 
