1 # ===================================================================== 2 # editPage: W-TW page editor. 3 # 4 # Copyright (c) 2007,2008,2009,2010 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 # Local variables and functions 23 # ===================================================================== 24 25 cgi.group = () 26 cgi.page = () 27 cgi.group.literal = () 28 cgi.page.literal = () 29 cgi.author = () 30 cgi.revision = () 31 32 tpl_file = /dev/null 33 tmp2 = /dev/null 34 sum_file = /dev/null 35 title_fmt = () 36 tpl.var.checksum = () 37 tpl.var.tw.page.comments = $'nls.cmt.deny' # default 38 39 # ===================================================================== 40 # Main program 41 # ===================================================================== 42 43 csaGetArgs GET 44 45 #~ $REMOTE_ADDR 192.168.1.2 && csaExit.env 46 47 . $CSA_ROOT/lib/group-stuff.rc 48 49 # Check the second most important arg. 50 ~ $'cgi.page' () && csaExit.fault 1001 51 52 # Page names beginning with tw-* are reserved for TW use, and usually 53 # refer to views that do not correspond to actual pages on disk. 54 55 ~ $'cgi.page' tw-* && csaExit.fault 1009 $'cgi.page' 56 57 tw_pstem = $tw_gstem/$'cgi.page' 58 59 tpl.var.tw.group.unx = $'cgi.group' 60 tpl.var.tw.page.unx = $'cgi.page' 61 62 # Check page required metadata. 63 ~ $'cgi.page.literal' () && csaExit.fault 0041 cgi.page.literal 64 65 . $CSA_ROOT/lib/group-editor.rc 66 67 ~ ,$TNS_AUTH_GRP, *,editor,* || csaExit.needauth 68 69 #~ $REMOTE_ADDR 192.168.1.2 || csaExit.fault --back 0035 70 71 # It is assumed that editor hook files have these very names 72 # and are located in the webmaster-accessible template directory. 73 74 switch ($TNS_USE_GUI) { 75 case tinymce 76 tpl.include.tw.user.gui = $CSA_TPL_ROOT/tinymce.txt 77 78 case nicedit 79 tpl.include.tw.user.gui = $CSA_TPL_ROOT/nicedit.txt 80 81 case ckeditor 82 tpl.include.tw.user.gui = $CSA_TPL_ROOT/ckeditor.txt 83 84 # add more cases here as needed. 85 } 86 87 csaMkTemp tmp2 tpl.include.tw.page 88 89 # See if it is a new page that we are creating. 90 91 if (csaIsFullPath --exists --quiet $tw_pstem+wki) { 92 93 # The HTML file is rebuilt upon every new edit, 94 # so I only need to test its checksum and not also 95 # the one of the associated page+pwk, if any. 96 97 sum_file = $tw_pstem+wki 98 99 if (~ $TNS_USE_GUI parsewiki) { 100 101 # If the html2wiki(1) filter is not available then cat(1) will be 102 # used, which means that the editor will have to manually convert 103 # the syntax from HTML to UseMod upon the first creation of page+pwk. 104 # A parsewiki-based group of pages should only allow "parsewiki" as 105 # the "GUI" of choice. Otherwise, if different editors use different 106 # GUIs they would disrupt each other formats upon every new editing 107 # session. Page history also follows two independent paths, one 108 # for page+wki and another one for page+pwk. However, while the 109 # former is re-built and re-versioned upon every change, the latter 110 # will be lef lagging behind if the editing mode is changed from 111 # parsewiki to a different GUI. 112 113 if (csaIsFullPath --exists --quiet $tw_pstem+pwk) { 114 115 if (!~ $'cgi.revision' ()) { 116 co -q -p -zLT -d$'cgi.revision' \ 117 $tw_pstem+pwk > $'tpl.include.tw.page' || csaExit.fault 0003 co 118 } else tpl.include.tw.page = $tw_pstem+pwk 119 120 } else { 121 122 $TNS_CMD_HTML2WIKI $tw_pstem+wki > $tmp2 || 123 csaExit.fault 0003 $TNS_CMD_HTML2WIKI(1) 124 tpl.include.tw.page = $tmp2 125 } 126 127 } else { 128 129 if (!~ $'cgi.revision' ()) { 130 co -q -p -zLT -d$'cgi.revision' \ 131 $tw_pstem+wki > $'tpl.include.tw.page' || csaExit.fault 0003 co 132 } else tpl.include.tw.page = $tw_pstem+wki 133 } 134 135 # Override page meta-data with actual values if available. 136 keysearch $'cgi.page' $tw_gstem/page+dat | 137 csa-tbl2rc --prefix tbl_page. > $tmp1 138 . $tmp1 139 140 } else { 141 142 # Use page name and author supplied by the user. 143 tbl_page.p_name = $'cgi.page.literal' 144 tbl_page.p_creau = $'cgi.author' 145 tbl_page.p_ntbk = 0 146 tbl_page.p_npriv = 0 147 tbl_page.p_npub = 0 148 149 # The first time a page is opened for creation it does not exis yet, 150 # so some of the output template fields will not apply and should be 151 # switched-off. 152 153 tpl.if.tw.ispage = '(::DEL:)' 154 tpl.fi.tw.ispage = '(:DEL::)' 155 156 # Set default title if new page. 157 if (~ $TNS_USE_GUI parsewiki) { 158 title_fmt = '== %s ==' 159 } else title_fmt = '