Class: ClWiki::Page

Inherits:
Object
  • Object
show all
Defined in:
lib/cl_wiki/page.rb

Constant Summary collapse

@@wikiIndexClient =
nil

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(fullName, wiki_path = $wiki_path) ⇒ Page

refactor away wikiPath … should be taken care of elsewhere, otherwise ClWiki must know it, and it should be storage independent



22
23
24
25
26
27
28
# File 'lib/cl_wiki/page.rb', line 22

def initialize(fullName, wiki_path=$wiki_path)
  @full_name = fullName
  @wiki_path = wiki_path
  @wikiFile = ClWiki::File.new(@full_name, @wiki_path)
  @pagePath = @wikiFile.pagePath
  @name = @wikiFile.name
end

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



12
13
14
# File 'lib/cl_wiki/page.rb', line 12

def content
  @content
end

#fileFullPathAndNameObject (readonly)

Returns the value of attribute fileFullPathAndName.



12
13
14
# File 'lib/cl_wiki/page.rb', line 12

def fileFullPathAndName
  @fileFullPathAndName
end

#full_nameObject (readonly)

Returns the value of attribute full_name.



12
13
14
# File 'lib/cl_wiki/page.rb', line 12

def full_name
  @full_name
end

#mtimeObject (readonly)

Returns the value of attribute mtime.



12
13
14
# File 'lib/cl_wiki/page.rb', line 12

def mtime
  @mtime
end

#nameObject (readonly)

Returns the value of attribute name.



12
13
14
# File 'lib/cl_wiki/page.rb', line 12

def name
  @name
end

#pagePathObject (readonly)

Returns the value of attribute pagePath.



12
13
14
# File 'lib/cl_wiki/page.rb', line 12

def pagePath
  @pagePath
end

#raw_contentObject (readonly)

Returns the value of attribute raw_content.



12
13
14
# File 'lib/cl_wiki/page.rb', line 12

def raw_content
  @raw_content
end

Class Method Details

.page_exists?(page_name) ⇒ Boolean

Returns:

  • (Boolean)


175
176
177
178
179
180
181
182
183
184
# File 'lib/cl_wiki/page.rb', line 175

def self.page_exists?(page_name)
  if ($wiki_conf.useIndex != ClWiki::Configuration::USE_INDEX_NO) &&
      ($wiki_conf.useIndexForPageExists)
    res = ClWiki::Page.wikiIndexClient.page_exists?(page_name)
  else
    wiki_file = ClWiki::File.new(page_name, $wiki_path, $wikiPageExt, false)
    res = wiki_file.file_exists?
  end
  res
end

.read_file_full_path_and_name(full_name, wiki_path = $wiki_path) ⇒ Object



69
70
71
72
# File 'lib/cl_wiki/page.rb', line 69

def self.read_file_full_path_and_name(full_name, wiki_path=$wiki_path)
  wiki_file = ClWikiFile.new(full_name, wiki_path, $wikiPageExt, false)
  wiki_file.fullPathAndName
end

.wikiIndexClientObject



50
51
52
53
# File 'lib/cl_wiki/page.rb', line 50

def self.wikiIndexClient
  @@wikiIndexClient = ClWikiIndexClient.new if !@@wikiIndexClient
  @@wikiIndexClient
end

Instance Method Details

#content_never_edited?Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/cl_wiki/page.rb', line 61

def content_never_edited?
  @wikiFile.content_is_default?
end

#convert_newline_to_brObject

<pre> text in 1.13.2 had extra line feeds, because the n were xformed to
n, which results in two line feeds when rendered by Mozilla. The change a few versions ago inside convert_newline_to_br which started converting n to
n is the culprit here. I did this for more readable html, but that does screw up <pre> sections, so it’s put back now.



35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/cl_wiki/page.rb', line 35

def convert_newline_to_br
  newcontent = ""
  insideHtmlTags = false
  @content.each_line do |substr|
    insideHtmlTags = true if (substr =~ /#{$HTML_START}/)
    insideHtmlTags = false if (substr =~ /#{$HTML_END}/)
    if ((!ClWiki::PageFormatter.only_html(substr)) or (substr == "\n")) and !insideHtmlTags
      newcontent = newcontent + substr.gsub(/\n/, "<br>")
    else
      newcontent = newcontent + substr
    end
  end
  @content = newcontent
end

#deleteObject



65
66
67
# File 'lib/cl_wiki/page.rb', line 65

def delete
  @wikiFile.delete
end


138
139
140
141
# File 'lib/cl_wiki/page.rb', line 138

def get_footer
  f = ClWiki::PageFormatter.new(nil, @full_name)
  f.footer(self)
end

#get_forward_ref(content) ⇒ Object



143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# File 'lib/cl_wiki/page.rb', line 143

def get_forward_ref(content)
  content_ary = content.split("\n")
  res = (content_ary.collect { |ln| ln.strip.empty? ? nil : ln }.compact.length == 1)
  if res
    res = content_ary[0] =~ /^see (.*)/i
  end

  if res
    page_name = $1
    f = ClWiki::PageFormatter.new(content, @full_name)
    res = f.is_wiki_name?(page_name)
    if res
      res = ClWiki::Page.page_exists?(page_name)
    end
  end
  if res
    page_name
  else
    nil
  end
end

#get_headerObject



133
134
135
136
# File 'lib/cl_wiki/page.rb', line 133

def get_header
  f = ClWiki::PageFormatter.new(nil, @full_name)
  f.header(@full_name, self)
end

#process_custom_renderersObject



122
123
124
125
126
127
128
129
130
131
# File 'lib/cl_wiki/page.rb', line 122

def process_custom_renderers
  root_dirs = [::File.join(::File.dirname(__FILE__), 'format')] + $wiki_conf.custom_formatter_load_path
  root_dirs.each do |root_dir|
    Dir[::File.join(root_dir, 'format.*')].each do |fn|
      require fn
    end
  end

  ClWiki::CustomFormatters.instance.process_formatters(@content, self)
end

#read_content(include_header_and_footer = true, include_diff = false) ⇒ Object



108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/cl_wiki/page.rb', line 108

def read_content(include_header_and_footer=true, include_diff=false)
  read_page_attributes
  @content, final_page_name = read_raw_content_with_forwarding(@full_name)
  process_custom_renderers
  convert_newline_to_br
  f = ClWiki::PageFormatter.new(@content, final_page_name)
  @content = "<div class='wikiBody'>#{f.formatLinks}</div>"
  if include_header_and_footer
    @content = get_header + @content + get_footer
  end
  @content = CLabs::WikiDiffFormatter.format_diff(@wikiFile.diff) + @content if include_diff
  @content
end

#read_page_attributesObject



74
75
76
77
78
# File 'lib/cl_wiki/page.rb', line 74

def read_page_attributes
  wikiFile = @wikiFile # ClWikiFile.new(@fullName, @wikiPath)
  @mtime = wikiFile.modTimeAtLastRead
  @fileFullPathAndName = wikiFile.fullPathAndName
end

#read_raw_contentObject



55
56
57
58
59
# File 'lib/cl_wiki/page.rb', line 55

def read_raw_content
  @raw_content = @wikiFile.content.join.gsub(/\r\n/, "\n")
  read_page_attributes
  ClWiki::Page.wikiIndexClient.add_hit(@full_name) if $wiki_conf.access_log_index
end

#read_raw_content_with_forwarding(full_page_name) ⇒ Object



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/cl_wiki/page.rb', line 80

def read_raw_content_with_forwarding(full_page_name)
  stack = []
  history = []
  content = ''
  final_page_name = full_page_name
  stack.push(full_page_name)
  while !stack.empty?
    this_pg_name = stack.pop
    if history.index(this_pg_name)
      pg_content = '-= CIRCULAR FORWARDING DETECTED =-'
    else
      pg = ClWiki::Page.new(this_pg_name)
      pg.read_raw_content
      pg_content = pg.raw_content
      fwd_full_page_name = get_forward_ref(pg_content)
      if fwd_full_page_name
        pg_content = "Auto forwarded from #{this_pg_name.strip_slash_prefix}<br><br>#{fwd_full_page_name}<br><br>"
        stack.push fwd_full_page_name
      else
        final_page_name = this_pg_name
      end
    end
    content << pg_content << "\n"
    history << this_pg_name
  end
  [content, final_page_name]
end

#update_content(newcontent, mtime) ⇒ Object



165
166
167
168
169
170
171
172
173
# File 'lib/cl_wiki/page.rb', line 165

def update_content(newcontent, mtime)
  wikiFile = @wikiFile # ClWikiFile.new(@fullName, @wikiPath)
  wikiFile.clientLastReadModTime = mtime
  wikiFile.content = newcontent
  if $wiki_conf.useIndex != ClWiki::Configuration::USE_INDEX_NO
    wikiIndexClient = ClWiki::IndexClient.new
    wikiIndexClient.reindex_page(@full_name)
  end
end