Changeset 1324
- Timestamp:
- 02/18/08 18:11:59
- Files:
-
- HTTP/WikiContent.lua (modified) (4 diffs)
- HTTP/WikiContentService.lua (modified) (4 diffs)
- HTTP/WikiContentService.txt (modified) (1 diff)
- HTTP/WikiEditorService.lua (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
HTTP/WikiContent.lua
r1305 r1324 25 25 local tonumber = tonumber 26 26 local tostring = tostring 27 local print = print 27 28 28 29 -------------------------------------------------------------------------------- … … 313 314 end 314 315 316 local function CanWrite( aName ) 317 local File = require( 'File' ) 318 local aDirectory = Directory( aName ) 319 local aFile = File( aDirectory.path, 'nowrite' ) 320 321 if aFile.exists then 322 return false 323 end 324 325 return true 326 end 327 328 local function SetWrite( aName, aValue ) 329 local File = require( 'File' ) 330 local aDirectory = Directory( aName ) 331 local aFile = File( aDirectory.path, 'nowrite' ) 332 333 print( 'SetWrite', aFile, aValue ) 334 335 if aValue then 336 aFile.delete = true 337 else 338 aFile.content = 'nowrite' 339 end 340 end 341 315 342 -------------------------------------------------------------------------------- 316 343 -- File utilities … … 412 439 413 440 function self:__index( aKey ) 414 if aKey == 'data' then 441 if aKey == 'canWrite' then 442 return CanWrite( self.name ) 443 elseif aKey == 'data' then 415 444 local someData = ContentData( self.name, self.version ) 416 445 rawset( self, 'data', someData ) … … 447 476 448 477 function self:__newindex( aKey, aValue ) 449 if aKey == ' file' then450 AddFile( self.name, aValue )451 452 return 478 if aKey == 'canWrite' then 479 return SetWrite( self.name, aValue ) 480 elseif aKey == 'file' then 481 return AddFile( self.name, aValue ) 453 482 elseif aKey == 'link' then 454 AddLink( self.name, aValue ) 455 456 return 483 return AddLink( self.name, aValue ) 457 484 elseif aKey == 'modification' then 458 485 DataFile( self.name, self.version ).modification = aValue HTTP/WikiContentService.lua
r1314 r1324 96 96 97 97 return isLastWeek, aStartTime, anEndTime 98 end 99 100 local function EditorLink( self ) 101 local aContent = self.content 102 local aTitle = Encode( aContent.data.title ) 103 104 if aContent.canWrite then 105 local aLink = Encode( self.path( 'editor' ) ) 106 107 return ( '<a href=\'%s\' title=\'Editor\' rel=\'nofollow\'>%s</a>' ):format( aLink, aTitle ) 108 109 end 110 111 return aTitle 98 112 end 99 113 … … 177 191 178 192 -------------------------------------------------------------------------------- 193 -- Default content 194 -------------------------------------------------------------------------------- 195 196 local function Syntax() 197 local aContent = WikiContent( 'markdown-syntax-reference' ) 198 199 if not aContent.exists then 200 local WikiDate = require( 'WikiDate' ) 201 local WikiRecent = require( 'WikiRecent' ) 202 local WikiSearch = require( 'WikiSearch' ) 203 local aTemplate = Template[ 'MarkdownSyntaxReference.txt' ] 204 205 aContent.by = 'file://nanoki@localhost/' 206 aContent.title = 'Markdown syntax reference' 207 aContent.text = tostring( aTemplate ) 208 aContent() 209 210 WikiDate[ aContent.creation ] = aContent.name 211 WikiRecent[ aContent.modification ] = aContent.name 212 WikiSearch[ aContent.name ] = aContent.name 213 end 214 end 215 216 local function Nanoki() 217 local aContent = WikiContent( 'nanoki' ) 218 219 if not aContent.exists then 220 local File = require( 'File' ) 221 local WikiDate = require( 'WikiDate' ) 222 local WikiRecent = require( 'WikiRecent' ) 223 local WikiSearch = require( 'WikiSearch' ) 224 local aDirectory = File( 'Nanoki' ) 225 local aTemplate = Template[ 'Nanoki.txt' ] 226 227 aContent.by = 'file://nanoki@localhost/' 228 aContent.title = 'Nanoki' 229 aContent.text = tostring( aTemplate ) 230 aContent() 231 232 for aFile in aDirectory() do 233 aContent.file = aFile 234 end 235 236 aContent.canWrite = false 237 WikiDate[ aContent.creation ] = aContent.name 238 WikiRecent[ aContent.modification ] = aContent.name 239 WikiSearch[ aContent.name ] = aContent.name 240 end 241 end 242 243 Syntax() 244 Nanoki() 245 246 -------------------------------------------------------------------------------- 179 247 -- Service methods 180 248 -------------------------------------------------------------------------------- … … 214 282 Referer( self ) 215 283 216 aTemplate[ 'editorLink' ] = Encode( self.path( 'editor' ) ) 217 aTemplate[ 'historyLink' ] = Encode( self.path( 'editor' )( 'history' ) ) 284 aTemplate[ 'editorLink' ] = EditorLink( self ) 218 285 aTemplate[ 'version' ] = Encode(self.content.version ) 219 286 aTemplate[ 'title' ] = Encode( self.content.data.title ) … … 297 364 local aContent = WikiContent( self.content.name, aVersion ) 298 365 299 if not aContent.exists then 300 aContent = self.content 301 end 302 303 if not aContent.exists then 304 HTTP.response.status.code = 404 305 HTTP.response.status.description = 'Not Found' 306 end 307 308 return WikiEditorService( aContent, self ) 366 if aContent.canWrite then 367 if not aContent.exists then 368 aContent = self.content 369 end 370 371 if not aContent.exists then 372 HTTP.response.status.code = 404 373 HTTP.response.status.description = 'Not Found' 374 end 375 376 return WikiEditorService( aContent, self ) 377 end 309 378 end 310 379 HTTP/WikiContentService.txt
r1286 r1324 1 <h1> <a href='[v:editorLink]' title='Editor' rel='nofollow'>[v:title]</a></h1>1 <h1>[v:editorLink]</h1> 2 2 <h4>Published on <a href='[v:dateLink]' title='Published on [v:creation]. Edited on [v:modification] by [v:by].'>[v:creation]</a> [v:tag]</h4> 3 3 [v:message] HTTP/WikiEditorService.lua
r1322 r1324 254 254 end 255 255 256 local function Syntax()257 local aContent = WikiContent( 'markdown-syntax-reference' )258 259 if not aContent.exists then260 local aTemplate = Template[ 'MarkdownSyntaxReference.txt' ]261 262 aContent.by = 'file://nanoki@localhost/'263 aContent.title = 'Markdown syntax reference'264 aContent.text = tostring( aTemplate )265 aContent()266 267 WikiDate[ aContent.creation ] = aContent.name268 WikiSearch[ aContent.name ] = aContent.name269 WikiRecent[ aContent.modification ] = aContent.name270 end271 end272 273 local function Nanoki()274 local aContent = WikiContent( 'nanoki' )275 276 if not aContent.exists then277 local File = require( 'File' )278 local aDirectory = File( 'Nanoki' )279 local aTemplate = Template[ 'Nanoki.txt' ]280 281 aContent.by = 'file://nanoki@localhost/'282 aContent.title = 'Nanoki'283 aContent.text = tostring( aTemplate )284 aContent()285 286 for aFile in aDirectory() do287 aContent.file = aFile288 end289 290 WikiDate[ aContent.creation ] = aContent.name291 WikiSearch[ aContent.name ] = aContent.name292 WikiRecent[ aContent.modification ] = aContent.name293 end294 end295 296 256 -------------------------------------------------------------------------------- 297 257 -- Service methods … … 306 266 local aContext = Context() 307 267 local aToken = Token() 308 309 Syntax()310 Nanoki()311 268 312 269 aTemplate[ 'actionPath' ] = Encode( HTTP.request.url.path )