~ubuntu-branches/ubuntu/natty/moin/natty-updates

« back to all changes in this revision

Viewing changes to MoinMoin/action/LikePages.py

  • Committer: Bazaar Package Importer
  • Author(s): Jonas Smedegaard
  • Date: 2008-06-22 21:17:13 UTC
  • mfrom: (0.9.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20080622211713-fpo2zrq3s5dfecxg
Tags: 1.7.0-3
Simplify /etc/moin/wikilist format: "USER URL" (drop unneeded middle
CONFIG_DIR that was wrongly advertised as DATA_DIR).  Make
moin-mass-migrate handle both formats and warn about deprecation of
the old one.

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
    with the same word as the current pagename. If only one matching
7
7
    page is found, that page is displayed directly.
8
8
 
9
 
    @copyright: (c) 2001 by Richard Jones <richard@bizarsoftware.com.au>
10
 
    @copyright: (c) 2001 by J�rgen Hermann <jh@web.de>
 
9
    @copyright: 2001 Richard Jones <richard@bizarsoftware.com.au>,
 
10
                2001 Juergen Hermann <jh@web.de>
11
11
    @license: GNU GPL, see COPYING for details.
12
12
"""
13
13
 
14
14
import re
15
15
 
 
16
from MoinMoin import config, wikiutil
16
17
from MoinMoin.support import difflib
17
 
from MoinMoin import config, wikiutil
18
18
from MoinMoin.Page import Page
19
19
 
20
20
 
24
24
 
25
25
    # Error?
26
26
    if isinstance(matches, (str, unicode)):
27
 
        Page(request, pagename).send_page(request, msg=matches)
 
27
        request.theme.add_msg(matches, "info")
 
28
        Page(request, pagename).send_page()
28
29
        return
29
30
 
30
31
    # No matches
31
32
    if not matches:
32
 
        Page(request, pagename).send_page(request,
33
 
            msg = _('No pages like "%s"!') % (pagename,))
 
33
        request.theme.add_msg(_('No pages like "%s"!') % (pagename, ), "error")
 
34
        Page(request, pagename).send_page()
34
35
        return
35
36
 
36
37
    # One match - display it
37
38
    if len(matches) == 1:
38
 
        Page(request, matches.keys()[0]).send_page(request,
39
 
            msg = _('Exactly one page like "%s" found, redirecting to page.') % (
40
 
            pagename,))
 
39
        request.theme.add_msg(_('Exactly one page like "%s" found, redirecting to page.') % (pagename, ), "info")
 
40
        Page(request, matches.keys()[0]).send_page()
41
41
        return
42
42
 
43
43
    # more than one match, list 'em
44
 
    request.http_headers()
 
44
    request.emit_http_headers()
45
45
 
46
46
    # This action generate data using the user language
47
47
    request.setContentLanguage(request.lang)
48
48
 
49
 
    wikiutil.send_title(request, _('Pages like "%s"') % (pagename),
50
 
                        pagename=pagename)
51
 
        
 
49
    request.theme.send_title(_('Pages like "%s"') % (pagename), pagename=pagename)
 
50
 
52
51
    # Start content - IMPORTANT - without content div, there is no
53
52
    # direction support!
54
53
    request.write(request.formatter.startContent("content"))
57
56
 
58
57
    # End content and send footer
59
58
    request.write(request.formatter.endContent())
60
 
    wikiutil.send_footer(request, pagename)
61
 
        
 
59
    request.theme.send_footer(pagename)
 
60
    request.theme.send_closing_html()
62
61
 
63
 
def findMatches(pagename, request, s_re=None, e_re=None,):
 
62
def findMatches(pagename, request, s_re=None, e_re=None):
64
63
    """ Find like pages
65
 
    
 
64
 
66
65
    @param pagename: name to match
67
66
    @param request: current reqeust
68
67
    @param s_re: start re for wiki matching
100
99
            # Stop after 10 matches
101
100
            if found == 10:
102
101
                break
103
 
    
 
102
 
104
103
    # Filter deleted pages or pages the user can't read from
105
104
    # matches. Order is important!
106
 
    for name in matches.keys():
 
105
    for name in matches.keys(): # we need .keys() because we modify the dict
107
106
        page = Page(request, name)
108
107
        if not (page.exists() and request.user.may.read(name)):
109
 
            del matches[name]    
 
108
            del matches[name]
110
109
 
111
110
    # Finally, merge both dicts
112
111
    matches.update(close_matches)
132
131
    @return: start, end, matches dict
133
132
    """
134
133
    if start_re is None:
135
 
        start_re=re.compile('([%s][%s]+)' % (config.chars_upper,
136
 
                                             config.chars_lower))
 
134
        start_re = re.compile('([%s][%s]+)' % (config.chars_upper,
 
135
                                               config.chars_lower))
137
136
    if end_re is None:
138
 
        end_re=re.compile('([%s][%s]+)$' % (config.chars_upper,
139
 
                                            config.chars_lower))
 
137
        end_re = re.compile('([%s][%s]+)$' % (config.chars_upper,
 
138
                                              config.chars_lower))
140
139
 
141
140
    # If we don't get results with wiki words matching, fall back to
142
141
    # simple first word and last word, using spaces.
145
144
    if match:
146
145
        start = match.group(1)
147
146
    else:
148
 
       start = words[0] 
149
 
        
 
147
        start = words[0]
 
148
 
150
149
    match = end_re.search(pagename)
151
150
    if match:
152
151
        end = match.group(1)
153
152
    else:
154
 
        end = words[-1] 
155
 
    
 
153
        end = words[-1]
 
154
 
156
155
    matches = {}
157
156
    subpage = pagename + '/'
158
157
 
202
201
    return matches
203
202
 
204
203
 
205
 
def showMatches(pagename, request, start, end, matches, show_count = True):
 
204
def showMatches(pagename, request, start, end, matches, show_count=True):
206
205
    keys = matches.keys()
207
206
    keys.sort()
208
207
    _showMatchGroup(request, matches, keys, 8, pagename, show_count)
209
208
    _showMatchGroup(request, matches, keys, 4, "%s/..." % pagename, show_count)
210
209
    _showMatchGroup(request, matches, keys, 3, "%s...%s" % (start, end), show_count)
211
 
    _showMatchGroup(request, matches, keys, 1, "%s..." % (start,), show_count)
212
 
    _showMatchGroup(request, matches, keys, 2, "...%s" % (end,), show_count)
213
 
 
214
 
 
215
 
def _showMatchGroup(request, matches, keys, match, title, show_count = True):
 
210
    _showMatchGroup(request, matches, keys, 1, "%s..." % (start, ), show_count)
 
211
    _showMatchGroup(request, matches, keys, 2, "...%s" % (end, ), show_count)
 
212
 
 
213
 
 
214
def _showMatchGroup(request, matches, keys, match, title, show_count=True):
216
215
    _ = request.getText
217
216
    matchcount = matches.values().count(match)
218
217
 
221
220
            # Render title line
222
221
            request.write(request.formatter.paragraph(1))
223
222
            request.write(request.formatter.strong(1))
224
 
            request.write(_('%(matchcount)d %(matches)s for "%(title)s"') % {
225
 
                'matchcount': matchcount,
226
 
                'matches': ' ' + (_('match'), _('matches'))[matchcount != 1],
227
 
                'title': wikiutil.escape(title)})
 
223
            request.write(request.formatter.text(
 
224
                _('%(matchcount)d %(matches)s for "%(title)s"') % {
 
225
                    'matchcount': matchcount,
 
226
                    'matches': ' ' + (_('match'), _('matches'))[matchcount != 1],
 
227
                    'title': title}))
228
228
            request.write(request.formatter.strong(0))
229
229
            request.write(request.formatter.paragraph(0))
230
230
 
233
233
        for key in keys:
234
234
            if matches[key] == match:
235
235
                request.write(request.formatter.listitem(1))
236
 
                request.write(request.formatter.pagelink(1, key))
 
236
                request.write(request.formatter.pagelink(1, key, generated=True))
237
237
                request.write(request.formatter.text(key))
238
 
                request.write(request.formatter.pagelink(0, key))
 
238
                request.write(request.formatter.pagelink(0, key, generated=True))
239
239
                request.write(request.formatter.listitem(0))
240
240
        request.write(request.formatter.bullet_list(0))
241
241