From 87fba6bd157caef67629da28ec0f4fe11c6c7a8b Mon Sep 17 00:00:00 2001 From: RogerHaase Date: Wed, 21 Feb 2024 07:47:35 -0700 Subject: [PATCH 1/4] import19 lacks support for UserGroup and WikiDict conversion; fixes #1595 Added 2 macros to display usergroup and wikidict attributes. --- src/moin/cli/migration/moin19/import19.py | 53 +++++++++++++++++++++++ src/moin/macros/ShowUserGroup.py | 22 ++++++++++ src/moin/macros/ShowWikiDict.py | 22 ++++++++++ src/moin/macros/_base.py | 10 +++++ 4 files changed, 107 insertions(+) create mode 100644 src/moin/macros/ShowUserGroup.py create mode 100644 src/moin/macros/ShowWikiDict.py diff --git a/src/moin/cli/migration/moin19/import19.py b/src/moin/cli/migration/moin19/import19.py index 230617280..477ee34f9 100644 --- a/src/moin/cli/migration/moin19/import19.py +++ b/src/moin/cli/migration/moin19/import19.py @@ -229,6 +229,12 @@ def ImportMoin19(data_dir=None, markup_out=None, namespace=None): # bumping modified time makes global and item history views more useful meta[MTIME] = meta[MTIME] + 1 meta[COMMENT] = 'Converted moin 1.9 markup to ' + markup_out + ' markup' + if meta[NAME][0].endswith('Group') and meta[USERGROUP]: + msg = 'Moin1.x user list moved to User Group metadata; item content ignored. Use ShowUserGroup macro. ' + meta[COMMENT] = msg + meta[COMMENT] + if meta[NAME][0].endswith('Dict') and meta[WIKIDICT]: + msg = 'Moin1.x Wiki Dict data moved to Wiki Dict metadata; item content ignored. Use ShowWikiDict macro. ' + meta[COMMENT] = msg + meta[COMMENT] meta[CONTENTTYPE] = CONTENTTYPE_MARKUP_OUT[markup_out] del meta[DATAID] out.seek(0) @@ -457,6 +463,11 @@ def __init__(self, item, revno, path, target_namespace): meta[TAGS].append(TEMPLATE) else: meta[TAGS] = [TEMPLATE] + if meta[NAME][0].endswith('Group'): + meta[USERGROUP] = self._parse_acl_list(content) + if meta[NAME][0].endswith('Dict'): + meta[WIKIDICT] = self._parse_wikidict(content) + # if this revision matches a custom namespace defined in wikiconfig, # then modify the meta data for namespace and name for custom_namespace in custom_namespaces: @@ -514,6 +525,48 @@ def _process_data(self, meta, data): data = process_categories(meta, data, self.backend.item_category_regex) return data + def _parse_acl_list(self, content): + """ + Return ACL list extracted from item's content + """ + ret = [] + first_user = True + start = 'not a hit yet' + lines = content.splitlines() + for line in lines: + if first_user: + parts = line.split('*') + if len(parts) == 2 and parts[1].startswith(' '): + # only select lines with consistent indentation + start = parts[0] + '* ' + first_user = False + if line.startswith(start): + parts = line.split('*') + if len(parts) == 2 and parts[1].startswith(' '): + username = parts[1].strip() + # link conversion may have enclosed all links with [[...]], maybe a leading +/-: "+[[UserName]]" + if username.startswith('[[') and username.endswith(']]'): + ret.append(username[2:-2]) + elif username.startswith('+[[') or username.startswith('-[[') and username.endswith(']]'): + username.replace('[', '') + ret.append(username[:-2]) + else: + ret.append(username) + return ret + + def _parse_wikidict(self, content): + """ + Return a dict of key, value pairs: {key: val,...} + """ + ret = {} + lines = content.splitlines() + for line in lines: + line = line.strip() + parts = line.split(':: ') + if len(parts) == 2: + ret[parts[0]] = parts[1] + return ret + def migrate_itemlinks(dom, namespace, itemlinks2chg): """ Walk the DOM tree and change itemlinks to users namespace diff --git a/src/moin/macros/ShowUserGroup.py b/src/moin/macros/ShowUserGroup.py new file mode 100644 index 000000000..da9de4601 --- /dev/null +++ b/src/moin/macros/ShowUserGroup.py @@ -0,0 +1,22 @@ +# Copyright: 2024 MoinMoin:RogerHaase +# License: GNU GPL v2 (or any later version), see LICENSE.txt for details. + +""" +Show contents of UserGroup attribute in metadata. +""" + +from moin.macros._base import MacroBlockBase, fail_message +from moin.items import Item +from moin.constants.keys import USERGROUP +from moin.i18n import _ + + +class Macro(MacroBlockBase): + def macro(self, content, arguments, page_url, alternative): + url = str(page_url.path)[1:] + try: + item = Item.create(url) + return item.meta[USERGROUP] + except KeyError: + msg = _('ShowUserGroup macro failed - metadata lacks "usergroup" attribute.') + return fail_message(msg) diff --git a/src/moin/macros/ShowWikiDict.py b/src/moin/macros/ShowWikiDict.py new file mode 100644 index 000000000..0ab9a3899 --- /dev/null +++ b/src/moin/macros/ShowWikiDict.py @@ -0,0 +1,22 @@ +# Copyright: 2024 MoinMoin:RogerHaase +# License: GNU GPL v2 (or any later version), see LICENSE.txt for details. + +""" +Show contents of WikiDict attribute in metadata. +""" + +from moin.macros._base import MacroBlockBase, fail_message +from moin.items import Item +from moin.constants.keys import WIKIDICT +from moin.i18n import _ + + +class Macro(MacroBlockBase): + def macro(self, content, arguments, page_url, alternative): + url = str(page_url.path)[1:] + try: + item = Item.create(url) + return item.meta[WIKIDICT] + except KeyError: + msg = _('ShowWikiDict macro failed - metadata lacks "wikidict" attribute.') + return fail_message(msg) diff --git a/src/moin/macros/_base.py b/src/moin/macros/_base.py index a52e439b6..b23b60cad 100644 --- a/src/moin/macros/_base.py +++ b/src/moin/macros/_base.py @@ -9,6 +9,7 @@ import re from moin.utils import iri from moin.items import Item +from moin.utils.tree import html from moin.i18n import _ from werkzeug.exceptions import abort from moin.utils.tree import moin_page, xlink @@ -61,6 +62,15 @@ def get_item_names(name='', startswith='', kind='files', skiptag=''): return item_names +def fail_message(msg, severity='error'): + """ + Return an error message in admonition-like format. + + Severity may be: attention, caution, danger, error, hint, important, note, or tip. + """ + return html.div(attrib={html.class_: '{0} moin-nowiki'.format(severity)}, children=msg) + + class MacroBase: """ Macro base class. From aafc24a873a58c8a2a37719045bfbe286b51aa57 Mon Sep 17 00:00:00 2001 From: RogerHaase Date: Wed, 21 Feb 2024 08:29:23 -0700 Subject: [PATCH 2/4] add admonition classes defined in common.css but not in moinwiki.rst --- docs/user/moinwiki.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/user/moinwiki.rst b/docs/user/moinwiki.rst index 6bcf32504..a965102b6 100644 --- a/docs/user/moinwiki.rst +++ b/docs/user/moinwiki.rst @@ -713,7 +713,7 @@ CSS classes for use with the wiki parser, tables, comments, and links - Background colors: red, green, blue, yellow, or orange - Borders: solid, dashed, or dotted - Text-alignment: left, center, right, or justify - - Admonitions: caution, important, note, tip, warning + - Admonitions: attention, caution, danger, error, hint, important, note, tip, warning - Tables: moin-sortable, no-borders - Comments: comment - Position parsers and tables: float-left, float-right, inline, middle, clear-right, clear-left or clear-both From b71ada8721f3ab4aff227f0296691789a745e999 Mon Sep 17 00:00:00 2001 From: RogerHaase Date: Wed, 21 Feb 2024 08:54:28 -0700 Subject: [PATCH 3/4] add docs for new ShowUserGroup and ShowWikiDict macros; #1595 --- docs/user/moinwiki.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/user/moinwiki.rst b/docs/user/moinwiki.rst index a965102b6..ae900444d 100644 --- a/docs/user/moinwiki.rst +++ b/docs/user/moinwiki.rst @@ -822,6 +822,10 @@ extra features. The following is a table of MoinMoin's macros. +-------------------------------------------+------------------------------------------------------------+ | ``<>`` | Displays available smileys and the corresponding markup | +-------------------------------------------+------------------------------------------------------------+ +| ``<>`` | Displays metadata defined in usergroup attribute | ++-------------------------------------------+------------------------------------------------------------+ +| ``<>`` | Displays metadata defined in wikidict attribute | ++-------------------------------------------+------------------------------------------------------------+ | ``<>`` | Shows a table of contents up to level 2 | +-------------------------------------------+------------------------------------------------------------+ | ``<>`` | Lists all itemnames for the namespace of the current item, | From 1f6d905152d35e1c2f7cd681510905af8f346e5f Mon Sep 17 00:00:00 2001 From: RogerHaase Date: Wed, 21 Feb 2024 12:02:02 -0700 Subject: [PATCH 4/4] add ShowUserGroup and ShowWikiDict macros to help-en; #1595 moved some definitions into alphabetical order, used consistent spacing. --- src/moin/help/help-en/MoinWikiMacros.data | 103 ++++++++++++++++------ src/moin/help/help-en/MoinWikiMacros.meta | 10 +-- 2 files changed, 80 insertions(+), 33 deletions(-) diff --git a/src/moin/help/help-en/MoinWikiMacros.data b/src/moin/help/help-en/MoinWikiMacros.data index 5e63126a0..7a4f89ac6 100644 --- a/src/moin/help/help-en/MoinWikiMacros.data +++ b/src/moin/help/help-en/MoinWikiMacros.data @@ -8,6 +8,7 @@ Features that are not working correctly are marked with '''MOINTODO:''' There are four built-in macros. + === TableOfContents === The number of levels in the table of contents can be limited by passing an integer parameter. @@ -23,6 +24,7 @@ The number of levels in the table of contents can be limited by passing an integ See TOC floated to right. + === FootNotes === '''Markup:''' @@ -47,6 +49,7 @@ By default footnotes are placed at the bottom of the page. Explicit placement of Subsequent footnotes<> will be numbered starting with 1 and placed at the bottom of the page by default. + === BR - Forced Line Break === '''Markup:''' @@ -59,6 +62,7 @@ Use a BR macro <
>to force a line break. Use a BR macro <
>to force a line break. + === Include === '''Markup:''' @@ -117,6 +121,7 @@ link inside Item Views to show/hide the inclusion. == Extension Macros from MoinMoin/macro/ == + === Anchor === Anchors are created (but invisible of course). Click [[#anchorname|here]] to scroll the window to the anchor following '''Result''' below. @@ -131,6 +136,7 @@ Anchors are created (but invisible of course). Click [[#anchorname|here]] to scr <> + === Date === '''Markup:''' @@ -155,6 +161,7 @@ Do this after <> but before <>. Do this after <> but before <>. + === DateTime === '''Markup:''' @@ -179,6 +186,7 @@ Do this after <> but before <>. Do this after <> but before <>. + === FontAwesome === The FontAwesome macro displays FontAwesome fonts. @@ -223,6 +231,7 @@ create a character half the current size. <> <> + === GetText === Loads I18N texts. If this browser is set to German/Deutsch the macro output will be: Einstellungen ("Settings" is included in the translation files). @@ -237,6 +246,7 @@ Loads I18N texts. If this browser is set to German/Deutsch the macro output will <> + === GetVal === For GetVal to work, there must be either a ConfigDict or WikiDict defined (see config docs). This example depends upon an item named [[help-en/WikiDict]] having specific metadata. See configuration docs for details. @@ -251,6 +261,7 @@ For GetVal to work, there must be either a ConfigDict or WikiDict defined (see c <> + === Icon === The Icon macro displays an icon. The complete list of available icons are listed within [[/Icons]]. @@ -265,24 +276,6 @@ Here is the moin icon: <> Here is the moin icon: <> -=== MailTo === - -The MailTo macro exports different markup when the user is logged in. - -'''Markup:''' - -{{{ -<> - -<> -}}} - -'''Result:''' - -<> - -<> - === ItemList === @@ -291,10 +284,8 @@ This section is partitioned into subsections, one for each ItemPageList paramete Most of the examples below search for descendents under the top-level "OtherTextItems" item, the only sample-wiki item that contains a significant number of descendents. - ===== The "item" parameter ===== - '''Markup:''' {{{ @@ -443,6 +434,39 @@ Displayed using "UnCameled": <> + +=== MailTo === + +The MailTo macro exports different markup when the user is logged in. + +'''Markup:''' + +{{{ +<> + +<> +}}} + +'''Result:''' + +<> + +<> + + +=== MonthCalendar === + +The MonthCalendar macro is for those who need a calendar wiki integration or want to use MoinMoin as a Personal Information Manager. + +'''Markup:''' + +{{{ +<> +}}} + +For more details see [[/MonthCalendar]] + + === RandomItem === '''Markup:''' @@ -467,33 +491,56 @@ Five random items: <> -=== TitleIndex === -TitleIndex gives a List of all Itemnames in the current namespace grouped by initials. +=== ShowUserGroup === + +This macro displays the contents of the metadata defined in the "usergroup" attribute. +Because this item has no metadata usergroup attribute, the result shown below +represents sample output. '''Markup:''' {{{ + <> +}}} -<> +'''Result:''' + +['JillDoe', 'JaneDoeGroup', '+JohnDoe'] + +=== ShowWikiDict === + +This macro displays the contents of the metadata defined in the "wikidict" attribute. +Because this item has no metadata usergroup attribute, the result shown below +represents sample output. + +'''Markup:''' +{{{ + <> }}} '''Result:''' -<> +{'dog': 'Hund', 'cat': 'Katze'} -=== MonthCalendar === -The MonthCalendar macro is for those who need a calendar wiki integration or want to use MoinMoin as a Personal Information Manager. +=== TitleIndex === + +TitleIndex gives a List of all Itemnames in the current namespace grouped by initials. '''Markup:''' {{{ -<> + +<> + }}} -For more details see [[/MonthCalendar]] +'''Result:''' + +<> + === Verbatim === diff --git a/src/moin/help/help-en/MoinWikiMacros.meta b/src/moin/help/help-en/MoinWikiMacros.meta index b4cc6b2cd..1f0e1788d 100644 --- a/src/moin/help/help-en/MoinWikiMacros.meta +++ b/src/moin/help/help-en/MoinWikiMacros.meta @@ -3,7 +3,7 @@ "address": "127.0.0.1", "comment": "", "contenttype": "text/x.moin.wiki;charset=utf-8", - "dataid": "ab509237fd3d4be9976f961da142d5b5", + "dataid": "9262cede73cd48629f7db4b397ee0835", "externallinks": [ "https://fontawesome.com/search?o=r&m=free", "https://moinmo.in/HelpOnMacros/Include" @@ -18,16 +18,16 @@ "help-common/logo.png" ], "itemtype": "default", - "mtime": 1707909302, + "mtime": 1708540585, "name": [ "MoinWikiMacros" ], "name_old": [], "namespace": "help-en", "rev_number": 1, - "revid": "397c78f382924549bda167b7639d1078", - "sha1": "406b9ead3b66237e9d3452f3bc99b2f9d281a92c", - "size": 12447, + "revid": "e1f1896173f24726bdc16811778b1c04", + "sha1": "cb14ea7833e4c378cf6ced5bbaddb00ed05a1d26", + "size": 13140, "summary": "", "tags": [ "macros",