Details

Applies to
1.5.0
Purpose
Links to long page names that are shortened with "..." will now show complete name in tooltip
Description

In various places (especially the navibar or pagetrail) links to pages with very long names are abbreviated or shortened with an ellipsis (...) replacing several characters in the middle of the page name. This can also happen with interwiki-links to other wikis. This shortening helps preserve the asthetic layout of the header area, but can result in user confusion if long page names are frequently encountered.

The shortening is performed by the theme class, of which moin's shipping themes do this (because of the common theme base class).

This patch will alter any links which are shortened so that the original full name is supplied as a title attribute (which for the HTML formatter will result in a tooltip displaying the complete name when the mouse hovers). Any links which are not shortened will not have any tooltip title set.

For interwiki-links (other than Self), the tooltip title has traditionally contained the name of the interwiki site. So this patch will, if it detects a shortened name, append the complete name to the tooltip rather than replacing it. -- DeronMeranda 2006-01-15 09:18:11

Patch

Be sure to see the note about the HTML escaping problem which appears after the code listing for this patch.

   1 --- MoinMoin/theme/__init__.py.orig	2006-01-01 16:37:12.000000000 -0500
   2 +++ MoinMoin/theme/__init__.py	2006-01-15 03:35:14.000000000 -0500
   3 @@ -275,9 +275,12 @@
   4              else:
   5                  page = Page(request, text)
   6              pagename = page.page_name
   7 -            title = page.split_title(request)
   8 -            title = self.shortenPagename(title)
   9 -            link = page.link_to(request, title)
  10 +            fulltitle = page.split_title(request)
  11 +            title = self.shortenPagename(fulltitle)
  12 +            if title != fulltitle:
  13 +                link = page.link_to(request, title, title=fulltitle)
  14 +            else:
  15 +                link = page.link_to(request, title)
  16  
  17  
  18          from MoinMoin import config
  19 @@ -384,9 +387,12 @@
  20  
  21          # Add current page at end
  22          if not current in found:
  23 -            title = d['page'].split_title(request)
  24 -            title = self.shortenPagename(title)
  25 -            link = d['page'].link_to(request, title)
  26 +            fulltitle = d['page'].split_title(request)
  27 +            title = self.shortenPagename(fulltitle)
  28 +            if title != fulltitle:
  29 +                link = d['page'].link_to(request, title, title=fulltitle)
  30 +            else:
  31 +                link = d['page'].link_to(request, title)
  32              cls = 'current'
  33              items.append(item % (cls, link))
  34  
  35 @@ -521,9 +527,13 @@
  36                          # links, using _ for spaces.
  37                          page = page.replace('_', ' ')
  38                          if request.cfg.interwikiname != interwiki:
  39 -                            link = (self.request.formatter.interwikilink(
  40 -                                True, interwiki, page) +
  41 -                                    self.shortenPagename(page) +
  42 +                            shortenedpage = self.shortenPagename(page)
  43 +                            if shortenedpage != page:
  44 +                                link = self.request.formatter.interwikilink(True, interwiki, page, title=page)
  45 +                            else:
  46 +                                link = self.request.formatter.interwikilink(True, interwiki, page)
  47 +
  48 +                            link = link + shortenedpage +
  49                                      self.request.formatter.interwikilink(False))
  50                              items.append('<li>%s</li>' % link)
  51                              continue
  52 @@ -533,9 +543,12 @@
  53                      except ValueError:
  54                          pass
  55                      page = Page(request, pagename)
  56 -                    title = page.split_title(request)
  57 -                    title = self.shortenPagename(title)
  58 -                    link = page.link_to(request, title)
  59 +                    fulltitle = page.split_title(request)
  60 +                    title = self.shortenPagename(fulltitle)
  61 +                    if title != fulltitle:
  62 +                        link = page.link_to(request, title, title=fulltitle)
  63 +                    else:
  64 +                        link = page.link_to(request, title)
  65                      items.append('<li>%s</li>' % link)
  66                  html = '''
  67  <ul id="pagetrail">

theme-init.py.diff

   1 --- MoinMoin/formatter/text_html.py.orig	2005-12-04 07:37:54.000000000 -0500
   2 +++ MoinMoin/formatter/text_html.py	2006-01-15 03:31:17.000000000 -0500
   3 @@ -254,7 +254,9 @@
   4                  html_class = 'badinterwiki'
   5              else:
   6                  html_class = 'interwiki'
   7 -            title = kw.get('title', wikitag)
   8 +            title = wikitag
   9 +            if kw.has_key('title'):
  10 +                title = title + ': ' + kw['title']
  11              return self.url(1, href, title=title, unescaped=0, css=html_class)
  12              # unescaped=1 was changed to 0 to make interwiki links with pages with umlauts (or other non-ascii) work
  13  
text_html.py.diff

You will also need to fix html-escaping bug

Note that the 1.5.0 HTML formatter has a bug in which the title attribute of the link is not properly escaped. So if you apply the above patches and any of your long page names has any reserved HTML character it may break your browser. So you should either:

  1. Also install the MoinMoinPatch/FormatterApiConsistencyForHtmlAttributes patch (but it's a big patch), or

  2. Manually patch your MoinMoin/formatter/text_html.py file to force the escaping.

The manual fix for the escaping is a one-line change in text_html.py in the def url(...) method:

- title = kw.get('title', None)
+ title = wikiutil.escape( kw.get('title',''), 1 )

Discussion

Plan


CategoryMoinMoinPatch

MoinMoin: MoinMoinPatch/ShortenedPageLinksExpandedInTooltip (last edited 2007-10-29 19:06:57 by localhost)