Module: Web::Wiki::Store
- Included in:
- Web::Wiki
- Defined in:
- lib/web/wiki.rb
Overview
Instance Method Summary collapse
- #load_page(name = ) ⇒ Object
- #more_news ⇒ Object
-
#move_asset(from, filename) ⇒ Object
:nodoc:.
- #news ⇒ Object
- #open_permissions ⇒ Object
- #page_list ⇒ Object
- #recent ⇒ Object
- #save(page) ⇒ Object
- #store(name) ⇒ Object
- #store_basedir ⇒ Object
- #store_dir ⇒ Object
- #store_dirname ⇒ Object
- #store_url ⇒ Object
- #vandal? ⇒ Boolean
- #vandals ⇒ Object
Instance Method Details
#load_page(name = ) ⇒ Object
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 |
# File 'lib/web/wiki.rb', line 178 def load_page( name = Web["page.name"] ) if name.size == 0 if (Web.path_info) name = Web.path_info.gsub( Regexp.new(Web.script_name), "" ).gsub(/^\/|\.html$/,"") end if name.size == 0 name = Web::Wiki::pref( :home_page ) end end page = "" page_file = store( name ) if File.exists? page_file File.open( page_file, "r" ) { |f| page = YAML.load( f ) } else page = Web::Wiki::Page.new( name ) end {/\\r/ => "\r", /\\n/ => "\n", /\\"/ => "\"", /\\'/ => "'", }.each{ |find, replace| page.content.gsub!( find, replace ) } page end |
#more_news ⇒ Object
211 212 213 214 215 216 217 218 219 220 221 222 |
# File 'lib/web/wiki.rb', line 211 def more_news if File.exists?(store_dir + "/more_news.yaml") contents = File.open( store_dir + "/more_news.yaml" ) { |f| f.read } unless contents.empty? YAML.load(contents) else [ ] end else [ ] end end |
#move_asset(from, filename) ⇒ Object
:nodoc:
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/web/wiki.rb', line 151 def move_asset( from, filename ) historical = File.(filename) i=0 while( File.exists? historical ) i += 1 historical = File.dirname( historical ) + "/\#" + i.to_s + "." + File.basename( historical ).gsub( /^\#\d*\./, "" ) end File.move( filename, historical ) if File.exists? filename if (from.is_a? Web::Upload) from.save(filename) else File.move( from, filename ) end end |
#news ⇒ Object
207 208 209 |
# File 'lib/web/wiki.rb', line 207 def news more_news[0..4] end |
#open_permissions ⇒ Object
329 330 331 332 333 334 335 336 337 338 339 340 341 342 |
# File 'lib/web/wiki.rb', line 329 def require 'find' Find.find( store_dir ) { |name| begin if File.directory? name File.chmod( 0777, name ) else File.chmod( 0666, name ) end rescue Exception # this should be more specific to access errors end } end |
#page_list ⇒ Object
168 169 170 171 172 |
# File 'lib/web/wiki.rb', line 168 def page_list Dir[store_dir + "/*.yaml"].entries.collect { |e| File.basename( e, ".yaml" ).gsub( /-slash-/, "/" ) } end |
#recent ⇒ Object
224 225 226 227 228 229 230 231 232 233 234 235 |
# File 'lib/web/wiki.rb', line 224 def recent if File.exists?(store_dir + "/recent.yaml") contents = File.open( store_dir + "/recent.yaml" ) { |f| f.read } unless contents.empty? YAML.load(contents) else [ ] end else [ ] end end |
#save(page) ⇒ Object
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 |
# File 'lib/web/wiki.rb', line 237 def save( page ) # save a slim version of the page for recent changes rcpage = page.clone rcpage.content = "" rcpage.history = [ ] rc = more_news rc = rc.unshift(rcpage) unless rcpage.comment.empty? rc.pop if rc.size > Page::max_revisions yaml = rc.to_yaml File.open( store_dir + "/more_news.yaml", "w" ) { |f| f.write(yaml) } rc = recent rc = rc.unshift(rcpage) recent_page_names = [ ] rc.delete_if do |p| if recent_page_names.include? p.name true else recent_page_names.push p.name false end end rc.pop if rc.size > Page::max_revisions yaml = rc.to_yaml File.open( store_dir + "/recent.yaml", "w" ) do |f| f.write(yaml) end comment = page.comment # clear out comment now that we've saved more news page.comment = "" yaml = page.to_yaml File.open( store( page.name ), "w" ) { |f| f.write(yaml) } end |
#store(name) ⇒ Object
174 175 176 |
# File 'lib/web/wiki.rb', line 174 def store( name ) File.join( store_dir, name.gsub(/\//, "-slash-") + ".yaml" ) end |
#store_basedir ⇒ Object
279 280 281 282 283 284 285 |
# File 'lib/web/wiki.rb', line 279 def store_basedir if ( vandal? ) Wiki.pref( "tarpit_dir" ) else Wiki.pref( "store_dir" ) end end |
#store_dir ⇒ Object
287 288 289 290 291 292 |
# File 'lib/web/wiki.rb', line 287 def store_dir unless (File.exists? store_dirname) File.makedirs( store_dirname) end store_dirname end |
#store_dirname ⇒ Object
298 299 300 301 302 303 304 |
# File 'lib/web/wiki.rb', line 298 def store_dirname unless ( store_basedir =~ /^(\w:)?\// ) File.( Dir.pwd + "/" + self.store_basedir ) else store_basedir end end |
#store_url ⇒ Object
294 295 296 |
# File 'lib/web/wiki.rb', line 294 def store_url Wiki::pref( :store_url ) || Wiki::pref( :store_dir ) end |
#vandal? ⇒ Boolean
306 307 308 309 310 311 312 313 314 315 |
# File 'lib/web/wiki.rb', line 306 def vandal? vandal = false vandals.each do |pattern| if pattern =~ ENV["REMOTE_ADDR"] vandal = true break end end vandal end |