Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1595 new macros #1612

Merged
merged 5 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion docs/user/moinwiki.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -822,6 +822,10 @@ extra features. The following is a table of MoinMoin's macros.
+-------------------------------------------+------------------------------------------------------------+
| ``<<ShowSmileys()>>`` | Displays available smileys and the corresponding markup |
+-------------------------------------------+------------------------------------------------------------+
| ``<<ShowUserGroup()>>`` | Displays metadata defined in usergroup attribute |
+-------------------------------------------+------------------------------------------------------------+
| ``<<ShowWikiDict()>>`` | Displays metadata defined in wikidict attribute |
+-------------------------------------------+------------------------------------------------------------+
| ``<<TableOfContents(2)>>`` | Shows a table of contents up to level 2 |
+-------------------------------------------+------------------------------------------------------------+
| ``<<TitleIndex()>>`` | Lists all itemnames for the namespace of the current item, |
Expand Down
53 changes: 53 additions & 0 deletions src/moin/cli/migration/moin19/import19.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
103 changes: 75 additions & 28 deletions src/moin/help/help-en/MoinWikiMacros.data
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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:'''
Expand All @@ -47,6 +49,7 @@ By default footnotes are placed at the bottom of the page. Explicit placement of

Subsequent footnotes<<FootNote(This footnote is placed at bottom of page by default.)>> will be numbered starting with 1 and placed at the bottom of the page by default.


=== BR - Forced Line Break ===

'''Markup:'''
Expand All @@ -59,6 +62,7 @@ Use a BR macro <<BR>>to force a line break.

Use a BR macro <<BR>>to force a line break.


=== Include ===

'''Markup:'''
Expand Down Expand Up @@ -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.
Expand All @@ -131,6 +136,7 @@ Anchors are created (but invisible of course). Click [[#anchorname|here]] to scr

<<Anchor(anchorname)>>


=== Date ===

'''Markup:'''
Expand All @@ -155,6 +161,7 @@ Do this after <<Date()>> but before <<Date(2022-01-23T12:34:56)>>.

Do this after <<Date()>> but before <<Date(2022-01-23T12:34:56)>>.


=== DateTime ===

'''Markup:'''
Expand All @@ -179,6 +186,7 @@ Do this after <<DateTime()>> but before <<DateTime(2022-01-23T12:34:56)>>.

Do this after <<DateTime()>> but before <<DateTime(2022-01-23T12:34:56)>>.


=== FontAwesome ===

The FontAwesome macro displays FontAwesome fonts.
Expand Down Expand Up @@ -223,6 +231,7 @@ create a character half the current size.

<<FontAwesome(spin spinner,plum,2.5)>> <<FontAwesome(fan spin-reverse,orange,2.5)>>


=== 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).
Expand All @@ -237,6 +246,7 @@ Loads I18N texts. If this browser is set to German/Deutsch the macro output will

<<GetText(Settings)>>


=== 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.
Expand All @@ -251,6 +261,7 @@ For GetVal to work, there must be either a ConfigDict or WikiDict defined (see c

<<GetVal(help-en/WikiDict,var1)>>


=== Icon ===

The Icon macro displays an icon. The complete list of available icons are listed within [[/Icons]].
Expand All @@ -265,24 +276,6 @@ Here is the moin icon: <<Icon(moin-logo.png)>>

Here is the moin icon: <<Icon(moin-logo.png)>>

=== MailTo ===

The MailTo macro exports different markup when the user is logged in.

'''Markup:'''

{{{
<<MailTo(user AT example DOT org)>>

<<MailTo(user AT example DOT org, write me)>>
}}}

'''Result:'''

<<MailTo(user AT example DOT org)>>

<<MailTo(user AT example DOT org, write me)>>


=== ItemList ===

Expand All @@ -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:'''

{{{
Expand Down Expand Up @@ -443,6 +434,39 @@ Displayed using "UnCameled":

<<ItemList(item="OtherTextItems", regex="PlainText", display="UnCameled")>>


=== MailTo ===

The MailTo macro exports different markup when the user is logged in.

'''Markup:'''

{{{
<<MailTo(user AT example DOT org)>>

<<MailTo(user AT example DOT org, write me)>>
}}}

'''Result:'''

<<MailTo(user AT example DOT org)>>

<<MailTo(user AT example DOT org, write me)>>


=== MonthCalendar ===

The MonthCalendar macro is for those who need a calendar wiki integration or want to use MoinMoin as a Personal Information Manager.

'''Markup:'''

{{{
<<MonthCalendar(item,year,month,month_offset,fixed_height,anniversary)>>
}}}

For more details see [[/MonthCalendar]]


=== RandomItem ===

'''Markup:'''
Expand All @@ -467,33 +491,56 @@ Five random items:

<<RandomItem(5)>>

=== 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:'''

{{{
<<ShowUserGroup()>>
}}}

<<TitleIndex()>>
'''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:'''

{{{
<<ShowWikiDict()>>
}}}

'''Result:'''

<<TitleIndex()>>
{'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:'''

{{{
<<MonthCalendar(item,year,month,month_offset,fixed_height,anniversary)>>

<<TitleIndex()>>

}}}

For more details see [[/MonthCalendar]]
'''Result:'''

<<TitleIndex()>>


=== Verbatim ===

Expand Down
10 changes: 5 additions & 5 deletions src/moin/help/help-en/MoinWikiMacros.meta
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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",
Expand Down
22 changes: 22 additions & 0 deletions src/moin/macros/ShowUserGroup.py
Original file line number Diff line number Diff line change
@@ -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)
22 changes: 22 additions & 0 deletions src/moin/macros/ShowWikiDict.py
Original file line number Diff line number Diff line change
@@ -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)
Loading