Mercurial > moin > 1.9
annotate MoinMoin/macro/__init__.py @ 2538:070294763d3e
clean up parser argument handling, allow tuples for choices
author | Johannes Berg <johannes AT sipsolutions DOT net> |
---|---|
date | Mon, 23 Jul 2007 19:34:40 +0200 |
parents | 72a31f09d5a1 |
children | fa4252cb4077 |
rev | line source |
---|---|
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
1 # -*- coding: iso-8859-1 -*- |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
2 """ |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
3 MoinMoin - Macro Implementation |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
4 |
657
016a8a3ef354
wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
636
diff
changeset
|
5 These macros are used by the wiki parser module to implement complex |
016a8a3ef354
wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
636
diff
changeset
|
6 and/or dynamic page content. |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
7 |
635
9e17ec23650c
moved wikimacro.py to macro/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
615
diff
changeset
|
8 The canonical interface to plugin macros is their execute() function, |
9e17ec23650c
moved wikimacro.py to macro/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
615
diff
changeset
|
9 which gets passed an instance of the Macro class. Such an instance |
9e17ec23650c
moved wikimacro.py to macro/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
615
diff
changeset
|
10 has the four members parser, formatter, form and request. |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
11 |
635
9e17ec23650c
moved wikimacro.py to macro/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
615
diff
changeset
|
12 Using "form" directly is deprecated and should be replaced by "request.form". |
9e17ec23650c
moved wikimacro.py to macro/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
615
diff
changeset
|
13 |
1918
bb2e053067fb
fixing copyright headers: remove umlauts (encoding troubles), make epydoc compatible, reformat
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1870
diff
changeset
|
14 @copyright: 2000-2004 Juergen Hermann <jh@web.de>, |
2515
41bc022c2160
use new arg parser for buitlin macros
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2513
diff
changeset
|
15 2006-2007 MoinMoin:ThomasWaldmann, |
41bc022c2160
use new arg parser for buitlin macros
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2513
diff
changeset
|
16 2007 MoinMoin:JohannesBerg |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
17 @license: GNU GPL, see COPYING for details. |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
18 """ |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
19 |
635
9e17ec23650c
moved wikimacro.py to macro/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
615
diff
changeset
|
20 from MoinMoin.util import pysupport |
1133
db56bd53fc32
cleanup plugin related code / attributes, remove unused stuff
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1001
diff
changeset
|
21 modules = pysupport.getPackageModules(__file__) |
635
9e17ec23650c
moved wikimacro.py to macro/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
615
diff
changeset
|
22 |
510
e1990b501b22
human readable SystemInfo, added disk usage
Thomas Waldmann <tw@waldmann-edv.de>
parents:
413
diff
changeset
|
23 import re, time, os |
635
9e17ec23650c
moved wikimacro.py to macro/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
615
diff
changeset
|
24 from MoinMoin import action, config, util |
636
b77ab6ea0c18
move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
635
diff
changeset
|
25 from MoinMoin import wikiutil, i18n |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
26 from MoinMoin.Page import Page |
2529
df375ab9fbde
automatically convert macro args with defaults to the default's type
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2523
diff
changeset
|
27 from inspect import getargspec |
df375ab9fbde
automatically convert macro args with defaults to the default's type
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2523
diff
changeset
|
28 |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
29 |
2521
b4118a77105d
externalize PageCount macro
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2520
diff
changeset
|
30 names = ["TitleSearch", "WordIndex", "TitleIndex", "GoTo", |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
31 # Macros with arguments |
2521
b4118a77105d
externalize PageCount macro
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2520
diff
changeset
|
32 "Icon", "PageList", "Date", "DateTime", "Anchor", "MailTo", "GetVal", "TemplateList", |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
33 ] |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
34 |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
35 ############################################################################# |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
36 ### Helpers |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
37 ############################################################################# |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
38 |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
39 def getNames(cfg): |
1550
a4f0632414da
using request.cfg.cache more
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1449
diff
changeset
|
40 if not hasattr(cfg.cache, 'macro_names'): |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
41 lnames = names[:] |
688
15c55ecd7ccb
fix some i18n bugs
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
684
diff
changeset
|
42 lnames.extend(i18n.wikiLanguages().keys()) |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
43 lnames.extend(wikiutil.getPlugins('macro', cfg)) |
1550
a4f0632414da
using request.cfg.cache more
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1449
diff
changeset
|
44 cfg.cache.macro_names = lnames # remember it |
a4f0632414da
using request.cfg.cache more
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1449
diff
changeset
|
45 return cfg.cache.macro_names |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
46 |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
47 |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
48 ############################################################################# |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
49 ### Macros - Handlers for [[macroname]] markup |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
50 ############################################################################# |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
51 |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
52 class Macro: |
2286
01f05e74aa9c
Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2226
diff
changeset
|
53 """ Macro handler |
01f05e74aa9c
Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2226
diff
changeset
|
54 |
01f05e74aa9c
Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2226
diff
changeset
|
55 There are three kinds of macros: |
2515
41bc022c2160
use new arg parser for buitlin macros
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2513
diff
changeset
|
56 * Builtin Macros - implemented in this file and named macro_[name] |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
57 * Language Pseudo Macros - any lang the wiki knows can be use as |
2286
01f05e74aa9c
Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2226
diff
changeset
|
58 macro and is implemented here by _m_lang() |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
59 * External macros - implemented in either MoinMoin.macro package, or |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
60 in the specific wiki instance in the plugin/macro directory |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
61 """ |
51
54d5932d5a03
merge moin--main--1.3--patch-930: fix error handling in plugins, fix broken chart action
Nir Soffer <nirs@freeshell.org>
parents:
39
diff
changeset
|
62 defaultDependency = ["time"] |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
63 |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
64 Dependencies = { |
1001
ed7febba892b
whitespace-only cleanup and minor style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
950
diff
changeset
|
65 "TitleSearch": ["namespace"], |
2520
02766a483465
builtin macros: just reorder, no other changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2519
diff
changeset
|
66 "PageList": ["namespace"], |
02766a483465
builtin macros: just reorder, no other changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2519
diff
changeset
|
67 "TemplateList": ["namespace"], |
1001
ed7febba892b
whitespace-only cleanup and minor style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
950
diff
changeset
|
68 "WordIndex": ["namespace"], |
ed7febba892b
whitespace-only cleanup and minor style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
950
diff
changeset
|
69 "TitleIndex": ["namespace"], |
2520
02766a483465
builtin macros: just reorder, no other changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2519
diff
changeset
|
70 "Goto": [], |
1001
ed7febba892b
whitespace-only cleanup and minor style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
950
diff
changeset
|
71 "Icon": ["user"], # users have different themes and user prefs |
ed7febba892b
whitespace-only cleanup and minor style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
950
diff
changeset
|
72 "Date": ["time"], |
ed7febba892b
whitespace-only cleanup and minor style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
950
diff
changeset
|
73 "DateTime": ["time"], |
ed7febba892b
whitespace-only cleanup and minor style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
950
diff
changeset
|
74 "Anchor": [], |
ed7febba892b
whitespace-only cleanup and minor style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
950
diff
changeset
|
75 "Mailto": ["user"], |
ed7febba892b
whitespace-only cleanup and minor style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
950
diff
changeset
|
76 "GetVal": ["pages"], |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
77 } |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
78 |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
79 # we need the lang macros to execute when html is generated, |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
80 # to have correct dir and lang html attributes |
1870
9406e02388cf
reduce usage of .keys()
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1832
diff
changeset
|
81 for lang in i18n.wikiLanguages(): |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
82 Dependencies[lang] = [] |
950
4eb66637ccd0
whitespace-only cleanup, small style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
919
diff
changeset
|
83 |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
84 |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
85 def __init__(self, parser): |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
86 self.parser = parser |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
87 self.form = self.parser.form |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
88 self.request = self.parser.request |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
89 self.formatter = self.request.formatter |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
90 self._ = self.request.getText |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
91 self.cfg = self.request.cfg |
950
4eb66637ccd0
whitespace-only cleanup, small style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
919
diff
changeset
|
92 |
51
54d5932d5a03
merge moin--main--1.3--patch-930: fix error handling in plugins, fix broken chart action
Nir Soffer <nirs@freeshell.org>
parents:
39
diff
changeset
|
93 # Initialized on execute |
54d5932d5a03
merge moin--main--1.3--patch-930: fix error handling in plugins, fix broken chart action
Nir Soffer <nirs@freeshell.org>
parents:
39
diff
changeset
|
94 self.name = None |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
95 |
2529
df375ab9fbde
automatically convert macro args with defaults to the default's type
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2523
diff
changeset
|
96 def _convert_arg(self, value, default, name=None): |
2531
1184922dc419
some more explanations of the type magic for macro args
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2530
diff
changeset
|
97 """ |
1184922dc419
some more explanations of the type magic for macro args
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2530
diff
changeset
|
98 Using the wikiutil argument parser get_* functions, |
1184922dc419
some more explanations of the type magic for macro args
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2530
diff
changeset
|
99 convert argument to the type of the default if that is |
1184922dc419
some more explanations of the type magic for macro args
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2530
diff
changeset
|
100 any of bool, int, long, float or unicode; otherwise |
1184922dc419
some more explanations of the type magic for macro args
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2530
diff
changeset
|
101 return the value itself. |
1184922dc419
some more explanations of the type magic for macro args
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2530
diff
changeset
|
102 """ |
2529
df375ab9fbde
automatically convert macro args with defaults to the default's type
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2523
diff
changeset
|
103 if isinstance(default, bool): |
2532
cc125871c8a0
whoops, get_boolean was renamed to get_bool
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2531
diff
changeset
|
104 return wikiutil.get_bool(self.request, value, name, default) |
2529
df375ab9fbde
automatically convert macro args with defaults to the default's type
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2523
diff
changeset
|
105 elif isinstance(default, int) or isinstance(default, long): |
df375ab9fbde
automatically convert macro args with defaults to the default's type
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2523
diff
changeset
|
106 return wikiutil.get_int(self.request, value, name, default) |
df375ab9fbde
automatically convert macro args with defaults to the default's type
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2523
diff
changeset
|
107 elif isinstance(default, float): |
df375ab9fbde
automatically convert macro args with defaults to the default's type
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2523
diff
changeset
|
108 return wikiutil.get_float(self.request, value, name, default) |
df375ab9fbde
automatically convert macro args with defaults to the default's type
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2523
diff
changeset
|
109 elif isinstance(default, unicode): |
df375ab9fbde
automatically convert macro args with defaults to the default's type
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2523
diff
changeset
|
110 return wikiutil.get_unicode(self.request, value, name, default) |
2538
070294763d3e
clean up parser argument handling, allow tuples for choices
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2536
diff
changeset
|
111 elif isinstance(default, tuple) or isinstance(default, list): |
070294763d3e
clean up parser argument handling, allow tuples for choices
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2536
diff
changeset
|
112 return wikiutil.get_choice(self.request, value, name, default) |
2536
72a31f09d5a1
allow types as defaults for macro args to force conversion to that type
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2532
diff
changeset
|
113 elif default is bool: |
72a31f09d5a1
allow types as defaults for macro args to force conversion to that type
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2532
diff
changeset
|
114 return wikiutil.get_bool(self.request, value, name) |
72a31f09d5a1
allow types as defaults for macro args to force conversion to that type
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2532
diff
changeset
|
115 elif default is int or default is long: |
72a31f09d5a1
allow types as defaults for macro args to force conversion to that type
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2532
diff
changeset
|
116 return wikiutil.get_int(self.request, value, name) |
72a31f09d5a1
allow types as defaults for macro args to force conversion to that type
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2532
diff
changeset
|
117 elif default is float: |
72a31f09d5a1
allow types as defaults for macro args to force conversion to that type
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2532
diff
changeset
|
118 return wikiutil.get_float(self.request, value, name) |
2529
df375ab9fbde
automatically convert macro args with defaults to the default's type
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2523
diff
changeset
|
119 return value |
df375ab9fbde
automatically convert macro args with defaults to the default's type
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2523
diff
changeset
|
120 |
2507
ea255685d6b0
add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2294
diff
changeset
|
121 def _wrap(self, macro_name, fn, args): |
ea255685d6b0
add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2294
diff
changeset
|
122 """ |
ea255685d6b0
add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2294
diff
changeset
|
123 Parses arguments for a macro call and calls the macro |
ea255685d6b0
add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2294
diff
changeset
|
124 function with the arguments. |
2531
1184922dc419
some more explanations of the type magic for macro args
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2530
diff
changeset
|
125 |
1184922dc419
some more explanations of the type magic for macro args
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2530
diff
changeset
|
126 If the macro function has a default value that is a bool, |
1184922dc419
some more explanations of the type magic for macro args
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2530
diff
changeset
|
127 int, long, float or unicode object, then the given value |
1184922dc419
some more explanations of the type magic for macro args
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2530
diff
changeset
|
128 is converted to the type of that default value before passing |
1184922dc419
some more explanations of the type magic for macro args
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2530
diff
changeset
|
129 it to the macro function. That way, macros need not call the |
1184922dc419
some more explanations of the type magic for macro args
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2530
diff
changeset
|
130 wikiutil.get_* functions for any arguments that have a default. |
2507
ea255685d6b0
add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2294
diff
changeset
|
131 """ |
2536
72a31f09d5a1
allow types as defaults for macro args to force conversion to that type
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2532
diff
changeset
|
132 _ = self.request.getText |
2507
ea255685d6b0
add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2294
diff
changeset
|
133 if args: |
ea255685d6b0
add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2294
diff
changeset
|
134 positional, keyword, trailing = \ |
ea255685d6b0
add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2294
diff
changeset
|
135 wikiutil.parse_quoted_separated(args) |
ea255685d6b0
add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2294
diff
changeset
|
136 |
ea255685d6b0
add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2294
diff
changeset
|
137 kwargs = {} |
ea255685d6b0
add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2294
diff
changeset
|
138 nonascii = {} |
ea255685d6b0
add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2294
diff
changeset
|
139 for kw in keyword: |
ea255685d6b0
add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2294
diff
changeset
|
140 try: |
ea255685d6b0
add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2294
diff
changeset
|
141 kwargs[str(kw)] = keyword[kw] |
ea255685d6b0
add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2294
diff
changeset
|
142 except UnicodeEncodeError: |
ea255685d6b0
add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2294
diff
changeset
|
143 nonascii[kw] = keyword[kw] |
ea255685d6b0
add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2294
diff
changeset
|
144 |
ea255685d6b0
add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2294
diff
changeset
|
145 # add trailing args as keyword argument if present, |
ea255685d6b0
add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2294
diff
changeset
|
146 # otherwise remove if the user entered some |
ea255685d6b0
add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2294
diff
changeset
|
147 # (so macros don't get a string where they expect a list) |
ea255685d6b0
add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2294
diff
changeset
|
148 if trailing: |
ea255685d6b0
add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2294
diff
changeset
|
149 kwargs['_trailing_args'] = trailing |
ea255685d6b0
add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2294
diff
changeset
|
150 elif '_trailing_args' in kwargs: |
ea255685d6b0
add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2294
diff
changeset
|
151 del kwargs['_trailing_args'] |
ea255685d6b0
add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2294
diff
changeset
|
152 |
ea255685d6b0
add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2294
diff
changeset
|
153 # add nonascii args as keyword argument if present, |
ea255685d6b0
add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2294
diff
changeset
|
154 # otherwise remove if the user entered some |
ea255685d6b0
add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2294
diff
changeset
|
155 # (so macros don't get a string where they expect a list) |
ea255685d6b0
add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2294
diff
changeset
|
156 if nonascii: |
ea255685d6b0
add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2294
diff
changeset
|
157 kwargs['_non_ascii_kwargs'] = nonascii |
ea255685d6b0
add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2294
diff
changeset
|
158 elif '_non_ascii_kwargs' in kwargs: |
ea255685d6b0
add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2294
diff
changeset
|
159 del kwargs['_non_ascii_kwargs'] |
ea255685d6b0
add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2294
diff
changeset
|
160 |
ea255685d6b0
add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2294
diff
changeset
|
161 else: |
ea255685d6b0
add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2294
diff
changeset
|
162 positional = [] |
ea255685d6b0
add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2294
diff
changeset
|
163 kwargs = {} |
ea255685d6b0
add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2294
diff
changeset
|
164 |
2538
070294763d3e
clean up parser argument handling, allow tuples for choices
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2536
diff
changeset
|
165 argnames, varargs, varkw, defaultlist = getargspec(fn) |
070294763d3e
clean up parser argument handling, allow tuples for choices
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2536
diff
changeset
|
166 argnames = argnames[1:] |
070294763d3e
clean up parser argument handling, allow tuples for choices
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2536
diff
changeset
|
167 argc = len(argnames) |
070294763d3e
clean up parser argument handling, allow tuples for choices
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2536
diff
changeset
|
168 if not defaultlist: |
070294763d3e
clean up parser argument handling, allow tuples for choices
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2536
diff
changeset
|
169 defaultlist = [] |
2529
df375ab9fbde
automatically convert macro args with defaults to the default's type
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2523
diff
changeset
|
170 |
df375ab9fbde
automatically convert macro args with defaults to the default's type
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2523
diff
changeset
|
171 # if the first (macro) parameter has a default too... |
2538
070294763d3e
clean up parser argument handling, allow tuples for choices
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2536
diff
changeset
|
172 if argc < len(defaultlist): |
070294763d3e
clean up parser argument handling, allow tuples for choices
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2536
diff
changeset
|
173 defaultlist = defaultlist[1:] |
070294763d3e
clean up parser argument handling, allow tuples for choices
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2536
diff
changeset
|
174 defstart = argc - len(defaultlist) |
070294763d3e
clean up parser argument handling, allow tuples for choices
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2536
diff
changeset
|
175 |
070294763d3e
clean up parser argument handling, allow tuples for choices
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2536
diff
changeset
|
176 defaults = {} |
070294763d3e
clean up parser argument handling, allow tuples for choices
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2536
diff
changeset
|
177 # convert all arguments to keyword arguments, |
070294763d3e
clean up parser argument handling, allow tuples for choices
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2536
diff
changeset
|
178 # fill all arguments that weren't given with None |
070294763d3e
clean up parser argument handling, allow tuples for choices
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2536
diff
changeset
|
179 for idx in range(argc): |
070294763d3e
clean up parser argument handling, allow tuples for choices
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2536
diff
changeset
|
180 if idx < len(positional): |
070294763d3e
clean up parser argument handling, allow tuples for choices
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2536
diff
changeset
|
181 kwargs[argnames[idx]] = positional[idx] |
070294763d3e
clean up parser argument handling, allow tuples for choices
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2536
diff
changeset
|
182 if not argnames[idx] in kwargs: |
070294763d3e
clean up parser argument handling, allow tuples for choices
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2536
diff
changeset
|
183 kwargs[argnames[idx]] = None |
070294763d3e
clean up parser argument handling, allow tuples for choices
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2536
diff
changeset
|
184 if idx >= defstart: |
070294763d3e
clean up parser argument handling, allow tuples for choices
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2536
diff
changeset
|
185 defaults[argnames[idx]] = defaultlist[idx - defstart] |
2529
df375ab9fbde
automatically convert macro args with defaults to the default's type
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2523
diff
changeset
|
186 |
2507
ea255685d6b0
add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2294
diff
changeset
|
187 try: |
2538
070294763d3e
clean up parser argument handling, allow tuples for choices
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2536
diff
changeset
|
188 # type-convert all keyword arguments to the type |
070294763d3e
clean up parser argument handling, allow tuples for choices
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2536
diff
changeset
|
189 # that the default value indicates |
2529
df375ab9fbde
automatically convert macro args with defaults to the default's type
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2523
diff
changeset
|
190 for idx in range(defstart, argc): |
2538
070294763d3e
clean up parser argument handling, allow tuples for choices
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2536
diff
changeset
|
191 argname = argnames[idx] |
070294763d3e
clean up parser argument handling, allow tuples for choices
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2536
diff
changeset
|
192 default = defaults.get(argname, None) |
2531
1184922dc419
some more explanations of the type magic for macro args
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2530
diff
changeset
|
193 |
1184922dc419
some more explanations of the type magic for macro args
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2530
diff
changeset
|
194 # the value of 'argname' from kwargs will be put into the |
1184922dc419
some more explanations of the type magic for macro args
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2530
diff
changeset
|
195 # macro's 'argname' argument, so convert that giving the |
1184922dc419
some more explanations of the type magic for macro args
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2530
diff
changeset
|
196 # name to the converter so the user is told which argument |
1184922dc419
some more explanations of the type magic for macro args
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2530
diff
changeset
|
197 # went wrong (if it does) |
2538
070294763d3e
clean up parser argument handling, allow tuples for choices
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2536
diff
changeset
|
198 kwargs[argname] = self._convert_arg(kwargs[argname], |
070294763d3e
clean up parser argument handling, allow tuples for choices
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2536
diff
changeset
|
199 default, argname) |
2529
df375ab9fbde
automatically convert macro args with defaults to the default's type
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2523
diff
changeset
|
200 |
2538
070294763d3e
clean up parser argument handling, allow tuples for choices
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2536
diff
changeset
|
201 return fn(self, **kwargs) |
2513
6de0e14591f7
macro.format_error to format what a macro shows in case of ValueError/TypeError happening, refactor MonthCalendar to use new arg parsing
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2507
diff
changeset
|
202 except (ValueError, TypeError), e: |
6de0e14591f7
macro.format_error to format what a macro shows in case of ValueError/TypeError happening, refactor MonthCalendar to use new arg parsing
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2507
diff
changeset
|
203 return self.format_error(e) |
6de0e14591f7
macro.format_error to format what a macro shows in case of ValueError/TypeError happening, refactor MonthCalendar to use new arg parsing
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2507
diff
changeset
|
204 |
6de0e14591f7
macro.format_error to format what a macro shows in case of ValueError/TypeError happening, refactor MonthCalendar to use new arg parsing
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2507
diff
changeset
|
205 def format_error(self, err): |
2517
50b12f981890
builtin macros: fix bug, handle errors giving help to users
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2515
diff
changeset
|
206 """ format an error object for output instead of normal macro output """ |
2523
ee8d1a2cc252
XSS fix for format_error
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2521
diff
changeset
|
207 return self.formatter.text(u'[[%s: %s]]' % (self.name, unicode(err))) |
2507
ea255685d6b0
add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2294
diff
changeset
|
208 |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
209 def execute(self, macro_name, args): |
2286
01f05e74aa9c
Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2226
diff
changeset
|
210 """ Get and execute a macro |
01f05e74aa9c
Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2226
diff
changeset
|
211 |
51
54d5932d5a03
merge moin--main--1.3--patch-930: fix error handling in plugins, fix broken chart action
Nir Soffer <nirs@freeshell.org>
parents:
39
diff
changeset
|
212 Try to get a plugin macro, or a builtin macro or a language |
2286
01f05e74aa9c
Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2226
diff
changeset
|
213 macro, or just raise ImportError. |
51
54d5932d5a03
merge moin--main--1.3--patch-930: fix error handling in plugins, fix broken chart action
Nir Soffer <nirs@freeshell.org>
parents:
39
diff
changeset
|
214 """ |
54d5932d5a03
merge moin--main--1.3--patch-930: fix error handling in plugins, fix broken chart action
Nir Soffer <nirs@freeshell.org>
parents:
39
diff
changeset
|
215 self.name = macro_name |
54d5932d5a03
merge moin--main--1.3--patch-930: fix error handling in plugins, fix broken chart action
Nir Soffer <nirs@freeshell.org>
parents:
39
diff
changeset
|
216 try: |
2507
ea255685d6b0
add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2294
diff
changeset
|
217 try: |
ea255685d6b0
add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2294
diff
changeset
|
218 call = wikiutil.importPlugin(self.cfg, 'macro', macro_name, |
ea255685d6b0
add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2294
diff
changeset
|
219 function='macro_%s' % macro_name) |
ea255685d6b0
add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2294
diff
changeset
|
220 execute = lambda _self, _args: _self._wrap(macro_name, call, _args) |
ea255685d6b0
add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2294
diff
changeset
|
221 except wikiutil.PluginAttributeError: |
ea255685d6b0
add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2294
diff
changeset
|
222 execute = wikiutil.importPlugin(self.cfg, 'macro', macro_name) |
53
699811601bed
merge moin--main--1.3--patch-934,935: detect correctly missing plguins and missing names in plugins
Nir Soffer <nirs@freeshell.org>
parents:
51
diff
changeset
|
223 except wikiutil.PluginMissingError: |
51
54d5932d5a03
merge moin--main--1.3--patch-930: fix error handling in plugins, fix broken chart action
Nir Soffer <nirs@freeshell.org>
parents:
39
diff
changeset
|
224 try: |
2515
41bc022c2160
use new arg parser for buitlin macros
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2513
diff
changeset
|
225 call = getattr(self.__class__, 'macro_%s' % macro_name) |
41bc022c2160
use new arg parser for buitlin macros
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2513
diff
changeset
|
226 execute = lambda _self, _args: _self._wrap(macro_name, call, _args) |
51
54d5932d5a03
merge moin--main--1.3--patch-930: fix error handling in plugins, fix broken chart action
Nir Soffer <nirs@freeshell.org>
parents:
39
diff
changeset
|
227 except AttributeError: |
688
15c55ecd7ccb
fix some i18n bugs
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
684
diff
changeset
|
228 if macro_name in i18n.wikiLanguages(): |
51
54d5932d5a03
merge moin--main--1.3--patch-930: fix error handling in plugins, fix broken chart action
Nir Soffer <nirs@freeshell.org>
parents:
39
diff
changeset
|
229 execute = builtins._m_lang |
54d5932d5a03
merge moin--main--1.3--patch-930: fix error handling in plugins, fix broken chart action
Nir Soffer <nirs@freeshell.org>
parents:
39
diff
changeset
|
230 else: |
53
699811601bed
merge moin--main--1.3--patch-934,935: detect correctly missing plguins and missing names in plugins
Nir Soffer <nirs@freeshell.org>
parents:
51
diff
changeset
|
231 raise ImportError("Cannot load macro %s" % macro_name) |
51
54d5932d5a03
merge moin--main--1.3--patch-930: fix error handling in plugins, fix broken chart action
Nir Soffer <nirs@freeshell.org>
parents:
39
diff
changeset
|
232 return execute(self, args) |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
233 |
51
54d5932d5a03
merge moin--main--1.3--patch-930: fix error handling in plugins, fix broken chart action
Nir Soffer <nirs@freeshell.org>
parents:
39
diff
changeset
|
234 def _m_lang(self, text): |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
235 """ Set the current language for page content. |
2286
01f05e74aa9c
Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2226
diff
changeset
|
236 |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
237 Language macro are used in two ways: |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
238 * [lang] - set the current language until next lang macro |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
239 * [lang(text)] - insert text with specific lang inside page |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
240 """ |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
241 if text: |
51
54d5932d5a03
merge moin--main--1.3--patch-930: fix error handling in plugins, fix broken chart action
Nir Soffer <nirs@freeshell.org>
parents:
39
diff
changeset
|
242 return (self.formatter.lang(1, self.name) + |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
243 self.formatter.text(text) + |
51
54d5932d5a03
merge moin--main--1.3--patch-930: fix error handling in plugins, fix broken chart action
Nir Soffer <nirs@freeshell.org>
parents:
39
diff
changeset
|
244 self.formatter.lang(0, self.name)) |
950
4eb66637ccd0
whitespace-only cleanup, small style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
919
diff
changeset
|
245 |
51
54d5932d5a03
merge moin--main--1.3--patch-930: fix error handling in plugins, fix broken chart action
Nir Soffer <nirs@freeshell.org>
parents:
39
diff
changeset
|
246 self.request.current_lang = self.name |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
247 return '' |
950
4eb66637ccd0
whitespace-only cleanup, small style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
919
diff
changeset
|
248 |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
249 def get_dependencies(self, macro_name): |
51
54d5932d5a03
merge moin--main--1.3--patch-930: fix error handling in plugins, fix broken chart action
Nir Soffer <nirs@freeshell.org>
parents:
39
diff
changeset
|
250 if macro_name in self.Dependencies: |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
251 return self.Dependencies[macro_name] |
51
54d5932d5a03
merge moin--main--1.3--patch-930: fix error handling in plugins, fix broken chart action
Nir Soffer <nirs@freeshell.org>
parents:
39
diff
changeset
|
252 try: |
54d5932d5a03
merge moin--main--1.3--patch-930: fix error handling in plugins, fix broken chart action
Nir Soffer <nirs@freeshell.org>
parents:
39
diff
changeset
|
253 return wikiutil.importPlugin(self.request.cfg, 'macro', |
54d5932d5a03
merge moin--main--1.3--patch-930: fix error handling in plugins, fix broken chart action
Nir Soffer <nirs@freeshell.org>
parents:
39
diff
changeset
|
254 macro_name, 'Dependencies') |
53
699811601bed
merge moin--main--1.3--patch-934,935: detect correctly missing plguins and missing names in plugins
Nir Soffer <nirs@freeshell.org>
parents:
51
diff
changeset
|
255 except wikiutil.PluginError: |
51
54d5932d5a03
merge moin--main--1.3--patch-930: fix error handling in plugins, fix broken chart action
Nir Soffer <nirs@freeshell.org>
parents:
39
diff
changeset
|
256 return self.defaultDependency |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
257 |
2515
41bc022c2160
use new arg parser for buitlin macros
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2513
diff
changeset
|
258 def macro_TitleSearch(self): |
1924
5dc0896d145a
search: fixed wrong import
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1920
diff
changeset
|
259 from MoinMoin.macro.FullSearch import search_box |
1217
237ca54182a7
copied code for search box over to macro/FullSearch.py
Franz Pletz <fpletz AT franz-pletz DOT org>
parents:
1198
diff
changeset
|
260 return search_box("titlesearch", self) |
950
4eb66637ccd0
whitespace-only cleanup, small style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
919
diff
changeset
|
261 |
2520
02766a483465
builtin macros: just reorder, no other changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2519
diff
changeset
|
262 def macro_PageList(self, needle=None): |
02766a483465
builtin macros: just reorder, no other changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2519
diff
changeset
|
263 from MoinMoin import search |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
264 _ = self._ |
2520
02766a483465
builtin macros: just reorder, no other changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2519
diff
changeset
|
265 case = 0 |
02766a483465
builtin macros: just reorder, no other changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2519
diff
changeset
|
266 |
02766a483465
builtin macros: just reorder, no other changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2519
diff
changeset
|
267 # If called with empty or no argument, default to regex search for .+, the full page list. |
02766a483465
builtin macros: just reorder, no other changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2519
diff
changeset
|
268 needle = wikiutil.get_unicode(self.request, needle, 'needle', u'regex:.+') |
02766a483465
builtin macros: just reorder, no other changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2519
diff
changeset
|
269 |
02766a483465
builtin macros: just reorder, no other changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2519
diff
changeset
|
270 # With whitespace argument, return same error message as FullSearch |
02766a483465
builtin macros: just reorder, no other changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2519
diff
changeset
|
271 if not needle.strip(): |
02766a483465
builtin macros: just reorder, no other changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2519
diff
changeset
|
272 err = _('Please use a more selective search term instead of {{{"%s"}}}') % needle |
02766a483465
builtin macros: just reorder, no other changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2519
diff
changeset
|
273 return '<span class="error">%s</span>' % err |
02766a483465
builtin macros: just reorder, no other changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2519
diff
changeset
|
274 |
02766a483465
builtin macros: just reorder, no other changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2519
diff
changeset
|
275 # Return a title search for needle, sorted by name. |
02766a483465
builtin macros: just reorder, no other changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2519
diff
changeset
|
276 results = search.searchPages(self.request, needle, |
02766a483465
builtin macros: just reorder, no other changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2519
diff
changeset
|
277 titlesearch=1, case=case, sort='page_name') |
02766a483465
builtin macros: just reorder, no other changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2519
diff
changeset
|
278 return results.pageList(self.request, self.formatter, paging=False) |
02766a483465
builtin macros: just reorder, no other changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2519
diff
changeset
|
279 |
2530
0a8fc701e40d
use the new automatic macro arg conversion in some internal macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2529
diff
changeset
|
280 def macro_TemplateList(self, needle=u'.+'): |
2520
02766a483465
builtin macros: just reorder, no other changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2519
diff
changeset
|
281 # TODO: this should be renamed (RegExPageNameList?), it does not list only Templates... |
02766a483465
builtin macros: just reorder, no other changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2519
diff
changeset
|
282 _ = self._ |
02766a483465
builtin macros: just reorder, no other changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2519
diff
changeset
|
283 try: |
02766a483465
builtin macros: just reorder, no other changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2519
diff
changeset
|
284 needle_re = re.compile(needle, re.IGNORECASE) |
02766a483465
builtin macros: just reorder, no other changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2519
diff
changeset
|
285 except re.error, err: |
02766a483465
builtin macros: just reorder, no other changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2519
diff
changeset
|
286 raise ValueError("Error in regex %r: %s" % (needle, err)) |
02766a483465
builtin macros: just reorder, no other changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2519
diff
changeset
|
287 |
02766a483465
builtin macros: just reorder, no other changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2519
diff
changeset
|
288 # Get page list readable by current user, filtered by needle |
02766a483465
builtin macros: just reorder, no other changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2519
diff
changeset
|
289 hits = self.request.rootpage.getPageList(filter=needle_re.search) |
02766a483465
builtin macros: just reorder, no other changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2519
diff
changeset
|
290 hits.sort() |
02766a483465
builtin macros: just reorder, no other changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2519
diff
changeset
|
291 |
02766a483465
builtin macros: just reorder, no other changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2519
diff
changeset
|
292 result = [] |
02766a483465
builtin macros: just reorder, no other changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2519
diff
changeset
|
293 result.append(self.formatter.bullet_list(1)) |
02766a483465
builtin macros: just reorder, no other changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2519
diff
changeset
|
294 for pagename in hits: |
02766a483465
builtin macros: just reorder, no other changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2519
diff
changeset
|
295 result.append(self.formatter.listitem(1)) |
02766a483465
builtin macros: just reorder, no other changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2519
diff
changeset
|
296 result.append(self.formatter.pagelink(1, pagename, generated=1)) |
02766a483465
builtin macros: just reorder, no other changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2519
diff
changeset
|
297 result.append(self.formatter.text(pagename)) |
02766a483465
builtin macros: just reorder, no other changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2519
diff
changeset
|
298 result.append(self.formatter.pagelink(0, pagename)) |
02766a483465
builtin macros: just reorder, no other changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2519
diff
changeset
|
299 result.append(self.formatter.listitem(0)) |
02766a483465
builtin macros: just reorder, no other changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2519
diff
changeset
|
300 result.append(self.formatter.bullet_list(0)) |
02766a483465
builtin macros: just reorder, no other changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2519
diff
changeset
|
301 return ''.join(result) |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
302 |
2515
41bc022c2160
use new arg parser for buitlin macros
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2513
diff
changeset
|
303 def _make_index(self, word_re=u'.+'): |
735
e3c44dc8f488
merge common code of TitleIndex and WordIndex into _make_index
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
688
diff
changeset
|
304 """ make an index page (used for TitleIndex and WordIndex macro) |
e3c44dc8f488
merge common code of TitleIndex and WordIndex into _make_index
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
688
diff
changeset
|
305 |
e3c44dc8f488
merge common code of TitleIndex and WordIndex into _make_index
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
688
diff
changeset
|
306 word_re is a regex used for splitting a pagename into fragments |
e3c44dc8f488
merge common code of TitleIndex and WordIndex into _make_index
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
688
diff
changeset
|
307 matched by it (used for WordIndex). For TitleIndex, we just match |
e3c44dc8f488
merge common code of TitleIndex and WordIndex into _make_index
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
688
diff
changeset
|
308 the whole page name, so we only get one fragment that is the same |
e3c44dc8f488
merge common code of TitleIndex and WordIndex into _make_index
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
688
diff
changeset
|
309 as the pagename. |
e3c44dc8f488
merge common code of TitleIndex and WordIndex into _make_index
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
688
diff
changeset
|
310 |
1832
b180f047d918
comments only: cleaned up TODO, XXX, ...
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1805
diff
changeset
|
311 TODO: _make_index could get a macro on its own, more powerful / less special than WordIndex and TitleIndex. |
b180f047d918
comments only: cleaned up TODO, XXX, ...
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1805
diff
changeset
|
312 It should be able to filter for specific mimetypes, maybe match pagenames by regex (replace PageList?), etc. |
735
e3c44dc8f488
merge common code of TitleIndex and WordIndex into _make_index
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
688
diff
changeset
|
313 """ |
28
ef8b90110f33
WordIndex: make systempages excludeable
Thomas Waldmann <tw@waldmann-edv.de>
parents:
27
diff
changeset
|
314 _ = self._ |
1785
e54f99c9beba
make TitleIndex/WordIndex use the formatter
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1674
diff
changeset
|
315 request = self.request |
e54f99c9beba
make TitleIndex/WordIndex use the formatter
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1674
diff
changeset
|
316 fmt = self.formatter |
28
ef8b90110f33
WordIndex: make systempages excludeable
Thomas Waldmann <tw@waldmann-edv.de>
parents:
27
diff
changeset
|
317 allpages = int(self.form.get('allpages', [0])[0]) != 0 |
1785
e54f99c9beba
make TitleIndex/WordIndex use the formatter
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1674
diff
changeset
|
318 # Get page list readable by current user, filter by isSystemPage if needed |
28
ef8b90110f33
WordIndex: make systempages excludeable
Thomas Waldmann <tw@waldmann-edv.de>
parents:
27
diff
changeset
|
319 if allpages: |
1785
e54f99c9beba
make TitleIndex/WordIndex use the formatter
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1674
diff
changeset
|
320 pages = request.rootpage.getPageList() |
28
ef8b90110f33
WordIndex: make systempages excludeable
Thomas Waldmann <tw@waldmann-edv.de>
parents:
27
diff
changeset
|
321 else: |
1920
b06ef2a53efa
'make pylint', fixed lots of minor stuff found by pylint (and there is still lots left to do)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1918
diff
changeset
|
322 def nosyspage(name): |
1785
e54f99c9beba
make TitleIndex/WordIndex use the formatter
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1674
diff
changeset
|
323 return not wikiutil.isSystemPage(request, name) |
1920
b06ef2a53efa
'make pylint', fixed lots of minor stuff found by pylint (and there is still lots left to do)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1918
diff
changeset
|
324 pages = request.rootpage.getPageList(filter=nosyspage) |
950
4eb66637ccd0
whitespace-only cleanup, small style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
919
diff
changeset
|
325 |
735
e3c44dc8f488
merge common code of TitleIndex and WordIndex into _make_index
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
688
diff
changeset
|
326 word_re = re.compile(word_re, re.UNICODE) |
1920
b06ef2a53efa
'make pylint', fixed lots of minor stuff found by pylint (and there is still lots left to do)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1918
diff
changeset
|
327 wordmap = {} |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
328 for name in pages: |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
329 for word in word_re.findall(name): |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
330 try: |
1920
b06ef2a53efa
'make pylint', fixed lots of minor stuff found by pylint (and there is still lots left to do)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1918
diff
changeset
|
331 if not wordmap[word].count(name): |
b06ef2a53efa
'make pylint', fixed lots of minor stuff found by pylint (and there is still lots left to do)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1918
diff
changeset
|
332 wordmap[word].append(name) |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
333 except KeyError: |
1920
b06ef2a53efa
'make pylint', fixed lots of minor stuff found by pylint (and there is still lots left to do)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1918
diff
changeset
|
334 wordmap[word] = [name] |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
335 |
735
e3c44dc8f488
merge common code of TitleIndex and WordIndex into _make_index
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
688
diff
changeset
|
336 # Sort ignoring case |
1920
b06ef2a53efa
'make pylint', fixed lots of minor stuff found by pylint (and there is still lots left to do)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1918
diff
changeset
|
337 tmp = [(word.upper(), word) for word in wordmap] |
735
e3c44dc8f488
merge common code of TitleIndex and WordIndex into _make_index
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
688
diff
changeset
|
338 tmp.sort() |
e3c44dc8f488
merge common code of TitleIndex and WordIndex into _make_index
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
688
diff
changeset
|
339 all_words = [item[1] for item in tmp] |
e3c44dc8f488
merge common code of TitleIndex and WordIndex into _make_index
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
688
diff
changeset
|
340 |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
341 index_letters = [] |
28
ef8b90110f33
WordIndex: make systempages excludeable
Thomas Waldmann <tw@waldmann-edv.de>
parents:
27
diff
changeset
|
342 current_letter = None |
1785
e54f99c9beba
make TitleIndex/WordIndex use the formatter
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1674
diff
changeset
|
343 output = [] |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
344 for word in all_words: |
28
ef8b90110f33
WordIndex: make systempages excludeable
Thomas Waldmann <tw@waldmann-edv.de>
parents:
27
diff
changeset
|
345 letter = wikiutil.getUnicodeIndexGroup(word) |
ef8b90110f33
WordIndex: make systempages excludeable
Thomas Waldmann <tw@waldmann-edv.de>
parents:
27
diff
changeset
|
346 if letter != current_letter: |
2286
01f05e74aa9c
Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2226
diff
changeset
|
347 cssid = "idx" + wikiutil.quoteWikinameURL(letter).replace('%', '') |
1785
e54f99c9beba
make TitleIndex/WordIndex use the formatter
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1674
diff
changeset
|
348 output.append(fmt.heading(1, 2, id=cssid)) # fmt.anchordef didn't work |
e54f99c9beba
make TitleIndex/WordIndex use the formatter
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1674
diff
changeset
|
349 output.append(fmt.text(letter.replace('~', 'Others'))) |
e54f99c9beba
make TitleIndex/WordIndex use the formatter
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1674
diff
changeset
|
350 output.append(fmt.heading(0, 2)) |
28
ef8b90110f33
WordIndex: make systempages excludeable
Thomas Waldmann <tw@waldmann-edv.de>
parents:
27
diff
changeset
|
351 current_letter = letter |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
352 if letter not in index_letters: |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
353 index_letters.append(letter) |
1958
aa3e4fb31c62
WordIndex/TitleIndex: fix wrong attr name
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1924
diff
changeset
|
354 links = wordmap[word] |
735
e3c44dc8f488
merge common code of TitleIndex and WordIndex into _make_index
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
688
diff
changeset
|
355 if len(links) and links[0] != word: # show word fragment as on WordIndex |
1785
e54f99c9beba
make TitleIndex/WordIndex use the formatter
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1674
diff
changeset
|
356 output.append(fmt.strong(1)) |
e54f99c9beba
make TitleIndex/WordIndex use the formatter
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1674
diff
changeset
|
357 output.append(word) |
e54f99c9beba
make TitleIndex/WordIndex use the formatter
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1674
diff
changeset
|
358 output.append(fmt.strong(0)) |
950
4eb66637ccd0
whitespace-only cleanup, small style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
919
diff
changeset
|
359 |
1785
e54f99c9beba
make TitleIndex/WordIndex use the formatter
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1674
diff
changeset
|
360 output.append(fmt.bullet_list(1)) |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
361 links.sort() |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
362 last_page = None |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
363 for name in links: |
28
ef8b90110f33
WordIndex: make systempages excludeable
Thomas Waldmann <tw@waldmann-edv.de>
parents:
27
diff
changeset
|
364 if name == last_page: |
ef8b90110f33
WordIndex: make systempages excludeable
Thomas Waldmann <tw@waldmann-edv.de>
parents:
27
diff
changeset
|
365 continue |
1785
e54f99c9beba
make TitleIndex/WordIndex use the formatter
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1674
diff
changeset
|
366 output.append(fmt.listitem(1)) |
e54f99c9beba
make TitleIndex/WordIndex use the formatter
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1674
diff
changeset
|
367 output.append(Page(request, name).link_to(request, attachment_indicator=1)) |
e54f99c9beba
make TitleIndex/WordIndex use the formatter
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1674
diff
changeset
|
368 output.append(fmt.listitem(0)) |
e54f99c9beba
make TitleIndex/WordIndex use the formatter
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1674
diff
changeset
|
369 output.append(fmt.bullet_list(0)) |
950
4eb66637ccd0
whitespace-only cleanup, small style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
919
diff
changeset
|
370 |
1785
e54f99c9beba
make TitleIndex/WordIndex use the formatter
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1674
diff
changeset
|
371 def _make_index_key(index_letters): |
735
e3c44dc8f488
merge common code of TitleIndex and WordIndex into _make_index
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
688
diff
changeset
|
372 index_letters.sort() |
e3c44dc8f488
merge common code of TitleIndex and WordIndex into _make_index
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
688
diff
changeset
|
373 def letter_link(ch): |
2286
01f05e74aa9c
Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2226
diff
changeset
|
374 cssid = "idx" + wikiutil.quoteWikinameURL(ch).replace('%', '') |
1785
e54f99c9beba
make TitleIndex/WordIndex use the formatter
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1674
diff
changeset
|
375 return fmt.anchorlink(1, cssid) + fmt.text(ch.replace('~', 'Others')) + fmt.anchorlink(0) |
735
e3c44dc8f488
merge common code of TitleIndex and WordIndex into _make_index
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
688
diff
changeset
|
376 links = [letter_link(letter) for letter in index_letters] |
1785
e54f99c9beba
make TitleIndex/WordIndex use the formatter
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1674
diff
changeset
|
377 return ' | '.join(links) |
735
e3c44dc8f488
merge common code of TitleIndex and WordIndex into _make_index
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
688
diff
changeset
|
378 |
1785
e54f99c9beba
make TitleIndex/WordIndex use the formatter
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1674
diff
changeset
|
379 page = fmt.page |
735
e3c44dc8f488
merge common code of TitleIndex and WordIndex into _make_index
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
688
diff
changeset
|
380 allpages_txt = (_('Include system pages'), _('Exclude system pages'))[allpages] |
2226
cff573edd028
fixed wrong link generation for WordIndex/TitleIndex
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2207
diff
changeset
|
381 allpages_url = page.url(request, querystr={'allpages': allpages and '0' or '1'}, relative=False) |
735
e3c44dc8f488
merge common code of TitleIndex and WordIndex into _make_index
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
688
diff
changeset
|
382 |
1785
e54f99c9beba
make TitleIndex/WordIndex use the formatter
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1674
diff
changeset
|
383 output = [fmt.paragraph(1), _make_index_key(index_letters), fmt.linebreak(0), |
e54f99c9beba
make TitleIndex/WordIndex use the formatter
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1674
diff
changeset
|
384 fmt.url(1, allpages_url), fmt.text(allpages_txt), fmt.url(0), fmt.paragraph(0)] + output |
e54f99c9beba
make TitleIndex/WordIndex use the formatter
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1674
diff
changeset
|
385 return u''.join(output) |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
386 |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
387 |
2515
41bc022c2160
use new arg parser for buitlin macros
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2513
diff
changeset
|
388 def macro_TitleIndex(self): |
41bc022c2160
use new arg parser for buitlin macros
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2513
diff
changeset
|
389 return self._make_index() |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
390 |
2515
41bc022c2160
use new arg parser for buitlin macros
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2513
diff
changeset
|
391 def macro_WordIndex(self): |
2207
7ae581d79352
updated bot useragents list, reduce bot cpu usage of some macros (ported from 1.5 repo)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1965
diff
changeset
|
392 if self.request.isSpiderAgent: # reduce bot cpu usage |
7ae581d79352
updated bot useragents list, reduce bot cpu usage of some macros (ported from 1.5 repo)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1965
diff
changeset
|
393 return '' |
735
e3c44dc8f488
merge common code of TitleIndex and WordIndex into _make_index
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
688
diff
changeset
|
394 word_re = u'[%s][%s]+' % (config.chars_upper, config.chars_lower) |
2515
41bc022c2160
use new arg parser for buitlin macros
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2513
diff
changeset
|
395 return self._make_index(word_re=word_re) |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
396 |
2520
02766a483465
builtin macros: just reorder, no other changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2519
diff
changeset
|
397 def macro_GoTo(self): |
02766a483465
builtin macros: just reorder, no other changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2519
diff
changeset
|
398 """ Make a goto box |
735
e3c44dc8f488
merge common code of TitleIndex and WordIndex into _make_index
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
688
diff
changeset
|
399 |
2520
02766a483465
builtin macros: just reorder, no other changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2519
diff
changeset
|
400 @rtype: unicode |
02766a483465
builtin macros: just reorder, no other changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2519
diff
changeset
|
401 @return: goto box html fragment |
02766a483465
builtin macros: just reorder, no other changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2519
diff
changeset
|
402 """ |
02766a483465
builtin macros: just reorder, no other changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2519
diff
changeset
|
403 _ = self._ |
02766a483465
builtin macros: just reorder, no other changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2519
diff
changeset
|
404 html = [ |
02766a483465
builtin macros: just reorder, no other changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2519
diff
changeset
|
405 u'<form method="get" action="">', |
02766a483465
builtin macros: just reorder, no other changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2519
diff
changeset
|
406 u'<div>', |
02766a483465
builtin macros: just reorder, no other changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2519
diff
changeset
|
407 u'<input type="hidden" name="action" value="goto">', |
02766a483465
builtin macros: just reorder, no other changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2519
diff
changeset
|
408 u'<input type="text" name="target" size="30">', |
02766a483465
builtin macros: just reorder, no other changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2519
diff
changeset
|
409 u'<input type="submit" value="%s">' % _("Go To Page"), |
02766a483465
builtin macros: just reorder, no other changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2519
diff
changeset
|
410 u'</div>', |
02766a483465
builtin macros: just reorder, no other changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2519
diff
changeset
|
411 u'</form>', |
02766a483465
builtin macros: just reorder, no other changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2519
diff
changeset
|
412 ] |
02766a483465
builtin macros: just reorder, no other changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2519
diff
changeset
|
413 html = u'\n'.join(html) |
02766a483465
builtin macros: just reorder, no other changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2519
diff
changeset
|
414 return self.formatter.rawHTML(html) |
950
4eb66637ccd0
whitespace-only cleanup, small style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
919
diff
changeset
|
415 |
2530
0a8fc701e40d
use the new automatic macro arg conversion in some internal macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2529
diff
changeset
|
416 def macro_Icon(self, icon=u''): |
0a8fc701e40d
use the new automatic macro arg conversion in some internal macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2529
diff
changeset
|
417 # empty icon name isn't valid either |
0a8fc701e40d
use the new automatic macro arg conversion in some internal macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2529
diff
changeset
|
418 if not icon: |
0a8fc701e40d
use the new automatic macro arg conversion in some internal macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2529
diff
changeset
|
419 raise ValueError("You need to give a non-empty icon name") |
2515
41bc022c2160
use new arg parser for buitlin macros
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2513
diff
changeset
|
420 return self.formatter.icon(icon.lower()) |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
421 |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
422 def __get_Date(self, args, format_date): |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
423 _ = self._ |
2517
50b12f981890
builtin macros: fix bug, handle errors giving help to users
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2515
diff
changeset
|
424 if args is None: |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
425 tm = time.time() # always UTC |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
426 elif len(args) >= 19 and args[4] == '-' and args[7] == '-' \ |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
427 and args[10] == 'T' and args[13] == ':' and args[16] == ':': |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
428 # we ignore any time zone offsets here, assume UTC, |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
429 # and accept (and ignore) any trailing stuff |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
430 try: |
950
4eb66637ccd0
whitespace-only cleanup, small style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
919
diff
changeset
|
431 year, month, day = int(args[0:4]), int(args[5:7]), int(args[8:10]) |
4eb66637ccd0
whitespace-only cleanup, small style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
919
diff
changeset
|
432 hour, minute, second = int(args[11:13]), int(args[14:16]), int(args[17:19]) |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
433 tz = args[19:] # +HHMM, -HHMM or Z or nothing (then we assume Z) |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
434 tzoffset = 0 # we assume UTC no matter if there is a Z |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
435 if tz: |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
436 sign = tz[0] |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
437 if sign in '+-': |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
438 tzh, tzm = int(tz[1:3]), int(tz[3:]) |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
439 tzoffset = (tzh*60+tzm)*60 |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
440 if sign == '-': |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
441 tzoffset = -tzoffset |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
442 tm = (year, month, day, hour, minute, second, 0, 0, 0) |
2517
50b12f981890
builtin macros: fix bug, handle errors giving help to users
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2515
diff
changeset
|
443 except ValueError, err: |
50b12f981890
builtin macros: fix bug, handle errors giving help to users
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2515
diff
changeset
|
444 raise ValueError("Bad timestamp %r: %s" % (args, err)) |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
445 # as mktime wants a localtime argument (but we only have UTC), |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
446 # we adjust by our local timezone's offset |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
447 try: |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
448 tm = time.mktime(tm) - time.timezone - tzoffset |
1805
ebcebba1afb3
removed some unused attributes, used 'dummy' for dummies
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1794
diff
changeset
|
449 except (OverflowError, ValueError): |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
450 tm = 0 # incorrect, but we avoid an ugly backtrace |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
451 else: |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
452 # try raw seconds since epoch in UTC |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
453 try: |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
454 tm = float(args) |
2517
50b12f981890
builtin macros: fix bug, handle errors giving help to users
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2515
diff
changeset
|
455 except ValueError, err: |
50b12f981890
builtin macros: fix bug, handle errors giving help to users
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2515
diff
changeset
|
456 raise ValueError("Bad timestamp %r: %s" % (args, err)) |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
457 return format_date(tm) |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
458 |
2515
41bc022c2160
use new arg parser for buitlin macros
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2513
diff
changeset
|
459 def macro_Date(self, stamp=None): |
41bc022c2160
use new arg parser for buitlin macros
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2513
diff
changeset
|
460 return self.__get_Date(stamp, self.request.user.getFormattedDate) |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
461 |
2515
41bc022c2160
use new arg parser for buitlin macros
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2513
diff
changeset
|
462 def macro_DateTime(self, stamp=None): |
41bc022c2160
use new arg parser for buitlin macros
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2513
diff
changeset
|
463 return self.__get_Date(stamp, self.request.user.getFormattedDateTime) |
41bc022c2160
use new arg parser for buitlin macros
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2513
diff
changeset
|
464 |
2517
50b12f981890
builtin macros: fix bug, handle errors giving help to users
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2515
diff
changeset
|
465 def macro_Anchor(self, anchor=None): |
50b12f981890
builtin macros: fix bug, handle errors giving help to users
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2515
diff
changeset
|
466 anchor = wikiutil.get_unicode(self.request, anchor, 'anchor', u'anchor') |
50b12f981890
builtin macros: fix bug, handle errors giving help to users
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2515
diff
changeset
|
467 return self.formatter.anchordef(anchor) |
2515
41bc022c2160
use new arg parser for buitlin macros
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2513
diff
changeset
|
468 |
2536
72a31f09d5a1
allow types as defaults for macro args to force conversion to that type
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2532
diff
changeset
|
469 def macro_MailTo(self, email=unicode, text=u''): |
2530
0a8fc701e40d
use the new automatic macro arg conversion in some internal macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2529
diff
changeset
|
470 if not email: |
2517
50b12f981890
builtin macros: fix bug, handle errors giving help to users
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2515
diff
changeset
|
471 raise ValueError("You need to give an (obfuscated) email address") |
50b12f981890
builtin macros: fix bug, handle errors giving help to users
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2515
diff
changeset
|
472 |
753
d48400378d4c
fixed MailTo macro import
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
735
diff
changeset
|
473 from MoinMoin.mail.sendmail import decodeSpamSafeEmail |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
474 |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
475 if self.request.user.valid: |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
476 # decode address and generate mailto: link |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
477 email = decodeSpamSafeEmail(email) |
410
1a2bd0457cf3
fix some wrong attributes, todo: fix quoting, see comment in text_html.url
Thomas Waldmann <tw@waldmann-edv.de>
parents:
407
diff
changeset
|
478 result = (self.formatter.url(1, 'mailto:' + email, css='mailto', do_escape=0) + |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
479 self.formatter.text(text or email) + |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
480 self.formatter.url(0)) |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
481 else: |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
482 # unknown user, maybe even a spambot, so |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
483 # just return text as given in macro args |
2286
01f05e74aa9c
Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2226
diff
changeset
|
484 |
1674
a45b23e6217d
minor MailTo macro change from docbook branch
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1550
diff
changeset
|
485 if text: |
a45b23e6217d
minor MailTo macro change from docbook branch
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1550
diff
changeset
|
486 result = self.formatter.text(text+" ") |
2286
01f05e74aa9c
Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2226
diff
changeset
|
487 |
1674
a45b23e6217d
minor MailTo macro change from docbook branch
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1550
diff
changeset
|
488 result += self.formatter.code(1) + \ |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
489 self.formatter.text("<%s>" % email) + \ |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
490 self.formatter.code(0) |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
491 |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
492 return result |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
493 |
2517
50b12f981890
builtin macros: fix bug, handle errors giving help to users
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2515
diff
changeset
|
494 def macro_GetVal(self, page=None, key=None): |
50b12f981890
builtin macros: fix bug, handle errors giving help to users
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2515
diff
changeset
|
495 page = wikiutil.get_unicode(self.request, page, 'page') |
50b12f981890
builtin macros: fix bug, handle errors giving help to users
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2515
diff
changeset
|
496 key = wikiutil.get_unicode(self.request, key, 'key') |
50b12f981890
builtin macros: fix bug, handle errors giving help to users
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2515
diff
changeset
|
497 if page is None or key is None: |
50b12f981890
builtin macros: fix bug, handle errors giving help to users
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2515
diff
changeset
|
498 raise ValueError("You need to give: pagename, key") |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
499 d = self.request.dicts.dict(page) |
950
4eb66637ccd0
whitespace-only cleanup, small style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
919
diff
changeset
|
500 result = d.get(key, '') |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
501 return self.formatter.text(result) |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
502 |