#11455 closed enhancement (fixed)
TitleIndex Macro should also take relative prefixes
Reported by: | Owned by: | Peter Suter | |
---|---|---|---|
Priority: | normal | Milestone: | 1.1.2 |
Component: | wiki system | Version: | |
Severity: | normal | Keywords: | TitleIndex |
Cc: | Branch: | ||
Release Notes: |
Added support for the prefix in |
||
API Changes: | |||
Internal Changes: |
Description
The TitleIndex macro only takes the full path of a Wiki page.
For instance, if you are on Wiki page WikiStart:Top/Deeper/Deepest
and want to include a list of all subpages of Deepest
, you have to include [[TitleIndex(Top/Deeper/Deepest/)]]
in your page.
It would be great if you could also use [[TitleIndex(./)]]
to achieve the same.
Similarly, [[TitleIndex(../)]]
should give the same result as [[TitleIndex(Top/Deeper/)]]
Attachments (3)
Change History (13)
comment:1 by , 11 years ago
Keywords: | TitleIndex added |
---|---|
Milestone: | → 1.1.2 |
Owner: | set to |
Status: | new → assigned |
by , 11 years ago
Attachment: | T11455-relative-titleindex-prefix.patch added |
---|
by , 11 years ago
Attachment: | 20140310T002856.png added |
---|
follow-up: 4 comment:2 by , 11 years ago
comment:3 by , 11 years ago
Thanks for testing. You are of course correct on both accounts. I will attach an updated patch later.
by , 11 years ago
Attachment: | T11455-relative-titleindex-prefix-fixed-with-tests.patch added |
---|
follow-up: 5 comment:4 by , 11 years ago
Replying to jomae:
It is inconsistent between
[[TitleIndex(./)]]
and[[TitleIndex(SandBox/)]]
. Also, we should add unit tests for this feature.
This updated patch fixes the inconsistency ([[TitleIndex(./)]]
does not list the current wiki page anymore) and adds unit tests.
(The fix is changing _resolve_relative_name
:
-elif comp and comp != '.': +elif comp != '.':
It is not immediately obvious that this breaks no other callers, but I can not come up with a scenario where this change would affect the only other caller after pagename.rstrip('/')
and pagename.startswith(('./', '../')) or pagename in ('.', '..')
.)
comment:5 by , 11 years ago
(The fix is changing
_resolve_relative_name
:-elif comp and comp != '.': +elif comp != '.':It is not immediately obvious that this breaks no other callers, but I can not come up with a scenario where this change would affect the only other caller after
pagename.rstrip('/')
andpagename.startswith(('./', '../')) or pagename in ('.', '..')
.)
After the changes, in SandBox page,
- ..//WikiStart will be
WikiStart?
text - ../WikiStart will link to WikiStart page
Before the changes, both will link to WikiStart page.
But I think the patch is okay because page name doesn't have repeated-slashes.
Unit and functional tests pass on Python 2.5 - 2.7 with SQLite, PostgreSQL and MySQL on Linux.
comment:6 by , 11 years ago
Release Notes: | modified (diff) |
---|---|
Resolution: | → fixed |
Status: | assigned → closed |
Committed in [12584]. Thanks for reviewing and testing. I had not considered such "invalid" page names with repeated slashes.
follow-up: 8 comment:7 by , 11 years ago
How does the following documentation update look?
-
trac/wiki/macros.py
diff --git a/trac/wiki/macros.py b/trac/wiki/macros.py index cda7dba..9bee07c 100644
a b class TitleIndexMacro(WikiMacroBase): 84 84 """Insert an alphabetic list of all wiki pages into the output. 85 85 86 86 Accepts a prefix string as parameter: if provided, only pages with names 87 that start with the prefix are included in the resulting list. If this 88 parameter is omitted, all pages are listed. 89 If the prefix is specified, a second argument of value `hideprefix` 90 can be given as well, in order to remove that prefix from the output. 87 that start with the prefix are included in the resulting list. The 88 commonly-used relative-path notation is supported: a prefix string 89 starting with `./` will be relative to the current page, and parent pages 90 can be specified using `../`. If this parameter is omitted, all pages are 91 listed. If the prefix is specified, a second argument of value 92 `hideprefix` can be given as well, in order to remove that prefix from 93 the output. 91 94 92 95 Alternate `format` and `depth` named parameters can be specified: 93 96 - `format=compact`: The pages are displayed as comma-separated links.
comment:8 by , 11 years ago
Your proposed text sounds fine.
I didn't think a documentation update was necessary as it seemed just like a standard use of wiki:TracLinks#Relativelinks. But documenting it explicitly doesn't hurt.
More details that may or may not be obvious:
./
is probably the most common use case, but this is not restricted just to plain./
and../
. E.g. on TracDev one might use./ReleaseNotes/
. (More complex combinations like../../Wiki
and even./.././.././Wiki
also "work".)- These only work on wiki pages, while absolute prefixes could also be used here in a ticket comment for example.
comment:9 by , 10 years ago
Sorry for the delay. Documentation change committed to trunk in [13014].
comment:10 by , 10 years ago
Just FYI, the changes to TitleIndex macro in this ticket provide equivalent functionality to the old SubWiki macro (th:HierWikiPlugin). I've marked HierWikiplugin as deprecated since it doesn't work with at least Trac 1.0 and later.
The attached patch implements this functionality that I've been missing myself.