1 # ===================================================================== 2 # wikiLink.awk: identify Wiki links in a Wiki page body. 3 # 4 # Copyright (c) 2007,2009 Carlo Strozzi 5 # 6 # This program is free software; you can redistribute it and/or modify 7 # it under the terms of the GNU General Public License as published by 8 # the Free Software Foundation; version 2 dated June, 1991. 9 # 10 # This program is distributed in the hope that it will be useful, 11 # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 # GNU General Public License for more details. 14 # 15 # You should have received a copy of the GNU General Public License 16 # along with this program; if not, write to the Free Software 17 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 # 19 # ===================================================================== 20 21 # ===================================================================== 22 # string wikiLink(string link, string groupdir) 23 # ===================================================================== 24 25 function wikiLink(link,groupdir, tmp,url) { 26 27 url = ENVIRON["CSA_RPC_URI"] "/" ENVIRON["CSA_LANG"] "/" 28 29 tmp = link 30 sub(/'.*/,"",tmp) # retain only page name. 31 32 # Make sure we retain only the actual page name, discarding any 33 # trailing stuff that may refer to a virtual view of some kind. 34 # Fragment identifiers in the form of trailing "#..." must also 35 # be discarded, as we are only concerned about the existence of 36 # a page and we have no easy way to assess whether an anchor 37 # actually exists or not. 38 39 if (!sub(_escreg(url),_NULL,tmp)) # canonical URL 40 sub(_escreg(ENVIRON["CSA_CGI_STEM"]) "I?/" \ 41 _escreg(ENVIRON["CSA_ID"] "/" ENVIRON["CSA_LANG"]) \ 42 "/",_NULL,tmp) # absolute URL 43 44 sub(/[^\/]+\//,_NULL,tmp) 45 sub(/\/.*/,"",tmp) 46 sub(/#.*/,"",tmp) 47 48 # Build actual file name from page name, accounting for the 49 # possibility that the relevant URLs be UTF-8 encoded. 50 51 #if (_isutf8((tmp=_uridecode(tmp,_O_PATHINFO))) == _TRUE) 52 # tmp = _u8decode(tmp) 53 54 tmp = _uridecode(tmp,_O_PATHINFO) 55 tmp = unixify(tmp,1) 56 57 # If the specified page does not exist (and we are 58 # at the confirmation prompt) mark it with a (?), 59 # unless it is a TW view and not a real page. 60 61 if (tmp !~ /^([1-9]|tw-)/ && \ 62 _stat(ENVIRON["CSA_ROOT"] "/var/pages/" \ 63 ENVIRON["CSA_LANG"] "/" groupdir "/" \ 64 tmp "+wki") != _TRUE && \ 65 _csa("confirmed") == _FALSE) { 66 sub(/<\/a>/,"?",link) 67 link = extLink(link) 68 } 69 70 #if (link ~ /^[^\/']+'/) link = "