Commits

Thomas Waldmann  committed 6267829 Merge

merged

  • Participants
  • Parent commits 2086792, a1bebd2

Comments (0)

Files changed (12)

File MoinMoin/converter/_table.py

 from __future__ import absolute_import, division
 
 from MoinMoin.util.tree import moin_page
+from emeraldtree import ElementTree as ET
+
+WORDBREAK_LEN = 30
 
 class TableMixin(object):
     """
     Mixin to support building a DOM table.
     """
+    def add_numeric_class (self, cell, table_cell):
+        """
+        Add numeric class attribute if cell is numeric.
+        """
+        try:
+            float(cell)
+            table_cell.attrib[moin_page('class')] = 'moin-integer'
+        except:
+            pass
+
     def build_dom_table(self, rows, head=None, cls=None):
         """
         Build a DOM table with data from <rows>.
         if head is not None:
             table_head = moin_page.table_header()
             table_row = moin_page.table_row()
-            for cell in head:
-                table_cell = moin_page.table_cell(children=[cell, ])
+            for idx, cell in enumerate(head):
+                table_cell = moin_page.table_cell(children=[cell, ],)
+                if rows:
+                    # add "align: right" to heading cell if cell in first data row is numeric
+                    self.add_numeric_class(rows[0][idx], table_cell)
                 table_row.append(table_cell)
             table_head.append(table_row)
             table.append(table_head)
         for row in rows:
             table_row = moin_page.table_row()
             for cell in row:
-                table_cell = moin_page.table_cell(children=[cell, ])
+                if isinstance(cell, ET.Node) and isinstance(cell[0], unicode) and \
+                    len(cell[0].split()) == 1 and len(cell[0]) > WORDBREAK_LEN:
+                    # avoid destroying table layout by applying special styling to cells with long file name hyperlinks
+                    table_cell = moin_page.table_cell(children=[cell, ], attrib={moin_page.class_: 'moin-wordbreak'})
+                else:
+                    table_cell = moin_page.table_cell(children=[cell, ],)
+                    self.add_numeric_class(cell, table_cell)
                 table_row.append(table_cell)
             table_body.append(table_row)
         table.append(table_body)

File MoinMoin/converter/_tests/test_moinwiki_in.py

                 '<page><body><p>Text <emphasis>Emphasis</emphasis></p><p>Text</p></body></page>'),
             ("Text''''''Text''''",
                 '<page><body><p>TextText</p></body></page>'),
+            ("''italic '''strongitalic ''''' normal",
+                '<page><body><p><emphasis>italic <strong>strongitalic </strong></emphasis> normal</p></body></page>'),
+            ("'''strong '''''italic '''strongitalic''''' normal",
+                '<page><body><p><strong>strong </strong><emphasis>italic <strong>strongitalic</strong></emphasis> normal</p></body></page>'),
         ]
         for i in data:
             yield (self.do, ) + i
                 '<page><body><p><span font-size="120%">larger</span></p></body></page>'),
             ("--(strike through)--",
                 '<page><body><p><span text-decoration="line-through">strike through</span></p></body></page>'),
+            ("normal ~+big __underline__ big+~ normal",
+                '<page><body><p>normal <span font-size="120%">big <span text-decoration="underline">underline</span> big</span> normal</p></body></page>'),
+            ("/* normal __underline__ normal */",
+                '<page><body><p><span class="comment">normal <span text-decoration="underline">underline</span> normal</span></p></body></page>'),
             (u'&quot;',
                 '<page><body><p>"</p></body></page>'),
             (u'&#34;',

File MoinMoin/converter/_util.py

         if elem:
             self.top_append(elem)
 
-    def top_check(self, *names):
+    def top_check(self, *names, **kwargs):
         """
-        Checks if the name of the top of the stack matches the parameters.
+        Check if the top of the stack name and attrib matches the parameters.
         """
-        return self._list[-1].name in names
+        attrib = kwargs.get('attrib', {})
+        return self._list[-1].name in names and set(attrib.items()).issubset(self._list[-1].elem.attrib.items())

File MoinMoin/converter/archive_in.py

         return cls()
 
     def process_name(self, member_name):
+        name = unicode(member_name, 'utf-8')
         attrib = {
-            xlink.href: Iri(scheme='wiki', authority='', path='/'+self.item_name, query=u'do=get&member={0}'.format(member_name)),
+            xlink.href: Iri(scheme='wiki', authority='', path='/'+self.item_name, query=u'do=get&member={0}'.format(name)),
         }
-        return moin_page.a(attrib=attrib, children=[member_name, ])
+        return moin_page.a(attrib=attrib, children=[name, ])
 
     def process_datetime(self, dt):
-        return dt.isoformat()
+        return unicode(dt.isoformat(' '))
 
     def process_size(self, size):
         return unicode(size)
                          self.process_datetime(dt),
                          self.process_name(name),
                         ) for size, dt, name in contents]
-            table = self.build_dom_table(contents, head=[_("Size"), _("Date"), _("Name")], cls='zebra')
+            table = self.build_dom_table(contents, head=[_("Size"), _("Timestamp"), _("Name")], cls='zebra')
             body = moin_page.body(children=(table, ))
             return moin_page.page(children=(body, ))
         except ArchiveException as err:
             rows = []
             tf = tarfile.open(fileobj=fileobj, mode='r')
             for tinfo in tf.getmembers():
-                rows.append((
-                    tinfo.size,
-                    datetime.utcfromtimestamp(tinfo.mtime),
-                    tinfo.name,
-                ))
+                if tinfo.isfile():
+                    # display only normal files, not directories
+                    rows.append((
+                        tinfo.size,
+                        datetime.utcfromtimestamp(tinfo.mtime),
+                        tinfo.name,
+                    ))
             return rows
         except tarfile.TarError as err:
             raise ArchiveException(str(err))
             rows = []
             zf = zipfile.ZipFile(fileobj, mode='r')
             for zinfo in zf.filelist:
-                rows.append((
-                    zinfo.file_size,
-                    datetime(*zinfo.date_time), # y,m,d,h,m,s
-                    zinfo.filename,
-                ))
+                if not (zinfo.file_size == 0 and zinfo.filename.endswith('/')):
+                    # display only normal files, not directories
+                    rows.append((
+                        zinfo.file_size,
+                        datetime(*zinfo.date_time), # y,m,d,h,m,s
+                        zinfo.filename,
+                    ))
             return rows
         except (RuntimeError, zipfile.BadZipfile) as err:
             # RuntimeError is raised by zipfile stdlib module in case of

File MoinMoin/converter/moinwiki_in.py

                 else:
                     stack.push(moin_page.strong())
             elif stack.top_check('strong'):
-                if stack.top_check('strong'):
+                stack.pop()
+                if stack.top_check('emphasis'):
                     stack.pop()
                 else:
-                    stack.push(moin_page.strong())
+                    stack.push(moin_page.emphasis())
             else:
                 if len(emphstrong_follow) == 3:
                     stack.push(moin_page.emphasis())
     """
 
     def inline_underline_repl(self, stack, underline):
-        if not stack.top_check('span'):
-            attrib = {moin_page.text_decoration: 'underline'}
+        attrib = {moin_page.text_decoration: 'underline'}
+        if stack.top_check('span', attrib=attrib):
+            stack.pop()
+        else:
             stack.push(moin_page.span(attrib=attrib))
-        else:
-            stack.pop()
 
     inline_link = r"""
         (?P<link>

File MoinMoin/mail/sendmail.py

     from email.Utils import formatdate, make_msgid
 
     cfg = app.cfg
+    if not cfg.mail_enabled:
+        return (0, _("Contact administrator: cannot send password recovery e-mail because mail configuration is incomplete."))
     mail_from = mail_from or cfg.mail_from
 
     logging.debug("send mail, from: {0!r}, subj: {1!r}".format(mail_from, subject))

File MoinMoin/templates/common.js

 $(document).ready(selected_link);
 
 
-// Insert Zero-Width-Space characters into long text strings of textNode elements.  Executed on page load.
-// Firefox does not support CSS with {word-wrap: break-word;} within tables.
-// As a result, Firefox may display tables with long urls or page names as very wide tables.
-// This function alters table cells by inserting a zero-width-space into long text strings after every 5 characters.
-// The moin-wordbreak class is intended for use on TD elements, but may be used on TABLE, TR, THEAD, TBODY, or TFOOT.
-function moinFirefoxWordBreak() {
-    "use strict";
-    // TODO:  Test for browser version when/if a future Firefox supports break-word within tables.
-    if (!$.browser.mozilla) {
-        return;
-    }
-    var child, words, parents, i, j;
-    // Only textNodes are of interest, but there is no way to select them directly.
-    // Select all elements with the moin-wordbreak class and add all selectable descendants of those elements.
-    // Then search for children that are textNodes; TDs or THs and elements descended from them are likely parents of textNodes.
-    parents = $(".moin-wordbreak").add(".moin-wordbreak *");
-    for (i = 0; i < parents.length; i += 1) {
-        child = parents[i].firstChild;
-        while (child) {
-            if (child.nodeType === 3) {
-                words = child.textContent.split(" ");
-                for (j = 0; j < words.length; j += 1) {
-                    // \u200B denotes a zero-width-space character (for easy testing, replace with a visible character like Q)
-                    words[j] = words[j].replace(/(.{5})/g, "$1\u200B");
-                }
-                child.textContent = words.join(" ");
-            }
-            child = child.nextSibling;
-        }
-    }
-}
-$(moinFirefoxWordBreak);
-
-
-
 // toggleComments is executed when user clicks a Comments button and conditionally on dom ready.
 var pageComments = null; // will hold list of elements with class "comment"
 function toggleComments() {

File MoinMoin/themes/foobar/static/css/common.css

 .moin-permalink{display:none}
 sub{vertical-align:sub}
 sup{vertical-align:super}
+ins{background-color:inherit;text-decoration:underline}
 .moin-big{font-size:1.17em}
 .moin-small{font-size:.83em}
 .moin-integer{text-align:right;padding-right:1em;width:2%}

File MoinMoin/themes/foobar/static/css/stylus/main.styl

     vertical-align sub
 sup
     vertical-align super
+ins
+    background-color inherit // needed for "/* __My Comment__ */"
+    text-decoration underline
 .moin-big
     font-size 1.17em
 .moin-small

File MoinMoin/themes/modernized/static/css/common.css

 p{margin:1em 0;font-size:1em;line-height:1.3em}
 sub{vertical-align:sub}
 sup{vertical-align:super}
-ins{background-color:#fff;text-decoration:underline}
+ins{background-color:inherit;text-decoration:underline}
 .moin-big{font-size:1.17em}
 .moin-small{font-size:.83em}
 .moin-integer{text-align:right;padding-right:1em;width:2%}

File MoinMoin/themes/modernized/static/css/stylus/main.styl

     vertical-align super
 
 ins
-    background-color page_color
+    background-color inherit // needed for "/* __My Comment__ */"
     text-decoration underline
 
 .moin-big

File MoinMoin/user.py

         try:
             password_correct, recomputed_hash = pwd_context.verify_and_update(password, pw_hash)
         except (ValueError, TypeError) as err:
-            logging.error('in user profile %r, verifying the passlib pw hash raised an Exception [%s]' % (self.id, str(err)))
+            logging.error('in user profile %r, verifying the passlib pw hash raised an Exception [%s]' % (self.name, str(err)))
         else:
             if recomputed_hash is not None:
                 data[ENC_PASSWORD] = recomputed_hash