Mercurial > moin > 1.9
changeset 2521:b4118a77105d
externalize PageCount macro
author | Thomas Waldmann <tw AT waldmann-edv DOT de> |
---|---|
date | Mon, 23 Jul 2007 02:22:32 +0200 |
parents | 02766a483465 |
children | d73957833b45 |
files | MoinMoin/macro/PageCount.py MoinMoin/macro/__init__.py |
diffstat | 2 files changed, 33 insertions(+), 28 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MoinMoin/macro/PageCount.py Mon Jul 23 02:22:32 2007 +0200 @@ -0,0 +1,31 @@ +# -*- coding: iso-8859-1 -*- +""" + Outputs the page count of the wiki. + + @copyright: 2007 MoinMoin:ThomasWaldmann + @license: GNU GPL, see COPYING for details +""" + +Dependencies = ['namespace'] + +from MoinMoin import wikiutil + +def macro_PageCount(macro, exists=None): + """ Return number of pages readable by current user + + Return either an exact count (slow!) or fast count including deleted pages. + + TODO: make macro syntax more sane + """ + request = macro.request + exists = wikiutil.get_unicode(request, exists, 'exists') + # Check input + only_existing = False + if exists == u'exists': + only_existing = True + elif exists: + raise ValueError("Wrong argument: %r" % exists) + + count = request.rootpage.getPageCount(exists=only_existing) + return macro.formatter.text("%d" % count) +
--- a/MoinMoin/macro/__init__.py Mon Jul 23 01:07:19 2007 +0200 +++ b/MoinMoin/macro/__init__.py Mon Jul 23 02:22:32 2007 +0200 @@ -25,11 +25,9 @@ from MoinMoin import wikiutil, i18n from MoinMoin.Page import Page -names = ["TitleSearch", "WordIndex", "TitleIndex", - "GoTo", "PageCount", +names = ["TitleSearch", "WordIndex", "TitleIndex", "GoTo", # Macros with arguments - "Icon", "PageList", "Date", "DateTime", "Anchor", "MailTo", "GetVal", - "TemplateList", + "Icon", "PageList", "Date", "DateTime", "Anchor", "MailTo", "GetVal", "TemplateList", ] ############################################################################# @@ -67,7 +65,6 @@ "TemplateList": ["namespace"], "WordIndex": ["namespace"], "TitleIndex": ["namespace"], - "PageCount": ["namespace"], "Goto": [], "Icon": ["user"], # users have different themes and user prefs "Date": ["time"], @@ -348,29 +345,6 @@ html = u'\n'.join(html) return self.formatter.rawHTML(html) - def macro_PageCount(self, exists=None): - """ Return number of pages readable by current user - - Return either an exact count (slow!) or fast count including - deleted pages. - - TODO: make macro syntax more sane - """ - exists = wikiutil.get_unicode(self.request, exists, 'exists') - # Check input - only_existing = False - if exists == u'exists': - only_existing = True - elif exists: - # Wrong argument, return inline error message - arg = self.formatter.text(args) - return (self.formatter.span(1, css_class="error") + - 'Wrong argument: %s' % arg + - self.formatter.span(0)) - - count = self.request.rootpage.getPageCount(exists=only_existing) - return self.formatter.text("%d" % count) - def macro_Icon(self, icon=None): icon = wikiutil.get_unicode(self.request, icon, 'icon') if icon is None: