1 # ===================================================================== 2 # pageHistory: list revisions of the specified W-TW page. 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.group.literal = () 27 cgi.page = () 28 cgi.page.literal = () 29 cgi.revisions = () 30 31 wiki_file = /dev/null 32 hist_tpl = tw-page-history.txt # default 33 34 # ===================================================================== 35 # Main program 36 # ===================================================================== 37 38 # Load call arguments. 39 csaGetArgs GET 40 41 #~ $REMOTE_ADDR 192.168.1.2 && csaExit.env 42 43 . $CSA_ROOT/lib/group-stuff.rc 44 45 . $CSA_ROOT/lib/group-editor.rc 46 47 . $CSA_ROOT/lib/page-stuff.rc 48 49 . $CSA_ROOT/lib/tpl-stuff.rc 50 51 # Policy checks should always come after the inclusion of group 52 # (and possibly also page) meta-data. 53 54 if (!~ ,$TNS_AUTH_GRP, *,editor,* && csaTrue $TNS_HISTORY_RESTRICT) { 55 56 # # Prepare the error message "back" button. 57 # 58 # if (csaIsFullPath --exists --quiet $CSA_TPL_ROOT/tw-nav-back.txt) { 59 # # custom "back" action template. 60 # tpl.include.nav.next = $CSA_TPL_ROOT/tw-nav-back.txt 61 # } else { 62 # # default "back" action template. 63 # tpl.include.nav.next = $tw_dstem/tw-nav-back.txt 64 # } 65 66 CSA_EXIT_SCRIPT = ($CSA_EXIT_SCRIPT back) 67 csaExit.needauth 68 } 69 70 csaMkTemp TNS_RCS_OUT tpl.include.tw.page 71 72 # If 'parsewiki' is the preferred GUI (or the only allowed one) 73 # then behave accordingly. 74 75 csaUnlist TNS_ALLOW_GUI default 76 77 if (~ $CSA_SESSION(11) parsewiki || 78 {~ $TNS_ALLOW_GUI parsewiki && ~ $#TNS_ALLOW_GUI 1}) { 79 80 if (csaIsFullPath --exists --quiet $tw_pstem+pwk) { 81 wiki_file = $tw_pstem+pwk 82 hist_tpl = tw-page-history-pwk.txt 83 } 84 85 } else wiki_file = $tw_pstem+wki 86 87 88 if (csaIsFullPath --exists --quiet $CSA_TPL_ROOT/$hist_tpl) { 89 # custom page-history template. 90 tpl.include.html.body = $CSA_TPL_ROOT/$hist_tpl 91 } else { 92 # default page-history template. 93 tpl.include.html.body = $tw_dstem/$hist_tpl 94 } 95 96 # Just in case ... 97 if (!~ $wiki_file /dev/null && csaIsFullPath --exists --quiet $wiki_file) { 98 csaTrue $CSA_AUDIT || csaExit.fault 0031 99 rlog -zLT $wiki_file > $TNS_RCS_OUT || csaExit.fault 0003 rlog 100 } else touch $TNS_RCS_OUT 101 102 if (!test -s $TNS_RCS_OUT) { 103 104 # page has no revisions (at least not in the current editing mode). 105 106 # if (csaIsFullPath --exists --quiet $CSA_TPL_ROOT/tw-nav-back.txt) { 107 # # custom "back" action template. 108 # tpl.include.nav.next = $CSA_TPL_ROOT/tw-nav-back.txt 109 # } else { 110 # # default "back" action template. 111 # tpl.include.nav.next = $tw_dstem/tw-nav-back.txt 112 # } 113 114 csaExit.fault --back 1034 115 } 116 117 #csaExit.bdata --mime 'Content-Type: text/plain' $TNS_RCS_OUT 118 119 # Show inline diff section if appropriate. 120 if (~ $#'cgi.revisions' 1 2) { 121 csaMkTemp tpl.include.tw.page.diff^(1 2 3) 122 123 if (~ $wiki_file /dev/null) { 124 125 touch $'tpl.include.tw.page.diff1' \ 126 $'tpl.include.tw.page.diff2' $'tpl.include.tw.page.diff3' 127 128 } else { 129 130 * = -r^$'cgi.revisions' 131 132 co -q -p -zLT $1 $wiki_file > $'tpl.include.tw.page.diff1' || 133 csaExit.fault 0003 co 134 135 co -q -p -zLT $2 $wiki_file > $'tpl.include.tw.page.diff3' || 136 csaExit.fault 0003 co 137 138 # wdiff(1) returns non-zero if the specified revisions differ, so 139 # a non-zero code isn't a sign of failure and must not be used to 140 # trigger a fault exit here. 141 142 wdiff -3n $'tpl.include.tw.page.diff1' $'tpl.include.tw.page.diff3' | 143 sed '/^==*$/d 144 /\({+\|\[-\)/!d' > $'tpl.include.tw.page.diff2' 145 #s/ $'tpl.include.tw.page.diff2' 146 #s/$/
/' > $'tpl.include.tw.page.diff2' 147 } 148 } 149 150 # This view does not correspond to an actual page on disk, 151 # so we need to toggle unapplicable sections in templates. 152 153 tpl.if.tw.ispage = '(::DEL:)' 154 tpl.fi.tw.ispage = '(:DEL::)' 155 tpl.if.tw.printable = '(::DEL:)' 156 tpl.fi.tw.printable = '(:DEL::)' 157 tpl.if.tw.isview = () 158 tpl.fi.tw.isview = () 159 160 csaExit.ok $tpl_file 161 162 # End of program.