Edgewall Software
Modify

Opened 10 years ago

Closed 10 years ago

Last modified 9 years ago

#11455 closed enhancement (fixed)

TitleIndex Macro should also take relative prefixes

Reported by: glinders@… 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 TitleIndex macro to be resolved relative to current wiki page. (E.g. [[TitleIndex(./)]] lists all subpages.)

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)

T11455-relative-titleindex-prefix.patch (1.9 KB ) - added by Peter Suter 10 years ago.
20140310T002856.png (4.5 KB ) - added by Jun Omae 10 years ago.
T11455-relative-titleindex-prefix-fixed-with-tests.patch (5.8 KB ) - added by Peter Suter 10 years ago.

Download all attachments as: .zip

Change History (13)

comment:1 by Peter Suter, 10 years ago

Keywords: TitleIndex added
Milestone: 1.1.2
Owner: set to Peter Suter
Status: newassigned

The attached patch implements this functionality that I've been missing myself.

by Peter Suter, 10 years ago

by Jun Omae, 10 years ago

Attachment: 20140310T002856.png added

comment:2 by Jun Omae, 10 years ago

I tried the patch. It is inconsistent between [[TitleIndex(./)]] and [[TitleIndex(SandBox/)]].

Also, we should add unit tests for this feature.

comment:3 by Peter Suter, 10 years ago

Thanks for testing. You are of course correct on both accounts. I will attach an updated patch later.

in reply to:  2 ; comment:4 by Peter Suter, 10 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 ('.', '..').)

in reply to:  4 comment:5 by Jun Omae, 10 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('/') and pagename.startswith(('./', '../')) or pagename in ('.', '..').)

After the changes, in SandBox 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 Peter Suter, 10 years ago

Release Notes: modified (diff)
Resolution: fixed
Status: assignedclosed

Committed in [12584]. Thanks for reviewing and testing. I had not considered such "invalid" page names with repeated slashes.

comment:7 by Ryan J Ollos, 10 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):  
    8484    """Insert an alphabetic list of all wiki pages into the output.
    8585
    8686    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.
    9194
    9295    Alternate `format` and `depth` named parameters can be specified:
    9396     - `format=compact`: The pages are displayed as comma-separated links.

in reply to:  7 comment:8 by Peter Suter, 10 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 Ryan J Ollos, 10 years ago

Sorry for the delay. Documentation change committed to trunk in [13014].

comment:10 by Ryan J Ollos, 9 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.

Last edited 9 years ago by Ryan J Ollos (previous) (diff)

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Peter Suter.
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from Peter Suter to the specified user.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.