--- /tmp/tmp_snapshot/samizdat/lib/samizdat/controllers/member_controller.rb	2007-08-14 01:37:57.000000000 +0200
+++ /usr/lib/ruby/1.8/samizdat/controllers/member_controller.rb	2007-08-25 02:20:24.000000000 +0200
@@ -70,7 +70,7 @@
   # store UI options in cookies
   #
   def set
-    %w[lang style nostatic ui].each do |param|
+    %w[lang monolanguage style nostatic ui].each do |param|
       value, = @request.values_at([param])
       if value
         @request.set_cookie(param, value)
--- /tmp/tmp_snapshot/samizdat/lib/samizdat/engine/request.rb	2007-08-14 01:16:53.000000000 +0200
+++ /usr/lib/ruby/1.8/samizdat/engine/request.rb	2007-08-29 23:02:06.000000000 +0200
@@ -121,6 +123,12 @@
   # current language
   attr_reader :language
 
+  # monolanguage - show content from preferred language only?
+  def monolanguage?
+    (cookie('monolanguage').to_s == 'mono')?
+      true : false
+  end
+
   # set default CGI headers (set charset to UTF-8)
   #
   # set id and refresh session if there's a valid session cookie,

--- /tmp/tmp_snapshot/samizdat/lib/samizdat/helpers/message_helper.rb	2007-06-18 21:19:43.000000000 +0200
+++ /usr/lib/ruby/1.8/samizdat/helpers/message_helper.rb	2007-08-25 03:08:26.000000000 +0200
@@ -208,7 +231,7 @@
       if desc   # prepend content with description box
         content << box(resource_href(message.desc, _('Description')), desc, 'desc')
       end
-      content << message_content(translation, mode)
+      content << message_content(translation, mode).to_s
     end
 
     html =

--- /tmp/tmp_snapshot/samizdat/lib/samizdat/controllers/frontpage_controller.rb	2007-06-21 20:52:49.000000000 +0200
+++ /usr/lib/ruby/1.8/samizdat/controllers/frontpage_controller.rb	2007-09-29 11:04:50.609618472 +0200
@@ -28,7 +33,8 @@
 
     # try to run from cache
     cache_key = 'index' + @request.uri_prefix + '/' + @request.accept_language.join(':') +
-      %{/#{skip}/#{skip_feature}/#{'yes' != @request.cookie('nostatic')}}
+      %{/#{skip}/#{skip_feature}/#{'yes' != @request.cookie('nostatic')}} +
+      %{/#{@request.monolanguage?}}
     if page = cache[cache_key]
       return @content_for_layout = page
     end
@@ -168,44 +221,143 @@
   # in case of multiple related focuses, the one related most recently is used
   #
   def collect_features(skip, limit=config['limit']['features'])
-    list = cache.fetch_or_add(%{features/#{skip}/#{limit}}) do
+    if @request.monolanguage?
+      lang = @request.accept_language[0]
+      lang_cache_index = lang + '/'
+      check_lang =  " AND  ?language = :accept_lang " 
+    else
+      lang = ''
+      lang_cache_index = ''
+      check_lang = ''
+    end
+
+    list = cache.fetch_or_add(%{features/#{lang_cache_index}#{skip}/#{limit}}) do
       rdf.select_all( %{
-SELECT ?msg
+SELECT ?msg, ?date
 WHERE (rdf::predicate ?stmt dc::relation)
       (rdf::subject ?stmt ?msg)
       (rdf::object ?stmt ?focus)
       (dc::date ?stmt ?date)
+      (dc::language ?msg ?language)
       (s::inReplyTo ?msg ?parent)
       (dct::isVersionOf ?msg ?version_of)
       (s::rating ?stmt ?rating)
       (s::hidden ?msg ?hidden)
 LITERAL ?rating >= :threshold AND
-        ?parent IS NULL AND ?version_of IS NULL #{exclude_hidden}
-GROUP BY ?msg
+        ?parent IS NULL AND ?version_of IS NULL #{exclude_hidden} #{check_lang} 
+GROUP BY ?msg, ?date
 ORDER BY max(?date) DESC}, limit, limit * skip,
-        { :threshold => config['limit']['features_threshold'] }
-      ).collect {|m,| m }   # unwrap DBI::Row
+                      { :threshold => config['limit']['features_threshold'], 
+                        :accept_lang =>  lang }
+                      ) # .collect {|m,| m }   # unwrap DBI::Row
     end
-    list.collect {|msg| yield msg }
+
+    # translated list
+    if @request.monolanguage?
+      t_list = cache.fetch_or_add(%{features_t/#{lang}/#{skip}/#{limit}}) do
+        rdf.select_all( %{
+SELECT ?parent, ?date
+WHERE (s::inReplyTo ?msg ?parent)
+      (rdf::predicate ?stmt dc::relation)
+      (rdf::subject ?stmt ?parent)
+      (rdf::object ?stmt ?focus)
+      (rdf::predicate ?m_stmt dc::relation)
+      (rdf::subject ?m_stmt ?msg)
+      (rdf::object ?m_stmt focus::Translation)
+      (dc::date ?stmt ?date)
+      (dc::language ?msg ?language)
+      (dct::isVersionOf ?msg ?version_of)
+      (s::rating ?stmt ?rating)
+      (s::hidden ?msg ?hidden)
+LITERAL ?rating >= :threshold AND
+        (NOT ?parent IS NULL) AND ?version_of IS NULL #{exclude_hidden} #{check_lang}
+GROUP BY ?parent, ?date
+ORDER BY max(?date) DESC}, limit, limit * skip,
+                        { :threshold => config['limit']['features_threshold'], 
+                          :accept_lang =>  lang }
+                        ) #.collect {|m,| m }   # unwrap DBI::Row
+        
+      end
+      list += t_list 
+      list.sort!{|x,y| y[1].to_s <=> x[1].to_s }
+    end
+
+    list.collect{|msg,| yield msg }
   end
 
+
   # messages that are not comments or older version, sorted chronologically
   #
   def collect_updates(skip)
-    list = cache.fetch_or_add(%{updates/#{skip}}) do
+    limit_page_cal = 
+      config['calendar'] ?
+       limit_page * 3 : limit_page  # TODO: define multiplying factor elsewhere
+
+    if @request.monolanguage?
+      lang = @request.accept_language[0]
+      lang_cache_index = lang + '/'
+      check_lang = " AND  ?language = :accept_lang " 
+    else
+      lang = nil
+      lang_cache_index = nil
+      check_lang = nil
+    end
+    list = cache.fetch_or_add(%{updates/#{lang_cache_index}#{skip}}) do
       rdf.select_all( %{
-SELECT ?msg
+SELECT ?msg, ?date, ?title
 WHERE (dc::date ?msg ?date)
+      (dc::language ?msg ?language)
+      (dc::title ?msg ?title)
       (s::inReplyTo ?msg ?parent)
       (dct::isVersionOf ?msg ?version_of)
       (s::hidden ?msg ?hidden)
-LITERAL ?parent IS NULL AND ?version_of IS NULL #{exclude_hidden}
-ORDER BY ?date DESC}, limit_page, limit_page * skip
-      ).collect {|m,| m }   # unwrap DBI::Row
-    end
-    list.collect {|msg| yield msg }
+LITERAL ?parent IS NULL AND 
+      ?version_of IS NULL #{exclude_hidden} #{check_lang} 
+ORDER BY ?date DESC}, limit_page_cal, limit_page * skip,
+                      { :accept_lang =>  lang }
+      ) #.collect {|m,| m }   # unwrap DBI::Row
+    end
+
+     if @request.monolanguage?
+       t_list = cache.fetch_or_add(%{updates_t/#{lang_cache_index}#{skip}}) do
+         rdf.select_all( %{
+ SELECT ?parent, ?date, ?title
+ WHERE (dc::date ?msg ?date)
+       (s::inReplyTo ?msg ?parent)
+       (dc::language ?msg ?language)
+       (dc::title ?msg ?title)
+       (dct::isVersionOf ?msg ?version_of)
+       (rdf::predicate ?stmt dc::relation)
+       (rdf::subject ?stmt ?msg)
+       (rdf::object ?stmt focus::Translation)
+       (s::hidden ?msg ?hidden)
+ LITERAL  ?version_of IS NULL AND (NOT ?parent IS NULL) #{exclude_hidden}  AND  
+          ?language = :accept_lang  
+ ORDER BY ?date DESC}, limit_page_cal, limit_page * skip,
+                         { :accept_lang =>  lang }
+                         ) #.collect {|m,| m }   # unwrap DBI::Row
+       end
+       
+       list += t_list
+       list.sort!{|x,y| y[1].to_s <=> x[1].to_s }
+    end
+
+#    list = list.collect{|m,d,t| [m,d] if not match_cal_focus_title(t)}  - [[]]
+#    list.collect{|m,d,t| (t =~ %r{[2-9][0-9]{3}-[01][0-9]-[0-3][0-9]})? [] : [m,d] }
+#    list = list.collect{|m,d,t| (m.to_i == 3534)? [] : [m,d] } - [[]]
+    list = list.collect{|m,d,t| (match_cal_focus_title(t))? [] : [m,d] } - [[]]
+
+#    list.collect {|msg| yield msg }
+    list[0..limit_page-1].collect{|msg,| yield msg }
+  end
+
+  # this should probably be moved to helpers.rb or calendar_helpers.rb
+  # (or as a method on titles?)
+  def match_cal_focus_title(title) # Y10K unsafe
+     title =~ %r{\A[2-9][0-9]{3}-[01][0-9]-[0-3][0-9]\z}
   end
 
+
   # do Apache's job and include files in static headers
   #
   def gsub_ssi_file(static)
@@ -245,8 +397,19 @@
       next if 'English' == name and 'en' != lang   # broken localization
       name += _(' (default language)') if
         lang == default_language
-      name = %{<strong>#{name}</strong>} if lang == old_language
-      list += %{<a href="member/set?lang=#{lang}">#{name}</a>\n}
+      if lang == old_language
+        list += %{<strong>#{name}</strong>\n} 
+      else
+        list += %{<a href="member/set?lang=#{lang}">#{name}</a>\n}
+      end
+
+    end
+    if config['monolanguage']
+      list += ( (@request.monolanguage?)?
+                %{ | <strong>mono</strong>} +
+                  %{ <a href="member/set?monolanguage=multi">multi</a>\n} :
+                  %{ | <a href="member/set?monolanguage=mono">mono</a>} +
+                  %{ <strong>multi</strong> } )
     end
     %{<div id="languages">#{list}</div>}
   end
