User:AnomieBOT/source/d/Templates.pm/doc

NAME edit

d::Templates - AnomieBOT template-handling decorator

SYNOPSIS edit

 use AnomieBOT::API;
 
 $api = new AnomieBOT::API('conf.ini', 1);
 $api->decorators(qw/d::Templates/);

DESCRIPTION edit

d::Templates contains template manipulating functions for use by an AnomieBOT task. When "d::Templates" is used as a decorator on the API object, the following methods are available.

In addition, all d::Nowiki methods are also available, as this decorator uses them internally.

METHODS PROVIDED edit

$api->process_templates( $wikitext, $callback, $data )
Runs a parser over the wikitext, calling the callback function for each template, magic word, or parser function found (basically anything encosed in double-braces). The callback may return a replacement string, and the final processed version is returned.
The callback function will be passed the following parameters:
$name
The template name or the parser function/magic word invocation. For example, "reflist" or "#tag:ref". Stripped of leading/trailing spaces and with the first character uppercased.
$params
An array of the parameters. Spaces are not stripped, nor is there any attempt to interpret named parameters.
$wikitext
The raw wikitext of the template.
$data
The data object passed in the original call.
$orig_name
$name before the stripping and uppercasing.
$nl
Boolean, whether the template invocation immediately follows a newline. Possibly useful for working around T14974.
Any non-undef return value will be used to replace the original template.
$api->process_paramlist( @params )
Parse named parameters. Returns an array of objects having name, oname, value, and text parameters. If the parameter was unnamed, oname will be undef and name will be the calculated parameter number.
$api->strip_templates( $wikitext, \&callback, $data )
$api->strip_templates( $wikitext, \&callback, $data, \%matches )
Runs a parser over the wikitext, calling the callback function for each template, magic word, or parser function found (basically anything encosed in double-braces). If the callback returns a true value, the template is replaced by an opaque token.
The callback function will be passed the same parameters as for process_templates. The return value is the same as for strip_regex from the d:Nowiki decorator.
$api->strip_templates( $wikitext, \@templates )
$api->strip_templates( $wikitext, \@templates, \%matches )
As above, with a callback function that just tests whether the $name is in (or matches a regex in) the provided array.

COPYRIGHT edit

Copyright 2008–2013 Anomie

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.