changeset 734:bf2435e61f97

moved smileys from MoinMoin.config to theme, fixed smiley text_python caching bug
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Fri, 02 Jun 2006 16:58:56 +0200
parents 5b2029e9fc58
children e3c44dc8f488
files MoinMoin/config.py MoinMoin/converter/text_html_text_moin_wiki.py MoinMoin/formatter/text_docbook.py MoinMoin/formatter/text_html.py MoinMoin/formatter/text_python.py MoinMoin/macro/ShowSmileys.py MoinMoin/parser/text_moin_wiki.py MoinMoin/theme/__init__.py docs/CHANGES
diffstat 9 files changed, 73 insertions(+), 85 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/config.py	Wed May 31 12:04:43 2006 +0200
+++ b/MoinMoin/config.py	Fri Jun 02 16:58:56 2006 +0200
@@ -2,7 +2,7 @@
 """
     MoinMoin - site-wide configuration defaults (NOT per single wiki!)
 
-    @copyright: 2005 by Thomas Waldmann (MoinMoin:ThomasWaldmann)
+    @copyright: 2005-2006 by Thomas Waldmann (MoinMoin:ThomasWaldmann)
     @license: GNU GPL, see COPYING for details.
 """
 import re
@@ -13,8 +13,7 @@
 
 # Charset - we support only 'utf-8'. While older encodings might work,
 # we don't have the resources to test them, and there is no real
-# benefit for the user.
-# IMPORTANT: use only lowercase 'utf-8'!
+# benefit for the user. IMPORTANT: use only lowercase 'utf-8'!
 charset = 'utf-8'
 
 # Invalid characters - invisible characters that should not be in page
@@ -37,48 +36,8 @@
 umask = 0770
 url_schemas = []
 
-smileys = {
-    "X-(":  (15, 15, 0, "angry.png"),
-    ":D":   (15, 15, 0, "biggrin.png"),
-    "<:(":  (15, 15, 0, "frown.png"),
-    ":o":   (15, 15, 0, "redface.png"),
-    ":(":   (15, 15, 0, "sad.png"),
-    ":)":   (15, 15, 0, "smile.png"),
-    "B)":   (15, 15, 0, "smile2.png"),
-    ":))":  (15, 15, 0, "smile3.png"),
-    ";)":   (15, 15, 0, "smile4.png"),
-    "/!\\": (15, 15, 0, "alert.png"),
-    "<!>":  (15, 15, 0, "attention.png"),
-    "(!)":  (15, 15, 0, "idea.png"),
-
-    # copied 2001-11-16 from http://pikie.darktech.org/cgi/pikie.py?EmotIcon
-    ":-?":  (15, 15, 0, "tongue.png"),
-    ":\\":  (15, 15, 0, "ohwell.png"),
-    ">:>":  (15, 15, 0, "devil.png"),
-    "|)":   (15, 15, 0, "tired.png"),
-    
-    # some folks use noses in their emoticons
-    ":-(":  (15, 15, 0, "sad.png"),
-    ":-)":  (15, 15, 0, "smile.png"),
-    "B-)":  (15, 15, 0, "smile2.png"),
-    ":-))": (15, 15, 0, "smile3.png"),
-    ";-)":  (15, 15, 0, "smile4.png"),
-    "|-)":  (15, 15, 0, "tired.png"),
-    
-    # version 1.0
-    "(./)":  (20, 15, 0, "checkmark.png"),
-    "{OK}":  (14, 12, 0, "thumbs-up.png"),
-    "{X}":   (16, 16, 0, "icon-error.png"),
-    "{i}":   (16, 16, 0, "icon-info.png"),
-    "{1}":   (15, 13, 0, "prio1.png"),
-    "{2}":   (15, 13, 0, "prio2.png"),
-    "{3}":   (15, 13, 0, "prio3.png"),
-
-    # version 1.3.4 (stars)
-    # try {*}{*}{o}
-    "{*}":   (15, 15, 0, "star_on.png"),
-    "{o}":   (15, 15, 0, "star_off.png"),
-}
+smileys = (r"X-( :D <:( :o :( :) B) :)) ;) /!\ <!> (!) :-? :\ >:> |) " +
+           r":-( :-) B-) :-)) ;-) |-) (./) {OK} {X} {i} {1} {2} {3} {*} {o}").split()
 
 # unicode: set the char types (upper, lower, digits, spaces)
 from MoinMoin.util.chartypes import _chartypes
--- a/MoinMoin/converter/text_html_text_moin_wiki.py	Wed May 31 12:04:43 2006 +0200
+++ b/MoinMoin/converter/text_html_text_moin_wiki.py	Fri Jun 02 16:58:56 2006 +0200
@@ -1182,9 +1182,9 @@
         # Smiley
         elif src and (self.request.cfg.url_prefix in src or '../' in src) and "img/" in src: # XXX this is dirty!
             filename = src.split("/")[-1]
-            for name, data in config.smileys.iteritems():
-                if data[3] == filename:
-                    self.text.extend([self.white_space, name, self.white_space])
+            for markup, data in self.request.theme.icons.iteritems():
+                if data[1] == filename:
+                    self.text.extend([self.white_space, markup, self.white_space])
                     return
                 else:
                     pass #print name, data, filename, alt
@@ -1193,7 +1193,7 @@
         elif src and src.startswith("http") and wikiutil.isPicture(src): # matches http: and https: !
             self.text.extend([self.white_space, src, self.white_space])
         else:
-            raise ConvertError("Strange image src: '%s'" % src)
+            raise ConvertError("Strange image src: '%s' alt == '%r'" % (src, alt))
 
 
 def parse(request, text):
--- a/MoinMoin/formatter/text_docbook.py	Wed May 31 12:04:43 2006 +0200
+++ b/MoinMoin/formatter/text_docbook.py	Fri Jun 02 16:58:56 2006 +0200
@@ -451,9 +451,9 @@
         if kw.has_key('src'):
             image.setAttribute('fileref', kw['src'])
         if kw.has_key('width'):
-            image.setAttribute('width', kw['width'])
+            image.setAttribute('width', str(kw['width']))
         if kw.has_key('height'):
-            image.setAttribute('depth', kw['height'])
+            image.setAttribute('depth', str(kw['height']))
         imagewrap.appendChild(image)
 
         title = ''
@@ -472,11 +472,7 @@
         return ""        
  
     def smiley(self, text):
-        w, h, b, img = config.smileys[text.strip()]
-        href = img
-        if not href.startswith('/'):
-            href = self.request.theme.img_url(img)
-        return self.image(src=href, alt=text, width=str(w), height=str(h))
+        return self.request.theme.make_icon(text)
 
     def icon(self, type):
         return '' # self.request.theme.make_icon(type)
--- a/MoinMoin/formatter/text_html.py	Wed May 31 12:04:43 2006 +0200
+++ b/MoinMoin/formatter/text_html.py	Fri Jun 02 16:58:56 2006 +0200
@@ -1055,12 +1055,7 @@
     def icon(self, type):
         return self.request.theme.make_icon(type)
 
-    def smiley(self, text):
-        w, h, b, img = config.smileys[text.strip()]
-        href = img
-        if not href.startswith('/'):
-            href = self.request.theme.img_url(img)
-        return self.image(src=href, alt=text, width=str(w), height=str(h))
+    smiley = icon
 
     def image(self, src=None, **kw):
         """Creates an inline image with an <img> element.
--- a/MoinMoin/formatter/text_python.py	Wed May 31 12:04:43 2006 +0200
+++ b/MoinMoin/formatter/text_python.py	Fri Jun 02 16:58:56 2006 +0200
@@ -171,6 +171,8 @@
             return self.__insert_code('request.write(%s.icon(%r))' %
                                       (self.__formatter, type))
 
+    smiley = icon
+
     def macro(self, macro_obj, name, args):
         if self.__is_static(macro_obj.get_dependencies(name)):
             return macro_obj.execute(name, args)
--- a/MoinMoin/macro/ShowSmileys.py	Wed May 31 12:04:43 2006 +0200
+++ b/MoinMoin/macro/ShowSmileys.py	Fri Jun 02 16:58:56 2006 +0200
@@ -14,7 +14,7 @@
 from MoinMoin.util.dataset import TupleDataset, Column
 from MoinMoin.widget.browser import DataBrowserWidget
 
-COLUMNS = 3
+COLUMNS = 4
 
 Dependencies = ['user'] # different users have different themes and different user prefs (text/gfx)
 
@@ -29,28 +29,20 @@
         data.columns.extend([
             Column('markup', label=_('Markup')),
             Column('image', label=_('Display'), align='center'),
-            Column('filename', label=_('Filename')),
             Column('', label=''),
         ])
     data.columns[-1].hidden = 1
 
     # iterate over smileys, in groups of size COLUMNS
-    smileys = config.smileys.items()
-    smileys.sort()
+    smileys = config.smileys
     for idx in range(0, len(smileys), COLUMNS):
         row = []
         for off in range(COLUMNS):
             if idx+off < len(smileys):
-                markup, smiley = smileys[idx+off]
-                img = fmt.smiley(markup)
-                row.extend([
-                    fmt.code(1) + fmt.text(markup) + fmt.code(0),
-                    img,
-                    fmt.code(1) + smiley[3] + fmt.code(0),
-                    '',
-                ])
+                markup = smileys[idx+off]
+                row.extend([fmt.code(1) + fmt.text(markup) + fmt.code(0), fmt.smiley(markup), '', ])
             else:
-                row.extend(['&nbsp;'] * 4)
+                row.extend(['&nbsp;'] * 3)
         data.addRow(tuple(row))
 
     # display table
--- a/MoinMoin/parser/text_moin_wiki.py	Wed May 31 12:04:43 2006 +0200
+++ b/MoinMoin/parser/text_moin_wiki.py	Fri Jun 02 16:58:56 2006 +0200
@@ -96,7 +96,7 @@
         'dl_rule': dl_rule,
         'url_rule': url_rule,
         'word_rule': word_rule,
-        'smiley': u'|'.join(map(re.escape, config.smileys.keys()))}
+        'smiley': u'|'.join(map(re.escape, config.smileys))}
 
     # Don't start p before these 
     no_new_p_before = ("heading rule table tableZ tr td "
--- a/MoinMoin/theme/__init__.py	Wed May 31 12:04:43 2006 +0200
+++ b/MoinMoin/theme/__init__.py	Fri Jun 02 16:58:56 2006 +0200
@@ -64,6 +64,50 @@
         # search forms
         'searchbutton': ("[?]",                  "moin-search.png", 12, 12),
         'interwiki':  ("[%(wikitag)s]",          "moin-inter.png",  16, 16),
+    
+        # smileys (this is CONTENT, but good looking smileys depend on looking
+        # adapted to the theme background color and theme style in general)
+        #vvv    ==      vvv  this must be the same for GUI editor converter
+        'X-(':        ("X-(",                    'angry.png',       15, 15),
+        ':D':         (":D",                     'biggrin.png',     15, 15),
+        '<:(':        ("<:(",                    'frown.png',       15, 15),
+        ':o':         (":o",                     'redface.png',     15, 15),
+        ':(':         (":(",                     'sad.png',         15, 15),
+        ':)':         (":)",                     'smile.png',       15, 15),
+        'B)':         ("B)",                     'smile2.png',      15, 15),
+        ':))':        (":))",                    'smile3.png',      15, 15),
+        ';)':         (";)",                     'smile4.png',      15, 15),
+        '/!\\':       ("/!\\",                   'alert.png',       15, 15),
+        '<!>':        ("<!>",                    'attention.png',   15, 15),
+        '(!)':        ("(!)",                    'idea.png',        15, 15),
+
+        # copied 2001-11-16 from http://pikie.darktech.org/cgi/pikie.py?EmotIcon
+        ':-?':        (":-?",                    'tongue.png',      15, 15),
+        ':\\':        (":\\",                    'ohwell.png',      15, 15),
+        '>:>':        (">:>",                    'devil.png',       15, 15),
+        '|)':         ("|)",                     'tired.png',       15, 15),
+        
+        # some folks use noses in their emoticons
+        ':-(':        (":-(",                    'sad.png',         15, 15),
+        ':-)':        (":-)",                    'smile.png',       15, 15),
+        'B-)':        ("B-)",                    'smile2.png',      15, 15),
+        ':-))':       (":-))",                   'smile3.png',      15, 15),
+        ';-)':        (";-)",                    'smile4.png',      15, 15),
+        '|-)':        ("|-)",                    'tired.png',       15, 15),
+        
+        # version 1.0
+        '(./)':       ("(./)",                   'checkmark.png',   20, 15),
+        '{OK}':       ("{OK}",                   'thumbs-up.png',   14, 12),
+        '{X}':        ("{X}",                    'icon-error.png',  16, 16),
+        '{i}':        ("{i}",                    'icon-info.png',   16, 16),
+        '{1}':        ("{1}",                    'prio1.png',       15, 13),
+        '{2}':        ("{2}",                    'prio2.png',       15, 13),
+        '{3}':        ("{3}",                    'prio3.png',       15, 13),
+
+        # version 1.3.4 (stars)
+        # try {*}{*}{o}
+        '{*}':        ("{*}",                    'star_on.png',     15, 15),
+        '{o}':        ("{o}",                    'star_off.png',    15, 15),
     }
     del _
 
@@ -406,7 +450,7 @@
         @return: alt (unicode), href (string), width, height (int)
         """
         if icon in self.icons:
-            alt, filename, w, h = self.icons[icon]
+            alt, icon, w, h = self.icons[icon]
         else:
             # Create filenames to icon data mapping on first call, then
             # cache in class for next calls.
@@ -417,19 +461,18 @@
                 self.__class__.iconsByFile = d
 
             # Try to get icon data by file name
-            filename = icon.replace('.gif','.png')
-            if filename in self.iconsByFile:
-                alt, filename, w, h = self.iconsByFile[filename]
+            if icon in self.iconsByFile:
+                alt, icon, w, h = self.iconsByFile[icon]
             else:
-                alt, filename, w, h = '', icon, '', ''
+                alt, icon, w, h = '', icon, '', ''
                 
-        return alt, self.img_url(filename), w, h
+        return alt, self.img_url(icon), w, h
    
     def make_icon(self, icon, vars=None):
         """
         This is the central routine for making <img> tags for icons!
-        All icons stuff except the top left logo, smileys and search
-        field icons are handled here.
+        All icons stuff except the top left logo and search field icons are
+        handled here.
         
         @param icon: icon id (dict key)
         @param vars: ...
--- a/docs/CHANGES	Wed May 31 12:04:43 2006 +0200
+++ b/docs/CHANGES	Fri Jun 02 16:58:56 2006 +0200
@@ -67,6 +67,7 @@
       specify 'wiki', it will use a cache directory per wiki and if you specify
       'item', it will use a cache directory per item (== per page).
       Creating a CacheEntry without explicit scope is DEPRECATED.
+    * smileys moved from MoinMoin.config to MoinMoin.theme
 
   New Features:
 
@@ -85,7 +86,7 @@
     * fix mod_python attachment upload bug (thanks to Nick Phillips)
     * fix show_version to show it in the same way as SystemInfo
     * allow "-" in usernames (fixes "Invalid user name" msg)
-
+    * fixed smiley caching bug (smileys didn't change theme)
 
 Version 1.5.current:
   Developer notes: