function addHelpBlock2Wiki(service, token, spacekey, filepath, routinenames)

[pathstr, name, ext] = fileparts(filepath);
% get help block
pagetext = help(filepath);

% apply wiki formatting to help block text
criticalCharacters={'[',']','*','{','}','(',')'};
if ~isempty(pagetext)
    for i = 1:length(criticalCharacters)
        pagetext = strrep(pagetext,criticalCharacters{i},['\' criticalCharacters{i}]);
    end
end

try
    pagecontent = ['{tip:title=' name '} ' pagetext ' {tip}' char(13)];

    rootdir = 'f:\mctools';
    if strcmp(lower(name),'analysetransect')
        xx=0
    end
    out = unique(getCalls(name,fileparts(which(name))));
    pagecontent = [pagecontent char(13) '*Routine: "' name '" calls:*' char(13)];
    for i = 1:length(out)
        [rest, fname] = fileparts(strtok(which(out{i}),'.'));
        if ~strcmp(name, fname)
            pagecontent = [pagecontent '[' fname ']' char(13)];
        end
    end

    pagecontent = [pagecontent char(13) '*Routine: "' name '" is called by:*' char(13)];
    try
        [rest, searchdir] = fileparts(fileparts(which(name))); % Look one dir up
    catch
        searchdir = fileparts(which(name));
    end
    in  = unique(getIsCalledBy(name,searchdir));
    for i = 1:length(in)
        if ~strcmp(name, strtok(in{i},'.'))
            pagecontent = [pagecontent '[' strtok(in{i},'.') ']' char(13)];
        end
    end
catch
    pagecontent = ['{tip:title=' name '} ' pagetext ' {tip}' char(13)];
end
page.space         = spacekey;
page.title         = name;
page.version       = 1;
page.content       = pagecontent;
page.creator       = 'don';
page.modifier      = 'mark van koningsveld';
page.homePage      = 0;
page.contentStatus = 'current';

% apply wiki formatting to help block text
tic
changed = 0;
testcharacters = {'[',']','_','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','1','2','3','4','5','6','7','8','9','0'};
for ii = 1: length(routinenames)
    if ~strcmp(lower(page.title),lower(routinenames{ii}))
        result = strfind(lower(page.content),lower(routinenames{ii}));
        if ~isempty(result)
            for i = 1: length(result)
                if ~ismember(lower(page.content(result(i)-1)),lower(testcharacters)) & ~ismember(lower(page.content(result(i)+length(routinenames{ii}))),lower(testcharacters))
                    changed = 1;
                    page.content = [page.content(1:result(i)-1) '[' routinenames{ii} ']' page.content(result(i)+length(routinenames{ii}):end)];
                end
                result = strfind(lower(page.content),lower(routinenames{ii}));
            end
        end
    end
end
disp([' Potential links activated : ' num2str(toc,'%.2f') ' seconds'])

if changed
    pagetext = page.content;
    page2 = page; %getPage(service, activateService(service), spacekey, page.title);
    page2.content = pagetext;
    storePage(service, activateService(service), page2);
    disp([' Page changed              : ' num2str(toc,'%.2f') ' seconds - ' page.title])
else
    storePage(service, activateService(service), page);
    disp([' Page not changed          : ' num2str(toc,'%.2f') ' seconds - ' page.title])
end



