From aa95acb4f7b8536064a570b267cb6559c42eb186 Mon Sep 17 00:00:00 2001 From: Alexey Verkhovsky Date: Fri, 18 Feb 2005 02:24:16 +0000 Subject: [PATCH] RSS feeds accept query parameter start, end and limit --- CHANGELOG | 2 ++ app/controllers/wiki_controller.rb | 30 +++++++++++++++---- test/functional/wiki_controller_test.rb | 40 ++++++++++++++++++++++++- test/test_helper.rb | 7 +++++ 4 files changed, 73 insertions(+), 6 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 2a6a962f..6f0a567c 100755 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,4 +1,6 @@ HEAD: + RSS feeds accept query parameters, sush as + http://localhost:2500/wiki/rss_with_headlines?start=2005-02-18&end=2005-02-19&limit=10 RedCloth 3.0.3 (read: mixing Textile and Markdown in the same page) Files/pictures can be uploaded to a wiki and served from / displayed in wiki pages Wiki link syntax doesn't conflict with Textile hyperlink syntax. Therefore diff --git a/app/controllers/wiki_controller.rb b/app/controllers/wiki_controller.rb index 65098210..dba74af6 100644 --- a/app/controllers/wiki_controller.rb +++ b/app/controllers/wiki_controller.rb @@ -1,10 +1,11 @@ require 'application' require 'fileutils' require 'redcloth_for_tex' +require 'parsedate' class WikiController < ApplicationController - layout 'default', :except => [:rss_feed, :rss_with_headlines, :tex, :export_tex, :export_html] + layout 'default', :except => [:rss_feed, :rss_with_content, :rss_with_headlines, :tex, :export_tex, :export_html] def index if @web_name @@ -89,11 +90,11 @@ class WikiController < ApplicationController end def rss_with_content - render_rss + render_rss(hide_description = false, *parse_rss_params) end def rss_with_headlines - render_rss(hide_description = true) + render_rss(hide_description = true, *parse_rss_params) end def search @@ -291,6 +292,18 @@ class WikiController < ApplicationController } end + def parse_rss_params + if @params.include? 'limit' + limit = @params['limit'].to_i rescue nil + limit = nil if limit == 0 + else + limit = 15 + end + start_date = Time.local(*ParseDate::parsedate(@params['start'])) rescue nil + end_date = Time.local(*ParseDate::parsedate(@params['end'])) rescue nil + [ limit, start_date, end_date ] + end + def password_check(password) if password == @web.password cookies['web_address'] = password @@ -306,8 +319,15 @@ class WikiController < ApplicationController ip end - def render_rss(hide_description = false) - @pages_by_revision = @web.select.by_revision.first(15) + def render_rss(hide_description = false, limit = 15, start_date = nil, end_date = nil) + if limit && !start_date && !end_date + @pages_by_revision = @web.select.by_revision.first(limit) + else + @pages_by_revision = @web.select.by_revision + @pages_by_revision.reject! { |page| page.created_at < start_date } if start_date + @pages_by_revision.reject! { |page| page.created_at > end_date } if end_date + end + @hide_description = hide_description @response.headers['Content-Type'] = 'text/xml' render 'wiki/rss_feed' diff --git a/test/functional/wiki_controller_test.rb b/test/functional/wiki_controller_test.rb index bf3b64ec..525fcae7 100755 --- a/test/functional/wiki_controller_test.rb +++ b/test/functional/wiki_controller_test.rb @@ -344,7 +344,6 @@ class WikiControllerTest < Test::Unit::TestCase assert_equal @home.revisions[0], r.template_objects['revision'] end - def test_rss_with_content setup_wiki_with_three_pages @@ -388,6 +387,45 @@ class WikiControllerTest < Test::Unit::TestCase assert_template_xpath_match '/rss/channel/item/link', expected_page_links end + def test_rss_with_params + setup_wiki_with_30_pages + + r = process 'rss_with_headlines', 'web' => 'wiki1' + assert_success + pages = r.template_objects['pages_by_revision'] + assert_equal 15, pages.size, 15 + + r = process 'rss_with_headlines', 'web' => 'wiki1', 'limit' => '5' + assert_success + pages = r.template_objects['pages_by_revision'] + assert_equal 5, pages.size + + r = process 'rss_with_headlines', 'web' => 'wiki1', 'limit' => '25' + assert_success + pages = r.template_objects['pages_by_revision'] + assert_equal 25, pages.size + + r = process 'rss_with_headlines', 'web' => 'wiki1', 'limit' => 'all' + assert_success + pages = r.template_objects['pages_by_revision'] + assert_equal 31, pages.size + + r = process 'rss_with_headlines', 'web' => 'wiki1', 'start' => '1976-10-16' + assert_success + pages = r.template_objects['pages_by_revision'] + assert_equal 16, pages.size + + r = process 'rss_with_headlines', 'web' => 'wiki1', 'end' => '1976-10-16' + assert_success + pages = r.template_objects['pages_by_revision'] + assert_equal 15, pages.size + + r = process 'rss_with_headlines', 'web' => 'wiki1', 'start' => '1976-10-01', 'end' => '1976-10-06' + assert_success + pages = r.template_objects['pages_by_revision'] + assert_equal 5, pages.size + end + def test_save r = process 'save', 'web' => 'wiki1', 'id' => 'NewPage', 'content' => 'Contents of a new page', 'author' => 'AuthorOfNewPage' diff --git a/test/test_helper.rb b/test/test_helper.rb index b321d11f..9f8fc128 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -45,6 +45,13 @@ class Test::Unit::TestCase 10.minutes.ago, Author.new('Guest', '127.0.0.2')) end + def setup_wiki_with_30_pages + (1..30).each { |i| + @wiki.write_page('wiki1', "page#{i}", "Test page #{i}\ncategory: test", + Time.local(1976, 10, i, 12, 00, 00), Author.new('Dema', '127.0.0.2')) + } + end + def tear_down_wiki ApplicationController.wiki = nil end