Class: Web::Wiki::Request

Inherits:
Object show all
Defined in:
lib/web/wiki.rb

Overview

:nodoc:

Defined Under Namespace

Classes: Action

Constant Summary collapse

@@actions =
{}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(wiki) ⇒ Request

Returns a new instance of Request.



331
332
333
334
335
336
337
338
339
# File 'lib/web/wiki.rb', line 331

def initialize( wiki )
  @handled = false
  @wiki = wiki
  @template = if (File.basename(Web.script_name || '') == "admin.rb")
                "admin.html"
              else
                "template.html"
              end
end

Instance Attribute Details

#content_templateObject

Returns the value of attribute content_template.



329
330
331
# File 'lib/web/wiki.rb', line 329

def content_template
  @content_template
end

#pageObject

Returns the value of attribute page.



329
330
331
# File 'lib/web/wiki.rb', line 329

def page
  @page
end

#templateObject

Returns the value of attribute template.



329
330
331
# File 'lib/web/wiki.rb', line 329

def template
  @template
end

#varsObject

Returns the value of attribute vars.



329
330
331
# File 'lib/web/wiki.rb', line 329

def vars
  @vars
end

#wikiObject

Returns the value of attribute wiki.



329
330
331
# File 'lib/web/wiki.rb', line 329

def wiki
  @wiki
end

Class Method Details

.action(name, &action) ⇒ Object



386
387
388
# File 'lib/web/wiki.rb', line 386

def Request.action( name, &action )
  Action.new name, &action
end

.actionsObject



382
383
384
# File 'lib/web/wiki.rb', line 382

def Request.actions
  @@actions
end

Instance Method Details

#download_file(basedir, requested_asset) ⇒ Object



438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
# File 'lib/web/wiki.rb', line 438

def download_file( basedir, requested_asset )
  self.template = nil
  self.content_template = nil

  basedir = File.expand_path( basedir )
  requested_asset = File.expand_path( File.join(basedir,
                                                requested_asset.gsub( /\\/, "/") ) )
  # security check on the requested_asset --
  # it must be underneath the basedir
  if ( requested_asset.index( basedir ) == 0 && \
       File.exists?( requested_asset ) )
    # deliver the file
    Web.content_type = Web.get_mime_type( requested_asset )
    Web.write File.open(requested_asset, "r" ) { |f|
      f.read
    }
    Web.flush
  else
    Web.status = "404";
    Web.write "404 File Not Found"
    Web.flush
  end
end

#handle_requestObject



364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
# File 'lib/web/wiki.rb', line 364

def handle_request
  cmd = Web["action"]
  cmd = "default" if cmd.empty? || cmd == "view_revision"
  cmd = "download_resource" if Web::path_info =~ /^\/resources\//
  cmd = "default" unless Web::Wiki::pref("allowed_actions").include?(cmd)
  
  Request.actions[cmd].call(self)
  
  
  unless @handled
    Web.template_include_path << Web::Wiki::pref("resource_dir")
    self.vars["content_template"] = self.content_template
    Web.print_template( self.template, self.vars ) if self.template
    @handled = true
  end
end