Macros

Macros allow the insertion of system features into normal wiki pages; the only thing that makes those pages special is that they contain macros. If you edit pages like RecentChanges or SystemInfo, you'll see what that means.

For more information on the possible markup, see HelpOnEditing.

Search macros

MoinMoin now uses a new search engine, that lets your make sophisticated searches using both the interactive search box or any of the search macros. For more help, see HelpOnSearching.

Macro

Description

Example

[[TitleSearch]]

create a search box on the page, which search the page titles

See FindPage

[[FullSearch]]

create a search box on the page, which search the page contents

See FindPage

[[FullSearch()]]

print a list of pages whose content matches the current page title (like clicking on the page title)

See the CategoryCategory page

[[FullSearch(text)]]

print a list of pages whose content matches the search term

Search for powered:

[[GoTo]]

directly go to the page you enter

See the FindPage

[[PageList(Help)]]

print a list of pages whose title matches the search term

See the HelpIndex

Navigation

Macro

Description

Example

[[RecentChanges]]

a list of recently edited pages

See RecentChanges

[[TitleIndex]]

an index of all page titles

See TitleIndex

[[WordIndex]]

an index of all words in page titles

See WordIndex

[[WantedPages]]

list links to non-existent pages

See WantedPages

[[OrphanedPages]]

list pages no other page links to

See OrphanedPages

[[AbandonedPages]]

list pages that were not edited for the longest time

See AbandonedPages

[[RandomPage]]

a link to a random page

WikiCourse

[[RandomPage(#)]]

links to a number of random pages

Two random pages:

[[TableOfContents([maxdepth])]]

display a local table of contents, possibly limited to a maximal depth

See above

[[Anchor(anchorname)]]

macro to insert anchors into a page

#here

[[Navigation(children[,maxdepth])]]

macro to list all of a pages' children

See start of this page

[[Navigation(siblings[,maxdepth])]]

quick navigation to siblings of a page

See /MailTo

[[Navigation(slideshow)]]

creates a link to toggle between slide show and wiki mode, and a link to start the slide show

See HelpOnSlideShows

[[Navigation(slides)]]

displays first/prev/next/last links

See HelpOnSlideShows

[[AttachInfo]]

displays number of attachments for current page

See HelpOnActions/AttachFile

[[AttachInfo(page)]]

displays number of attachments for page

See HelpOnActions/AttachFile

[[AttachList]]

displays list of attachments for current page

See HelpOnActions/AttachFile

[[AttachList(page)]]

displays list of attachments for page

See HelpOnActions/AttachFile

System information

Macro

Description

Example

[[InterWiki]]

a list of all known InterWiki names

InterWiki

[[SystemInfo]]

info on the wiki, the python interpreter and the host system

SystemInfo

[[PageCount(exists)]]

current page count. If exists is supplied as an argument, only existing pages will be shown.

613 pages

[[PageSize]]

list the sizes of all pages

See PageSize

[[StatsChart(type)]]

shows statistical charts (currently defined types: hitcounts, pagesize, useragents)

See EventStats and subpages

[[SystemAdmin]]

Information for system administrators

Needs admin rights.

Others

Macro

Description

Example

[[Icon(image)]]

display system icons

See HelpOnNavigation

[[UserPreferences]]

display a user preferences dialog

See UserPreferences

[[BR]]

insert a line break

1st line
2nd line

[[RandomQuote(pagename)]]

Select a random quote from the given page, or from FortuneCookies if ommitted

Hint: you can search for multiple words, just like Google. See also HelpOnSearching.

[[Include(HelloWorld[,"heading"[,level]])]]

include contents of another page

for details see /Include

[[FootNote(text)]]

Add a footnote (the text cannot contain any wiki markup), or explicitely display collected footnotes when no args are given

See HelpOnPageCreation for an example

[[Date(timestamp)]]

display a timestamp according to system settings

2023-05-01

[[DateTime(timestamp)]]

display a timestamp1 according to user settings

2023-05-01 13:44:57

[[GetText(text)]]

loads I18N texts (mainly intended for use on Help pages)

"EditText" is translated to "EditText"

[[TeudView]]

useful for intranet developer wikis, a means to view pydoc documentation, formatted via a XSLT stylesheet

See http://twistedmatrix.com/wiki/python/TeudProject

[[MailTo(email)]]

protect your email address from spam bots

for details see /MailTo

[[NewPage(PageTemplate,ButtonLabel,ParentPage[,NameTemplate])]]

Allow the user to create (sub-) pages easily, using the page PageTemplateas the template for the new page and the string NameTemplate as a template for the name.2

[[GetVal(NeatSnippets,regards)]]

Retrieve dictionary entries from dict pages.

If you have a page called GermanDict which contains the entry Test, you should see the translation here:

  • 1 "timestamp" can be empty (current time), a number of seconds since 1970 (unix timestamp), or a W3C time specification ("2002-01-23T12:34:56"). See RFC822, sect. 5.

  • 2 NameTemplate is formatted with time.strftime(), with the exception of %s which is replaced by the input into the edit box (which is only shown if necessary). If NameTemplate is not specified or empty, it defaults to %s.

Writing your own macro

Create a python file called MacroName.py located in your data/plugins/macro directory. Ensure it has a single method called execute(macro, arguments), which is the entry-point.

All Macro instances have a request member through which you can access the form parameters and other information related to user interaction.

execute() should use the formatter to construct valid markup for the current target format. In most cases this is HTML, so writing a macro which returns HTML will work in most cases but fail when formats like XML or text/plain are requested.

For example, your wiki page has the following line on it:

[[MacroName(arg1,arg2,arg3)]]

You could write a MacroName.py file like this:

Dependencies = []

def execute(macro, args):
    return macro.formatter.text("I got these args from a macro %s: %s" %
    (str(macro), args))

LocalWikiList Example

The following is an example of a working macro called LocalWikiList. This macro is used to generate a bullet-list of the other wikis within the local MoinMoin instance.

   1 """
   2 LocalWikiList.py
   3 
   4 MoinMoin macro which returns a bullet-list formatted set of wikis hosted
   5 within the local MoinMoin instance. This will only pick up wikis configured
   6 in the local farmconfig.py
   7 
   8 Macro usage:
   9  [[LocalWikiList()]]
  10 
  11 """
  12 
  13 ############################################################
  14 # Modules
  15 #
  16 import imp
  17 import farmconfig
  18 
  19 ############################################################
  20 # MoinMoin configuration
  21 #
  22 Dependencies = ['farmconfig']
  23 
  24 ############################################################
  25 # Functions
  26 #
  27 def wiki_dict_cmp(dict):
  28     """ Compare wiki_dict values for key sort
  29 
  30         This function should be used to generate a cmp function
  31         for a specific dictionary of wiki_conf dictionaries
  32     """
  33     def mycmp(x, y):
  34         return cmp(dict[x]['name'], dict[y]['name'])
  35     return mycmp
  36 
  37 ############################################################
  38 # Main program
  39 #
  40 def execute(macro, args):
  41     result = []
  42 
  43     # Load up the farmconfig modules
  44     wiki_dict = {}
  45     for wikiconf, wikipattern in farmconfig.wikis:
  46         fp, pathname, description = imp.find_module(wikiconf)
  47         loaded_module = imp.load_module(wikiconf, fp, pathname, description)
  48 
  49         wiki_dict[wikiconf] = { 'name' : loaded_module.Config.sitename,
  50                                 'url_prefix' : loaded_module.Config.url_prefix,
  51                               }
  52 
  53     # Start the bullet list
  54     result.append(macro.formatter.bullet_list(1))
  55 
  56     # Build the list
  57     wiki_list = wiki_dict.keys()
  58     wiki_list.sort(wiki_dict_cmp(wiki_dict))
  59     for wikiconf in wiki_list:
  60         result.append(macro.formatter.listitem(1))
  61         result.append(macro.formatter.url(1, "%smoin.cgi/" % wiki_dict[wikiconf]['url_prefix']))
  62         result.append(macro.formatter.text(wiki_dict[wikiconf]['name']))
  63         result.append(macro.formatter.url(0))
  64         result.append(macro.formatter.listitem(0))
  65 
  66     # End the bullet list
  67     result.append(macro.formatter.bullet_list(0))
  68     return ''.join(result)

BradsWiki: HelpOnMacros (last edited 2005-11-04 13:04:20 by BradleyDean)