%@ LANGUAGE=VBScript LCID=1033 %>
<%
' =========================================================
' EZ-ASP-Wiki : first pass at producing a simple, single
' file wiki-wiki. Derived from FpWiki, see
' comments below for the FpWiki info.
'
' This wiki uses no database. ASP objects are used to
' access the host filesystem, which makes this wiki a
' little slow. But many cheap hosting services charge for data-
' base access, so this wiki is well suited to small wikis
' where no db is available.
' =========================================================
' FpWiki : Wiki server in ASP made to be Frontpage friendly
'
' This code is inspired by Aspwiki by dinoch@adelphia.net, tanks for releasing it
' you can get the original code on http://www6.brinkster.com/dpchiesa/
'
' Pre-requisites:
' MDAC 2.5+, IIS, IE55+
'
' Instructions:
' install on an IIS Server
' with frontpage extension, use Frontpage to copy Fpwiki.asp and Wiki.mdb, name the DB "Wiki"
' without frontpage extension, use ODBC to declare a system source to Wiki.mdb
'
' Features (v1.0):
' - frontpage friendly
' - db installation by drag & drop mdb
' - use frontpages's odbc declaration
' - html changed so frontpage dont mess it
' - HTML Wysiwyg editor (works only with IE55+ now)
' - make use of if_modified_since html header to speed up browsing
' - run on IIS with or without Frontpage extension, run on www.brinkster.com
' - timestamps are supported. But page timeouts and page locking are not. last write wins.
' - fulltitle of page in DB and used in link if present
' - tab key in textearea handled with javascript
' - history of pages modifications in DB
'
' No-features:
' - no support of NS or Mozilla for editing (should implement xopus.org lib)
' - no page timeouts and page locking while editing
' - no diff support (what has been changed recently?)
' - no user list or access rigth management
' - no revision history cleanup
'
'
option explicit
response.buffer = true
response.charset = "windows-1252"
const cEzwVersion = "EZ-ASP-Wiki 0.01"
' Configuration constants
const cEzwTopName = "top~" ' Default name of top wiki file
const cbEzwLogEdit = false ' log edits in .wkl files
const cEzwPasswd = "" ' global site password
const cEzwWikiEx = ".wik" ' Wiki file extension
const cEzwWikiLog = ".wkl" ' Wiki log file extension
const cEzwUnicode = False ' Set to true to use unicode files
' Version francaise
' set LCID=1036 in first line of source
'const txtBtHome = "Accueil"
'const txtBtHomeHlp = "Retour à la page d'accueil"
'const txtBtMod = "[Modifier]"
'const txtBtModHlp = "Modifier la page "
'const txtBtList = "Liste"
'const txtBtListHlp = "Liste des pages existantes"
'const txtBtChng = "Changements"
'const txtBtChngHlp = "Liste des pages récement modifiées"
'const txtBtLog = "Révisions"
'const txtBtLogHlp = "Révisions de la page "
'const txtBtRef = "Références"
'const txtBtRefHlp = "Liste des référence de la page "
'const txtBtSearch = "Rechercher: "
'const txtBtSearchHlp= "Entrez le texte recherché puis [Entrée]"
'const txtBtSubmit = "Envoyer"
'const txtIsbnUrl = "http://www.alapage.com/mx/?tp=F&type=1&l_isbn="
'const txtIsbnHlp = "Rechercher cet ouvrage sur www.alapage.com"
'const txtNotFound = "Non trouvé !"
'const txtLastUpdt = "Dernière mise à jour : "
'const txtModTitle = "Modification de "
'const txtSrchTitle = "Recherche de "
'const txtListTitle = "Liste des pages"
'const txtTTitle = "Titre"
'const txtTLastUpdt = "Modification"
'const txtTLastEd = "Editeur"
'const txtTCreation = "Création"
'const txtTOwner = "Auteur"
'const txtTNBRev = "Révisions"
'const txtBtBold = "G"
'const txtBtItal = "I"
'const txtBtUnder = "S"
'const txtBtNormal = "Normal"
'const txtBtPre = "Formaté"
'const txtBtTitle = "Titre"
'const txtPass = "Mot de passe : "
'const txtPassHello = "Ce site est privé, pour y accéder il vous faut le mot de passe."
' English version
' set LCID=1033 in first line of source
const txtBtHome = "Home"
const txtBtHomeHlp = "Go back to Home page"
const txtBtMod = "[Modify]"
const txtBtModHlp = "Modify page "
const txtBtList = "List"
const txtBtListHlp = "List all pages"
const txtBtChng = "Changes"
const txtBtChngHlp = "List last changed pages"
const txtBtLog = "History"
const txtBtLogHlp = "Modification history of "
const txtBtRef = "Reference"
const txtBtRefHlp = "List all pages who call "
const txtBtSearch = "Search: "
const txtBtSearchHlp = "Enter text then [Enter]"
const txtBtSubmit = "Submit"
const txtIsbnUrl = "http://www.amazon.com/exec/obidos/isbn="
const txtIsbnHlp = "Link to Amazon.com"
const txtNotFound = "Not found here !"
const txtLastUpdt = "Last update : "
const txtModTitle = "Modify "
const txtSrchTitle = "Search result of "
const txtListTitle = "Pages list"
const txtTTitle = "Title"
const txtTLastUpdt = "Modification"
const txtTLastEd = "Editor"
const txtTCreation = "Creation"
const txtTOwner = "Creator"
const txtTNBRev = "Revisions"
const txtBtBold = "B"
const txtBtItal = "I"
const txtBtUnder = "U"
const txtBtNormal = "Normal"
const txtBtPre = "Format."
const txtBtTitle = "Title"
const txtPass = "password : "
const txtPassHello = "This website is private, you need a password to enter."
dim tblName ' as string
dim gScript ' as string
dim gScriptURL ' as string
dim gEzwMode ' as string
dim gEzwTopic ' as string
dim glsFullTitle ' as string
dim wikiTitle ' as string
dim wikiMenu ' as string
dim wikiMain ' as string
dim gdGMTNow ' as date, now in GMT time
dim maxLastUpdate ' as date, last Update in DB
dim gEzwServerRootPath ' string, root script path on server
dim gObjEzwFSO ' global file system object, for server
dim gEzwTristate ' for unicode modes
dim gEzwWikiPage ' filename + ext, no path
'*********************************************************************
%>
<%
'-----------------------------------------------------------------------------
' Control the last update date send by browser, and decide if the page need to be resend
' Eric Segui 11/2002
'-----------------------------------------------------------------------------
sub CacheControl(dLastMod)
dim sIfmodsince, dIfmodsince, lcid
lcid = session.lcid
session.lcid = 1033 ' US date mode
' Adjust date to GMT using JScript function - not necessary here, already set in DB
'dLastMod = DateAdd("h",JSTimezoneOffset(),dLastMod)
' Get the date of the page in browser cache
sIfmodsince = Request.ServerVariables("HTTP_IF_MODIFIED_SINCE")
if len(sIfmodsince)>=25 then
dIfmodsince = CDate(mid(sIfmodsince,6,20))
else
dIfmodsince = 0
end if
' Construct Last Modified String
sIfmodsince = WeekDayName(WeekDay(dLastMod),TRUE) & ", " & right(cstr(100+Day(dLastMod)),2) & " " & _
MonthName(Month(dLastMod),TRUE) & " " & Year(dLastMod) &" "& right(cstr(100+Hour(dLastMod)),2) & ":" & _
right(cstr(100+Minute(dLastMod)),2) & ":" & right(cstr(100+Second(dLastMod)),2) & " GMT"
' Set Headers then continue
Response.AddHeader "Last-modified", sIfmodsince ' set date for next time
Response.CacheControl = "Public" ' proxy should cache too
Response.Expires = 1 ' browser will recheck after 1 min
session.lcid = lcid 'restore date mode
' if Browser cache is up to date, tell him, then exit program
If abs(datediff("s", dIfmodsince, dLastMod)) < 2 Then
Response.Clear
Response.Status = "304 Not Modified"
Response.End
End If
end sub
'-----------------------------------------------------------------------------
' format string for safe insert in Access
'-----------------------------------------------------------------------------
sub SetApplication
'FIXME!! if (application(tblName & "_Creation") = "") or (application(tblName & "_LastUpdate") = "") then
' sqlQuery = "select max(LastUpdate),max(Creation) from " & safeQuote(tblName)
' set rs = DataConn.execute(sqlQuery)
' application(tblName & "_LastUpdate") = rs("LastUpdate")
' application(tblName & "_Creation") = rs("Creation")
' end if
end sub
'-----------------------------------------------------------------------------
' format string for safe insert in Access
'-----------------------------------------------------------------------------
function safeQuote(txt)
if txt<>"" then
safeQuote=replace(txt,"'","''")
else
safeQuote=""
end if
end function
'-----------------------------------------------------------------------------
' format date for safe insert in Access (with non-us formats)
'-----------------------------------------------------------------------------
function safeDate(date)
safeDate = year(date) & "-" & right(cstr(100+month(date)),2) & "-" & right(cstr(100+day(date)),2) & " " & _
right(cstr(100+hour(date)),2) & ":" & right(cstr(100+minute(date)),2) & ":" & right(cstr(100+second(date)),2)
end function
'-----------------------------------------------------------------------------
' This routine replace all WikiWords with link to proper page.
' Should work on any html text without messing it
'-----------------------------------------------------------------------------
function WalkWiki(text)
dim gRE ' as RegExp
dim wikiNames
dim objFSO
dim pathXlat, pathXLatRoot, wikiPage ' string
dim hit
dim wikiLink,newText,sTitle 'as string
dim offset
' Create RegExp
set gre = new RegExp
gre.IgnoreCase = false
gre.Global = true
newText = text
offset = 0
Set objFolder = gObjEzwFSO.GetFolder( gEzwPathXlatRoot )
Set colFolders = objFolder.SubFolders
' find wikiNames (no replace inside tag or anchor)
gRE.Pattern = "(?!(?!<[Aa]).+[Aa]>|[^<]+>)\b(([A-Z][a-z]+)([A-Z][a-z]+)+)\b"
set wikiNames = gRE.Execute(newText)
for each hit in wikiNames
'response.write hit.FirstIndex & " " & hit.Length & " " & hit.FirstIndex+hit.Length & " " & offset & " '" & hit.value & "'"
wikiPage = hit.value & cEzwWikiEx
if gObjEzwFSO.FileExists( pathXlatRoot & wikiPage ) then
wikiLink = "" & hitValue & ""
else ' not found, make a ? link
wikiLink = "" & sTitle & "?"
end if
newText = mid(newText, 1, hit.FirstIndex+offset) & wikiLink & mid(newText, hit.FirstIndex+hit.Length+1+offset)
offset = offset + len(myText) - hit.length
next
set gre = nothing
set rsPages = nothing
set wikiNames = nothing
WalkWiki = newText
end function
'-----------------------------------------------------------------------------
sub EmitTabularOutput(sqlQuery, initialRow)
dim field
if not rs.eof then
wikiMain = wikiMain & "
"
if initialRow<>"" then
wikiMain = wikiMain & "" & initialRow & "
"
end if
do while (not rs.eof)
wikiMain = wikiMain & ""
for each field in rs.fields
select case field.name
case "Title"
wikiMain = wikiMain & "| " & field.value & " | "
case "LastUpdate"
wikiMain = wikiMain & "" & field.value & " | "
case "NBRev"
wikiMain = wikiMain & "" & field.value & " | "
case else
wikiMain = wikiMain & "" & field.value & " | "
end select
next
wikiMain = wikiMain & "
" & vbcrlf
rs.MoveNext
loop
wikiMain = wikiMain & "
" & vbcrlf
else
wikiMain = wikiMain & "
" & txtNotFound & "
" & vbcrlf
end if
end sub
'*****************************************************************************
'-----------------------------------------------------------------------------
sub handleSearch
'Fixme
Response.Write "Search"
end sub
sub handleSearchXXX
dim initialRow, search
wikiTitle = txtSrchTitle & gEzwTopic
initialRow= "" & txtTTitle & " | " & txtTLastUpdt & " | " & txtTLastEd & " | " & txtTCreation & " | " & txtTOwner & " | "
search = safeQuote(gEzwTopic)
search = Replace(search, " ", "%' and PageData like '%")
search = " where (PageData like '%" & search & "%')"
sqlQuery = "select top 50 T1.Title,T1.LastUpdate,T1.LastEditor,T1.Creation,T1.Owner" & _
" from " & safeQuote(tblName) & " as T1," & _
" (select WikiData.Title,max(WikiData.LastUpdate) as LastUpdate from " & safeQuote(tblName) & _
search & " group by Title) as T2" & _
" where T1.Title=T2.Title and T1.LastUpdate=T2.LastUpdate"
set rs = DataConn.execute(sqlQuery)
EmitTabularOutput sqlQuery, initialRow
end sub
'-----------------------------------------------------------------------------
sub handleLog
'Fixme!!!
Response.Write "Log"
end sub
sub handleLogXXX
dim initialRow, maxLastUpdate
wikiTitle = txtBtLogHlp & gEzwTopic
initialRow= "" & txtTTitle & " | " & txtTLastUpdt & " | " & txtTLastEd & " | " & _
txtTCreation & " | " & txtTOwner & " | "
sqlQuery = "select top 50 Title,LastUpdate,LastEditor,Creation,Owner from " & safeQuote(tblName) & _
" where title='" & safeQuote(gEzwTopic) & "' order by Lastupdate desc"
set rs = DataConn.execute(sqlQuery)
EmitTabularOutput sqlQuery, initialRow
end sub
'-----------------------------------------------------------------------------
sub handleList
'Fixme!!!
Response.Write "List"
end sub
sub handleListXXX
dim initialRow
wikiTitle = txtListTitle
sqlQuery = "select top 50 T1.Title,T1.LastUpdate,T1.LastEditor,T1.Creation,T1.Owner,T2.NBRev" & _
" from " & safeQuote(tblName) & " as T1," & _
" (select WikiData.Title,max(WikiData.LastUpdate) as LastUpdate,count(Title) as NBRev from " & safeQuote(tblName) & " group by Title) as T2" & _
" where T1.Title=T2.Title and T1.LastUpdate=T2.LastUpdate"
if gEzwTopic = "ByDate" then
sqlQuery = sqlQuery & " order by T1.LastUpdate"
else
sqlQuery = sqlQuery & " order by T1.Title"
end if
if glsDir = "d" then
sqlQuery = sqlQuery & " desc"
glsDir = "a" 'next direction
else
glsDir = "d" 'next direction
end if
initialRow= "" & txtTTitle & " | " & _
"" & txtTLastUpdt & " | " & _
"" & txtTLastEd & " | " & txtTCreation & " | " & txtTOwner & " | " & txtTNBRev & " | "
set rs = DataConn.execute(sqlQuery)
EmitTabularOutput sqlQuery, initialRow
end sub
'-----------------------------------------------------------------------------
sub handlePass
if request("pass") = cEzwPasswd then
session("pass") = cEzwPasswd
Response.Clear
Response.Redirect(gScriptURL & "&o=" & gEzwTopic)
end if
end sub
'-----------------------------------------------------------------------------
sub handleUpdate
dim sEditor, sPageData, sFullTitle 'as string
dim sFullPagePath
dim bOVERWRITE
Response.Write"Update"
bOVERWRITE = TRUE
sFullPagePath = gEzwWikiPage
sEditor = request.ServerVariables("REMOTE_HOST")
sPageData = request.Form("content")
sFullTitle = request.Form("fulltitle")
Response.Write "" & sFullPagePath
Set objTStream = gObjEzwFSO.CreateTextFile(sFullPagePath, bOVERWRITE)
objTStream.Write( sPageData )
objTStream.Close()
wikiMain = "
" & sFullPagePath & " updated.
" & _
sPageData & "" & sEditor & "" & sFullPagePath
end sub
'-----------------------------------------------------------------------------
sub handleRead
dim sFullPagePath, sPageData, wikiTitle, sFullTitle
dim sLastUpdate, sLastEditor
dim objTStream
dim objFO
dim ioRead, format
dim bNoCreate
if gEzwMode = "browse" then
Response.Write "Browse"
end if
if gEzwMode = "update" then
Response.Write "Update"
end if
ioRead = 1 ' For reading
format = gEzwTristate ' Unicode mode
bNoCreate = False ' Don't create
sFullPagePath = gEzwServerRootPath & gEzwWikiPage
if gObjEzwFSO.FileExists( sFullPagePath ) then
Set objTStream = gObjEzwFSO.OpenTextFile(sFullPagePath, ioRead, bNoCreate, format )
sPageData = objTStream.ReadAll()
objTStream.Close()
objFO = gObjFSO.GetFile( sFullPagePath )
sLastModified = objFO.DateLastModified
wikiTitle = gEzwTopic
if sFullTitle <>"" then
wikiTitle = wikiTitle & " (" & sFullTitle & ")"
end if
if gEzwMode = "browse" then
wikiMain = vbcrlf & vbcrlf & WalkWiki(gEzwPageData) & vbcrlf & _
vbcrlf & "
" & txtLastUpdt & _
FormatDateTime(sLastUpdate,1) & " " & _
FormatDateTime(sLastUpdate,3) & " (" & sLastEditor & ")"
else
wikiMain = gEzwPageData
end if
else
'wikiMain = "
" & txtNotFound & "
"
wikiMain = "
" & sFullPagePath & " " & txtNotFound & "
"
end if
end sub
'-----------------------------------------------------------------------------
' Returns the root path to the executing script, server side
'-----------------------------------------------------------------------------
FUNCTION GetRootPath()
dim pathXlat
pathXlat = Request.ServerVariables("PATH_TRANSLATED")
GetRootPath = Left( pathXlat, InStrRev( pathXlat, "\" ) )
END FUNCTION
'-----------------------------------------------------------------------------
'*********************************************************************
' PROGRAM START
' get form variables
gEzwMode = request("a") ' action (update/browse/modify/list/search)
if gEzwMode = "" then
gEzwMode = "browse"
end if
gEzwTopic= request("w") ' topic (= wiki page)
if gEzwTopic = "" or gEzwTopic = txtBtHome then
gEzwTopic = txtBtHome
gEzwWikiPage = cEzwTopName & cEzwWikiEx
else
gEzwWikiPage = gEzwTopic & cEzwWikiEx
end if
Set gObjEzwFSO = Server.CreateObject("Scripting.FileSystemObject")
gEzwServerRootPath = GetRootPath()
gScript = request.servervariables("SCRIPT_NAME")
gScriptURL = gScript
if cEzwUnicode then
gEzwTristate = -1
else
gEzwTristate = 0
end if
gdGMTNow = DateAdd("h",JSTimezoneOffset(),now) ' 'Now' in GMT time
if (cEzwPasswd <> "") and (session("pass") <> cEzwPasswd) then
gEzwMode = "pass"
end if
select case gEzwMode
case "browse"
handleRead
case "update"
handleUpdate
case "log"
handleLog
case "list"
handleList
case "search"
handleSearch
case "pass"
handlePass
case "modify"
handleRead
end select
'*********************************************************************
%>
EZ-ASP-Wiki: <%=wikiTitle%>
|
|
|
<%
select case gEzwMode
case "modify"
%>
|
|
|
<% case "pass" %>
<%=txtPassHello%>
<% case else %>
<%=wikiMain%>
<% end select %>
<%=cEzwVersion & " - Last update: " & safeDate(maxLastUpdate) & " - Page created: " & safeDate(gdGMTNow) %>