Skip to content

Commit 55ebb80

Browse files
committed
Merge branch 'release/1.1.0'
2 parents e039030 + 39bafc7 commit 55ebb80

File tree

6 files changed

+105
-37
lines changed

6 files changed

+105
-37
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
[![Maintainability](https://api.codeclimate.com/v1/badges/35932ef513dece9c304c/maintainability)](https://codeclimate.com/github/haru/redmine_wiki_extensions/maintainability)
55
[![Ask DeepWiki](https://deepwiki.com/badge.svg)](https://deepwiki.com/haru/redmine_wiki_extensions)
66
[![codecov](https://codecov.io/gh/haru/redmine_wiki_extensions/branch/develop/graph/badge.svg?token=8WUARY4BRK)](https://codecov.io/gh/haru/redmine_wiki_extensions)
7+
![Redmine](https://img.shields.io/badge/redmine->=6.0-blue?logo=redmine&logoColor=%23B32024&labelColor=f0f0f0&link=https%3A%2F%2Fwww.redmine.org)
78

89
A comprehensive Redmine plugin that extends wiki functionality with powerful macros, comments, tagging, voting, and enhanced formatting capabilities.
910

db/migrate/0014_add_index_tags.rb

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Wiki Extensions plugin for Redmine
2+
# Copyright (C) 2009-2017 Haruyuki Iida
3+
#
4+
# This program is free software; you can redistribute it and/or
5+
# modify it under the terms of the GNU General Public License
6+
# as published by the Free Software Foundation; either version 2
7+
# of the License, or (at your option) any later version.
8+
#
9+
# This program is distributed in the hope that it will be useful,
10+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
# GNU General Public License for more details.
13+
#
14+
# You should have received a copy of the GNU General Public License
15+
# along with this program; if not, write to the Free Software
16+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17+
class AddIndexTags < ActiveRecord::Migration[4.2]
18+
def self.up
19+
add_index :wiki_extensions_tags, :name
20+
add_index :wiki_extensions_tags, :project_id
21+
end
22+
23+
def self.down
24+
remove_index :wiki_extensions_tags, :name
25+
remove_index :wiki_extensions_tags, :project_id
26+
end
27+
end

init.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
author_url 'http://twitter.com/haru_iida'
4343
description 'This is a Wiki Extensions plugin for Redmine'
4444
url 'http://www.r-labs.org/projects/r-labs/wiki/Wiki_Extensions_en'
45-
version '1.0.2'
45+
version '1.1.0'
4646
requires_redmine :version_or_higher => '6.0.0'
4747

4848
project_module :wiki_extensions do

lib/wiki_extensions_div_macro.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ module WikiExtensionsDivMacro
2222
" !{{div_start_tag(id_name, class_name)}}"
2323
macro :div_start_tag do |obj, args|
2424
o = '<div>' if args.length == 0
25-
o = '<div id="' + args[0].strip + '">' if args.length == 1
26-
o = '<div id="' + args[0].strip + '" class="' + args[1].strip + '">' if args.length == 2
25+
o = '<div id="' + h(args[0].strip) + '">' if args.length == 1
26+
o = '<div id="' + h(args[0].strip) + '" class="' + h(args[1].strip) + '">' if args.length == 2
2727
o.html_safe
2828
end
2929
end

lib/wiki_extensions_footnote.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def WikiExtensionsFootnote.preview_page
3939

4040
o = ""
4141
o << word
42-
o << '<a href="#wiki_extensins_fn_' +"#{data[:footnotes].length}" + '" class="wiki_extensions_fn" title="' + description + '" name="wiki_extensins_fn_src_' +"#{data[:footnotes].length}" + '">'
42+
o << '<a href="#wiki_extensins_fn_' +"#{data[:footnotes].length}" + '" class="wiki_extensions_fn" title="' + h(description) + '" name="wiki_extensins_fn_src_' +"#{data[:footnotes].length}" + '">'
4343
o << "*#{data[:footnotes].length}"
4444
o << '</a>'
4545
return o.html_safe
@@ -60,7 +60,7 @@ def WikiExtensionsFootnote.preview_page
6060
cnt = 0
6161
data[:footnotes].each {|fn|
6262
cnt += 1
63-
o << '<li><span class="wiki_extensions_fn">'+ "*#{cnt}</span> " +'<a name="wiki_extensins_fn_' + "#{cnt}" + '" href="#wiki_extensins_fn_src_' + "#{cnt}" + '"' + ">#{fn['word']}</a>:#{fn['description']}</li>"
63+
o << '<li><span class="wiki_extensions_fn">'+ "*#{cnt}</span> " +'<a name="wiki_extensins_fn_' + "#{cnt}" + '" href="#wiki_extensins_fn_src_' + "#{cnt}" + '"' + ">#{fn['word']}</a>:#{h fn['description']}</li>"
6464
}
6565
o << '</ul>'
6666
o << '</div>'

lib/wiki_extensions_taggedpages_macro.rb

Lines changed: 72 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -20,55 +20,95 @@ module WikiExtensionsTaggedpagesMacro
2020
Redmine::WikiFormatting::Macros.register do
2121
desc "Displays pages that have specified tag.\n\n"+
2222
" !{{taggedpages(tagname)}}\n" +
23-
" !{{taggedpages(tagname, project)}}\n"
23+
" !{{taggedpages(tagname, tagname, project)}}\n" +
24+
" !{{taggedpages(tagname, tagname, project=all, operator=AND)}}\n" +
25+
" !{{taggedpages(tagname, tagname, project=proj1 proj2)}}"
2426
macro :taggedpages do |obj, args|
2527
return nil unless WikiExtensionsUtil.is_enabled?(@project)
2628
return nil unless WikiExtensionsUtil.tag_enabled?(@project)
2729

28-
return nil if args.length < 1
30+
return nil if args.empty?
31+
32+
args, options = extract_macro_options(args, :project, :operator)
33+
project_arg = options[:project]
34+
operator = options[:operator]
35+
36+
project_arg = project_arg.split if project_arg
37+
operator = "OR" if operator.nil?
38+
2939
tag_names = []
30-
if (args.length == 1)
40+
if args.length == 1
3141
tag_names << args[0].strip
32-
project = @project
42+
project_arg = [@project.identifier] if project_arg.nil?
3343
else
34-
project = Project.find_by_name(args.pop.strip)
35-
args.each{|arg|
44+
project_arg = [args.pop.strip] if project_arg.nil?
45+
args.each do |arg|
3646
tag_names << arg.strip
37-
}
38-
end
47+
end
48+
end
49+
50+
projects = []
51+
# projects fill with id's
52+
project_arg.each do |name|
53+
find = Project.find_by_identifier(name)
54+
find = Project.find_by_name(name) if find.nil?
55+
find = Project.find_by_id(name.to_i) if find.nil?
56+
projects << find.id if find
57+
end
58+
59+
# if no project was found
60+
if projects.empty?
61+
projects = [@project.id]
62+
# if last parameter was not a project, just a tag
63+
tag_names += project_arg if options.empty?
64+
end
65+
66+
# find tags from all projects
67+
if !project_arg.empty? && project_arg[0].is_a?(String) && (project_arg[0] == "all" || project_arg[0] == "*")
68+
# all projects AND IN tagnames
69+
tags = WikiExtensionsTag.where(:name => tag_names).order(:project_id)
70+
else
71+
# IN projects AND IN tagnames
72+
tags = WikiExtensionsTag.where(:project_id => projects).where(:name => tag_names).order(:project_id)
3973

40-
tagged_pages = []
41-
and_op = false
42-
if (tag_names.length > 1 and tag_names[0] == 'and')
43-
and_op = true
44-
tag_names.delete_at 0
4574
end
46-
first_time = true
47-
tag_names.each {|tag_name|
48-
tag = WikiExtensionsTag.where(:project_id => project.id).where(:name => tag_name).first
49-
if and_op
50-
if tag
51-
if first_time
52-
tagged_pages = tag.pages
53-
first_time = false
54-
else
55-
tagged_pages = tagged_pages & tag.pages
56-
end
57-
else
58-
tagged_pages = []
59-
end
75+
76+
tagged_pages = []
77+
tagged_pages_tmp = []
78+
last_project_id = 0
79+
80+
tags.each do |tag|
81+
# get pages from a tag
82+
curr_pages = tag.pages
83+
84+
# if project changes, than tmp_tagged_pages into result
85+
if !tagged_pages_tmp.empty? && last_project_id > 0 && last_project_id != tag.project_id
86+
# new project_id begins
87+
tagged_pages += tagged_pages_tmp
88+
tagged_pages_tmp = []
89+
end
90+
91+
if tagged_pages_tmp.empty? || operator == "OR"
92+
tagged_pages_tmp += curr_pages
6093
else
61-
tagged_pages = tagged_pages | tag.pages if tag
94+
# AND Parameter, adds pages who is in both lists
95+
ids_in_liste = curr_pages.map { |e| e[:id] }
96+
tagged_pages_tmp = tagged_pages_tmp.select { |e| ids_in_liste.include?(e[:id]) }
6297
end
63-
}
98+
99+
# save for next run
100+
last_project_id = tag.project_id
101+
end
102+
103+
# tagged_pages final result
104+
tagged_pages += tagged_pages_tmp
64105

65106
o = '<ul class="wikiext-taggedpages">'
66-
tagged_pages.uniq.sort{|a, b| a.pretty_title <=> b.pretty_title}.each{|page|
107+
tagged_pages.uniq.sort_by(&:pretty_title).each do |page|
67108
o << '<li>' + link_to(page.pretty_title, :controller => 'wiki', :action => 'show', :project_id => page.project, :id => page.title) + '</li>'
68-
}
109+
end
69110
o << '</ul>'
70111
return o.html_safe
71112
end
72113
end
73114
end
74-

0 commit comments

Comments
 (0)