wiki:TracRedirect

Redirection for Trac

Purpose and Usage

The [[redirect(type:id)]] wiki macro provides redirect functionality for Trac with backlink support. It takes a qualified TracLink as argument, e.g. wiki:SandBox, source:README or ticket:123. Users with a JavaScript-enabled browser will get redirected to the page specified by this shortlink.

Download and Installation

For Trac 0.11

This version of the plugin works with Trac 0.11. It is available here (version 0.11.2, release 08/14/08):

Note: This version will not work with Trac 0.10!

For Trac 0.10

The TracRedirect macro has been converted into a plugin. Thanks to Michel Jouvin for doing the initial conversion!

The installation is very easy: Simply drop this Python egg into the plugin subdir of your project. Note: This requires Trac >= 0.9 and setuptools >= 0.6! The pre-packaged egg is for Python 2.4.

The source code is available, so you can build your own egg:

To enable the plugin, add this setting to your trac.ini file:

[components]
redirect.* = enabled

For more information about Trac plugins, see http://projects.edgewall.com/trac/wiki/TracPlugins.

For Trac 0.9

Download the redirect.py macro here and put it either in the global wiki-macros directory of your Trac installation (typically /usr/share/trac/wiki-macros) or into the wiki-macros subdirectory of your project.

Then add these lines to the templates/site_header.cs file within your project:

<?cs if:args.redirectedfrom ?>
<?cs set:chrome.nav.metanav.redirectedfrom =
  'Redirected from <a href="' + trac.href.wiki + '/' + args.redirectedfrom + '?redirect=no">' +
  args.redirectedfrom + '</a>' + ' (<a href="' + base_url + HTTP.PathInfo + '">hide</a>)' ?>
<?cs /if ?>

For Trac 0.8

You can download the latest version for Trac 0.8.x here. Put the redirect.py file in the global wiki-macros directory of your Trac installation (typically /usr/share/trac/wiki-macros).

Additionally, you need the following two patches in order to display a link on the target page of the redirection back to the alias page (e.g for editing the alias). When following the backlink, redirection is disabled.

  • templates/wiki.cs

     
    55<div id="ctxtnav" class="nav">
    66 <h2>Wiki Navigation</h2>
    77 <ul>
     8  <?cs if args.redirectedfrom ?>
     9   <li class="redirect">
     10    Redirected from:
     11    <a href="<?cs var:$trac.href.wiki ?>/<?cs var:args.redirectedfrom ?>?redirect=no">
     12     <?cs var:args.redirectedfrom ?></a>
     13    (<a href="<?cs var:args.page ?>">hide</a>)
     14   </li>
     15  <?cs /if ?>
     16
    817  <li><a href="<?cs var:$trac.href.wiki ?>">Start Page</a></li>
    918  <li><a href="<?cs var:$trac.href.wiki ?>/TitleIndex">Title Index</a></li>
    1019  <li><a href="<?cs var:$trac.href.wiki ?>/RecentChanges">Recent Changes</a></li>
  • htdocs/css/wiki.css

     
    5050.wiki-toc.trac-nav .edit a { color:blue; border-color:blue; }
    5151
     52/* Styles for Redirect */
     53.redirect {
     54  margin-bottom: 1em;
     55  color: #cccccc;
     56}
     57.redirect :link, .redirect :visited {
     58 color: #bb5555;
     59}

Feedback

Please send questions, bug-reports, suggestions, etc. per e-mail to either haui at haumacher dot de, or to thomas.moschny at gmx dot de.

Last modified 3 days ago Last modified on Apr 14, 2015 8:42:24 PM

Attachments (5)

Download all attachments as: .zip