Subversion Repositories DevTools

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
4012 dpurdie 1
<% @LANGUAGE = VBScript %>
2
<%
3
'+----------------------------------------------------------------------------+
4
'| Description:                                                               |
5
'|    WikiAsp is a derivative of AspWiki, a wiki program written in ASP.      |
6
'|    WikiAsp will run on Windows with IIS, MDAC v2.5. WikiAsp will           |
7
'|    automatically create MS Access DB on first time use.                    |
8
'|                                                                            |
9
'|    The following are the dlls to make mdb creation work.                   |
10
'|    1. Program Files\Common Files\System\ado\msadox.dll                     |
11
'|    2. WINDOWS\System32\scrrun.dll                                          |
12
'|                                                                            |
13
'| Credits:                                                                   |
14
'|    Elrey Ronald Velicaria. - Author of WikiAsp. (lambda326@hotmail.com)    |
15
'|    Dino Chiesa - AspWiki author.                                           |
16
'|    Contributors: Bjarne D, Julian Tosh                                     |
17
'|                                                                            |
18
'| Websites:                                                                  |
19
'|    http://www.c2.com/cgi/wiki,  http://www.c2.com/cgi/wiki?WikiAsp         |
20
'+----------------------------------------------------------------------------+
21
'| Please retain the above credits on any future versions of this program     |
22
'+----------------------------------------------------------------------------+
23
 
24
Option Explicit
25
Response.CacheControl  = "no-cache"
26
Response.Expires       = -1
27
Response.AddHeader "Pragma", "no-cache"
28
 
29
Dim gPassword, gDefaultIcon, gDefaultHomePage, gAutoCreateMdb
30
Dim gHttpDomain , gDebug, gEngineVersion, gDbTableName
31
Dim gProvider, gDataConn, gDataSource, gDataSourceName
32
Dim gDocRootDir, gDataSourceDir, gDataSourceFile, gSpaceNames
33
Dim gScript, gScriptURL, giEditAreaRows, giEditAreaCols, giNumRecentFiles
34
Dim gHomeTopic, gStyleSheet, gIconName, gEditPassword, gIsOpenWiki
35
Dim glsTopic, glsMode  , gHideLastEditor,  gLoginFlag, gRemoveHtml,gBlackListedIps
36
Dim gRE, gHighlightFlag, gHideWikiSource, gHideWikiFooter, gHideLogin, gHtmlHeadStr
37
Dim gDisableSave,gTimeZoneOffset, gRssStyle, gRedirectURL
38
Dim gBannerTemplate, gWikiBodyPrefix, gHideTopSearch, gDisableScripting
39
Dim gMdbExtension , gSearchLabel, gBlackListedIpsRE ,gDeletePassword , gPersistPassword
40
Dim gPasswordLabel, gFooterHtml, gEnableEdit
41
 
42
'+-----------------------------------------------------------------------------+
43
'| AN IMPORTANT NOTE:  !!!!!                                                   |
44
'| Enter your password below for creating new DB and for Delete.               |
45
'| Enter your URL inside quotes below e.g. http://www28.brinkster.com/site     |
46
'| Modify gDefaultIcon, gDefaultHomePage here is FSO objects is not installed  |
47
'+-----------------------------------------------------------------------------+
48
gAutoCreateMdb     =  true                            ' Create db automatically
49
gDisableSave       =  false                           ' Set to true if you have to fully disable save.
50
gBlackListedIps    =  ""                              ' List of IPs to reject. (Exact match 1st 3 digits of IP, delimit list by ~)
51
gBlackListedIpsRE  =  ""                              ' List of IPs to reject (Regular ExpressionMatch)
52
gRemoveHtml        =  false                           ' Set to true if  HTML input in wiki will be enabled.
53
gLoginFlag         =  "log"                           ' The default enable login flag ( must be overriden by config.asp).
54
gIsOpenWiki        =  true                            ' Allow editing or Password Protect Editing?
55
gHideWikiSource    =  false                           ' Allow viewing of unformatted wiki text when loggin in.
56
gHideWikiFooter    =  false                           ' Show or Hide the whole wiki footer
57
gHideLogin         =  false                           ' Enable/Disable double-click or Edit. This can be overriden by &log
58
gHideLastEditor    =  false                           ' Show/Hide in  the footer the info about last edit
59
gDeletePassword    = "passworddel"                    ' password  for deleting
60
gEditPassword      = "password"                       ' password  for editing the site
61
gPassword          = "password"                       ' password  for editing and delete and db creation.
62
gHttpDomain        = "auto"                           ' URL for RSS links to work. Override in config.asp . Set to "" to remove rss footer links
63
gDefaultIcon       = "icon"                           ' This default. Maybe overridden if your site has icon.gif, icon.jpg or xxxx.gif and if FSO is working.
64
gDefaultHomePage   = "WikiAsp"                        ' modify your start page here. this may be overridden by .ini file. The .ini file is same dir as mdb file
65
gDataSourceDir     = "db"                             ' MSAccess folder. this is normally `db`
66
gDocRootDir        = ""                               ' physical absolute path of root (e.g. c:/dc2/mysite.com)  make it blank if `gDataSourceDir` is relative to wiki.asp
67
gTimeZoneOffset    = "-0400"                          ' Put your serverTimezone offset here. East Coast is -0400 .
68
gRssStyle          = ""                               ' Example:  "<?xml-stylesheet type=""text/xsl"" href=""rss.xsl"" ?>"
69
gRedirectURL       = ""
70
gMdbExtension      = ".mdb"
71
gBannerTemplate    = ""                               ' Banner html is now replaceable you need to remember $$icon$$, $$banner_text$$ variable though
72
gWikiBodyPrefix    = ""
73
gHideTopSearch     = false
74
gDisableScripting  = true
75
gSearchLabel       = " Search On:"
76
gPersistPassword   = true                             ' Remember password by default
77
gPasswordLabel     = " To edit, enter the password: " ' The prompt label to use when entering a password. 4/2010
78
gFooterHtml        = "</body></html>"                 ' Now you can customize the footer with your chosen html. Even remove ads
79
gEnableEdit        = false
80
 
81
'+-----------------------------------------------------------------------------+
82
'| DO YOU WANT TO SEPARATE SOME CONFIG SETTINGS IN ANOTHER FILE?               |
83
'+-----------------------------------------------------------------------------+
84
'| IF yes,just uncomment line after this box (by removing single quote as      |
85
'| the first character. If you do this,  BE SURE TO CREATE config.asp          |
86
'| which will override the same variable settings above this box               |
87
'+-----------------------------------------------------------------------------+
88
 
89
%><!--#include file="config.asp"--><%
90
 
91
gDebug               = 0                             ' 0 - no debug message 1-6 for verbose debug
92
gEngineVersion       = "v1.6.4 beta  Elrey Ronald V."  ' Engine Version
93
gScript              = "wiki.asp"                    ' Main ASP filename (this file)
94
gProvider            = "Microsoft.Jet.OLEDB.4.0"     ' Db Provider
95
giEditAreaRows       = 30                            ' Edit Rows
96
giEditAreaCols       = 115                           ' Edit Columns
97
giNumRecentFiles     = 15                            ' No. of wikipages to list in Recent files page
98
gDbTableName         = "WikiData"                    ' Table name in the database
99
gSpaceNames          = 1                             ' 1 means put spaces in WikiNames, 0 - no spaces
100
 
101
 
102
' Elrey 3/06  Now Override the gHttpDomain with this!!
103
If gHttpDomain = "auto" Then
104
  gHttpDomain  = "http://" & Request.ServerVariables("HTTP_HOST") & _
105
                 Replace(Request.ServerVariables("URL"), "/" & gScript, "" )
106
End If
107
 
108
'check for database name
109
If len(request("db")) > 0 Then
110
    gDataSourceFile = request("db")
111
Else
112
    gDataSourceFile = gDefaultHomePage
113
End If
114
 
115
If len(gDocRootDir) > 0 Then
116
  gDataSource = gDocRootDir & "\" & gDataSourceDir & "\" & gDataSourceFile & gMdbExtension 
117
Else
118
  gDataSource = gDataSourceDir & "\" & gDataSourceFile & gMdbExtension 
119
End If
120
 
121
'check for database human-readable name
122
If len(request("dbname")) > 0 Then
123
    gDataSourceName = request("dbname")
124
Else
125
    gDataSourceName = "DefaultDb"
126
End If
127
 
128
' Can only Edit on the Test / Development System not on the Live System
129
If (IsEmpty(Application("LiveSystem"))) Then
130
    gHideLogin = false
131
    If (Session("login") <> 0) Then
132
            gHideWikiFooter = false
133
            gEnableEdit = true
134
            Session("login") = 1
135
    End If
136
    gHideWikiFooter = NOT gEnableEdit
137
Else
138
    gHideLogin = true
139
    gHideWikiFooter = true
140
End If
141
 
142
'set destination URL
143
gScriptURL    = gScript & "?db=" & gDataSourceFile  ' removed & "&dbname=" & server.urlencode(gDataSourceName)
144
gHomeTopic    = gDataSourceFile  ' default home topic is the same as ms access db name unless overwritten by .ini
145
gStyleSheet   = "wiki.css"
146
 
147
 
148
Call GetHomeTopic 'Get the topic from wiki.ini if it exists
149
 
150
gIconName = gDefaultIcon
151
 
152
Call GetIconName   'Get the real icon name
153
 
154
Dim rs, dts, i, sqlQuery
155
 
156
Const ADOERROR_NOFILE  = -2147467259  ' cannot find file (*.mdb)
157
Const ADOERROR_NOTABLE = -2147217865  ' Cannot find output table
158
Const FOR_READING      = 1
159
Const FOR_WRITING      = 2
160
 
161
' Determine the action mode (edit/browse/save/list/search) or browse
162
glsMode = ""
163
If Not isEmpty(request("a")) Then
164
   glsMode = request("a")
165
Else
166
   glsMode = "browse"
167
End If
168
 
169
' Determine the topic otherwise use home topic.
170
glsTopic = "WikiAsp"
171
If Not isEmpty(request("o")) Then
172
   glsTopic = request("o")
173
Else
174
   glsTopic = gHomeTopic
175
End If
176
 
177
' Determine if RSS contains highlighting or not
178
If Not isEmpty(request("h")) then
179
   gHighlightFlag = true
180
Else
181
   gHighlightFlag = false
182
End If
183
 
184
' Initialize the Regular Expression object variable
185
Set gRE=server.createobject("VBScript.Regexp")
186
gRE.IgnoreCase  = False
187
gRE.Global      = True
188
 
189
dim httpReferer
190
httpReferer= Request.ServerVariables("HTTP_REFERER")
191
 
192
 
193
' Get remote addresses globally
194
dim remoteIPHost
195
remoteIPHost = Request.ServerVariables("REMOTE_HOST")
196
 
197
dim remoteIPAddr
198
remoteIPAddr = Request.ServerVariables("REMOTE_ADDR")
199
 
200
If IsNull( remoteIPHost) Then
201
  remoteIPHost = "0.0.0.0"
202
End If
203
 
204
If IsNull( remoteIPHost) Then
205
  remoteIPAddr = "0.0.0.0"
206
End If
207
 
208
If  not IsEmpty(   Session("pwd") ) Then
209
    If  Session("pwd") = gPassword  Then
210
      remoteIPHost = "Editor"
211
      remoteIPAddr = ""
212
    End If
213
End If
214
 
215
'-- Let us get he IP first 3 numbers
216
dim remoteIPHost3numbers
217
Dim DotPos 
218
DotPos = InStrRev(remoteIPHost,".")
219
remoteIPHost3numbers= mid(remoteIPHost,1,DotPos)
220
 
221
 
222
 
223
'------------------------------------------------------------------------------------------------------------
224
'                                        SUBROUTINES AND FUNCTIONS
225
'------------------------------------------------------------------------------------------------------------
226
 
227
Sub GetHomeTopic
228
    '-----------------------------------------------------------------------
229
    ' This looks for the Home Topic Name from the 1-line file wiki.ini file.
230
    '-----------------------------------------------------------------------
231
    Dim objFSO
232
    err.Clear
233
    On Error Resume Next
234
    Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
235
    On Error GoTo 0
236
    If Not IsObject(objFSO) Then
237
        Exit Sub
238
    End If
239
 
240
    'Open the ini file whch should be at same dir as access db file
241
    Dim objTextStream
242
    Dim strIniFile
243
 
244
    if len(gDocRootDir) > 0 then
245
       strIniFile= gDocRootDir & "\" & gDataSourceDir & "\" & gDataSourceFile & ".ini"
246
    else
247
       strIniFile= Server.MapPath( gDataSourceDir & "\" & gDataSourceFile & ".ini")
248
    end if
249
 
250
    If objFSO.FileExists(strIniFile) Then
251
        Set objTextStream = objFSO.OpenTextFile(strIniFile, FOR_READING)
252
        gHomeTopic = objTextStream.ReadLine()
253
        objTextStream.Close
254
    End If
255
 
256
    '
257
    ' Check For db specific style sheet if any. First look CSS at the roo
258
    ' If it is not there, look in the DB Folder.  If not again there don't
259
    ' Override the default  (which is Wiki.css).
260
    '
261
    Dim strCss
262
    strCss= Server.MapPath( gDataSourceFile & ".css")
263
    If objFSO.FileExists(strCss) Then
264
        gStyleSheet = gDataSourceFile & ".css"
265
    Else
266
        Dim strCssFile
267
        strCssFile= Server.MapPath( gDataSourceDir & "\" & gDataSourceFile & ".css")
268
        If objFSO.FileExists(strCssFile) Then
269
            gStyleSheet =  gDataSourceDir & "\" & gDataSourceFile & ".css"
270
        End If
271
    End If
272
 
273
    Set objTextStream = Nothing
274
    Set objFSO = Nothing
275
 
276
End Sub
277
 
278
Function DayName (intDay)
279
  '------------------------------------------
280
  ' Returns Abbreviated Day of Week
281
  '------------------------------------------
282
  select case intDay
283
      case 1
284
          DayName = "Sun"
285
      case 2
286
          DayName = "Mon"
287
      case 3
288
          DayName = "Tue"
289
      case 4
290
          DayName = "Wed"
291
      case 5
292
          DayName = "Thu"
293
      case 6
294
          DayName = "Fri"
295
      case 7
296
          DayName = "Sat"
297
  end select
298
end function
299
 
300
function MonthName(intMonth)
301
  '-----------------------------------------
302
  ' Returns Abbreviated Month Name
303
  '-----------------------------------------
304
  select case intMonth
305
      case 1
306
         MonthName = "Jan"
307
      case 2
308
         MonthName = "Feb"
309
      case 3
310
         MonthName = "Mar"
311
      case 4
312
         MonthName = "Apr"
313
      case 5
314
         MonthName = "May"
315
      case 6
316
         MonthName = "Jun"
317
      case 7
318
         MonthName = "Jul"
319
      case 8
320
         MonthName = "Aug"
321
      case 9
322
         MonthName = "Sep"
323
      case 10
324
         MonthName = "Oct"
325
      case 11
326
         MonthName = "Nov"
327
      case 12
328
          MonthName = "Dec"
329
  end select
330
end function
331
 
332
Function GetRFC822date(dateVar)
333
   '----------------------------------------------
334
   ' Returns standard format date for RSS feeds
335
   '----------------------------------------------
336
   GetRFC822date =  DayName (WeekDay(dateVar)) & ", " & _
337
                    Day(dateVar) & " " & MonthName(Month(dateVar)) & " " & _
338
                    Year(dateVar) & " " & FormatDateTime(dateVar, 4) &":00 " & gTimeZoneOffset
339
End Function
340
 
341
 
342
Function WrappedQueryExecute( connObject, queryString )  
343
   '----------------------------------------------
344
   ' If something is wrong with db connection redirect to URL
345
   '----------------------------------------------
346
  Dim rsResult
347
  If gRedirectURL = "" Then
348
      set rsResult = connObject.execute(queryString)
349
  Else
350
      on error resume next
351
      set rsResult = connObject.execute(queryString)
352
      on error goto 0
353
 
354
      If  isEmpty(rsResult) then
355
	       Response.Redirect gRedirectURL
356
         Response.End
357
      End If
358
  End If
359
  Set WrappedQueryExecute = rsResult
360
End Function
361
 
362
 
363
Function AnyFileExistsIn( objFSO, extensions, baseFilename)
364
 
365
    Dim arrIconExts, sIconPathFile, sIconFile, element
366
 
367
    AnyFileExistsIn = false
368
    arrIconExts = Split(extensions, ",")
369
 
370
    For Each element In arrIconExts
371
 
372
        sIconFile =  baseFilename & element
373
        sIconPathFile= Server.MapPath( sIconFile)
374
 
375
        If objFSO.FileExists(sIconPathFile) Then
376
           gIconName = sIconFile
377
           AnyFileExistsIn = true
378
           Exit For
379
        End If
380
 
381
    Next
382
 
383
 
384
End Function
385
 
386
 
387
Sub GetIconName
388
    '-------------------------------------------------
389
    ' Get the icon file name. gif first then jpg
390
    ' Now it look a various places to guarantee an icon
391
    '-------------------------------------------------
392
    Dim objFSO, sIconPathFile, sIconFile
393
    err.Clear
394
    On Error Resume Next
395
    Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
396
    On Error GoTo 0
397
    If Not IsObject(objFSO)  Then
398
        Exit Sub
399
    End If
400
 
401
    ' look for <msaccessdb>.xxx icon file
402
 
403
    Dim iconSearchOrder 
404
    iconSearchOrder = ".gif,.jpg,.png"
405
 
406
    ' first look at the db directory, then on root , then for icon.xxx, otherwise default to the c2 icon
407
 
408
    If not AnyFileExistsIn( objFSO, iconSearchOrder, gDataSourceDir & "/" & gDataSourceFile ) Then
409
        If not AnyFileExistsIn( objFSO, iconSearchOrder, gDataSourceFile ) Then
410
            If not AnyFileExistsIn( objFSO, iconSearchOrder , gIconName ) Then
411
                gIconName = "http://c2.com/sig/wiki.gif"
412
            End If
413
        End If
414
    End If
415
    Set objFSO = Nothing
416
End Sub
417
 
418
Function SpaceName(strX)
419
   '------------------------------------------------------------
420
   ' This function splits up a string into words by inserting a
421
   ' space before each upper case letter. Ignores numbers and .
422
   '------------------------------------------------------------
423
   Dim i, strY
424
   i = 1
425
   strY = ""
426
   Do While i <= len(strX)
427
     If UCase(mid(strX,i,1)) = mid(strX,i,1) Then
428
       if  (( mid(strX,i,1) < "0" ) OR ( mid(strX,i,1) > "9")) AND ( mid(strX,i,1) <> ".")then
429
        strY = strY & " "
430
       end if
431
     End If
432
     strY = strY & mid(strX,i,1)
433
     i = i + 1
434
   Loop
435
   EmitDebug 9,  2, "Original string: " & strX & " ... Spaced out string: " & strY & "<br/>"
436
   SpaceName = strY
437
End Function
438
 
439
 
440
Function removeHTML(txt)
441
  removeHTML=server.htmlencode(txt)
442
End Function
443
 
444
Function safeQuote(txt)
445
  If IsNull(txt) Then
446
     txt = ""
447
  End If
448
  safeQuote=replace(txt,"'","''")
449
End Function
450
 
451
 
452
Function replaceBoundingPattern(txt, pattern, tag)
453
  Dim workingText
454
  workingText = txt
455
  gRE.Pattern = pattern & "([^\n]{0,}?)" & pattern    ' kgreiner
456
  workingText= gRE.Replace(workingText, "<" & tag & ">$1</" & tag & ">")
457
  replaceBoundingPattern = workingText
458
End Function
459
 
460
' Elrey Ronald
461
Function replaceTableColumnPattern(txt)
462
  Dim workingText
463
  Dim aryLines, aryLinesCount
464
  Dim i
465
  workingText = txt
466
 
467
  aryLines = Split(workingText,vbCRLF)
468
  aryLinesCount = UBound(aryLines)
469
 
470
  For i = 0 To aryLinesCount
471
           If left(aryLines(i), 6 ) = "_tmp_0"  Then
472
               aryLines(i) = Replace(aryLines(i), "_tmp_0", "<tr><td valign=top class=TableCell>")
473
               aryLines(i) = Replace(aryLines(i), "||", "</td><td  valign=top class=TableCell>")
474
           End If
475
           If left(aryLines(i), 6 ) = "_tmp_1"  Then
476
               aryLines(i) = Replace(aryLines(i), "_tmp_1", "<tr class=TableRow1><td  valign=top class=TableCell>")
477
               aryLines(i) = Replace(aryLines(i), "||", "</td><td  valign=top class=TableCell>")
478
           End If
479
           If left(aryLines(i), 6 ) = "_tmp_2"  Then
480
               aryLines(i) = Replace(aryLines(i), "_tmp_2", "<tr class=TableRow2><td  valign=top class=TableCell>")
481
               aryLines(i) = Replace(aryLines(i), "||", "</td><td  valign=top class=TableCell>")
482
           End If
483
           If left(aryLines(i), 6 ) = "_tmp_3"  Then
484
               aryLines(i) = Replace(aryLines(i), "_tmp_3", "<tr class=TableRow3><td  valign=top class=TableCell>")
485
               aryLines(i) = Replace(aryLines(i), "||", "</td><td  valign=top class=TableCell>")
486
           End If
487
  Next
488
  replaceTableColumnPattern= Join(aryLines,vbCRLF)
489
End Function
490
 
491
Function AddAnchors(txt)
492
  Dim workingText
493
  Dim aryLines, aryLinesCount
494
  Dim i
495
  Dim tocText
496
  workingText = txt
497
 
498
  dim toc(100)
499
  dim tocIndex: tocIndex = 0
500
 
501
  aryLines = Split(workingText,vbCRLF)
502
  aryLinesCount = UBound(aryLines)
503
 
504
  For i = 0 To aryLinesCount
505
           If left(aryLines(i), 3 ) = "== "  Then
506
               toc(tocIndex) = "<a href=""#Section_"& tocIndex &""">" & Mid(aryLines(i), 3) &"</a>"
507
               aryLines(i) = "<a name=""Section_"& tocIndex &"""></a>" & vbCRLF & aryLines(i)
508
               tocIndex = tocIndex + 1
509
           End If
510
  Next
511
 
512
  if ( tocIndex > 0 ) then
513
      Dim ii
514
      Dim Text
515
      For ii = 0 to tocIndex -1
516
          Text = Text & vbcrlf & " *" & toc(ii)
517
      Next
518
      tocText = Text & vbcrlf & tocText
519
  end if
520
 
521
  ' Look for the spot to drop the TOC
522
  ' [[TOC]]
523
  For i = 0 To aryLinesCount
524
           If left(aryLines(i), 7 ) = "[[TOC]]"  Then
525
            aryLines(i) = tocText & vbCRLF' & aryLines(i)
526
           End If
527
  Next
528
 
529
 
530
  AddAnchors = Join(aryLines,vbCRLF)
531
End Function
532
 
533
 
534
 
535
'Elrey 3/06
536
Function RandomInteger(HighValue , LowValue )
537
     Rnd -1
538
     Randomize (time)
539
     RandomInteger = Int((HighValue - Lowvalue + 1) * Rnd() + Lowvalue)
540
End Function
541
 
542
 
543
Function replaceListPattern(txt, wikiPattern, topPattern, bottomPattern, startLinePattern, endLinePattern)
544
  '
545
  ' Search through the text, creating numbered lists
546
  ' where so indicated by the pattern occurances.
547
  '
548
  ' To indicate a numbered list, the pattern must always
549
  ' appear at the very beginning of a line.
550
  '
551
  Dim workingText,replaceText
552
  Dim aryLines,aryLinesCount
553
  Dim nPatternLength,bInsidePattern
554
  Dim i
555
 
556
  'Elrey  - added multiple pattern
557
  Dim aPatterns
558
  Dim aPatternsCount
559
  Dim aPatternLength
560
  aPatterns = Split(wikiPattern,"^")
561
  aPatternsCount = UBound(aPatterns)
562
  Dim patternFound, j
563
 
564
  Dim aStartPattern
565
  aStartPattern = Split(startLinePattern,"^")
566
 
567
  workingText = txt
568
  nPatternLength = len(wikiPattern)
569
  bInsidePattern = False
570
  aryLines = Split(workingText,vbCRLF)
571
  aryLinesCount = UBound(aryLines)
572
 
573
  For i = 0 To aryLinesCount
574
         ' Elrey
575
         patternFound = 0
576
         For j = 0 to aPatternsCount
577
             aPatternLength = len( aPatterns(j) )
578
             If  left( aryLines(i), aPatternLength ) = aPatterns(j) Then
579
                patternFound = 1
580
                Exit For
581
             End If
582
         Next
583
 
584
    If patternFound = 1 Then
585
        If Not bInsidePattern Then
586
            replaceText = topPattern & vbCRLF & aStartPattern (j)
587
 
588
            bInsidePattern = True
589
        Else
590
            replaceText = aStartPattern (j)
591
        End If
592
        aryLines(i) = replaceText & right(aryLines(i),len(aryLines(i)) - aPatternLength ) & endLinePattern
593
    Else
594
        If bInsidePattern Then
595
            aryLines(i) = bottomPattern & vbCRLF & aryLines(i)
596
            bInsidePattern = False
597
        End If
598
    End If
599
  Next
600
 
601
  replaceListPattern = Join(aryLines,vbCRLF)
602
 
603
End Function
604
 
605
 
606
Function imageize(txt)
607
  ' Include a tag like img:http://www.brinkster.com/images/brinksterlogo.gif
608
  ' to get an inlined-image. <img src="foo">
609
  Dim workingText
610
  workingText = txt
611
 
612
  ' referencing local images  Elrey Ronald 1/2006
613
  gRE.IgnoreCase = True
614
  gRE.Pattern = "(\s)(image:local|img:local):([^ \t\n\r]+)"
615
  workingText=gRE.Replace(workingText,"$1<img src='$3'  >")
616
 
617
  gRE.IgnoreCase = True
618
  gRE.Pattern = "(\s)(imageleft:local|imgleft:local):([^ \t\n\r]+)"
619
  workingText=gRE.Replace(workingText,"$1<img src='$3' align='left' style='margin-right:15pt'>")
620
 
621
  gRE.IgnoreCase = True
622
  gRE.Pattern = "(\s)(imageright:local|imgright:local):([^ \t\n\r]+)"
623
  workingText=gRE.Replace(workingText,"$1<img src='$3' align='right' style='margin-left:15pt'>")
624
 
625
  gRE.IgnoreCase = True
626
  gRE.Pattern = "(\s)(imgcenter:local|imagecenter:local|imgmiddle:local|imagemiddle:local):([^ \t\n\r]+)"
627
  workingText=gRE.Replace(workingText,"$1<p align=center><img src='$3' align='middle'></p>" )
628
 
629
 
630
  gRE.IgnoreCase = True
631
  gRE.Pattern = "(\s)(img|image):([^ \t\n\r]+)"
632
  workingText=gRE.Replace(workingText,"$1<img title='$3' src='$3'>")
633
 
634
  gRE.Pattern = "(\s)(imgleft|imageleft):([^ \t\n\r]+)"
635
  workingText=gRE.Replace(workingText,"$1<img title='$3' src='$3' align='left' style='margin-right:15pt'>")
636
 
637
  gRE.Pattern = "(\s)(imgright|imageright):([^ \t\n\r]+)"
638
  workingText=gRE.Replace(workingText,"$1<img title='$3' src='$3' align='right' style='margin-left:15pt'>")
639
 
640
  gRE.Pattern = "(\s)(imgcenter|imagecenter|imgmiddle|imagemiddle):([^ \t\n\r]+)"
641
  workingText=gRE.Replace(workingText,"$1<p align=center><img title='$3' src='$3' align='middle' ></p>")
642
 
643
  ' local links
644
  gRE.IgnoreCase = True
645
  gRE.Pattern = "(\s)(local):([^ \t\n\r]+)"
646
  workingText=gRE.Replace(workingText,"$1<a href='$3' >$3</a>")
647
 
648
 
649
  gRE.IgnoreCase = False
650
  imageize = workingText
651
 
652
End Function
653
 
654
Function isbnize(txt)
655
  ' include a tag like isbn:0000000000
656
  ' to get a link to a book on Amazon <a href="amazonURL?isbn=0000">0000</a>
657
  Dim workingText
658
  workingText = txt
659
 
660
  gRE.IgnoreCase = True
661
  gRE.Pattern = "(\s)(isbn|ISBN):(\d{9}[\dX])"
662
  workingText=gRE.Replace(workingText,"$1<a  title='Amazon $3' href='http://www.amazon.com/exec/obidos/ISBN=$3'>ISBN:$3</a>")
663
 
664
  gRE.IgnoreCase = False  ' switch it back
665
  isbnize = workingText
666
 
667
End Function
668
 
669
Function IsRequestFromWikiASPPage
670
 
671
  dim sHidden
672
  sHidden = Request.Form("hiddenInput")
673
 
674
  If IsEmpty(sHidden) Then
675
     response.write "hmmm empty"
676
     IsRequestFromWikiASPPage = False
677
  End if
678
 
679
  If sHidden <> "errv2010" Then
680
     response.write "hmmm=" & sHidden
681
     IsRequestFromWikiASPPage = False
682
  End if
683
 
684
  IsRequestFromWikiASPPage = True
685
 
686
End Function
687
 
688
' Regular expression version ---------------------------
689
Function IsRemoteAdressBlackListedRE
690
 
691
  If Trim(gBlackListedIpsRE  ) = "" Then
692
     IsRemoteAdressBlackListedRE = False
693
  else
694
     gRE.Pattern = gBlackListedIpsRE  
695
 
696
     IsRemoteAdressBlackListedRE = gRE.Test( remoteIPHost)
697
  End If
698
End Function
699
 
700
' Non RE version (Exact)--------------------------------
701
Function IsRemoteBlackListed 
702
 
703
    IsRemoteBlackListed = False
704
 
705
    Dim pos
706
 
707
    pos =  InStr(gBlackListedIps, remoteIPHost3numbers) ' Leading 3 digits. Set IP list as ~1.2.3.~4.5.3~
708
 
709
    If Not IsNull(pos) and pos > 0 Then
710
       IsRemoteBlackListed = True
711
    End If
712
 
713
End Function
714
 
715
 
716
Function hyperlink(txt)
717
  Dim workingText
718
  Dim matches
719
  Dim nHits
720
  Dim thisMatchBefore, thisMatchAfter
721
 
722
  workingText = txt
723
 
724
 
725
  'pattern with no spaces:
726
  'gRE.Pattern = "(http|https)://[^ \t\n\r]+"
727
  'gRE.Pattern = "([^A-Za-z0-9'])((http://|https://|ftp://|mailto:|news:)[^\s\<\>\(\)\[\]]+)"
728
 
729
  'ElreyRonald 8/03  Bjarne 10/31
730
  gRE.Pattern = "([^\[])\[([^\|\]]+)\|((http://|https://|ftp://|mailto:|news:|file:)[^\]\r\n\t]+)\]"
731
  workingText=gRE.Replace(workingText,"$1<a href='$3'>$2</a>")
732
 
733
  'ElreyRonald  local links inside [ | ]
734
  gRE.Pattern = "([^\[])\[([^\|\]]+)\|(local):([^ \t\n\r]+)\]"
735
  workingText=gRE.Replace(workingText,"$1<a href='$4'>$2</a>")
736
 
737
 
738
  'gRE.Pattern = "([^A-Za-z0-9'])((http://|https://|ftp://|mailto:|news:)[^\s\<\>\(\)\[\]\r\n\t]+)"
739
  'Bjarne
740
  gRE.Pattern = "([^A-Za-z0-9'])((http://|https://|ftp://|mailto:|news:|file:)[^\s\<\>\(\)\[\]\r\n\t]+)"
741
  workingText=gRE.Replace(workingText,"$1<a href=""$2"">$2</a>")
742
 
743
 
744
   'This is new  5/2006 see [/Drop]
745
  '[Drop#001##Test]
746
            '       1    [    2      ::              3            ]
747
  gRE.Pattern = "([^\[])\[Drop\#(\S+)\#\#([^\<\>\(\)\=\r\n\t\]]+)\]"
748
  workingText=gRE.Replace(workingText,   _
749
   "$1<div><span style=""font-weight: bold; color: white; background-color: green ; cursor: pointer"" onclick=""var div=document.getElementById('$2');if(div.style.display=='none') {div.style.display='block'; this.innerText='&nbsp;&#8592;&nbsp;';} else {div.style.display='none';this.innerText='&nbsp;+&nbsp;'}"">&nbsp;+&nbsp;</span>$3<div id='$2' style='display:none'> " )
750
 
751
 
752
 
753
  ' interwiki  by Elrey
754
  ' example:  [Sample One=CpOrders::SampleOne]
755
            '       1    [     2    =   3      ::               4            ]
756
  gRE.Pattern = "([^\[])\[([^=\]]+)\=([^=\]]+)\:\:([^\s\<\>\(\)\=\r\n\t\]]+)\]"
757
  workingText=gRE.Replace(workingText,"$1<a href='" & gScript & "?db=$3&o=$4'>$2</a>")
758
 
759
  ' interwiki  by Elrey
760
  ' example:  [Sample One=CpOrders::]
761
            '       1    [     2    =   3      ::    ]
762
  gRE.Pattern = "([^\[])\[([^=\]]+)\=([^=\]]+)\:\:\]"
763
  workingText=gRE.Replace(workingText,"$1<a href='" & gScript & "?db=$3'>$2</a>")
764
 
765
 
766
 
767
  ' intern link by Bernd Michalke 9/15/2005
768
  ' [anything geht=WikiASP]
769
 
770
  gRE.Pattern = "([^\[])\[([^=\]]+)\=([^\s\<\>\(\)\=\r\n\t\]]+)\]"
771
  workingText=gRE.Replace(workingText,"$1<a href='"& gScriptURL & "&o=$3'>$2</a>")
772
 
773
  ' intern link by Elrey 3/2006
774
  ' [=WikiASP]
775
  '              (--1--)   (-2----)
776
  gRE.Pattern = "([^\[])\[=([^\]]+)\]"
777
  workingText=gRE.Replace(workingText,"$1<a href='"& gScriptURL & "&o=$2'>$2</a>")
778
 
779
' intern link by Elrey 3/2006
780
  ' [[WikiAS P topic]]
781
  '              (--1--)    (---2--)
782
  gRE.Pattern = "([^\[])\[\[([^\]]+)\]\]"
783
  workingText=gRE.Replace(workingText,"$1<a href='"& gScriptURL & "&o=$2'>$2</a>")
784
 
785
 
786
  ' interwiki  by Elrey
787
  ' example:  [CpOrders::SampleOne]
788
            '       1    [     2   ::   3         ]
789
  gRE.Pattern = "([^\[])\[([^=\]]+)\:\:([^\s\<\>\(\)\=\r\n\t\]]+)\]"
790
  workingText=gRE.Replace(workingText,"$1<a href='" & gScript & "?db=$2&o=$3'>$3</a>")
791
 
792
  ' interwiki  by Elrey
793
  ' example:  [CpOrders::]
794
            '       1    [    2  ::    ]
795
  gRE.Pattern = "([^\[])\[([^=\]]+)\:\:\]"
796
  workingText=gRE.Replace(workingText,"$1<a href='" & gScript & "?db=$2'>$2</a>")
797
 
798
 
799
  hyperlink = workingText
800
 
801
End Function
802
 
803
 
804
 
805
Function PreHack(isTeksten)
806
    Dim arr
807
    Dim element
808
    Dim preOn
809
    Dim newText
810
 
811
    preOn = False
812
    arr = Split(isTeksten, vbCrLf)
813
 
814
    For Each element In arr
815
    If newtext <> "" Then
816
        newtext = newtext & vbCrLf
817
    End If
818
    ' line begins with a space
819
    If left(element, 1) = " " Then
820
        ' start pre tag
821
        If preOn = False Then
822
        preon = true
823
        newText = newtext & "<pre>" & vbcrlf & element
824
        ' already in pre tag
825
        else
826
        newtext = newtext & element
827
        end if
828
    ' empty line
829
    elseif element = "" then
830
        newtext = newtext & vbcrlf
831
    ' line begins with something besides a space
832
    else
833
        ' turn pre off
834
        if preon then
835
        newText = newtext & "</pre>" & vbcrlf & element
836
        preon = false
837
        ' just append element
838
        else
839
        newtext = newtext & element
840
        end if
841
    end if
842
    next
843
    if preon then
844
    newtext = newtext & "</pre>"
845
    preon = false
846
    end if
847
    prehack = newtext
848
end function
849
 
850
 
851
 
852
function xform(isTeksten)
853
  ' this is the transformation routine, in which all the markup
854
  ' is transformed into HTML.
855
  '
856
  ' ordering of the stages is important.
857
  '
858
  dim newText
859
  newText = vbcrlf & isTeksten ' need a space to deal with first-line wikiname
860
 
861
  'Elrey - move HTML removal into here
862
  If gRemoveHtml Then
863
     newText = removeHTML(newText)
864
  End If
865
 
866
  ' indented paragraph second level using '>' (  '|' is now used with Tables - Elrey
867
  newText=replace(newText,vbcrlf & "&gt;&gt;&gt;&gt;",vbcrlf & "<p style=""margin-left:80pt;"">")
868
  newText=replace(newText,vbcrlf & "&gt;&gt;&gt;",vbcrlf & "<p style=""margin-left:60pt;"">")
869
  newText=replace(newText,vbcrlf & "&gt;&gt;",vbcrlf & "<p style=""margin-left:40pt;"">")
870
  newText=replace(newText,vbcrlf & "&gt;",vbcrlf & "<p style=""margin-left:20pt;"">")
871
 ' Elrey 3/2007
872
 newText=replace(newText,vbcrlf & ">>>>>>>>>*",vbcrlf & "<p style=""margin-left:135pt;margin-top:2pt;"">&#9827;&nbsp;")
873
 newText=replace(newText,vbcrlf & ">>>>>>>>*",vbcrlf & "<p style=""margin-left:120pt;margin-top:2pt;"">&#8574;&nbsp;")
874
 newText=replace(newText,vbcrlf & ">>>>>>>*",vbcrlf & "<p style=""margin-left:105pt;margin-top:2pt;"">&#959;&nbsp;")
875
 newText=replace(newText,vbcrlf & ">>>>>>*",vbcrlf & "<p style=""margin-left:90pt;margin-top:2pt;"">&#8226;&nbsp;")
876
 newText=replace(newText,vbcrlf & ">>>>>*",vbcrlf & "<p style=""margin-left:75pt;margin-top:2pt;"">&#9830;&nbsp;")
877
 newText=replace(newText,vbcrlf & ">>>>*",vbcrlf & "<p style=""margin-left:60pt;margin-top:2pt;"">&#8594;&nbsp;")
878
 newText=replace(newText,vbcrlf & ">>>*",vbcrlf & "<p style=""margin-left:45pt;margin-top:2pt;"">&#9674;&nbsp;")
879
 newText=replace(newText,vbcrlf & ">>*",vbcrlf & "<p style=""margin-left:30pt;margin-top:2pt;"">&#959;&nbsp;")
880
 newText=replace(newText,vbcrlf & ">*",vbcrlf & "<p style=""margin-left:15pt;margin-top:2pt;"">&#8226;&nbsp;")
881
 
882
 
883
 
884
  ' indented paragraph second level using '>' (  '|' is now used with Tables - Elrey  updated 3/2007
885
  newText=replace(newText,vbcrlf & ">>>>>>>>>",vbcrlf & "<p style=""margin-left:135pt;margin-top:2pt;"">")
886
  newText=replace(newText,vbcrlf & ">>>>>>>>",vbcrlf & "<p style=""margin-left:120pt;margin-top:2pt;"">")
887
  newText=replace(newText,vbcrlf & ">>>>>>>",vbcrlf & "<p style=""margin-left:105pt;margin-top:2pt;"">")
888
  newText=replace(newText,vbcrlf & ">>>>>>",vbcrlf & "<p style=""margin-left:90pt;margin-top:2pt;"">")
889
  newText=replace(newText,vbcrlf & ">>>>>",vbcrlf & "<p style=""margin-left:75pt;margin-top:2pt;"">")
890
  newText=replace(newText,vbcrlf & ">>>>",vbcrlf & "<p style=""margin-left:60pt;margin-top:2pt;"">")
891
  newText=replace(newText,vbcrlf & ">>>",vbcrlf & "<p style=""margin-left:45pt;margin-top:2pt;"">")
892
  newText=replace(newText,vbcrlf & ">>",vbcrlf & "<p style=""margin-left:30pt;margin-top:2pt;"">")
893
  newText=replace(newText,vbcrlf & ">",vbcrlf & "<p style=""margin-left:15pt;margin-top:2pt;"">")
894
 
895
 
896
 
897
 
898
  ' newlines: three newlines = a blank line
899
  newText=replace(newText,vbcrlf & vbcrlf & vbcrlf,vbcrlf & "<br/>&nbsp;<br/></p><p>" & vbcrlf )
900
 
901
  ' newlines: two newlines = a hard return
902
  newText=replace(newText,vbcrlf & vbcrlf,vbcrlf & "<br/></p><p>" & vbcrlf )
903
 
904
 
905
  EmitDebug 10, 4, "xform-before(" &  newText & ")<br/>"
906
 
907
  If right(newText,2) <> vbcrlf Then
908
    newText = newText & vbcrlf
909
  End If
910
 
911
  'David Purdie
912
  newText=replace(newText, "$Page$", glsTopic )
913
  newText=replace(newText, "$image$", "local:images/page_" + glsTopic )
914
  newText=replace(newText, "$domain$", gHttpDomain )
915
 
916
  ' toc david
917
  newText = AddAnchors(newText)
918
 
919
  'Elrey Ronald
920
  newText=replaceListPattern(newText, "        *", "<ul>", "</ul>", "<li> ", "</li>")
921
  newText=replaceListPattern(newText, "        :*", "<ol>", "</ol>", "<li> ", "</li>")
922
  newText=replaceListPattern(newText, "        1.", "<ol class='nlist'>", "</ol>", "<li> ", "</li>")
923
 
924
  'Elrey Ronald - more convenient bullet list
925
  newText=replaceListPattern(newText, " *", "<ul>", "</ul>", "<li> ", "</li>")
926
  newText=replaceListPattern(newText, " :*", "<ol>", "</ol>", "<li> ", "</li>")
927
  newText=replaceListPattern(newText, " 1.", "<ol class='nlist'>", "</ol>", "<li> ", "</li>")
928
 
929
  'Elrey Ronald - Table Pattern
930
  newText=replaceListPattern(newText, "||^!|^|!^!!", "<table border=1 class=TableClass>", "</table>", "_tmp_0^_tmp_1^_tmp_2^_tmp_3", "</td></tr>")
931
 
932
  newText=replaceTableColumnPattern(newText)
933
 
934
  ' leading space rule
935
  newText = PreHack(newText)
936
 
937
' outline ( ElreyRonald )
938
 
939
  gRE.Pattern = "\r\n\[(\d+)\]======([^\r\n]+)"
940
  newText=gRE.Replace(newText,"<h6>[<a name='$1' href='#fn_$1'>$1</a>] $2</h6>")
941
  gRE.Pattern = "\r\n\[(\d+)\]=====([^\r\n]+)"
942
  newText=gRE.Replace(newText,"<h5>[<a name='$1' href='#fn_$1'>$1</a>] $2</h5>")
943
  gRE.Pattern = "\r\n\[(\d+)\]====([^\r\n]+)"
944
  newText=gRE.Replace(newText,"<h4>[<a name='$1' href='#fn_$1'>$1</a>] $2</h4>")
945
  gRE.Pattern = "\r\n\[(\d+)\]===([^\r\n]+)"
946
  newText=gRE.Replace(newText,"<h3>[<a name='$1' href='#fn_$1'>$1</a>] $2</h3>")
947
  gRE.Pattern = "\r\n\[(\d+)\]==([^\r\n]+)"
948
  newText=gRE.Replace(newText,"<h2>[<a name='$1' href='#fn_$1'>$1</a>] $2</h2>")
949
 
950
  ' footnote ( ElreyRonald )
951
 
952
  gRE.Pattern = "\r\n\[(\d+)\]\r\n"    ' blank footnote will just be an anchor (ElreyRonald)
953
  newText=gRE.Replace(newText,  "<a name='$1' href='#fn_$1'><hr size=1></a>" & vbcrlf)
954
 
955
  gRE.Pattern = "\r\n\[(\d+)\]"
956
  newText=gRE.Replace(newText,  "<br>[<a name='$1' href='#fn_$1'>$1</a>]")
957
 
958
  gRE.Pattern = "\[(\d+)\]"
959
  newText=gRE.Replace(newText, "[<a href='#$1' name='fn_$1'>$1</a>]")
960
 
961
  ' topic line (ElreyRonald)
962
  gRE.Pattern = "\r\n======([^\r\n]+)"
963
  newText=gRE.Replace(newText,"<h6>$1</h6>")
964
  gRE.Pattern = "\r\n=====([^\r\n]+)"
965
  newText=gRE.Replace(newText,"<h5>$1</h5>")
966
  gRE.Pattern = "\r\n====([^\r\n]+)"
967
  newText=gRE.Replace(newText,"<h4>$1</h4>")
968
  gRE.Pattern = "\r\n===([^\r\n]+)"
969
  newText=gRE.Replace(newText,"<h3>$1</h3>")
970
  gRE.Pattern = "\r\n==([^\r\n]+)"
971
  newText=gRE.Replace(newText,"<h2>$1</h2>")
972
 
973
  ' horizontal rule
974
  gRE.Pattern = "\r\n-{4,}"
975
  newText=gRE.Replace(newText,vbCrLf & "<hr size=1 noshade=false />" & vbcrlf)
976
 
977
  ' special case for dash and a-umlaut - MARKUS
978
  'newText=replace(newText,"-", "&minus;")  ' this change breaks image URLs that include dashes
979
  newText=replace(newText,"", "&auml;")
980
 
981
  ' removed by ElreyRonald, use "|"
982
  ' newText=replace(newText,chr(9) & " :" & chr(9),"<p style=""margin-left:20pt;"">")
983
 
984
  ' Removed by ElreyRonald, use "|"
985
  ' newText=replace(newText,vbcrlf & chr(9) & "]",vbcrlf & "<p style=""margin-left:20pt;"">")
986
 
987
 
988
  '[MARKUS] Underline neu hinzugefgt - -_ irgendwas _-
989
  newText=replace(newText,"-_", "<u>")
990
  newText=replace(newText,"_-","</u>")
991
 
992
  '[Markus] LEERSTELLEN werden in HTML-Leerstellen umgewandelt
993
  'newText=replace(newText," ","&nbsp;")  ' this change screws up images.  Why necessary?   dinoch Thu, 17 Oct 2002
994
 
995
  ' bulleted lists: tab-star
996
  'newText=replace(newText,chr(9) & "*","<li> ")
997
  newText=replaceListPattern(newText, chr(9) & "*", "<ul>", "</ul>", "<li> ", "</li>")
998
 
999
  ' numbered lists: tab-colon-star
1000
  newText=replaceListPattern(newText, chr(9) & ":*", "<ol>", "</ol>", "<li> ", "</li>")
1001
 
1002
  ' numbered lists: Changed to use 1. to conform with http://www.c2.com/cgi/wiki?TextFormattingRules
1003
  newText=replaceListPattern(newText, chr(9) & "1.", "<ol>", "</ol>", "<li> ", "</li>")
1004
 
1005
  ' COLORS: (german and english)- german removed (ElreyRonald)
1006
  'SCHRIFTFARBEN {schwarz} {braun} {grn} {blau} {gelb} {rot} {orange}
1007
  '{farbe} {/farbe}
1008
  newText=replace(newText,"{black}","<font color=black>")
1009
  newText=replace(newText,"{/black}","</font>")
1010
  newText=replace(newText,"{green}","<font color=darkgreen>")
1011
  newText=replace(newText,"{/green}","</font>")
1012
  newText=replace(newText,"{blue}","<font color=darkblue>")
1013
  newText=replace(newText,"{/blue}","</font>")
1014
  newText=replace(newText,"{sienna}","<font color=sienna>")
1015
  newText=replace(newText,"{/sienna}","</font>")
1016
  newText=replace(newText,"{red}","<font color=firebrick>")
1017
  newText=replace(newText,"{/red}","</font>")
1018
  newText=replace(newText,"{pink}","<font color=deeppink>")
1019
  newText=replace(newText,"{/pink}","</font>")
1020
 
1021
  ' 5/2006
1022
  newText=replace(newText,"[/Drop]","</div></div>")
1023
 
1024
  '
1025
  newText=replace(newText,"{italic}","<I>")
1026
  newText=replace(newText,"{/italic}","</I>")
1027
  newText=replace(newText,"{bold}","<strong>")
1028
  newText=replace(newText,"{/bold}","</strong>")
1029
 
1030
  ' CHANGE SIZE / SCHRIFTGRSSE
1031
  'SMALLER / KLEINER
1032
  newText=replace(newText,"{small}","<font size='-1'>")
1033
  newText=replace(newText,"{/small}","</font>")
1034
  newText=replace(newText,"{smaller}","<font size='-2'>")
1035
  newText=replace(newText,"{/smaller}","</font>")
1036
  newText=replace(newText,"{smallest}","<font size='-3'>")
1037
  newText=replace(newText,"{/smallest}","</font>")
1038
  'LARGER / GRSSER
1039
  newText=replace(newText,"{big}","<font size='+1'>")
1040
  newText=replace(newText,"{/big}","</font>")
1041
  newText=replace(newText,"{bigger}","<font size='+2'>")
1042
  newText=replace(newText,"{/bigger}","</font>")
1043
  newText=replace(newText,"{biggest}","<font size='+3'>")
1044
  newText=replace(newText,"{/biggest}","</font>")
1045
 
1046
  ' this is were you can insert your own bracket comands...
1047
  newText=replace(newText,"{br}","<br/>")
1048
 
1049
 
1050
  ' images:
1051
  newText= imageize(newText)
1052
 
1053
  ' isbns:
1054
  newText= isbnize(newText)
1055
 
1056
  ' auto-hyperlinks
1057
  newText= hyperlink(newText)
1058
 
1059
  ' bold text: three single quotes
1060
  newText= replaceBoundingPattern(newText,"'''","b")
1061
 
1062
  ' em text: two single quotes
1063
  newText= replaceBoundingPattern(newText,"''","em")
1064
 
1065
  ' consolidate a series of trailing vbcrlf to just 2.
1066
  gRE.Pattern = "(\r\n){3,}$"
1067
  newText=gRE.Replace(newText, vbcrlf & vbcrlf)
1068
 
1069
  If  gDisableScripting = false Then
1070
    ' 2007.08.25 disable scripts
1071
    gRE.Pattern = "<([s|S][c|C][r|R][i|I][p|P][t|T])"
1072
    newText=gRE.Replace(newText, "&lt;$1")
1073
  End If
1074
 
1075
 
1076
  EmitDebug 11, 4, "xform-after(" &  newText & ")<br/>"
1077
 
1078
  newText = Replace(newText, "#@91;", "[")
1079
  newText = Replace(newText, "#@93;", "]")
1080
  newText = Replace(newText, "#@3A;", ":")
1081
  newText = Replace(newText, "#@3C;", "<")
1082
  newText = Replace(newText, "#@3E;", ">")
1083
 
1084
  xform = newText
1085
 
1086
End Function
1087
 
1088
 
1089
Function WalkWiki(isTeksten)
1090
    Dim myText
1091
    myText = isTeksten
1092
    WalkWiki = myText
1093
 
1094
End Function
1095
 
1096
function RemoveBrackets(s)
1097
  Dim ts
1098
  ts = replace( s, "[","")
1099
  ts = replace( ts, "]","")
1100
  RemoveBrackets = ts
1101
end function
1102
 
1103
function RemoveSpaces(s)
1104
  Dim ts
1105
  ts = replace( s, " ","")
1106
  RemoveSpaces = ts
1107
end function
1108
 
1109
 
1110
 
1111
Sub EmitDebug(sig,lvl,arg)
1112
  If gDebug >= lvl Then Response.Write("debug:" & sig & " " & arg & vbcrlf)
1113
End Sub
1114
 
1115
 
1116
'----------------------------------------------------
1117
' This function builds and returns the connection
1118
' string, based on input provided from the web form.
1119
'
1120
function ConnStr(includeMode)
1121
  dim localDs
1122
  ' Map MDB database to physical path
1123
   if len(gDocRootDir) > 0 then
1124
      localDs = gDataSource
1125
   else
1126
      localDs = Server.MapPath(gDataSource)
1127
   end if
1128
 
1129
  ConnStr= "Provider=" & gProvider & ";Data Source=" & localDs & ";"
1130
  if (includeMode) then
1131
      ConnStr=   ConnStr & "mode= Share Deny None"
1132
  end if
1133
  EmitDebug 20, 3, "ConnStr= (" &  ConnStr & ")<br/>"
1134
end function
1135
 
1136
 
1137
 
1138
sub CheckDbErrors
1139
  if  gDataConn.errors.count> 0 then
1140
    dim counter
1141
    response.write "<br/><b>Database Errors Occurred" & "</b><br/>" & vbcrlf
1142
    for counter= 0 to gDataConn.errors.count
1143
      response.write "Error #" & gDataConn.errors(counter).number & vbcrlf & "<br/>"
1144
      response.write "  Description(" & gDataConn.errors(counter).description & ")" & vbcrlf & "<br/>"
1145
    next
1146
  else
1147
    response.write "<br/><b>No Database Errors Occurred" & "</b><br/>" & vbcrlf
1148
  end if
1149
end sub
1150
 
1151
 
1152
' Elrey Ronald  2/21/05
1153
sub VerifyWikiTableNoAdoxComponent
1154
  on error resume next
1155
  gDataConn.Open ConnStr(0)
1156
  on error goto 0
1157
 
1158
  on error resume next
1159
  gDataConn.execute("select PageData, Title from " & gDbTableName & " where ID = 2")
1160
  on error goto 0
1161
 
1162
end sub
1163
 
1164
'----------------------------------------------------------------------------
1165
' VerifyWikiTable
1166
' This routine:
1167
' (a) verifies the existence of the target database (dbname) at the given
1168
'     ADO connection.  If necessary, this routine creates that
1169
'     database.
1170
' (b) verifies the existence of the table in that database.  If necessary,
1171
'     this routine will create the required table, and build the table
1172
'     structure.  The columns in the target table are determined by the
1173
'     fields in the source record set (sourceRs).   Two additional
1174
'     columns are also added. (in fact we do not use the entire recordset,
1175
'     but only the collection of fields in the recordset.
1176
'
1177
 
1178
sub VerifyWikiTable
1179
  if not gAutoCreateMdb then
1180
     Call VerifyWikiTableNoAdoxComponent
1181
     Exit Sub
1182
  End If
1183
  dim tbl, cat, dbname, fso
1184
  dim fsoErrMessage, adoxErrMessage, instructions
1185
 
1186
  fsoErrMessage  = "<font color=red >ERROR: Directory or MS Access File can not be created! Automatic DB creation is not possible. Your server is missing the needed <b>FileSystemObject component</b>.</font><BR>"
1187
  adoxErrMessage = "<font color=red >ERROR: Database file can not be created! Some file actions are disabled. Your server is missing the needed <b>ADOX.Catalog component</b>.</font><BR>"
1188
  instructions =   "<LI>You may have to <b>MANUALLY</b> create the folder/MsAccess file -> <b>" & gDataSource & " </b> </LI>"  & _
1189
                   "<LI>You may modify 'gDefaultIcon', 'gDefaultHomePage' variables in the WikiAsp program to view your default icon and access the proper Ms Access file (mdb).</LI>" & _
1190
                   "<LI>You may modify 'gAutoCreateMdb' and set it to false to prevent creation of MDB and avoid this message." & _
1191
                   "<LI>The program will attempt to continue using default values, if this works you can just remove these comments from the program (look for VerifyWikiTable  subroutine).</LI>" & _
1192
                   "<BR><BR><B><i>Now trying to use default values to see if this would work...</i></B>"
1193
 
1194
  err.clear
1195
  ' Check if ADOX.Catalog component is available in this computer
1196
  on error resume next
1197
  set cat= CreateObject("ADOX.Catalog")
1198
  on error goto 0
1199
 
1200
  ' Check if FileSystemObject component is available in this computer
1201
  on error resume next
1202
  set fso = CreateObject("Scripting.FileSystemObject")
1203
  on error goto 0
1204
 
1205
  If Not IsObject(cat) or cat is nothing Then
1206
     Response.Write( adoxErrMessage)
1207
     Response.Write( instructions )
1208
     Call VerifyWikiTableNoAdoxComponent
1209
     Exit Sub
1210
  End If
1211
 
1212
  err.clear
1213
  If Not IsObject(fso)  Then
1214
     Response.Write( fsoErrMessage)
1215
     Response.Write( instructions )
1216
     Call VerifyWikiTableNoAdoxComponent
1217
     Exit Sub
1218
  End If
1219
 
1220
  if len (gDocRootDir) > 0 then
1221
    dbname = gDataSource
1222
  else
1223
    dbname = Server.MapPath(gDataSource)
1224
  end if
1225
 
1226
  '--------------------------------------------
1227
  ' step 0: check the directory, create if necessary
1228
  dim folder, f1
1229
  if len (gDocRootDir) > 0 then
1230
    f1 = gDocRootDir & "\" & gDataSourceDir
1231
  else
1232
    f1 = Server.MapPath(gDataSourceDir)
1233
  end if
1234
  if not fso.FolderExists(f1) then
1235
      on error resume next
1236
      Set folder = fso.CreateFolder(f1)
1237
      on error goto 0
1238
      If Not IsObject(folder) Then
1239
         Response.Write( "Unable to create [" & f1 & "].  Please modify DOCROOT and gDataSourceDir in the program. Consult your website settings." )
1240
         Response.End
1241
      End If
1242
      set folder = nothing
1243
  end if
1244
  set fso = nothing
1245
  '---- some security here
1246
 
1247
  If gDataSourceFile <> gDefaultHomePage Then
1248
    Dim pwd
1249
    If Request.QueryString("pw") <> gPassword Then
1250
        Response.Write("Sorry but the Database (db) requested does not exist, or may not be writable.<br>Correct password must be sent to create it.")
1251
        Response.Write("<br>Hint. Add &pw=" & gPassword & " to the URL.")
1252
        Response.Write("<p>Folder:" & f1 & ".")
1253
        Response.Write("<br>DataBase:" & gDataSource & ".")
1254
        Response.End
1255
    End If
1256
  End If
1257
  '--------------------------------------------
1258
  ' step 1: create the new db catalog, if necessary
1259
  Err.Clear
1260
  EmitDebug 21, 2, vbcrlf & " creating db " & dbname & "<br/>"
1261
on error resume next
1262
  cat.Create ConnStr(0)
1263
  on error goto 0
1264
  EmitDebug 22, 2, ">> error(" & err.Number & "," & err.Description &  ")<br/>"
1265
  'EmitDebug 23, 2, vbcrlf & " catConnErrorCount(" & _
1266
  '    cat.ActiveConnection.errors.count  & ")<br/>"
1267
 
1268
  if not (err.Number = 0) then
1269
    if not (err.Description = "Database already exists." ) then
1270
      dim sError
1271
      sError = ">> error(" & err.Number & "," & err.Description & ")" & _
1272
          "(EXPECTED ""Database already exists"")..." & "<br/>"
1273
      EmitDebug 24, 2, sError
1274
      Response.Write( "<span style='color:red'>Fatal error creating db: " & err.Number & " " & err.description & "</span>")
1275
    else
1276
      EmitDebug 25, 2, ">> Database already exists..." & "<br/>"
1277
      cat.ActiveConnection= ConnStr(0)
1278
    end if
1279
  else
1280
    EmitDebug 26, 2, ">> Database has just been created..." & "<br/>"
1281
  end if
1282
  EmitDebug 27, 2, " Database now exists..." & "<br/>"
1283
 
1284
 
1285
  '--------------------------------------------
1286
  ' step 2: create the new table, with columns, if necessary
1287
  Err.Clear
1288
  EmitDebug 28, 2, " verifying presence of table(" & gDbTableName & ")<br/>"
1289
  'if not isNothing(gDataConn) then set gDataConn = nothing
1290
  on error resume next
1291
  set gDataConn = Server.CreateObject("ADODB.Connection")
1292
  on error goto 0
1293
  If Not IsObject(gDataConn) Then
1294
    Response.Write ( "Unable to establish connection. Missing ADO object.")
1295
    Response.End
1296
  End If
1297
 
1298
  on error resume next
1299
  gDataConn.Open ConnStr(0)
1300
  on error goto 0
1301
 
1302
 
1303
  on error resume next
1304
  gDataConn.execute("select PageData, Title from " & gDbTableName & " where ID = 2")
1305
  on error goto 0
1306
 
1307
  if (0 = gDataConn.errors.count) then
1308
      EmitDebug 29, 1, vbcrlf & "(no db errors, ergo table exists)"  & "<br/>"
1309
  elseif ((gDataConn.errors.count>0) and ( ADOERROR_NOTABLE = gDataConn.errors(0).number)) then
1310
      set gDataConn = nothing
1311
      ' error: table does not exist.
1312
      EmitDebug 30, 2, vbcrlf & " creating table " & gDbTableName  & "<br/>"
1313
      Dim idx 'As New ADOX.Index
1314
      set idx= CreateObject("ADOX.Index")
1315
      ' now, create a new table in the db:
1316
      set tbl= CreateObject("ADOX.Table")
1317
      With tbl
1318
      ' drop tbl into a MDB provider context; need to do this NOW
1319
      ' to be able to use autoIncrement, later.
1320
      set .ParentCatalog = cat
1321
 
1322
      ' Name the new table.
1323
      .Name = gDbTableName
1324
 
1325
      .Columns.Append "ID", 3
1326
      .Columns("ID").Properties("AutoIncrement") = True
1327
 
1328
      .Columns.Append "Title", 202, 127
1329
      .Columns.Append "PageData", 203
1330
      .Columns.Append "PrevPageData", 203
1331
      .Columns("PrevPageData").Properties("Jet OLEDB:Allow Zero Length") = True
1332
      .Columns("PrevPageData").Properties("Nullable") = True
1333
      .Columns.Append "LastUpdate", 7     ' timestamp
1334
      .Columns.Append "LastEditor", 202, 127
1335
 
1336
      ' create the Primary Key :
1337
      idx.Name = "RecordIndex"
1338
      idx.Columns.Append "ID"
1339
      idx.PrimaryKey = True
1340
      idx.Unique = True
1341
      .Indexes.Append idx
1342
 
1343
 
1344
 
1345
      End With
1346
 
1347
      ' this appends the table to the db catalog
1348
      cat.Tables.Append  tbl
1349
      EmitDebug 31, 2, vbcrlf & " post-append: catConnErrorCount(" & _
1350
      cat.ActiveConnection.errors.count  & ")<br/>"
1351
 
1352
      set idx= nothing
1353
 
1354
      ' insert the first record into the newly-created table
1355
      EmitDebug 32, 2,  ">> inserting into table(" & gDbTableName  & ")<br/>"
1356
 
1357
      set gDataConn = Server.CreateObject("ADODB.Connection")
1358
      gDataConn.Open ConnStr(1)
1359
 
1360
      dts = Now
1361
      EmitDebug 33, 2,  ">> the time is now(" & dts  & ")<br/>"
1362
 
1363
      DoInitialPageCreation(".")
1364
 
1365
  else
1366
      EmitDebug 34, 2,  ">> table " & tablename & " already exists?" & "<br/>"
1367
  end if
1368
 
1369
  set cat = nothing
1370
  set tbl = nothing
1371
  on error goto  0
1372
 
1373
end sub
1374
 
1375
 
1376
Function DoInitialPageCreation(folderspec)
1377
  Dim fso, f, f1, fc, s, dts, sPageData, fPage, stmnt
1378
  Set fso = CreateObject( "Scripting.FileSystemObject" )
1379
 
1380
  EmitDebug 35, 2,  ">> checking dir (" & Server.MapPath(folderspec) & ")<br/>"
1381
  Set f = fso.GetFolder(Server.MapPath(folderspec))
1382
  Set fc = f.Files
1383
  EmitDebug 36, 2,  ">> files counted (" & fc.Count & ")<br/>"
1384
  For Each f1 in fc
1385
    if (Right(f1.name, 4) = ".wik") then
1386
        s = Left(f1.name, Len(f1.name)-4)
1387
        EmitDebug 37, 2,  ">> found file  (" & s & ")<br/>"
1388
        on error resume next
1389
        set fPage= fso.OpenTextFile(Server.MapPath(f1.name),FOR_READING)
1390
        sPageData = fPage.ReadAll
1391
        on error goto 0
1392
        fPage.Close
1393
        set fPage = nothing
1394
        dts = Now  ' timestamp
1395
        EmitDebug 38, 2,  ">> inserting record (" & s & ")<br/>"
1396
 
1397
        stmnt = "INSERT INTO " & gDbTableName & " (Title,PageData,PrevPageData,LastUpdate,LastEditor) " & _
1398
        "VALUES ( '" & s & "','" & safeQuote(sPageData) & "', '--', '" & dts & "', '" & gScript & " (initial creation)');"
1399
        on error resume next
1400
        gDataConn.execute(stmnt)
1401
        on error goto 0
1402
        if gDebug>=1 then CheckDbErrors
1403
    end if
1404
  Next
1405
  set fso = nothing
1406
  set f = nothing
1407
  set fc = nothing
1408
 
1409
end Function
1410
 
1411
 
1412
 
1413
function theWhereClause(theStr)
1414
  dim result
1415
  result= ""
1416
  dim myArray
1417
  dim element
1418
  EmitDebug 39, 1, "whereClause(" & theStr & ")<br/>" & vbcrlf
1419
 
1420
  myArray = split(Trim(theStr), " ")
1421
  for each element in myArray
1422
    element = Trim(element)
1423
    if (result = "") then
1424
      result = " where "
1425
    else
1426
      result = result & " and "
1427
    end if
1428
    result= result &  " PageData like '%" & element & "%'"
1429
  next
1430
  EmitDebug 40, 1, "whereClause:result(" & result & ")<br/>" & vbcrlf
1431
  theWhereClause = result
1432
 
1433
end function
1434
 
1435
sub handleLogout
1436
    Dim url
1437
    url = gScriptURL & "&o=" & glsTopic
1438
    gEnableEdit = false
1439
    Session.Abandon
1440
    Response.Redirect(url)
1441
end sub
1442
 
1443
sub handleLogin
1444
    Dim url
1445
    url = gScriptURL & "&o=" & glsTopic
1446
    gEnableEdit = true
1447
    Session("login") = 1
1448
    Response.Redirect(url)
1449
end sub
1450
 
1451
sub handleEdit
1452
    If NOT gEnableEdit Then
1453
        Response.Write("<br/><br/><br/><br/><br/><center><h2>Editing is not allowed</h2></center>")
1454
        Response.End
1455
        exit sub
1456
    End If
1457
 
1458
    Dim readonlyflag, disableflag
1459
    readonlyflag = ""
1460
    disableflag  = ""
1461
 
1462
'   If glsTopic = "TextFormattingRules" Then
1463
'     exit sub
1464
'   End If
1465
 
1466
 
1467
    If IsRemoteBlackListed Then
1468
 
1469
        Response.Write("<br/><br/><br/><br/><br/><center><h2>Please send e-mail to this site's Web Master ASAP.</h2></center>")
1470
        Response.End
1471
        Exit Sub
1472
 
1473
    End If
1474
 
1475
      If glsTopic <> "WikiSandBox" _
1476
         and glsTopic <> "VwisitorsPage" _
1477
         and glsTopic <> "VisitorsPage" _
1478
         and ( not gIsOpenWiki  or _
1479
         glsTopic = "TextFormattingRules" ) Then
1480
        If Not IsEmpty(Request.Form("pwd")) Then  Session("pwd") = Request.Form("pwd")
1481
 
1482
        If IsEmpty( Session("pwd") ) or      _
1483
           ( Session("pwd") <> gEditpassword    and  _
1484
             Session("pwd") <> gPassword ) Then
1485
 
1486
            Response.Write "<br/><center><img src='" &gIconName   & "'><form id=form1 name=form1 method=post action='" & _
1487
                      gScript & "?a=edit&o=" & glsTopic & "&db=" & gDataSourceFile &  _
1488
                      "'> " & gPasswordLabel & "<input type=password name=pwd id=pwd><input type=submit value=Go></form>"
1489
                      ' "<hr><a href=mailto:lambda326@hotmail.com>Send me an E-mail </a> to get a password . For now, you can only <b>click and edit</b> <a href=wiki.asp?o=WikiSandBox>WikiSandBox</a><hr></center>"
1490
 
1491
            readonlyflag = "readonly style='font-size:8pt; background:silver; border:solid 1px '"
1492
            disableflag  = " disabled "
1493
        End If
1494
      End If
1495
 
1496
      sqlQuery = "select PageData,Title, lastupdate, PrevPageData from " & gDbTableName & " where title='" & glsTopic & "'"
1497
      EmitDebug 41, 2, "Edit query(" & sqlQuery & ")<br/>" & vbcrlf
1498
 
1499
      'set rs = gDataConn.execute(sqlQuery)
1500
      set rs = WrappedQueryExecute( gDataConn, sqlQuery )  ' ERV 3/2007        
1501
 
1502
 
1503
      dim strPageData, strTitle, strLastUpdate, strPrevPageData
1504
 
1505
      if not rs.eof then
1506
         'page exists
1507
          strTitle = rs("title")
1508
          strPageData = rs("pageData")
1509
          strLastUpdate = CStr(rs("lastupdate"))
1510
          strPrevPageData = rs("PrevPageData")
1511
      else
1512
          'page does not exist
1513
          strTitle = glsTopic
1514
          strPageData = ""
1515
          strLastUpdate = ""
1516
          strPrevPageData = ""
1517
      end if
1518
 
1519
     'If Not gHideWikiSource Then
1520
              response.write("<form id=form1 name=form1 method=""POST"" action=""" & gScript & """>" & vbcrlf)
1521
              response.write "<h4>Edit: <font color=blue>&nbsp;" & SpaceName(strTitle) & "</font>&nbsp;&nbsp;&nbsp;&nbsp;<input type=submit value=Save " & disableflag & ">&nbsp;&nbsp;&nbsp;&nbsp;<input type=button value='Cancel' onclick='location.href=""" & gScriptURL & "&o=" & strTitle & """'></h4>"  & vbcrlf
1522
              ' [MARKUS - replace virtual with hard]
1523
              response.write("<textarea id=""pagetext""  name=""pagetext"" rows='" & giEditAreaRows & "'  " & readonlyflag &" cols='" & giEditAreaCols & _
1524
                "'  style='width:100%'>"  & _
1525
                Server.HtmlEncode(strPageData) & _
1526
                "</textarea>" & vbcrlf & _
1527
                "<br/> <input type=submit value=' Save ' " & disableflag & " >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type=button value='Cancel' onclick='location.href=""" & gScriptURL & "&o=" & strTitle & """'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" & _
1528
                "<br/></br/> "  & _
1529
                vbcrlf & "<input type=hidden name=lupdt value='" & strLastUpdate & "'>" & _
1530
                vbcrlf & "<input type=hidden name=o value='" & strTitle & "'>" & _
1531
                vbcrlf & "<input type=hidden name=db value='" & gDataSourceFile & "'>" & _
1532
                vbcrlf & "<input type=hidden name=hiddenInput value='errv2010'>" & _
1533
                vbcrlf & "<input type=hidden name=dbname value='" & gDataSourceName & "'>" & _
1534
                vbcrlf & "<input type=hidden name='a' value='save'>" & vbcrlf )
1535
 
1536
 
1537
 
1538
    'End If
1539
 
1540
    If disableflag <> "" Then
1541
       exit sub
1542
    end if
1543
 
1544
    If gHideWikiSource then
1545
       exit sub
1546
    end if
1547
 
1548
    'History of changes
1549
    response.write("<br><br><br><br><br><h3>History of Changes:</h3><textarea readonly style='font-size:8pt; background:silver;' rows='" & giEditAreaRows & "' cols='" & giEditAreaCols & _
1550
    "'  style='width:100%'>" & strPrevPageData & "</textarea>")
1551
 
1552
    'Original Text
1553
    response.Write("<textarea name=""pagetextorig"" rows=0 cols=0 style='width:0;'>" & strPageData & "</textarea></form>" )
1554
    response.Write("<script language=javascript>form1.pagetext.rows=window.screen.height/26;</script>")
1555
 
1556
    Session("CurrentEditPage") = "# "  & strTitle 
1557
end sub
1558
 
1559
 
1560
sub handleSearch
1561
 
1562
  dim pageTitle, s
1563
  's= Request.QueryString("o")  BUG - Fri, 2002 jan 22 - Dan Shaw
1564
  s= glsTopic
1565
  if not isEmpty(s) then
1566
    EmitDebug 42, 2, "<br/>SEARCH(" & s & ")<br/>" & vbcrlf
1567
    pageTitle = "Search Results (" & s & ")"
1568
    dim myClause
1569
    myClause= theWhereClause(s)
1570
    sqlQuery="select ID, Title, LastUpdate , LastEditor from " & gDbTableName & myClause & " order by Title"
1571
  end if
1572
 
1573
  EmitTabularOutput pageTitle, ""
1574
 
1575
end sub
1576
 
1577
'ElreyRonald 4/2004
1578
Sub HandleDelete
1579
  Dim pwd, topic, sh
1580
   Response.Write("<center><h2>Page Deletion</h2></center><hr>")
1581
  sh = "<br><a href='" & gScriptURL & "' >Click here proceed to home page</a>"
1582
  If Request.QueryString("pw") <> gDeletePassword Then
1583
   Response.Write( "Authorization to delete failed. Try adding &pw=" & gDeletePassword & sh)
1584
   Response.End
1585
  End If
1586
  topic = Request.QueryString("o") ' Topic to delete
1587
  If IsNull(topic) or topic = "" Then
1588
   Response.Write( "Specify page name to delete i.e.  &o=MyPage" & sh)
1589
   Response.End
1590
  End If
1591
  Dim stmnt
1592
  stmnt = "delete from WikiData where Title='" & topic & "'"
1593
  Set gDataConn = Server.CreateObject("ADODB.Connection")
1594
  on error resume next
1595
  gDataConn.Open ConnStr(1)
1596
  on error goto 0
1597
  on error resume next
1598
  gDataConn.execute(stmnt)
1599
  on error goto 0
1600
  If  gDataConn.errors.count = 0 then
1601
    Response.Write( "<b>" & topic & " </b> was successfully deleted. " )
1602
  Else
1603
    Response.Write( "<b>" & topic & " </b>  was not deleted due to some errors. " )
1604
  End if
1605
  Set gDataConn = nothing
1606
  Response.write  sh
1607
  Response.End
1608
end sub
1609
 
1610
'ElreyRonald 4/2004
1611
sub handleRss
1612
 
1613
  dim pageTitle, initialRow, s, sSortOrder
1614
  dim modifiedUrl
1615
 
1616
  sqlQuery="select top " & giNumRecentFiles & " ID, LastEditor, Title,PageData,PrevPageData, LastUpdate from " & gDbTableName & " order by LastUpdate DESC"
1617
 
1618
  sqlQuery = sqlQuery & sSortOrder
1619
 
1620
  set gDataConn = Server.CreateObject("ADODB.Connection")
1621
 
1622
  on error resume next
1623
  gDataConn.Open ConnStr(1)
1624
  on error goto 0
1625
 
1626
  if not (0 = gDataConn.errors.count) then
1627
    if (ADOERROR_NOFILE = gDataConn.errors(0).number) then
1628
      EmitDebug 54, 1, "<br/>ErrorCount(" & gDataConn.errors.count & ")<br/>" & vbcrlf
1629
      EmitDebug 55, 1, "<br/>Error(" & gDataConn.errors(0).number &") desc(" &_
1630
      gDataConn.errors(0).description & ")<br/>" & vbcrlf
1631
      VerifyWikiTable
1632
    end if
1633
  end if
1634
 
1635
  'set rs= gDataConn.execute(sqlQuery)
1636
  set rs = WrappedQueryExecute( gDataConn, sqlQuery )  ' ERV 3/2007        
1637
 
1638
 
1639
  modifiedUrl = Replace(gScriptURL, "&", "&amp;")
1640
  if not rs.eof then
1641
    response.ContentType = "text/xml"
1642
    response.Write("<?xml version=""1.0"" encoding=""ISO-8859-1"" ?>")
1643
    response.Write(gRssStyle)
1644
    response.Write("<rss version=""2.0"">")
1645
    response.Write("<channel>")
1646
    response.Write("<title>" & SpaceName(gHomeTopic) & "</title> ")
1647
    response.Write("<link>" & gHttpDomain & "/" & modifiedUrl &  "&amp;a=rss</link> ")
1648
    Response.Write("<ttl>1000</ttl>")
1649
    response.Write("<description>Latest changes and postings for the topic:" & SpaceName(gHomeTopic) & ". </description> ")
1650
    response.Write("<copyright>Copyright (C)2003  Elrey Ronald Vel. All rights reserved.</copyright> ")
1651
    response.Write("<generator> WikiAsp RSS Generator by Elrey </generator> ")
1652
    Response.Write("<webMaster>lambda326@hotmail.com</webMaster>")
1653
    response.Write("<image><width>80</width><height>40</height>")
1654
    response.Write("<title>" & SpaceName(gHomeTopic) & "</title> ")
1655
    response.Write("<link>" & gHttpDomain & "/" & modifiedUrl & "</link> ")
1656
    If  left(gIconName,4) = "http" Then
1657
      response.Write("<url>" &  gIconName &" </url></image>")
1658
    Else
1659
      response.Write("<url>" & gHttpDomain & "/" & gIconName &" </url></image>")
1660
    End If
1661
 
1662
    Do while Not rs.eof
1663
      If rs("Title") <> "RegisteredUsers"  Then
1664
        Response.Write("<item>")
1665
        Response.Write("<title>" & SpaceName(rs("Title"))&  "</title>")
1666
        Response.Write("<link>" & gHttpDomain & "/" & modifiedUrl & "&amp;o=" & rs("Title") & "</link> ")
1667
        Response.Write("<category>" & SpaceName(gHomeTopic) & "</category>")
1668
        Response.Write("<author>user@" & rs("LastEditor")& "</author>")
1669
        Response.Write("<description>")
1670
        Response.Write( "<![CD" & "ATA[ ")
1671
        If gHighlightFlag Then
1672
            Response.Write(  ProcessRssItem(rs) )
1673
        Else
1674
            Response.Write WalkWiki(xform(  rs("PageData")  ))
1675
        End If
1676
        Response.Write("]]></description>")
1677
        Response.Write("<pubDate>" & GetRFC822date(rs("LastUpdate")) & "</pubDate> ")
1678
        Response.Write("</item>")
1679
      End If
1680
      rs.MoveNext
1681
      i= i+1
1682
    Loop
1683
 
1684
    response.Write( "</channel></rss>")
1685
  end if
1686
  Set gDataConn = nothing
1687
  Set rs = nothing
1688
end sub
1689
 
1690
 
1691
'Get the nth page in History
1692
'ElreyRonald
1693
Function GetPrevData(rs, n)
1694
   Dim arrD, tmpStr, i, cnt, getFlag
1695
   Dim prevData
1696
   prevData = rs("PrevPageData")
1697
   If    IsNull(prevData) Then
1698
      GetPrevData   = ""
1699
   Else
1700
 
1701
      arrD    =  Split( rs("PrevPageData"), vbCRLF)
1702
      cnt     = 0
1703
      getFlag = 0
1704
      tmpSTr  = ""
1705
      For i = 1 to UBound(arrD)
1706
         If left(arrD(i), 8) = "--------"   Then
1707
            cnt = cnt + 1
1708
            if getFlag = 1 Then Exit For
1709
            if  n =  cnt Then
1710
               getFlag = 1
1711
            end if
1712
         End If
1713
         If getFlag = 1 and left(arrD(i), 8) <> "--------" Then
1714
            tmpStr = tmpStr & arrD(i) & vbCRLF
1715
         End If
1716
 
1717
      Next
1718
      GetPrevData = tmpStr
1719
   End If
1720
End Function
1721
 
1722
 
1723
'Process the current record (rs) for RSS
1724
'ElreyRonald
1725
Function    ProcessRssItem(rs)
1726
   Dim currData, prevData, markedStr
1727
   Dim beginMark, endMark, tmpS
1728
   beginMark = "###s###"
1729
   endMark  = "###e###"
1730
   currData = rs("PageData")
1731
   prevData = GetPrevData( rs, 1 )
1732
   markedStr =  MarkWhatWasAdded( prevData, currData, beginMark , endMark)
1733
   tmpS = WalkWiki(xform(markedStr))
1734
   tmpS = Replace( tmpS, beginMark, "<U style='background:yellow' >")
1735
   tmpS = Replace( tmpS, endMark,   "</U>")
1736
   ProcessRssItem = tmpS
1737
End Function
1738
 
1739
Function MarkWhatWasAdded( prevData, currData, st, en)
1740
Dim arrCurrData, arrPrevData
1741
Dim currMaxIndex
1742
Dim prevMaxIndex, i
1743
arrCurrData  = Split( currData, vbCRLF)
1744
arrPrevData  = Split( prevData, vbCRLF)
1745
currMaxIndex =  UBound( arrCurrData )
1746
prevMaxIndex =  UBound( arrPrevData )
1747
If  prevMaxIndex <  0 Then
1748
  MarkWhatWasAdded = currData
1749
  Exit Function
1750
End If
1751
 
1752
Dim marked, prevPtr, started
1753
marked =    0
1754
prevPtr = 0
1755
started = 0
1756
'Search delta forward
1757
For i = 0 to prevMaxIndex
1758
   If lTrim(rtrim(arrPrevData(i))) <> "" Then Exit For
1759
Next
1760
prevPtr = i  'start here
1761
For i   = 0 to currMaxIndex
1762
   If lTrim(rtrim(arrCurrData(i))) = "" and started = 0Then
1763
 
1764
   Else
1765
      Started = 1
1766
      If    prevPtr <=  prevMaxIndex Then
1767
         If arrCurrData(i)  <>  arrPrevData( prevPtr) Then
1768
            if ( i > 0 ) then
1769
               if arrCurrData(i-1) = "" Then
1770
                 arrCurrData(i-1)   =  vbCRLF & arrCurrData(i-1) & st
1771
               else
1772
                 arrCurrData(i-1)   = arrCurrData(i-1) & st
1773
               end if
1774
            else
1775
               arrCurrData(i)   = st &   vbCRLF & arrCurrData(i)
1776
            end if
1777
            marked =    1
1778
            Exit For
1779
         End If
1780
         prevPtr = prevPtr + 1
1781
         if prevPtr >  prevMaxIndex and i < currMaxIndex then
1782
            arrCurrData(i)  = arrCurrData(i+1) & st
1783
            marked = 1
1784
            exit for
1785
         end if
1786
      End If
1787
   End If
1788
Next
1789
 
1790
If  marked =    0 Then
1791
   MarkWhatWasAdded = currData
1792
   exit function
1793
End If
1794
 
1795
'Search delta Backwards
1796
For i = prevMaxIndex to 0 step -1
1797
   If lTrim(rtrim(arrPrevData(i))) <> "" Then Exit For
1798
Next
1799
Dim pi
1800
pi  = i
1801
started = 0
1802
For i   = currMaxIndex  to  0 step -1
1803
  If lTrim(rtrim(arrCurrData(i))) = "" and started = 0Then
1804
     ' do nothing
1805
  Else
1806
    Started  = 1
1807
    If  pi  >= 0 Then
1808
      'Response.Write "backward Compare " & Cstr(i) & "-" & Cstr(pi) &" [" &arrCurrData(i) & "]=["& arrPrevData(pi) & "] " &    vbCRLF
1809
      If    arrCurrData(i)  <>  arrPrevData(pi) Then
1810
         arrCurrData(i) = arrCurrData(i) & en
1811
         Exit For
1812
      End If
1813
      pi    = pi - 1
1814
      if pi < 0 and i > 0 then
1815
         arrCurrData(i-1)   = arrCurrData(i-1) & en
1816
         exit for
1817
      End if
1818
    End If
1819
  End If
1820
Next
1821
 
1822
Dim sres
1823
sres = ""
1824
For i   = 0 to currMaxIndex
1825
   sres = sres  & arrCurrData(i) & vbCRLF
1826
Next
1827
MarkWhatWasAdded = sres
1828
 
1829
End Function
1830
 
1831
 
1832
 
1833
 
1834
sub handleList
1835
 
1836
  dim pageTitle, initialRow, s, sDirection, sSortOrder, sNextDirectionTitle, sNextDirectionDate
1837
  ' Request.ServerVariables("HTTP_REFERER")
1838
 
1839
  initialRow= ""
1840
  s = Request.QueryString("o")
1841
  EmitDebug 43, 2, "<br/>" & s & "<br/>" & vbcrlf
1842
  if (s = "recent") then
1843
    pageTitle = "Recently Modified Topics"
1844
    sqlQuery="select top " & giNumRecentFiles & " ID, Title, LastUpdate, LastEditor from " & gDbTableName & " order by LastUpdate DESC"
1845
  else
1846
    pageTitle = "List of All Topics"
1847
    sqlQuery= "select ID, Title, LastUpdate , LastEditor from " & gDbTableName & " order by "
1848
    sDirection = Request.QueryString("d")
1849
 
1850
    if (s = "ByDate") then
1851
      sqlQuery = sqlQuery & "LastUpdate "
1852
      if (sDirection = "down") then
1853
    sSortOrder = ""  ' the reverse natural sort order (oldest first)
1854
    sNextDirectionDate= ""
1855
      else
1856
    sSortOrder = "DESC"  ' the natural sort order (most recent first)
1857
    sNextDirectionDate= "&d=down"
1858
      end if
1859
    elseif (s = "ByTitle") then
1860
      sqlQuery = sqlQuery & "Title "
1861
      if (sDirection = "down") then
1862
    sSortOrder = "DESC"   ' the reverse natural sort order (alphabetic)
1863
    sNextDirectionTitle = ""
1864
      else
1865
    sSortOrder = ""   ' the natural sort order (alphabetic)
1866
    sNextDirectionTitle = "&d=down"
1867
      end if
1868
    end if
1869
 
1870
    sqlQuery = sqlQuery & sSortOrder
1871
 
1872
 
1873
    'initialRow= "<tr style='background-color:White;'> <td></td><td align='right'><a href='" & gScript & "?a=list&o=ByTitle" & sNextDirectionTitle & "'>Sort</a></td> <td align='right'><a href='" & gScript & "?a=list&o=ByDate" & sNextDirectionDate & "'>Sort</a></td></tr>"
1874
    initialRow= "<tr style='background-color:White;'> <td></td><td align='right'><a href='" & gScriptURL & "&a=list&o=ByTitle" & sNextDirectionTitle & "'>Sort by Title</a></td> <td align='right'><a href='" & gScriptURL & "&a=list&o=ByDate" & sNextDirectionDate & "'>Sort by Date</a></td></tr>"
1875
 
1876
 
1877
  end if
1878
 
1879
  EmitTabularOutput pageTitle, initialRow
1880
 
1881
end sub
1882
 
1883
 
1884
 
1885
sub EmitTabularOutput(pageTitle, initialRow)
1886
 
1887
  EmitDebug 44, 2, "<br/>query(" & sqlQuery & ")<br/>" & vbcrlf
1888
 
1889
  'set rs= gDataConn.execute(sqlQuery)
1890
  set rs = WrappedQueryExecute( gDataConn, sqlQuery )  ' ERV 3/2007        
1891
 
1892
  Call WriteBanner(pageTitle,"")
1893
 
1894
  if not rs.eof  then
1895
'    Response.write("<h2>" & pageTitle & ":</h2>)
1896
    Response.write("<table cellpadding=5  cellspacing=0 border=0 >" & vbcrlf)
1897
    i = 1
1898
    if not isEmpty(initialRow) then
1899
      Response.write initialRow & vbcrlf
1900
    end if
1901
    Do while (Not rs.eof )
1902
      if (i mod 2 = 0) then
1903
          Response.Write("<tr style=""background-color:whitesmoke;"">")
1904
      else
1905
          Response.Write("<tr style=""background-color:lightcyan;"">")
1906
      end if
1907
 
1908
      Dim deleteColumn
1909
      deleteColumn = ""
1910
 
1911
      ' gDelete is only passed on querystring
1912
      If Request.QueryString("pw") = gDeletePassword  Then
1913
          deleteColumn = "<td class='tabular'><a href=""" & gScriptURL & "&o=" & rs("Title")&"&a=del&pw=" & gDeletePassword   & """> del </td>" 
1914
      End If
1915
 
1916
 
1917
      if rs("Title") <> "RegisteredUsers" then
1918
        Response.Write("<td class='tabular'>" & i & ".</td><td class='tabular'><a href=""" &_
1919
                    gScriptURL & "&o=" & rs("Title") & """>" & rs("Title") & "</a></td> <td class='tabular'>" & _
1920
                    rs("LastUpdate") & " by " & rs("LastEditor")& "</td>" &  deleteColumn & _
1921
                    "</tr>" &  vbcrlf)
1922
        i= i+1
1923
      end if
1924
      rs.MoveNext
1925
    Loop
1926
    Response.write("</table>" & vbcrlf)
1927
  else
1928
'    Response.write("<h2>" & pageTitle & ":</h2>)
1929
    Response.write("<table style='border: 1px solid gainsboro'>" & vbcrlf)
1930
    Response.write("<tr><td>This topic is not mentioned on any other page! </td></tr>" & vbcrlf)
1931
    Response.write("</table>" & vbcrlf)
1932
  end if
1933
 
1934
   Call WriteFooter("","",""  )
1935
end sub
1936
 
1937
 
1938
sub handleSave
1939
  if gDisableSave = "yes" then
1940
    exit sub
1941
  end if
1942
 
1943
  dim sText, dts, sLupdt
1944
  dim sChanges, sTextOrig
1945
  sText=request.Form("pagetext")
1946
  sTextOrig=request.Form("pagetextorig")
1947
  sLupdt=request.Form("lupdt")  ' last update (ElreyRonald)
1948
 
1949
 
1950
  Dim lastPageEdited
1951
  if IsEmpty (Session("CurrentEditPage") ) Then
1952
        lastPageEdited = "*"
1953
        Exit Sub
1954
  else
1955
    lastPageEdited =Session("CurrentEditPage")
1956
  end if
1957
 
1958
  If not IsRequestFromWikiASPPage Then
1959
     response.write("1:>" & remoteIPHost & " - " & remoteIPAddr  )
1960
     response.end
1961
     exit sub
1962
  End if
1963
 
1964
  If IsRemoteAdressBlackListedRE Then
1965
     response.write("2:>" & remoteIPHost & " - " & remoteIPAddr  )
1966
     exit sub
1967
  End if
1968
 
1969
  If IsRemoteBlackListed Then
1970
     response.write("3:>" & remoteIPHost & " - " & remoteIPAddr  )
1971
     exit sub
1972
  End if
1973
 
1974
  If not gPersistPassword Then 
1975
    Session("pwd") = ""
1976
  End If
1977
 
1978
  sqlQuery = "select Title,PageData, lastupdate , PrevPageData, LastEditor from " & gDbTableName & " where title='" & glsTopic & "'"
1979
  EmitDebug 45, 2, "<br/>save-check query(" & sqlQuery & ")<br/>" & vbcrlf
1980
 
1981
 
1982
  'set rs = gDataConn.execute(sqlQuery)
1983
  set rs = WrappedQueryExecute( gDataConn, sqlQuery )  ' ERV 3/2007          
1984
 
1985
  dts = Now
1986
 
1987
  'update record
1988
  if not rs.eof then
1989
 
1990
 
1991
 
1992
      EmitDebug 46, 2, "Record already exists....<br/>" & vbcrlf
1993
 
1994
      ' check if someone has updated the record while you were editing (ElreyRonald)
1995
      if  Trim(Cstr( rs("lastupdate"))) <> Trim(sLupdt) then
1996
        response.write("<html><head></head><body>")
1997
        Response.Write(  "["& Trim(Cstr( rs("lastupdate"))) & "]["& Trim(sLupdt)& "]<br>" )
1998
        Response.Write("<b>Sorry! That page is being edited by another user or is in the process of being saved. <br>Your changes were not saved.</b>" )
1999
 
2000
        response.write( "<br><br> <a href='" & gScriptURL & "&a=edit&o=" & glsTopic & "'>Click here to re-edit the page. </a>" )
2001
        response.end
2002
      else
2003
 
2004
      ' consolidate a series of trailing vbcrlf to just 2.
2005
      gRE.Pattern = "(\r\n){3,}$"
2006
      sText=gRE.Replace(sText, vbcrlf & vbcrlf)
2007
 
2008
      ' replace 8 spaces with tab (ElreyRonald)
2009
      sText = replace(sText, vbcrlf & "        *", vbcrlf & chr(9) & "*" )
2010
      sText = replace(sText, vbcrlf & chr(9) & " :        ", vbcrlf & chr(9)& " :" & chr(9) )
2011
 
2012
      If abs( len(sText) - len(sTextOrig) ) > 10 Then
2013
        sChanges =  vbcrlf & vbcrlf & "@@@@@@@@@@@@@@@@" & rs("lastupdate") & " : " & _
2014
          rs("lasteditor") & "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@" & vbcrlf & vbcrlf &  rs("PageData")  & rs("PrevPageData")
2015
        sChanges =  left(sChanges, 15000)
2016
      else
2017
        sChanges = rs("PrevPageData")
2018
      End if
2019
 
2020
      sqlQuery = "UPDATE " & gDbTableName & " SET PageData='" &_
2021
      safeQuote(sText) & "',PrevPageData='" & safeQuote(  sChanges   ) &_
2022
      "',LastUpdate='" & dts & "', LastEditor='" & remoteIPHost  &_
2023
      "'  WHERE title='" & rs("title") & "'"
2024
 
2025
 
2026
      EmitDebug 47, 1, "update sqlQuery(" & sqlQuery & ")<br/>"
2027
 
2028
      'gDataConn.execute(sqlQuery)
2029
 
2030
      call WrappedQueryExecute( gDataConn, sqlQuery )  ' ERV 3/2007        
2031
 
2032
 
2033
      end if
2034
      ' new record
2035
  else
2036
 
2037
 
2038
      EmitDebug 48, 2, "Record does not exist, inserting...." & vbcrlf
2039
      sqlQuery = "INSERT INTO " & gDbTableName & " (Title,PageData,LastEditor,LastUpdate) " & _
2040
      "VALUES ('" & glsTopic   & "', '" & safeQuote(sText) & "', '" & remoteIPHost   &_
2041
       "', '" & dts & "')"
2042
      EmitDebug 49, 1, "<br/>sqlQuery(" & sqlQuery & ")<br/>"
2043
 
2044
      'gDataConn.execute(sqlQuery)
2045
 
2046
      call WrappedQueryExecute( gDataConn, sqlQuery )  ' ERV 3/2007        
2047
 
2048
 
2049
  end if
2050
 
2051
  ' direct to the newly saved page :
2052
  'Response.Redirect gScript & "?" & glsTopic
2053
  Response.Redirect gScriptURL & "&o=" & glsTopic
2054
 
2055
end sub
2056
 
2057
Sub WriteBanner(title,search)
2058
      Dim iconPart, bannerPart, bannerTextPart
2059
      iconPart = "<a  href='" & gScriptURL & "'><img src='" & gIconName & "' border='0' alt='Go to Start Page'></a>"
2060
 
2061
      if search <> "" then
2062
         bannerTextPart = "<a  title='Search for references to " & title & "' href='" & gScriptURL & "&a=search&o=" & search & "'>" &  SpaceName(title) & "</a>"
2063
      else
2064
         bannerTextPart = SpaceName(title)
2065
      end if
2066
 
2067
      If gBannerTemplate = "" Then
2068
         bannerPart = ""
2069
         bannerPart =  bannerPart &  "<a href='" & gScriptURL & "'>Wiki Home</a>"
2070
         bannerPart =  bannerPart &  "&nbsp;|&nbsp;<a href='" & gScriptURL & "&a=list&o=ByTitle' title='this may take a loooong time'>List all pages</a>"
2071
         if ( NOT gHideLogin ) Then
2072
            bannerPart =  bannerPart &  "&nbsp;|&nbsp;<a href='" & gScriptURL & "&a=list&o=recent'>Recent pages</a>"
2073
            bannerPart =  bannerPart &  "&nbsp;|&nbsp;<span style='color: #FF0000;font-weight: bold;'>Development Web Server</span>"
2074
            if (search <> "") AND (gEnableEdit) then
2075
            bannerPart =  bannerPart &  "&nbsp;|&nbsp;<a href='" & gScriptURL & "&a=edit&o=" & search & "'>Edit page</a>"
2076
            bannerPart =  bannerPart &  "&nbsp;|&nbsp;<a href='" & gScriptURL & "&a=del&o=" & search & "'>Del page</a>"
2077
            end if
2078
            bannerPart =  bannerPart &  "&nbsp;|&nbsp;<a href='" & gScript & "?db=ReleaseNotes&o=TextFormattingRules'>Formatting Rules</a>"
2079
            bannerPart =  bannerPart &  "&nbsp;|&nbsp;<a href='" & gScript & "?db=ReleaseNotes'>Release Notes</a>"
2080
            bannerPart =  bannerPart &  "&nbsp;|&nbsp;<a href='" & gScript & "?db=ImplementationNotes'>PM Dev Notes</a>"
2081
            if gEnableEdit Then
2082
                bannerPart =  bannerPart &  "&nbsp;|&nbsp;<a href='" & gScriptURL & "&a=logout&o=" & search & "'>Log out</a>"
2083
            Else
2084
                bannerPart =  bannerPart &  "&nbsp;|&nbsp;<a href='" & gScriptURL & "&a=login&o=" & search & "'>Log in</a>"
2085
            End If
2086
         End If
2087
         bannerPart =  bannerPart &  "<hr>"
2088
 
2089
         bannerPart =  bannerPart &  " <table class='cssBannerTable' id='idBannerTable' cellSpacing='0' cellPadding='0' border='0'>"
2090
         bannerPart =  bannerPart &  "    </tr>"
2091
         bannerPart =  bannerPart &  "    <tr class='cssBannerRow' id='idBannerRow'> "
2092
         bannerPart =  bannerPart &  "          <td class='cssBannerCellIcon' id='idBannerCellIcon' valign='top'> $$icon$$</td>"
2093
         bannerPart =  bannerPart &  "          <td width=90% class='cssBannerCellText' id='idBannerCellText' valign='bottom' align='left' >"
2094
         bannerPart =  bannerPart &  "            <h1 class='cssBannerSpanText' id='idBannerSpanText'>$$banner_text$$</h1>"
2095
         bannerPart =  bannerPart &  "          </td>"
2096
         bannerPart =  bannerPart &  "          <td>"
2097
         bannerPart =  bannerPart &  "          <td class='cssTopSearch'id='idTopSearch' >"         	
2098
         If not gHideTopSearch Then
2099
             bannerPart =  bannerPart &  "          <form method=POST action='wiki.asp?a=search&db="& gDataSourceFile &"' id=search001 name=search001 >" & gSearchLabel & "<br/><input class='cssTopSearchbox' id='idTopSearchbox' title='Click and enter search text here!' size=12 type=text name=o value='" & gDataSourceFile & "' onclick=this.value="""" /></form>&nbsp;&nbsp;&nbsp;&nbsp;"
2100
         End If
2101
         bannerPart =  bannerPart &  "          </td><td>&nbsp;&nbsp;&nbsp;</d>"
2102
         bannerPart =  bannerPart &  "    </tr>"
2103
         bannerPart =  bannerPart &  " </table>"
2104
 
2105
      Else
2106
 
2107
         bannerPart = gBannerTemplate
2108
      End if
2109
 
2110
      bannerPart = Replace( bannerPart, "$$icon$$", iconPart)
2111
      bannerPart = Replace( bannerPart, "$$banner_text$$", bannerTextPart)
2112
 
2113
 
2114
      Response.Write ( bannerPart )
2115
 
2116
End Sub
2117
 
2118
Sub WriteFooter(hideScript,lastUpdate,lastEditor)
2119
      If Not gHideWikiFooter Then
2120
          response.write "<div id=wikifooter class=footer ><form method='POST' action=""" & gScript & """ id=""formFooter"" name=""formFooter""><br>"
2121
          response.write "<hr size=1 noshade=true>"
2122
 
2123
          If Not gHideLastEditor Then
2124
            if lastUpdate <> "" Then
2125
                response.write "<span title='Click this now to prepare page for Printing by removing unnecessary portions! ' onclick=""" & hideScript & """ ><font size=-1>Last Updated " & lastUpdate & " by '" & lastEditor &  "' </font></span><br/>"
2126
            End If
2127
          end if
2128
          response.write "<font size=-1>Domain: " & gHttpDomain & "</font><br>"
2129
 
2130
'          response.write "<a href='" & gScriptURL & "' title='GO TO START PAGE'>Home</a> | "
2131
'          if  Not gHideLogin Then
2132
'            response.write "<a href='" & gScriptURL & "&a=edit&o=" & rs("title") & "'>Edit page</a> | "
2133
'          end if
2134
'          response.write "<a href='" & gScriptURL & "&a=logout&o=" & rs("title") & "'>Log out</a> | "
2135
'          response.write "<a href='" & gScriptURL & "&a=list&o=ByTitle'>List pages</a> |  "
2136
'          response.write "<a href='" & gScriptURL & "&a=list&o=recent'>Recent pages</a>"
2137
'          If gHttpDomain <> "" Then
2138
'            response.write " | <a href='" & gScriptURL & "&a=rss' ><span style='background:#FF6600;text-decoration:none;font-family:tahoma;' >&nbsp;<b><font color=white>RSS</font></b>&nbsp;</span></a>"
2139
'          End If
2140
'
2141
'          response.write "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"&gSearchLabel&"&nbsp;<input title='Type in your search terms and press [Enter]' type='text' name='o' value=''/><input type='hidden' name='db' value='"& gDataSourceFile & "'><input type='hidden' name='dbname' value='" & gDataSourceName & "'><input type='hidden' name='a' value='search'></form></div> "
2142
 
2143
          response.write "<font size='-1'>WikiAsp Engine version:  " & gEngineVersion & "</font>" & vbcrlf
2144
'          response.write "<br><font size='-1'>gScriptURL:  " & gScriptURL & "</font>" & vbcrlf
2145
          response.write "</div>"
2146
      End If
2147
 
2148
End Sub
2149
 
2150
Sub HandleBrowse
2151
 
2152
  ' Prevent this page from being viewed.
2153
  if not IsEmpty(Request.Form("pwd")) then Session("pwd") = Request.Form("pwd")
2154
  if glsTopic = "RegisteredUsers" then
2155
     If  IsEmpty( Session("pwd")) or  Session("pwd") <> gPassword then
2156
       exit sub
2157
     End If
2158
  end if
2159
 
2160
  sqlQuery = "select PageData,Title,LastEditor,LastUpdate from " & gDbTableName & " where title='" & glsTopic & "'"
2161
  EmitDebug 50, 2, "Browse query(" & sqlQuery & ")<br/>" & vbcrlf
2162
 
2163
  set rs = gDataConn.execute(sqlQuery)
2164
 
2165
  if rs.eof=true then
2166
        Response.Write("<center><h2>Page Creation</h2><hr>")
2167
    if gHideLogin Then
2168
        Response.Write("The page --> <b>" &  glsTopic & "</b> <--- Does not exit and it cannot be created on this Server")
2169
    ElseIf NOT gEnableEdit Then
2170
        Response.Write("The page --> <b>" &  glsTopic & "</b> <--- Does not exit and it cannot be created until you log in")
2171
    Else
2172
        response.write("Sorry! The page --> <b>" &  glsTopic & "</b>  <--- is not existing or it is a page that must be created </h4>")
2173
        response.write( "<br><a href='" & gScriptURL & "&a=edit&o=" & glsTopic & "'>Click this link to create this page.</a>" )
2174
        response.write( "<br><br><a href='" & gScriptURL & "'>No,  don't create it.</a>" )
2175
    End If
2176
        Response.Write("</center>")
2177
 
2178
  else
2179
      EmitDebug 51, 3, "found...(" & rs("PageData") & ")<br/>" & vbcrlf
2180
 
2181
      If gEnableEdit Then
2182
        response.write" <body ondblclick=" & chr(34) & "document.location.href='" & _
2183
            gScriptURL & "&a=edit&o=" & glsTopic    & "'" & chr(34) &">"
2184
      Else
2185
         response.write" <body >"
2186
 
2187
      End If
2188
 
2189
      Call WriteBanner(rs("title"),rs("title"))
2190
      response.write " <div class='wikibody'>" & WalkWiki(  xform( "<span id=bodyPrefix>" & vbcrlf & gWikiBodyPrefix & VbCrLF & "</span>" & VbCrLF &  rs("PageData")))  ' Elrey - xform func now removes html
2191
      response.write "</b></i></font></u></strong></font>"
2192
 
2193
 
2194
      dim hideScript
2195
      hideScript = "var div1=document.getElementById('wikifooter'); if (div1) {div1.style.display='none';}"
2196
      hideScript = hideScript & "div1=document.getElementById('bodyPrefix'); if (div1) {div1.style.display='none';}"
2197
      hideScript = hideScript & "div1=document.getElementById('idTopSearch'); if (div1) {div1.style.display='none';}"
2198
 
2199
      Call WriteFooter(hideScript, rs("LastUpdate"), rs("LastEditor")  )
2200
  end if
2201
 
2202
end sub
2203
 
2204
 
2205
 
2206
sub handleCreate
2207
    If gHideLogin Then
2208
        Response.Write("<br/><br/><br/><br/><br/><center><h2>Editing is not allowed</h2></center>")
2209
        Response.End
2210
        exit sub
2211
    End If
2212
 
2213
    If NOT gEnableEdit Then
2214
        Response.Write("<br/><br/><br/><br/><br/><center><h2>Editing is not allowed until logged in</h2></center>")
2215
        Response.End
2216
        exit sub
2217
    End If
2218
 
2219
  on error resume next
2220
  VerifyWikiTable
2221
  on error goto 0
2222
  Response.Redirect gScriptURL
2223
end sub
2224
 
2225
 
2226
'Intercept RSS request here
2227
if ( glsMode = "rss" ) then
2228
  If ( gHttpDomain = "" ) then
2229
    response.write("RSS is not enabled")
2230
  Else
2231
    handleRss
2232
  End If
2233
  response.End
2234
end if
2235
'Intercept delete request here
2236
if ( glsMode = "del") then
2237
  handleDelete
2238
  response.End
2239
end if
2240
 
2241
 
2242
'********************************************************************
2243
'*********************************************************************
2244
'<?xml version="1.0" encoding="UTF-8" ?>
2245
'<!DOCTYPE html
2246
'     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2247
'     "DTD/xhtml1-transitional.dtd">
2248
'
2249
 
2250
    Response.Buffer=TRUE
2251
%>
2252
<html>
2253
    <head>
2254
        <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
2255
        <title>
2256
<%
2257
        if not isEmpty(glsMode) and glsMode <> "browse" then
2258
            response.write(glsMode & " ")
2259
        end if
2260
        response.write(SpaceName(glsTopic) & vbcrlf)
2261
%>
2262
        </title>
2263
        <LINK REL="StyleSheet" HREF="<%=gStyleSheet%>" TYPE="text/css" >
2264
<%
2265
       Response.Write(gHtmlHeadStr)
2266
%>
2267
    </head>
2268
    <body>
2269
 
2270
    <%
2271
 
2272
      if  Session("Hits") = "" then
2273
    Session("Hits")= 1
2274
      else
2275
    Session("Hits")= Session("Hits") + 1
2276
      end if
2277
 
2278
      EmitDebug 52, 1, "debug(" & gDebug & ")<br/>" & vbcrlf
2279
      EmitDebug 53, 1, "<br/>QueryString = (" & Request.QueryString & ")<br/>" & _
2280
    "Hits(" & Session("Hits") & ")<br/>" & _
2281
    "mode(" & glsMode & ")<br/>" & _
2282
    "topic(" & glsTopic & ")<br/>"
2283
 
2284
      set gDataConn = Server.CreateObject("ADODB.Connection")
2285
 
2286
      ' 21 nov - need resume next to catch "no file" error
2287
      on error resume next
2288
      gDataConn.Open ConnStr(1)
2289
      on error goto 0
2290
 
2291
      if not (0 = gDataConn.errors.count) then
2292
    if (ADOERROR_NOFILE = gDataConn.errors(0).number) then
2293
      EmitDebug 54, 1, "<br/>ErrorCount(" & gDataConn.errors.count & ")<br/>" & vbcrlf
2294
      EmitDebug 55, 1, "<br/>Error(" & gDataConn.errors(0).number &") desc(" &_
2295
        gDataConn.errors(0).description & ")<br/>" & vbcrlf
2296
      VerifyWikiTable
2297
    end if
2298
      end if
2299
 
2300
      select case (glsMode)
2301
    case "edit"    handleEdit
2302
    case "list"    handleList
2303
    case "search"  handleSearch
2304
    case "create"  handleCreate
2305
    case "save"    handleSave
2306
    case "browse"  handleBrowse
2307
    case "logout"  handleLogout
2308
    case "login"   handleLogin
2309
    case else
2310
      end select
2311
 
2312
      EmitDebug 56, 2, "<br/>done...<br/>" & vbcrlf
2313
      gDataConn.Close()
2314
      set gDataConn = nothing
2315
    %>
2316
 
2317
<% Response.Write(gFooterHtml) %>
2318
<% Response.Flush  %>