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 = '

%s

' 160 161 printf $title_fmt\n\n $'cgi.page.literal' > $'tpl.include.tw.page' 162 } 163 164 # Whether the page is new or old, set new editor if available. 165 ~ $'cgi.author' () || tbl_page.p_modau = $'cgi.author' 166 167 #~ $REMOTE_ADDR 192.168.1.2 && csaExit.env 168 169 # Set template vars to their final values. 170 tpl.var.tw.group = $'tbl_group.g_name' 171 tpl.var.tw.page = $'tbl_page.p_name' 172 tpl.var.tw.page.object = $'tpl.var.tw.page' 173 tpl.var.tw.descr = $'tbl_page.p_descr' 174 tpl.var.tw.author = $'tbl_page.p_modau' 175 tpl.var.tw.tags = $'tbl_page.p_tags' 176 tpl.var.tw.reldate = $'tbl_page.p_vtime' 177 tpl.var.tw.expdate = $'tbl_page.p_etime' 178 tpl.var.tw.page.ping.count = $'tbl_page.p_ntbk' 179 tpl.var.tw.page.att.count.priv = $'tbl_page.p_npriv' 180 tpl.var.tw.page.store = $'tbl_page.p_store' 181 * = ``(' ':T+-){echo -n $'tbl_page.p_mtime'} 182 tpl.var.tw.chgdate = $1-$2-$3 183 ~ $'tpl.var.tw.chgdate' () || tpl.var.tw.chgtime = $4:$5 184 tpl.var.html.title = $'tpl.var.tw.group'/$'tpl.var.tw.page' 185 186 csaIsFullPath --exists --quiet $tw_pstem+cmt && 187 tpl.var.tw.page.comments = $'nls.cmt.accept' 188 189 # Page description ultimately defaults to group/page name. 190 ~ $'tpl.var.tw.descr' () && tpl.var.tw.descr = $'tpl.var.html.title' 191 192 if (csaIsFullPath --exists --quiet $CSA_TPL_ROOT/tw-edit-page.txt) { 193 # custom page-editing template. 194 tpl.include.html.body = $CSA_TPL_ROOT/tw-edit-page.txt 195 } else { 196 # default page-editing template. 197 tpl.include.html.body = $tw_dstem/tw-edit-page.txt 198 } 199 200 . $CSA_ROOT/lib/tpl-stuff.rc 201 202 csaSum --file $sum_file 203 tpl.var.checksum = $CSA_RESULT 204 205 # Make sure no-replace mode is used on the page body by prepending 206 # its name with '-', or any user-supplied CSA tags in the text will 207 # be happily parsed by _envtoxml() !! 208 209 tpl.include.tw.page = -$'tpl.include.tw.page':p 210 211 csaExit.ok $tpl_file 212 213 # End of program.