xowiki::Page instproc www-view (public)

 <instance of xowiki::Page[i]> www-view [ content ]

Defined in packages/xowiki/tcl/xowiki-www-procs.tcl

This web-callable method is called when viewing wiki content. The method "view" is used primarily as web API call, when the xowiki page is viewed. It is not intended for e.g. embedded wiki pages (use includes), since it contains full framing, etc. In most cases, the argument "content" is not provided, and it is computed via the "render" method of the current object. It is as well possible to reuse the rendering logic of the method for other pages, where some HTML content is already computed, but it should be viewed exactly as in the page viewing cases.

Parameters:
content (optional)

Partial Call Graph (max 5 caller/called nodes):
%3 test_xowiki_test_cases xowiki_test_cases (test xowiki) xowiki::Page instproc www-view xowiki::Page instproc www-view test_xowiki_test_cases->xowiki::Page instproc www-view ad_return_complaint ad_return_complaint (public) xowiki::Page instproc www-view->ad_return_complaint ad_return_url ad_return_url (public) xowiki::Page instproc www-view->ad_return_url ad_script_abort ad_script_abort (public) xowiki::Page instproc www-view->ad_script_abort ad_try ad_try (public) xowiki::Page instproc www-view->ad_try export_vars export_vars (public) xowiki::Page instproc www-view->export_vars

Testcases:
xowiki_test_cases
Source code:
#ns_log notice "www-view <$content>"

#
# The recursion_count os maintained to avoid recursive includes
# inside a page.
#
::xowiki::Page set recursion_count 0
set page_package_id    ${:package_id}
set context_package_id [::xo::cc package_id]
set folder_id [::$page_package_id folder_id]

#:msg "page_package_id=$page_package_id, context_package_id=$context_package_id"

set template_file [ns_normalizepath [:query_parameter "template_file"  [::$context_package_id get_parameter template_file:graph view-default]]]
if {[nsf::is object ::xowiki::$template_file]} {
  $template_file before_render [self]
}

#
# Set up template variables.
#
set object_type [::$page_package_id get_parameter object_type:graph [:info class]]
set rev_link    [::$page_package_id make_link [self] revisions]

if {[::$context_package_id query_parameter m:token ""] eq "edit"} {
  set view_link [::$page_package_id make_link [self] view return_url]
  set edit_link ""
} else {
  set edit_link [::$page_package_id make_link [self] edit return_url]
  set view_link ""
}

set delete_link [::$page_package_id make_link [self] delete return_url]
if {[info exists :__link(new)]} {
  set new_link [set :__link(new)]
} else {
  set new_link [:new_link $page_package_id]
}

set admin_link  [::$context_package_id make_link -privilege admin -link admin/ ::$context_package_id]
set index_link  [::$context_package_id make_link -privilege public ::$context_package_id]
set view_link   [::$page_package_id make_link [self] view return_url]

set notification_subscribe_link ""
if {[::$context_package_id get_parameter with_notifications:boolean 1]} {
  if {[::xo::cc user_id] != 0} {
    #
    # Notifications are only be displayed for logged-in users.
    #
    set notifications_return_url [expr {[info exists return_url] ? $return_url : [ad_return_url]}]
    set notification_type [notification::type::get_type_id -short_name xowiki_notif]
    set notification_text "Subscribe to [::$context_package_id instance_name]"
    set notification_subscribe_link  [export_vars -base /notifications/request-new  {{return_url $notifications_return_url}
               {pretty_name $notification_text}
               {type_id $notification_type}
               {object_id $context_package_id}}]
    set notification_image "<adp:icon name='envelope' title='[ns_quotehtml $notification_text]'>"
  }
}

#
# The content may be passed by other methods (e.g. edit) to
# make use of the same templating machinery below.
#
if {$content eq ""} {
  set content [:content_header_get][:render]
  #:msg "--after render"
} else {
  set content [:content_header_get]$content
}
#set content [::xowiki::adp_parse_tags $content]

#
# These variables can be influenced via set-parameter.
#
set autoname [::$page_package_id get_parameter autoname:boolean 0]

#
# Setup top includeletes and footers.
#

set footer [:htmlFooter -content $content]
set top_includelets ""
set vp [string trim [::$context_package_id get_parameter top_includelet ""]]
if {$vp ne "" && $vp ne "none"} {
  set top_includelets [:include $vp]
}

if {[::$context_package_id get_parameter MenuBar:boolean 0]} {
  #
  # When a "MenuBar" is used, it might contain folder-specific
  # content. Therefore, we have to compute the tree. The resulting
  # HTML code can be placed via adp templates differently (or it
  # can be ignored).

  set folderhtml [:include {folders -style folders}]
  ::xo::Page set_property body folderHTML $folderhtml
  # TODO: there should be no need to pass manually folderhtml,
  # use the property instead

  #
  # At this place, the menu should be complete, we can render it.
  #
  set mb [::xowiki::MenuBar info instances -closure]
  if {$mb ne ""} {
    set mbHTML [$mb render-preferred]
    ::xo::Page set_property body menubarHTML $mbHTML
  }
}

if {[::$context_package_id get_parameter with_user_tracking:boolean 1]} {
  :record_last_visited
}

#
# Deal with the views package (many thanks to Malte for this
# snippet!)
#
if {[::$context_package_id get_parameter with_views_package_if_available:boolean 1]
    && [info commands ::views::record_view] ne ""} {
  views::record_view -object_id ${:item_id} -viewer_id [::xo::cc user_id]
  array set views_data [views::get -object_id ${:item_id}]
}

if {[:exists_query_parameter return_url]} {
  set return_url [:query_parameter return_url:localurl]
}

#:log "--after notifications [info exists notification_image]"

set master [::$context_package_id get_parameter master:boolean 1]
if {![string is boolean -strict $master]} {
  ad_return_complaint 1 "value of master is not boolean"
  ad_script_abort
}

if {$master} {
  set context [list ${:title}]
  #:msg "$context_package_id title=[::$context_package_id instance_name] - ${:title}"
  #:msg "::xo::cc package_id = [::xo::cc package_id]  ::xo::cc url= [::xo::cc url] "
  ::xo::Page set_property doc title "[::$context_package_id instance_name] - ${:title}"
  ::xo::Page set_property body title ${:title}

  # We could offer a user to translate the current page to his preferred language
  #
  # set create_in_req_locale_link ""
  # if {[::$context_package_id get_parameter use_connection_locale:boolean 0]} {
  #  $context_package_id get_lang_and_name -path [::$context_package_id set object] req_lang req_local_name
  #  set default_lang [::$page_package_id default_language]
  #  if {$req_lang ne $default_lang} {
  #      set l [Link create new -destroy_on_cleanup  #             -page [self] -type language -stripped_name $req_local_name  #             -name ${default_lang}:$req_local_name -lang $default_lang  #             -label $req_local_name -parent_id ${:parent_id} -item_id 0  #                 -package_id $context_package_id -init  #             -return_only undefined]
  #      $l render
  #   }
  # }

  #:log "--after context delete_link=$delete_link "
  #set template [::$context_package_id get_parameter template ""]
  set template ""
  set page [self]

  foreach css [::$context_package_id get_parameter extra_css ""] {
    ::xo::Page requireCSS -order 10 $css
  }

  #
  # Refetch "template_file", since it might have been changed via
  # set-parameter. The cache-flush (next line) is not pretty here
  # and should be supported from xotcl-core.
  #
  ::xo::cc unset -nocomplain cache([list $context_package_id get_parameter template_file:graph])
  set template_file [:query_parameter "template_file"  [::$context_package_id get_parameter template_file:graph view-default]]
  #
  # If the template_file does not have a path, assume it in the
  # standard location.
  #
  if {[string range $template_file 0 0] eq "/"} {
    ns_log warning "ignore template as specified in parameter 'template_file'"  "on non-standard location: $template_file. The template should be"  " under\n/packages/[${:package_id} package_key]/resources/templates/..."
    set template_file [::$context_package_id get_parameter  -check_query_parameter false  -nocache  template_file view-default]
  }
  set validated_template_file [::${:package_id} get_adp_template $template_file]
  if {$validated_template_file eq ""} {
    ns_log error "invalid template specified in parameter 'template_file': '$template_file'"
  }
  set template_file $validated_template_file

  # Force xowiki*.css to be loaded first(ish), so we can override
  # its styling via the theme (e.g. different buttons...). This
  # uses the "template::head" API directly, since resources from
  # requireCSS are typically loaded later than those from the theme.

  template::head::add_css  -href urn:ad:css:xowiki-[::xowiki::CSS toolkit]  -order 0

  #
  # Popular tags handling (should probably go to includelets)
  #
  if {$footer ne ""} {
    template::add_body_script -script {
      function get_popular_tags(popular_tags_link, prefix) {
        var http = new XMLHttpRequest();
        http.open('GET', popular_tags_link, true);
        http.onreadystatechange = function() {
          if (http.readyState == 4) {
            if (http.status != 200) {
              alert('Something wrong in HTTP request, status code = ' + http.status);
            } else {
              var e = document.getElementById(prefix + '-popular_tags');
              e.innerHTML = http.responseText;
              e.style.display = 'block';
            }
          }
        };
        http.send(null);
      }
    }
  }

  #
  # The method header_stuff performs the required
  # template::head::add_script and template::head::add_css
  # etc. operations
  #
  ::xo::Page header_stuff

  if {![info exists :description]} {
    set :description [:get_description $content]
  }

  if {[info commands ::template::head::add_meta] ne ""} {
    #set meta(language) [:lang]
    ::xo::Page set_property doc title_lang [:lang]
    set meta(description) [:description]
    set meta(keywords) ""
    if {[:istype ::xowiki::FormPage]} {
      set meta(keywords) [string trim [:property keywords]]
      if {[:property html_title] ne ""} {
        ::xo::Page set_property doc title [:property html_title]
      }
    }
    if {$meta(keywords) eq ""} {
      set meta(keywords) [::$context_package_id get_parameter keywords ""]
    }
    foreach i [array names meta] {
      # don't set empty meta tags
      if {$meta($i) eq ""} continue
      template::head::add_meta -name $i -content $meta($i)
    }
  }

  #
  # Pass variables for properties doc and body.
  # Example: ::xo::Page set_property body class "yui-skin-sam"
  #
  array set body [::xo::Page get_property body]
  array set doc  [::xo::Page get_property doc]

  if {$page_package_id != $context_package_id} {
    set page_context [::$page_package_id instance_name]
  }

  if {$template ne ""} {

    #
    # Initialize and set the template variables, to be used by
    # a. "adp_compile" / "adp_eval"
    # b. "return_page" / "adp_include"
    #

    set __including_page $page
    set __adp_stub [::$context_package_id get_adp_template view-default]

    set template_code [template::adp_compile -string $template]
    #
    # Make sure that <master/> and <slave/> tags are processed
    #
    append template_code {
      if { [info exists __adp_master] } {
        set __adp_output [template::adp_parse $__adp_master   [concat [list __adp_slave $__adp_output]  [array get __adp_properties]]]
      }
    }
    ad_try {
      set content [template::adp_eval template_code]
      ns_return 200 text/html $content
    } on error {errMsg} {
      ns_return 200 text/html "Error in Page ${:name}$errMsg<br>$template"
    }
    ad_script_abort
  } else {
    #
    # Use adp file.
    #
    #:log "use adp content=$content"
    set package_id $context_package_id
    set title      ${:title}
    set name       ${:name}
    set item_id    ${:item_id}
    ::$context_package_id return_page -adp $template_file -variables {
      name title item_id context return_url
      content footer package_id page_package_id page_context
      rev_link edit_link delete_link new_link admin_link index_link view_link
      notification_subscribe_link notification_image
      top_includelets page views_data body doc
    }
  }
} else {
  set :mime_type [::xo::cc get_parameter content-type:graph text/html]
  return $content
}
XQL Not present:
Generic, PostgreSQL, Oracle
[ hide source ] | [ make this the default ]
Show another procedure: