CoCalc Shared Fileswww / wiki / HelpOnMacros.html
Author: William A. Stein
HelpOnMacros
 [top] [TitleIndex] [WordIndex]

# HelpOnMacros

## 1. 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.

### 1.1. 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: [[FullSearchCached(text)]] Works like the FullSearch macro but caches the results statically. Use it if you prefer speed over an up-to-date result 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

### 1.3. System information

 Macro Description Example [[InterWiki]] a list of all known InterWiki names [[SystemInfo]] info on the wiki, the python interpreter and the host system [[PageCount(exists)]] current page count. If exists is supplied as an argument, only existing pages will be shown. 816 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.

### 1.4. Others

• 1 the text cannot contain any wiki markup

• 2 "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.

• 3 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.

### 1.5. Writing your own macro

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

• macro is an instance of class Macro, and also evaluates to a string of the macroname.

• arguments is an arbitrary argument string you can pass in with parameters to your macro.

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:

   1 Dependencies = []
2
3 def execute(macro, args):
4     return macro.formatter.text("I got these args from a macro %s: %s" %
5     (str(macro), args))

• Add an entry into Dependencies if the output from your macro should not be cached. This is important if the macro output could change from one moment to another, for example if your macro searches in wiki pages which may be being edited by other users, or loads information from an external database whose contents may change. Currently the value of any entry does not matter and may be considered a short description for 'why results from this macro should not be cached', but please look at the entries used in other macros for values which may be suitable.

2013-05-11 18:32