wiki-categories-3274.patch

Rebased and squashed Sven's patch against r3017 - Eric Davis, 2009-11-08 02:39

Download (43.1 KB)

View differences:

app/controllers/wiki_controller.rb
181 181
      export = render_to_string :action => 'export_multiple', :layout => false
182 182
      send_data(export, :type => 'text/html', :filename => "wiki.html")
183 183
      return      
184
    when 'category'
185
      @category = params[:category].gsub(/_/, ' ')
186
      @pages = @wiki.find_pages_in_category(@category)
187
    when 'category_index'
188
      @categories = @wiki.find_all_categories
184 189
    else
185 190
      # requested special page doesn't exist, redirect to default page
186 191
      redirect_to :action => 'index', :id => @project, :page => nil and return
app/helpers/application_helper.rb
396 396

  
397 397
    project = options[:project] || @project || (obj && obj.respond_to?(:project) ? obj.project : nil)
398 398

  
399
    # Wiki category links
400
    #
401
    # Examples:
402
    #   [[category:mycategory]]
403
    #   [[category:mycategory|mytext]]
404
    # wiki links can refer other project wikis, using project name or identifier:
405
    #   [[myproject:category:mycategory]]
406
    #   [[myproject:category:mycategory|mytext]]
407
    text = text.gsub(/(!)?(\[\[(?:(.+?):)?category:(.+?)(?:\|(.+?))?\]\])/) do |m|
408
      esc, all, link_project, category, title = $1, $2, $3, $4, $5
409
      if esc.nil?
410
        if link_project.nil?
411
          link_project = project
412
        else
413
          link_project = Project.find_by_name(link_project) || Project.find_by_identifier(link_project)
414
        end
415
        if link_project && link_project.wiki
416
          link_to((title || category), :only_path => only_path, :controller => 'wiki', :id => project, :action => 'special', :page => 'category', :category => Wiki.titleize(category))
417
        else
418
          all
419
        end
420
      else
421
        '!' + all
422
      end
423
    end
424

  
399 425
    # Wiki links
400 426
    #
401 427
    # Examples:
app/models/wiki.rb
44 44
    end
45 45
    page
46 46
  end
47
  
47

  
48
  # Find pages which belong to a certain category.
49
  # Special category 'None' contains all pages with no particular category set.
50
  def find_pages_in_category(category)
51
    if category == 'None'
52
      pages.find :all, :conditions => "categories = '' OR categories IS NULL", :order=> 'title'
53
    else
54
      pages.find :all, :conditions => [ "LOWER(categories) LIKE LOWER(?)", "%|#{category.downcase}|%"], :order=> 'title'
55
    end
56
  end
57

  
58
  # Traverse all pages and compile a list of categories.
59
  def find_all_categories
60
    categories = {}
61
    groups = pages.find :all, :select => :categories, :conditions => "categories != ''", :group => :categories
62
    groups.map {|c| c.categories[1..-2].split('|') }.flatten.sort.each do |g|
63
      categories[g.downcase] = g   # case insensitive uniq
64
    end
65
    categories.values
66
  end
67

  
48 68
  # Finds a page by title
49 69
  # The given string can be of one of the forms: "title" or "project:title"
50 70
  # Examples:
......
63 83
      end
64 84
    end
65 85
  end
66
  
86

  
87
  # Upcase only the first letter of a title
88
  def self.upcase_first(title='')
89
    title = (title.slice(0..0).upcase + (title.slice(1..-1) || '')) if title
90
  end
91

  
67 92
  # turn a string into a valid page title
68 93
  def self.titleize(title)
69 94
    # replace spaces with _ and remove unwanted caracters
70 95
    title = title.gsub(/\s+/, '_').delete(',./?;|:') if title
71
    # upcase the first letter
72
    title = (title.slice(0..0).upcase + (title.slice(1..-1) || '')) if title
96
    title = self.upcase_first(title)
73 97
    title
74 98
  end  
75 99
end
app/models/wiki_content.rb
25 25
  validates_length_of :comments, :maximum => 255, :allow_nil => true
26 26
  
27 27
  acts_as_versioned
28
    
28

  
29
  def after_save
30
    page.categories = categories.join('|')
31
    page.categories = '|' + page.categories + '|' if !categories.empty? 
32
    page.save!
33
  end
34

  
29 35
  def project
30 36
    page.project
31 37
  end
38

  
39
  def categories
40
    if text.match(/\{\{categor(?:y|ies)\((.+?)\)\}\}/)
41
      $1.split(/\s*,\s*/).map { |c| Wiki.upcase_first(c) }
42
    else
43
      []
44
    end
45
  end
32 46
  
33 47
  class Version
34 48
    belongs_to :page, :class_name => '::WikiPage', :foreign_key => 'page_id'
app/views/wiki/_sidebar.rhtml
3 3
<%= link_to l(:field_start_page), {:action => 'index', :page => nil} %><br />
4 4
<%= link_to l(:label_index_by_title), {:action => 'special', :page => 'Page_index'} %><br />
5 5
<%= link_to l(:label_index_by_date), {:action => 'special', :page => 'Date_index'} %><br />
6
<%= link_to l(:label_index_by_category), {:action => 'special', :page => 'Category_index'} %><br />
7

  
8
<% if wiki_categories = @page.categories.sub(/^\|(.*)\|$/, '\1').split('|') rescue nil %>
9
  <% if (!wiki_categories.empty?) %>
10
    <h3><%= l((wiki_categories.length==1)?(:label_wiki_category):(:label_wiki_category_plural)) %></h3>
11
    <% wiki_categories.sort.each do |category| %>
12
      <%= link_to category, {:action => 'special', :page => 'category', :category => Wiki.titleize(category)} %><br />
13
    <% end %>
14
  <% end %>
15
<% end %>
app/views/wiki/special_category.rhtml
1
<% if @category == 'None' %>
2
  <h2><%= l(:label_pages_without_category) %></h2>
3
<% else %>
4
  <h2><%= l(:label_wiki_category) %>: <%= @category %></h2>
5
<% end %>
6

  
7
<% if @pages.empty? %>
8
  <p class="nodata"><%= l(:label_no_data) %></p>
9
<% end %>
10

  
11
<% content_for :sidebar do %>
12
  <%= render :partial => 'sidebar' %>
13
<% end %>
14

  
15
<% unless @pages.empty? %>
16
  <p>
17
    <ul>
18
      <% group = nil %>
19
      <% @pages.each do |page| %>
20
        <% if page.title[0,1].upcase != group %>
21
          </ul><h4><%= group = page.title[0,1].upcase %></h4><ul>
22
        <% end %>
23
        <li><%= link_to page.pretty_title, {:action => 'index', :page => page.title} %></li>
24
      <% end %>
25
    </ul>
26
  </p>
27
<% end %>
app/views/wiki/special_category_index.rhtml
1
<h2><%= l(:label_index_by_category) %></h2>
2

  
3
<% content_for :sidebar do %>
4
  <%= render :partial => 'sidebar' %>
5
<% end %>
6

  
7
<% unless @categories.empty? %>
8
  <p>
9
    <ul>
10
      <% group = nil %>
11
      <% @categories.each do |category| %>
12
        <% if category[0,1].upcase != group %>
13
          </ul><h4><%= group = category[0,1].upcase %></h4><ul>
14
        <% end %>
15
        <li><%= link_to category, {:action => 'special', :page => 'category', :category => category} %></li>
16
      <% end %>
17
    </ul>
18
  </p>
19
<% end %>
20

  
21
<h4><%= l(:label_special) %></h4>
22
<p>
23
  <ul>
24
    <li>
25
      <%= link_to l(:label_pages_without_category), {:action => 'special', :page => 'category', :category => 'None'} %>
26
    </li>
27
  </ul>
28
</p>
config/locales/bg.yml
448 448
  label_wiki_edit_plural: Wiki редакции
449 449
  label_wiki_page: Wiki page
450 450
  label_wiki_page_plural: Wiki pages
451
  label_wiki_category: Category
452
  label_wiki_category_plural: Categories
453
  label_special: Special
454
  label_pages_without_category: Pages without category
451 455
  label_index_by_title: Индекс
452 456
  label_index_by_date: Индекс по дата
457
  label_index_by_category: Index by category
453 458
  label_current_version: Текуща версия
454 459
  label_preview: Преглед
455 460
  label_feed_plural: Feeds
config/locales/bs.yml
597 597
  label_wiki_edit_plural: ispravke wiki-ja
598 598
  label_wiki_page: Wiki stranica
599 599
  label_wiki_page_plural: Wiki stranice
600
  label_wiki_category: Category
601
  label_wiki_category_plural: Categories
602
  label_special: Special
603
  label_pages_without_category: Pages without category
600 604
  label_index_by_title: Indeks prema naslovima
601 605
  label_index_by_date: Indeks po datumima
606
  label_index_by_category: Index by category
602 607
  label_current_version: Tekuća verzija
603 608
  label_preview: Pregled
604 609
  label_feed_plural: Feeds
config/locales/ca.yml
577 577
  label_wiki_edit_plural: Edicions wiki
578 578
  label_wiki_page: Pàgina wiki
579 579
  label_wiki_page_plural: Pàgines wiki
580
  label_wiki_category: Category
581
  label_wiki_category_plural: Categories
582
  label_special: Special
583
  label_pages_without_category: Pages without category
580 584
  label_index_by_title: Índex per títol
581 585
  label_index_by_date: Índex per data
586
  label_index_by_category: Index by category
582 587
  label_current_version: Versió actual
583 588
  label_preview: Previsualització
584 589
  label_feed_plural: Canals
config/locales/cs.yml
506 506
  label_wiki_edit_plural: Wiki úpravy
507 507
  label_wiki_page: Wiki stránka
508 508
  label_wiki_page_plural: Wiki stránky
509
  label_wiki_category: Category
510
  label_wiki_category_plural: Categories
511
  label_special: Special
512
  label_pages_without_category: Pages without category
509 513
  label_index_by_title: Index dle názvu
510 514
  label_index_by_date: Index dle data
515
  label_index_by_category: Index by category
511 516
  label_current_version: Aktuální verze
512 517
  label_preview: Náhled
513 518
  label_feed_plural: Příspěvky
config/locales/da.yml
517 517
  label_wiki_edit_plural: Wiki ændringer
518 518
  label_wiki_page: Wiki side
519 519
  label_wiki_page_plural: Wiki sider
520
  label_wiki_category: Category
521
  label_wiki_category_plural: Categories
522
  label_special: Special
523
  label_pages_without_category: Pages without category
520 524
  label_index_by_title: Indhold efter titel
521 525
  label_index_by_date: Indhold efter dato
526
  label_index_by_category: Index by category
522 527
  label_current_version: Nuværende version
523 528
  label_preview: Forhåndsvisning
524 529
  label_feed_plural: Feeds
config/locales/de.yml
592 592
  label_wiki_edit_plural: Wiki-Bearbeitungen
593 593
  label_wiki_page: Wiki-Seite
594 594
  label_wiki_page_plural: Wiki-Seiten
595
  label_wiki_category: Kategorie
596
  label_wiki_category_plural: Kategorien
597
  label_special: Speziell
598
  label_pages_without_category: Seiten ohne Kategorie
595 599
  label_index_by_title: Seiten nach Titel sortiert
596 600
  label_index_by_date: Seiten nach Datum sortiert
601
  label_index_by_category: Seiten nach Kategorie sortiert
597 602
  label_current_version: Gegenwärtige Version
598 603
  label_preview: Vorschau
599 604
  label_feed_plural: Feeds
config/locales/el.yml
595 595
  label_wiki_edit_plural: Επεξεργασία wiki
596 596
  label_wiki_page: Σελίδα Wiki
597 597
  label_wiki_page_plural: Σελίδες Wiki
598
  label_wiki_category: Category
599
  label_wiki_category_plural: Categories
600
  label_special: Special
601
  label_pages_without_category: Pages without category
598 602
  label_index_by_title: Δείκτης ανά τίτλο
599 603
  label_index_by_date: Δείκτης ανά ημερομηνία
604
  label_index_by_category: Index by category
600 605
  label_current_version: Τρέχουσα έκδοση
601 606
  label_preview: Προεπισκόπηση
602 607
  label_feed_plural: Feeds
config/locales/en.yml
594 594
  label_wiki_edit_plural: Wiki edits
595 595
  label_wiki_page: Wiki page
596 596
  label_wiki_page_plural: Wiki pages
597
  label_wiki_category: Category
598
  label_wiki_category_plural: Categories
599
  label_special: Special
600
  label_pages_without_category: Pages without category
597 601
  label_index_by_title: Index by title
598 602
  label_index_by_date: Index by date
603
  label_index_by_category: Index by category
599 604
  label_current_version: Current version
600 605
  label_preview: Preview
601 606
  label_feed_plural: Feeds
config/locales/es.yml
462 462
  label_incoming_emails: Correos entrantes
463 463
  label_index_by_date: Índice por fecha
464 464
  label_index_by_title: Índice por título
465
  label_index_by_category: Índice por categoría
465 466
  label_information: Información
466 467
  label_information_plural: Información
467 468
  label_integer: Número
......
647 648
  label_wiki_edit_plural: Wiki edicciones
648 649
  label_wiki_page: Wiki página
649 650
  label_wiki_page_plural: Wiki páginas
651
  label_wiki_category: Categoría
652
  label_wiki_category_plural: Categorías
653
  label_special: Especial
654
  label_pages_without_category: Páginas sin categoría
650 655
  label_workflow: Flujo de trabajo
651 656
  label_year: Año
652 657
  label_yesterday: ayer
config/locales/fi.yml
506 506
  label_wiki_edit_plural: Wiki muokkaukset
507 507
  label_wiki_page: Wiki sivu
508 508
  label_wiki_page_plural: Wiki sivut
509
  label_wiki_category: Category
510
  label_wiki_category_plural: Categories
511
  label_special: Special
512
  label_pages_without_category: Pages without category
509 513
  label_index_by_title: Hakemisto otsikoittain
510 514
  label_index_by_date: Hakemisto päivittäin
515
  label_index_by_category: Index by category
511 516
  label_current_version: Nykyinen versio
512 517
  label_preview: Esikatselu
513 518
  label_feed_plural: Syötteet
config/locales/fr.yml
611 611
  label_wiki_edit_plural: Révisions wiki
612 612
  label_wiki_page: Page wiki
613 613
  label_wiki_page_plural: Pages wiki
614
  label_wiki_category: Catégorie
615
  label_wiki_category_plural: Catégories
616
  label_special: Spécial
617
  label_pages_without_category: Pages sans catégorie
614 618
  label_index_by_title: Index par titre
615 619
  label_index_by_date: Index par date
620
  label_index_by_category: Index par catégorie
616 621
  label_current_version: Version actuelle
617 622
  label_preview: Prévisualisation
618 623
  label_feed_plural: Flux RSS
config/locales/gl.yml
441 441
  label_incoming_emails: Correos entrantes
442 442
  label_index_by_date: Índice por data
443 443
  label_index_by_title: Índice por título
444
  label_index_by_category: Index by category
444 445
  label_information: Información
445 446
  label_information_plural: Información
446 447
  label_integer: Número
......
626 627
  label_wiki_edit_plural: Wiki edicións
627 628
  label_wiki_page: Wiki páxina
628 629
  label_wiki_page_plural: Wiki páxinas
630
  label_wiki_category: Category
631
  label_wiki_category_plural: Categories
632
  label_special: Special
633
  label_pages_without_category: Pages without category
629 634
  label_workflow: Fluxo de traballo
630 635
  label_year: Ano
631 636
  label_yesterday: onte
config/locales/he.yml
463 463
  label_wiki_edit_plural: עריכות Wiki
464 464
  label_wiki_page: דף Wiki
465 465
  label_wiki_page_plural: דפי Wiki
466
  label_wiki_category: Category
467
  label_wiki_category_plural: Categories
468
  label_special: Special
469
  label_pages_without_category: Pages without category
466 470
  label_index_by_title: סדר על פי כותרת
467 471
  label_index_by_date: סדר על פי תאריך
472
  label_index_by_category: Index by category
468 473
  label_current_version: גירסא נוכאית
469 474
  label_preview: תצוגה מקדימה
470 475
  label_feed_plural: הזנות
config/locales/hu.yml
533 533
  label_wiki_edit_plural: Wiki szerkesztések
534 534
  label_wiki_page: Wiki oldal
535 535
  label_wiki_page_plural: Wiki oldalak
536
  label_wiki_category: Category
537
  label_wiki_category_plural: Categories
538
  label_special: Special
539
  label_pages_without_category: Pages without category
536 540
  label_index_by_title: Cím szerint indexelve
537 541
  label_index_by_date: Dátum szerint indexelve
542
  label_index_by_category: Index by category
538 543
  label_current_version: Jelenlegi verzió
539 544
  label_preview: Előnézet
540 545
  label_feed_plural: Visszajelzések
config/locales/it.yml
461 461
  label_wiki_edit_plural: Modfiche wiki
462 462
  label_wiki_page: Pagina Wiki
463 463
  label_wiki_page_plural: Pagine Wiki
464
  label_wiki_category: Category
465
  label_wiki_category_plural: Categories
466
  label_special: Special
467
  label_pages_without_category: Pages without category
464 468
  label_index_by_title: Ordina per titolo
465 469
  label_index_by_date: Ordina per data
470
  label_index_by_category: Index by category
466 471
  label_current_version: Versione corrente
467 472
  label_preview: Anteprima
468 473
  label_feed_plural: Feed
config/locales/ja.yml
624 624
  label_wiki_edit_plural: Wiki編集
625 625
  label_wiki_page: Wikiページ
626 626
  label_wiki_page_plural: Wikiページ
627
  label_wiki_category: Category
628
  label_wiki_category_plural: Categories
629
  label_special: Special
630
  label_pages_without_category: Pages without category
627 631
  label_index_by_title: 索引(名前順)
628 632
  label_index_by_date: 索引(日付順)
633
  label_index_by_category: Index by category
629 634
  label_current_version: 最新版
630 635
  label_preview: プレビュー
631 636
  label_feed_plural: フィード
config/locales/ko.yml
648 648
  label_wiki_edit_plural: 위키 편집
649 649
  label_wiki_page: 위키 페이지
650 650
  label_wiki_page_plural: 위키 페이지
651
  label_wiki_category: Category
652
  label_wiki_category_plural: Categories
653
  label_special: Special
654
  label_pages_without_category: Pages without category
651 655
  label_index_by_title: 제목별 색인
652 656
  label_index_by_date: 날짜별 색인
657
  label_index_by_category: Index by category
653 658
  label_current_version: 현재 버전
654 659
  label_preview: 미리보기
655 660
  label_feed_plural: 피드(Feeds)
config/locales/lt.yml
601 601
  label_wiki_edit_plural: Wiki redakcijos
602 602
  label_wiki_page: Wiki puslapis
603 603
  label_wiki_page_plural: Wiki puslapiai
604
  label_wiki_category: Category
605
  label_wiki_category_plural: Categories
606
  label_special: Special
607
  label_pages_without_category: Pages without category
604 608
  label_index_by_title: Indeksas prie pavadinimo
605 609
  label_index_by_date: Indeksas prie datos
610
  label_index_by_category: Index by category
606 611
  label_current_version: Einamoji versija
607 612
  label_preview: Peržiūra
608 613
  label_feed_plural: Įeitys(Feeds)
config/locales/nl.yml
403 403
  label_incoming_emails: Inkomende e-mail
404 404
  label_index_by_date: Indexeer op datum
405 405
  label_index_by_title: Indexeer op titel
406
  label_index_by_category: Index by category
406 407
  label_information: Informatie
407 408
  label_information_plural: Informatie
408 409
  label_integer: Integer
......
588 589
  label_wiki_edit_plural: Wiki edits
589 590
  label_wiki_page: Wikipagina
590 591
  label_wiki_page_plural: Wikipagina's
592
  label_wiki_category: Category
593
  label_wiki_category_plural: Categories
594
  label_special: Special
595
  label_pages_without_category: Pages without category
591 596
  label_workflow: Workflow
592 597
  label_year: Jaar
593 598
  label_yesterday: gisteren
config/locales/no.yml
506 506
  label_wiki_edit_plural: Wiki endringer
507 507
  label_wiki_page: Wiki-side
508 508
  label_wiki_page_plural: Wiki-sider
509
  label_wiki_category: Category
510
  label_wiki_category_plural: Categories
511
  label_special: Special
512
  label_pages_without_category: Pages without category
509 513
  label_index_by_title: Indekser etter tittel
510 514
  label_index_by_date: Indekser etter dato
515
  label_index_by_category: Index by category
511 516
  label_current_version: Gjeldende versjon
512 517
  label_preview: Forhåndsvis
513 518
  label_feed_plural: Feeder
config/locales/pl.yml
437 437
  label_incoming_emails: Przychodząca poczta elektroniczna
438 438
  label_index_by_date: Indeks wg daty
439 439
  label_index_by_title: Indeks
440
  label_index_by_category: Index by category
440 441
  label_information: Informacja
441 442
  label_information_plural: Informacje
442 443
  label_integer: Liczba całkowita
......
626 627
  label_wiki_edit_plural: Edycje wiki
627 628
  label_wiki_page: Strona wiki
628 629
  label_wiki_page_plural: Strony wiki
630
  label_wiki_category: Category
631
  label_wiki_category_plural: Categories
632
  label_special: Special
633
  label_pages_without_category: Pages without category
629 634
  label_workflow: Przepływ
630 635
  label_year: Rok
631 636
  label_yesterday: wczoraj
config/locales/pt-BR.yml
544 544
  label_wiki_edit_plural: Edições Wiki
545 545
  label_wiki_page: Página Wiki
546 546
  label_wiki_page_plural: páginas Wiki
547
  label_wiki_category: Category
548
  label_wiki_category_plural: Categories
549
  label_special: Special
550
  label_pages_without_category: Pages without category
547 551
  label_index_by_title: Índice por título
548 552
  label_index_by_date: Índice por data
553
  label_index_by_category: Index by category
549 554
  label_current_version: Versão atual
550 555
  label_preview: Pré-visualizar
551 556
  label_feed_plural: Feeds
config/locales/pt.yml
531 531
  label_wiki_edit_plural: Edições da Wiki
532 532
  label_wiki_page: Página da Wiki
533 533
  label_wiki_page_plural: Páginas da Wiki
534
  label_wiki_category: Category
535
  label_wiki_category_plural: Categories
536
  label_special: Special
537
  label_pages_without_category: Pages without category
534 538
  label_index_by_title: Índice por título
535 539
  label_index_by_date: Índice por data
540
  label_index_by_category: Index by category
536 541
  label_current_version: Versão actual
537 542
  label_preview: Pré-visualizar
538 543
  label_feed_plural: Feeds
config/locales/ro.yml
575 575
  label_wiki_edit_plural: Editări Wiki
576 576
  label_wiki_page: Pagină Wiki
577 577
  label_wiki_page_plural: Pagini Wiki
578
  label_wiki_category: Category
579
  label_wiki_category_plural: Categories
580
  label_special: Special
581
  label_pages_without_category: Pages without category
578 582
  label_index_by_title: Sortează după titlu
579 583
  label_index_by_date: Sortează după dată
584
  label_index_by_category: Index by category
580 585
  label_current_version: Versiunea curentă
581 586
  label_preview: Previzualizare
582 587
  label_feed_plural: Feed-uri
config/locales/ru.yml
505 505
  label_incoming_emails: Приём сообщений
506 506
  label_index_by_date: История страниц
507 507
  label_index_by_title: Оглавление
508
  label_index_by_category: Index by category
508 509
  label_information_plural: Информация
509 510
  label_information: Информация
510 511
  label_in_less_than: менее чем
......
699 700
  label_wiki_edit_plural: Wiki
700 701
  label_wiki_page: Страница Wiki
701 702
  label_wiki_page_plural: Страницы Wiki
703
  label_wiki_category: Category
704
  label_wiki_category_plural: Categories
705
  label_special: Special
706
  label_pages_without_category: Pages without category
702 707
  label_workflow: Последовательность действий
703 708
  label_x_closed_issues_abbr:
704 709
    zero:  0 закрыто
config/locales/sk.yml
504 504
  label_wiki_edit_plural: Wiki úpravy
505 505
  label_wiki_page: Wiki stránka
506 506
  label_wiki_page_plural: Wiki stránky
507
  label_wiki_category: Category
508
  label_wiki_category_plural: Categories
509
  label_special: Special
510
  label_pages_without_category: Pages without category
507 511
  label_index_by_title: Index podľa názvu
508 512
  label_index_by_date: Index podľa dátumu
513
  label_index_by_category: Index by category
509 514
  label_current_version: Aktuálna verzia
510 515
  label_preview: Náhľad
511 516
  label_feed_plural: Príspevky
config/locales/sl.yml
567 567
  label_wiki_edit_plural: Wiki urejanja
568 568
  label_wiki_page: Wiki stran
569 569
  label_wiki_page_plural: Wiki strani
570
  label_wiki_category: Category
571
  label_wiki_category_plural: Categories
572
  label_special: Special
573
  label_pages_without_category: Pages without category
570 574
  label_index_by_title: Razvrsti po naslovu
571 575
  label_index_by_date: Razvrsti po datumu
576
  label_index_by_category: Index by category
572 577
  label_current_version: Trenutna verzija
573 578
  label_preview: Predogled
574 579
  label_feed_plural: RSS viri
config/locales/sr.yml
479 479
  label_wiki_edit_plural: Wiki promene
480 480
  label_wiki_page: Wiki stranica
481 481
  label_wiki_page_plural: Wiki stranice
482
  label_wiki_category: Category
483
  label_wiki_category_plural: Categories
484
  label_special: Special
485
  label_pages_without_category: Pages without category
482 486
  label_index_by_title: Indeks po naslovima
483 487
  label_index_by_date: Indeks po datumu
488
  label_index_by_category: Index by category
484 489
  label_current_version: Trenutna verzija
485 490
  label_preview: Brzi pregled
486 491
  label_feed_plural: Feeds
config/locales/sv.yml
643 643
  label_wiki_edit_plural: Wikiändringar
644 644
  label_wiki_page: Wikisida
645 645
  label_wiki_page_plural: Wikisidor
646
  label_wiki_category: Category
647
  label_wiki_category_plural: Categories
648
  label_special: Special
649
  label_pages_without_category: Pages without category
646 650
  label_index_by_title: Innehåll efter titel
647 651
  label_index_by_date: Innehåll efter datum
652
  label_index_by_category: Index by category
648 653
  label_current_version: Nuvarande version
649 654
  label_preview: Förhandsgranska
650 655
  label_feed_plural: Feeds
config/locales/th.yml
504 504
  label_wiki_edit_plural: แก้ไข Wiki
505 505
  label_wiki_page: หน้า Wiki
506 506
  label_wiki_page_plural: หน้า Wiki
507
  label_wiki_category: Category
508
  label_wiki_category_plural: Categories
509
  label_special: Special
510
  label_pages_without_category: Pages without category
507 511
  label_index_by_title: เรียงตามชื่อเรื่อง
508 512
  label_index_by_date: เรียงตามวัน
513
  label_index_by_category: Index by category
509 514
  label_current_version: รุ่นปัจจุบัน
510 515
  label_preview: ตัวอย่างก่อนจัดเก็บ
511 516
  label_feed_plural: Feeds
config/locales/tr.yml
533 533
  label_wiki_edit_plural: Wiki düzenlemeleri
534 534
  label_wiki_page: Wiki sayfası
535 535
  label_wiki_page_plural: Wiki sayfaları
536
  label_wiki_category: Category
537
  label_wiki_category_plural: Categories
538
  label_special: Special
539
  label_pages_without_category: Pages without category
536 540
  label_index_by_title: Başlığa göre diz
537 541
  label_index_by_date: Tarihe göre diz
542
  label_index_by_category: Index by category
538 543
  label_current_version: Güncel versiyon
539 544
  label_preview: Önizleme
540 545
  label_feed_plural: Beslemeler
config/locales/uk.yml
464 464
  label_wiki_edit_plural: Редагування Wiki 
465 465
  label_wiki_page: Сторінка Wiki
466 466
  label_wiki_page_plural: Сторінки Wiki
467
  label_wiki_category: Category
468
  label_wiki_category_plural: Categories
469
  label_special: Special
470
  label_pages_without_category: Pages without category
467 471
  label_index_by_title: Індекс за назвою
468 472
  label_index_by_date: Індекс за датою
473
  label_index_by_category: Index by category
469 474
  label_current_version: Поточна версія
470 475
  label_preview: Попередній перегляд
471 476
  label_feed_plural: Подання
config/locales/vi.yml
576 576
  label_wiki_edit_plural: Thay đổi wiki
577 577
  label_wiki_page: Trang wiki
578 578
  label_wiki_page_plural: Trang wiki
579
  label_wiki_category: Category
580
  label_wiki_category_plural: Categories
581
  label_special: Special
582
  label_pages_without_category: Pages without category
579 583
  label_index_by_title: Danh sách theo tên
580 584
  label_index_by_date: Danh sách theo ngày
585
  label_index_by_category: Index by category
581 586
  label_current_version: Bản hiện tại
582 587
  label_preview: Xem trước
583 588
  label_feed_plural: Feeds
config/locales/zh-TW.yml
685 685
  label_wiki_edit_plural: Wiki 編輯
686 686
  label_wiki_page: Wiki 網頁
687 687
  label_wiki_page_plural: Wiki 網頁
688
  label_wiki_category: Category
689
  label_wiki_category_plural: Categories
690
  label_special: Special
691
  label_pages_without_category: Pages without category
688 692
  label_index_by_title: 依標題索引
689 693
  label_index_by_date: 依日期索引
694
  label_index_by_category: Index by category
690 695
  label_current_version: 現行版本
691 696
  label_preview: 預覽
692 697
  label_feed_plural: Feeds
config/locales/zh.yml
617 617
  label_wiki_edit_plural: Wiki 编辑记录
618 618
  label_wiki_page: Wiki 页面
619 619
  label_wiki_page_plural: Wiki 页面
620
  label_wiki_category: Category
621
  label_wiki_category_plural: Categories
622
  label_special: Special
623
  label_pages_without_category: Pages without category
620 624
  label_index_by_title: 按标题索引
621 625
  label_index_by_date: 按日期索引
626
  label_index_by_category: Index by category
622 627
  label_current_version: 当前版本
623 628
  label_preview: 预览
624 629
  label_feed_plural: Feeds
config/routes.rb
49 49
  map.connect 'projects/:id/wiki/destroy', :controller => 'wikis', :action => 'destroy', :conditions => {:method => :post}
50 50
  map.with_options :controller => 'wiki' do |wiki_routes|
51 51
    wiki_routes.with_options :conditions => {:method => :get} do |wiki_views|
52
      wiki_views.connect 'projects/:id/wiki/:page', :action => 'special', :page => /page_index|date_index|export/i
52
      wiki_views.connect 'projects/:id/wiki/:page', :action => 'special', :page => /page_index|date_index|category_index|export/i
53 53
      wiki_views.connect 'projects/:id/wiki/:page', :action => 'index', :page => nil
54 54
      wiki_views.connect 'projects/:id/wiki/:page/edit', :action => 'edit'
55 55
      wiki_views.connect 'projects/:id/wiki/:page/rename', :action => 'rename'
56 56
      wiki_views.connect 'projects/:id/wiki/:page/history', :action => 'history'
57 57
      wiki_views.connect 'projects/:id/wiki/:page/diff/:version/vs/:version_from', :action => 'diff'
58 58
      wiki_views.connect 'projects/:id/wiki/:page/annotate/:version', :action => 'annotate'
59
      wiki_views.connect 'projects/:id/wiki/category/:category', :action => 'special', :page => 'category'
59 60
    end
60 61
    
61 62
    wiki_routes.connect 'projects/:id/wiki/:page/:action', 
db/migrate/20091023203350_add_wiki_pages_categories.rb
1
class AddWikiPagesCategories < ActiveRecord::Migration
2
  def self.up
3
    add_column :wiki_pages, :categories, :string
4
  end
5

  
6
  def self.down
7
    remove_column :wiki_pages, :categories
8
  end
9
end
lib/redmine/wiki_formatting/macros.rb
116 116
        @included_wiki_pages.pop
117 117
        out
118 118
      end
119

  
120
      desc "Add the current wiki page to a category.\nExample: !{{category(Help)}}"
121
      macro :category do |obj, args|
122
        ''   # categories are listed in the sidebar
123
      end
124

  
125
      desc "Add the current wiki page to several categories.\nExample: !{{categories(Help, Snippets)}}"
126
      macro :categories do |obj, args|
127
        ''   # categories are listed in the sidebar
128
      end
129

  
130
      desc "Display a list of pages which belong to the specified category.\nExample: !{{pages_in_category(Help)}}"
131
      macro :pages_in_category do |obj, args|
132
        if !args.first.nil?
133
          content_tag :ul, :class => :pages_in_category  do
134
            @wiki.find_pages_in_category(args.first).map do |p|
135
              content_tag :li do
136
                link_to p.pretty_title, {:action => 'index', :page => p.title}
137
              end 
138
            end
139
          end
140
        end
141
      end
119 142
    end
120 143
  end
121 144
end
public/help/wiki_syntax.html
56 56
<tr><th></th><td>source:some/file</td><td><a href="#">source:some/file</a></td></tr>
57 57

  
58 58
<tr><th colspan="3">Inline images</th></tr>
59
<tr><th><img src="../images/jstoolbar/bt_img.png" style="border: 1px solid #bbb;" alt="Image" /></th><td>!<em>image_url</em>!</td><td></td></tr>
60
<tr><th></th><td>!<em>attached_image</em>!</td><td></td></tr>
59
<tr><th><img src="../images/jstoolbar/bt_img.png" style="border: 1px solid #bbb;" alt="Image" /></th><td colspan="2">!<em>image_url</em>!</td></tr>
60
<tr><th></th><td colspan="2">!<em>attached_image</em>!</td></tr>
61

  
62
<tr><th colspan="3">Assign to Page Categories</th></tr>
63
<tr><th></th><td colspan="2">{{category(My Category)}}</td></tr>
64
<tr><th></th><td colspan="2">{{categories(My Cat 1, My Cat 2)}}</td></tr>
61 65
</table>
62 66

  
63 67
<p><a href="wiki_syntax_detailed.html" onclick="window.open('wiki_syntax_detailed.html', '', ''); return false;">More Information</a></p>
public/help/wiki_syntax_detailed.html
206 206
<pre>
207 207
{{toc}} => left aligned toc
208 208
{{>toc}} => right aligned toc
209
</pre>
209
</pre>    
210 210

  
211 211
    <h2><a name="12" class="wiki-page"></a>Macros</h2>
212 212

  
......
243 243
<span class="no"><strong>10</strong></span> <span class="r">end</span>
244 244
</code>
245 245
</pre>
246

  
247
    <h2><a name="14" class="wiki-page"></a>Page Categories</h2>
248
    
249
    <p>To assign a page to one or more page categories, insert either of the following anywhere
250
    on the page:</p>
251

  
252
<pre>
253
{{cagetory(My Category)}}
254
{{categories(My Category 1, My Category 2)}}
255
</pre>
256

  
257
    <p>The above macros don't output anything, but if a page is assigned to one or more page
258
    categories, they are listed in the sidebar. Furthermore, these pages can be accessed using
259
    the "Index by category" in the sidebar.</p>
260
    
261
    <p>You can insert a link to a specific page category. Follow this link to get a list of all
262
    pages assigned to that page category.</p>
263

  
264
<pre>
265
[[category:My Category]]
266
</pre>
267

  
268
    <p>Or you can insert a list of pages assigned to a specific page category:</p>
269

  
270
<pre>
271
{{pages_in_category(My Category)}}
272
</pre>
273

  
246 274
</body>
247 275
</html>
test/fixtures/wiki_pages.yml
6 6
  wiki_id: 1
7 7
  protected: true
8 8
  parent_id: 
9
  categories: |Examples|Documentation|
9 10
wiki_pages_002: 
10 11
  created_on: 2007-03-08 00:18:07 +01:00
11 12
  title: Another_page
......
13 14
  wiki_id: 1
14 15
  protected: false
15 16
  parent_id: 
17
  categories: 
16 18
wiki_pages_003: 
17 19
  created_on: 2007-03-08 00:18:07 +01:00
18 20
  title: Start_page
......
20 22
  wiki_id: 2
21 23
  protected: false
22 24
  parent_id: 
25
  categories: 
23 26
wiki_pages_004: 
24 27
  created_on: 2007-03-08 00:18:07 +01:00
25 28
  title: Page_with_an_inline_image
......
27 30
  wiki_id: 1
28 31
  protected: false
29 32
  parent_id: 1
33
  categories: |Examples| 
30 34
wiki_pages_005: 
31 35
  created_on: 2007-03-08 00:18:07 +01:00
32 36
  title: Child_1
......
34 38
  wiki_id: 1
35 39
  protected: false
36 40
  parent_id: 2
41
  categories: |Examples| 
37 42
wiki_pages_006: 
38 43
  created_on: 2007-03-08 00:18:07 +01:00
39 44
  title: Child_2
......
41 46
  wiki_id: 1
42 47
  protected: false
43 48
  parent_id: 2
49
  categories: |Examples| 
44 50
  
test/functional/wiki_controller_test.rb
298 298
      :controller => 'wiki', :action => 'special', :id => '567', :page => 'date_index'
299 299
    )
300 300
    assert_routing(
301
      {:method => :get, :path => '/projects/567/wiki/category_index'},
302
      :controller => 'wiki', :action => 'special', :id => '567', :page => 'category_index'
303
    )
304
    assert_routing(
305
      {:method => :get, :path => '/projects/567/wiki/category/Test'},
306
      :controller => 'wiki', :action => 'special', :id => '567', :page => 'category', :category => 'Test'
307
    )    
308
    assert_routing(
301 309
      {:method => :get, :path => '/projects/567/wiki/export'},
302 310
      :controller => 'wiki', :action => 'special', :id => '567', :page => 'export'
303 311
    )
test/unit/helpers/application_helper_test.rb
226 226
      # project does not exist
227 227
      '[[unknowproject:Start]]' => '[[unknowproject:Start]]',
228 228
      '[[unknowproject:Start|Page title]]' => '[[unknowproject:Start|Page title]]',
229
      # categories
230
      '[[category:Test]]' => '<a href="/projects/ecookbook/wiki/category/Test">Test</a>',
231
      '[[category:Test|Text]]' => '<a href="/projects/ecookbook/wiki/category/Test">Text</a>',
232
      '[[ecookbook:category:Test]]' => '<a href="/projects/ecookbook/wiki/category/Test">Test</a>',
233
      '[[ecookbook:category:Test|Text]]' => '<a href="/projects/ecookbook/wiki/category/Test">Text</a>',
234
      '[[unknownproject:category:Test]]' => '[[unknownproject:category:Test]]',
235
      '[[unknownproject:category:Test|Text]]' => '[[unknownproject:category:Test|Text]]',
236
      '![[category:Test]]' => '[[category:Test]]',
229 237
    }
230 238
    @project = Project.find(1)
231 239
    to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
test/unit/wiki_content_test.rb
27 27
  
28 28
  def test_create
29 29
    page = WikiPage.new(:wiki => @wiki, :title => "Page")  
30
    page.content = WikiContent.new(:text => "Content text", :author => User.find(1), :comments => "My comment")
30
    page.content = WikiContent.new(:text => "{{category(Test)}}Content text", :author => User.find(1), :comments => "My comment")
31 31
    assert page.save
32 32
    page.reload
33 33
    
......
35 35
    assert_kind_of WikiContent, content
36 36
    assert_equal 1, content.version
37 37
    assert_equal 1, content.versions.length
38
    assert_equal "Content text", content.text
38
    assert_equal "{{category(Test)}}Content text", content.text
39
    assert_equal "|Test|", content.page.categories
39 40
    assert_equal "My comment", content.comments
40 41
    assert_equal User.find(1), content.author
41 42
    assert_equal content.text, content.versions.last.text
test/unit/wiki_test.rb
43 43
    assert_equal 'Page_title_with_CAPITALES', Wiki.titleize('page title with CAPITALES')
44 44
    assert_equal 'テスト', Wiki.titleize('テスト')
45 45
  end
46

  
47
  def test_upcase_first
48
    assert_equal 'Page title', Wiki.upcase_first('page title')
49
    assert_equal 'テスト', Wiki.titleize('テスト')
50
  end
51

  
52
  def test_find_categories
53
    @wiki = Wiki.find(1)
54
    assert_equal ['Examples', 'Documentation'], @wiki.find_all_categories
55
  end
56

  
57
  def test_find_pages_in_category
58
    @wiki = Wiki.find(1)
59
    assert_equal [1], @wiki.find_pages_in_category('Documentation').map {|c| c.id }.sort
60
    assert_equal [1, 4, 5, 6], @wiki.find_pages_in_category('Examples').map {|c| c.id }.sort
61
    assert_equal [2], @wiki.find_pages_in_category('None').map {|c| c.id }.sort
62
  end
46 63
end