Attachment 'recentchanges.diff'

Download

   1 # HG changeset patch
   2 # User Roger Haase <crosseyedpenguin@yahoo.com>
   3 # Date 1282508807 25200
   4 # Node ID 7dc33afe0996ff9f074b352e76431b2a20b30874
   5 # Parent  7a83cc907f6855d1254a94ab731854b4554539a2
   6 make RecentChanges page name and comment fields breakable with use of zero-width spaces and soft hyphen word breaks
   7 
   8 diff -r 7a83cc907f68 -r 7dc33afe0996 MoinMoin/Page.py
   9 --- a/MoinMoin/Page.py	Fri Jul 23 09:23:59 2010 -0700
  10 +++ b/MoinMoin/Page.py	Sun Aug 22 13:26:47 2010 -0700
  11 @@ -707,15 +707,14 @@
  12                  wikiutil.version2timestamp(t))
  13          return result
  14  
  15 -    def split_title(self, force=0):
  16 -        """ Return a string with the page name split by spaces, if the user wants that.
  17 +    def split_title(self):
  18 +        """ Return a string with the page name split by spaces per user preferences.
  19  
  20 -        @param force: if != 0, then force splitting the page_name
  21          @rtype: unicode
  22 -        @return: pagename of this page, splitted into space separated words
  23 +        @return: pagename of this page, split into space separated words
  24          """
  25          request = self.request
  26 -        if not force and not request.user.wikiname_add_spaces:
  27 +        if not request.user.wikiname_add_spaces:
  28              return self.page_name
  29  
  30          # look for the end of words and the start of a new word,
  31 @@ -773,7 +772,7 @@
  32                                   formatter=getattr(self, 'formatter', None), **kw)
  33          return link
  34  
  35 -    def link_to(self, request, text=None, querystr=None, anchor=None, **kw):
  36 +    def link_to(self, request, text=None, querystr=None, anchor=None, no_escape=None, **kw):
  37          """ Return HTML markup that links to this page.
  38  
  39          See wikiutil.link_tag() for possible keyword parameters.
  40 @@ -790,7 +789,8 @@
  41          """
  42          if not text:
  43              text = self.split_title()
  44 -        text = wikiutil.escape(text)
  45 +        if not no_escape:
  46 +            text = wikiutil.escape(text)
  47  
  48          # Add css class for non existing page
  49          if not self.exists():
  50 diff -r 7a83cc907f68 -r 7dc33afe0996 MoinMoin/_tests/test_Page.py
  51 --- a/MoinMoin/_tests/test_Page.py	Fri Jul 23 09:23:59 2010 -0700
  52 +++ b/MoinMoin/_tests/test_Page.py	Sun Aug 22 13:26:47 2010 -0700
  53 @@ -40,10 +40,6 @@
  54          edit_info = page.edit_info()
  55          assert edit_info == {}
  56  
  57 -    def testSplitTitle(self):
  58 -        page = Page(self.request, u"FrontPage")
  59 -        assert page.split_title(force=True) == u'Front Page'
  60 -
  61      def testGetRevList(self):
  62          page = Page(self.request, u"FrontPage")
  63          assert 1 in page.getRevList()
  64 diff -r 7a83cc907f68 -r 7dc33afe0996 MoinMoin/macro/RecentChanges.py
  65 --- a/MoinMoin/macro/RecentChanges.py	Fri Jul 23 09:23:59 2010 -0700
  66 +++ b/MoinMoin/macro/RecentChanges.py	Sun Aug 22 13:26:47 2010 -0700
  67 @@ -5,13 +5,15 @@
  68      Parameter "ddiffs" by Ralf Zosel <ralf@zosel.com>, 04.12.2003.
  69  
  70      @copyright: 2000-2004 Juergen Hermann <jh@web.de>
  71 +    @copyright: 2010 Roger D. Haase, added zero-width spaces and soft hyphen word breaks
  72      @license: GNU GPL, see COPYING for details.
  73  """
  74 -import time
  75 +import time, re
  76  
  77  from MoinMoin import util, wikiutil
  78  from MoinMoin.Page import Page
  79  from MoinMoin.logfile import editlog
  80 +from MoinMoin.util.chartypes import chars_lower, chars_upper
  81  
  82  _DAYS_SELECTION = [1, 2, 3, 7, 14, 30, 60, 90]
  83  _MAX_DAYS = 7
  84 @@ -24,6 +26,36 @@
  85  
  86  Dependencies = ["time"] # ["user", "pages", "pageparams", "bookmark"]
  87  
  88 +def split_page_name(page_name):
  89 +    """ Return a string with the page name split by zero-width spaces.
  90 +
  91 +    @param page_name: the name of the page to be split
  92 +    @rtype: unicode
  93 +    @return: pagename of this page, split into space separated words
  94 +    """
  95 +    if len(page_name) <= _MAX_PAGENAME_LENGTH:
  96 +        return page_name
  97 +
  98 +    zero_width_space = "&#8203;"
  99 +    # treat "/" as a lower case character
 100 +    split_regex = re.compile('([%s])([%s])' % ("/" + chars_lower, chars_upper), re.UNICODE)
 101 +    split_by_spaces = page_name.split(" ")
 102 +    space_parts = []
 103 +    for split_by_space in split_by_spaces:
 104 +        split_by_camelcases = split_regex.sub(r'\1 \2', split_by_space).split(" ")
 105 +        camelcase_parts = []
 106 +        for split_by_camelcase in split_by_camelcases:
 107 +            if len(split_by_camelcase) > _MAX_PAGENAME_LENGTH:
 108 +                lowercase_parts = []
 109 +                while split_by_camelcase:
 110 +                    lowercase_parts.append(wikiutil.escape(split_by_camelcase[:_MAX_PAGENAME_LENGTH]))
 111 +                    split_by_camelcase = split_by_camelcase[_MAX_PAGENAME_LENGTH:]
 112 +                camelcase_parts.append(zero_width_space.join(lowercase_parts))
 113 +            else:
 114 +                camelcase_parts.append(wikiutil.escape(split_by_camelcase))
 115 +        space_parts.append(zero_width_space.join(camelcase_parts))
 116 +    return " ".join(space_parts)
 117 +
 118  def format_comment(request, line):
 119      comment = line.comment
 120      action = line.action
 121 @@ -89,11 +121,8 @@
 122          img = request.theme.make_icon('diffrc')
 123          html_link = page.link_to_raw(request, img, querystr={'action': 'diff'}, rel='nofollow')
 124  
 125 -    # print name of page, with a link to it
 126 -    force_split = len(page.page_name) > _MAX_PAGENAME_LENGTH
 127 -
 128      d['icon_html'] = html_link
 129 -    d['pagelink_html'] = page.link_to(request, text=page.split_title(force=force_split))
 130 +    d['pagelink_html'] = page.link_to(request, text=split_page_name(page.page_name), no_escape=1)
 131  
 132      # print time of change
 133      d['time_html'] = None
 134 @@ -128,7 +157,7 @@
 135      for idx in range(len(lines)):
 136          comment = format_comment(request, lines[idx])
 137          if comment:
 138 -            comments.append((idx+1, wikiutil.escape(comment)))
 139 +            comments.append((idx+1, comment))
 140  
 141      d['changecount'] = len(lines)
 142      d['comments'] = comments
 143 diff -r 7a83cc907f68 -r 7dc33afe0996 MoinMoin/macro/_tests/test_recentchanges.py
 144 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
 145 +++ b/MoinMoin/macro/_tests/test_recentchanges.py	Sun Aug 22 13:26:47 2010 -0700
 146 @@ -0,0 +1,45 @@
 147 +# -*- coding: iso-8859-1 -*-
 148 +"""
 149 +    MoinMoin - MoinMoin.macro.RecentChanges.py tests
 150 +
 151 +    @copyright: 2010 by Roger D. Haase
 152 +    @license: GNU GPL, see COPYING for details.
 153 +"""
 154 +
 155 +import py
 156 +
 157 +from MoinMoin.macro.RecentChanges import split_page_name, _MAX_PAGENAME_LENGTH, _MAX_COMMENT_LENGTH
 158 +# make_breakable is only used in RecentChanges macro, so test it here
 159 +from MoinMoin.wikiutil import make_breakable
 160 +
 161 +shy = "&shy;" # soft_hyphen
 162 +zws = "&#8203;" # zero_width_space
 163 +
 164 +class Test_Split_Page_Name:
 165 +
 166 +    def test_split_page_name(self):
 167 +        assert _MAX_PAGENAME_LENGTH == 15
 168 +        name = 'MyPageName'
 169 +        assert split_page_name(name) == name
 170 +        name = 'My Page Name'
 171 +        assert split_page_name(name) == name
 172 +        name = 'Page Name Over Fifteen Characters'
 173 +        assert split_page_name(name) == name
 174 +        name = 'Page%sName%sOver%sFifteen%sCharacters'
 175 +        assert split_page_name(name % ("", "", "", "")) == name % (zws, zws, zws, zws)
 176 +        name = 'pagenamewithnoc%samelcase'
 177 +        assert split_page_name(name % ("")) == name % (zws)
 178 +        name = 'pagenamewithcam%smelcase%sStarting%sAfter%sPosition15'
 179 +        assert split_page_name(name % ("", "", "", "")) == name % (zws, zws, zws, zws)
 180 +
 181 +class Test_Split_Comment:
 182 +
 183 +    def test_split_comment(self):
 184 +        maxlen = _MAX_COMMENT_LENGTH
 185 +        assert _MAX_COMMENT_LENGTH == 20
 186 +        comment = 'my comment'
 187 +        assert make_breakable(comment, maxlen) == comment
 188 +        comment = 'my comment that has more than twenty characters'
 189 +        assert make_breakable(comment, maxlen) == comment
 190 +        comment = 'mycommentthathasmore%sthantwentycharacters%swithoutanyspaces'
 191 +        assert make_breakable(comment % ("", ""), maxlen) == comment % (shy, shy)
 192 diff -r 7a83cc907f68 -r 7dc33afe0996 MoinMoin/web/static/htdocs/classic/css/msie.css
 193 --- a/MoinMoin/web/static/htdocs/classic/css/msie.css	Fri Jul 23 09:23:59 2010 -0700
 194 +++ b/MoinMoin/web/static/htdocs/classic/css/msie.css	Sun Aug 22 13:26:47 2010 -0700
 195 @@ -35,3 +35,7 @@
 196   */
 197  * html div#page, * html div#header { height: 0.001%; }
 198  
 199 +/* IE6 support for zero width spaces on RecentChanges page */
 200 +td.rcpagelink {
 201 +	font-family:  "Lucida Sans Unicode", "Arial Unicode MS", "Arial Unicode";
 202 +}
 203 diff -r 7a83cc907f68 -r 7dc33afe0996 MoinMoin/web/static/htdocs/modern/css/msie.css
 204 --- a/MoinMoin/web/static/htdocs/modern/css/msie.css	Fri Jul 23 09:23:59 2010 -0700
 205 +++ b/MoinMoin/web/static/htdocs/modern/css/msie.css	Sun Aug 22 13:26:47 2010 -0700
 206 @@ -35,3 +35,7 @@
 207   */
 208  * html div#page, * html div#header { height: 0.001%; }
 209  
 210 +/* IE6 support for zero width spaces on RecentChanges page */
 211 +td.rcpagelink {
 212 +	font-family:  "Lucida Sans Unicode", "Arial Unicode MS", "Arial Unicode";
 213 +}
 214 diff -r 7a83cc907f68 -r 7dc33afe0996 MoinMoin/web/static/htdocs/modernized/css/msie.css
 215 --- a/MoinMoin/web/static/htdocs/modernized/css/msie.css	Fri Jul 23 09:23:59 2010 -0700
 216 +++ b/MoinMoin/web/static/htdocs/modernized/css/msie.css	Sun Aug 22 13:26:47 2010 -0700
 217 @@ -35,3 +35,7 @@
 218   */
 219  * html div#page, * html div#header { height: 0.001%; }
 220  
 221 +/* IE6 support for zero width spaces on RecentChanges page */
 222 +td.rcpagelink {
 223 +	font-family:  "Lucida Sans Unicode", "Arial Unicode MS", "Arial Unicode";
 224 +}
 225 diff -r 7a83cc907f68 -r 7dc33afe0996 MoinMoin/web/static/htdocs/rightsidebar/css/msie.css
 226 --- a/MoinMoin/web/static/htdocs/rightsidebar/css/msie.css	Fri Jul 23 09:23:59 2010 -0700
 227 +++ b/MoinMoin/web/static/htdocs/rightsidebar/css/msie.css	Sun Aug 22 13:26:47 2010 -0700
 228 @@ -38,3 +38,7 @@
 229   */
 230  * html div#page, * html div#header { height: 0.001%; }
 231  
 232 +/* IE6 support for zero width spaces on RecentChanges page */
 233 +td.rcpagelink {
 234 +	font-family:  "Lucida Sans Unicode", "Arial Unicode MS", "Arial Unicode";
 235 +}
 236 diff -r 7a83cc907f68 -r 7dc33afe0996 MoinMoin/wikiutil.py
 237 --- a/MoinMoin/wikiutil.py	Fri Jul 23 09:23:59 2010 -0700
 238 +++ b/MoinMoin/wikiutil.py	Sun Aug 22 13:26:47 2010 -0700
 239 @@ -201,17 +201,21 @@
 240  
 241  
 242  def make_breakable(text, maxlen):
 243 -    """ make a text breakable by inserting spaces into nonbreakable parts
 244 +    """ make a text breakable by inserting soft hyphens into nonbreakable parts and escaping special chars
 245      """
 246 +    soft_hyphen = "&shy;"
 247      text = text.split(" ")
 248      newtext = []
 249 -    for part in text:
 250 -        if len(part) > maxlen:
 251 -            while part:
 252 -                newtext.append(part[:maxlen])
 253 -                part = part[maxlen:]
 254 +    for word in text:
 255 +        if len(word) > maxlen:
 256 +            part = []
 257 +            while word:
 258 +                part.append(escape(word[:maxlen]))
 259 +                word = word[maxlen:]
 260 +            newtext.append(soft_hyphen.join(part))
 261          else:
 262 -            newtext.append(part)
 263 +            word = escape(word)
 264 +            newtext.append(word)
 265      return " ".join(newtext)
 266  
 267  ########################################################################

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2010-08-19 16:16:12, 73.3 KB) [[attachment:Page.py]]
  • [get | view] (2010-08-19 19:29:46, 13.9 KB) [[attachment:RecentChanges.py]]
  • [get | view] (2010-08-22 20:41:59, 10.7 KB) [[attachment:recentchanges.diff]]
  • [get | view] (2010-08-19 16:16:54, 91.8 KB) [[attachment:wikiutil.py]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.