Line: 5 to 5 | |||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Official list of stable TWiki functions for Plugin developers | |||||||||||||
Changed: | |||||||||||||
< < | This module defines official functions that Plugins | ||||||||||||
> > | This module defines official functions that Plugins | ||||||||||||
can use to interact with the TWiki engine and content. Refer to EmptyPlugin and lib/TWiki/Plugins/EmptyPlugin.pm for a template Plugin and documentation on how to write a Plugin. | |||||||||||||
Line: 20 to 20 | |||||||||||||
The version of the TWiki::Func module is defined by the VERSION number of the TWiki::Plugins module, currently 6.10. This can be shown | |||||||||||||
Changed: | |||||||||||||
< < | by the %PLUGINVERSION% variable. The 'Since' field in the function
documentation refers to the VERSION number and the date that the function
was addded.
Note: Beware! These methods should only ever be called
from the context of a TWiki Plugin. They require a Plugins SESSION context to be
established before they are called, and will not work if simply called from
another TWiki module. For example,
use TWiki; print TWiki::Func::getSkin(),"\n";will fail with Can't call method "getSkin" on an undefined value at TWiki/Func.pm line 83 .
If you want to call the methods outside the context of a plugin, you can create a Plugins SESSION object. For example,
the script:
use TWiki: $TWiki::Plugins::SESSION = new TWiki(); print TWiki::Func::getSkin(),"\n";will work happily. | ||||||||||||
> > | by the %PLUGINVERSION% TWiki variable, and accessed in code using
$TWiki::Plugins::VERSION . The 'Since' field in the function
documentation refers to $TWiki::Plugins::VERSION .
Notes on use of $TWiki::Plugins::VERSION (from 1.2 forwards):
| ||||||||||||
On this page:
| |||||||||||||
Line: 73 to 76 | |||||||||||||
| |||||||||||||
Changed: | |||||||||||||
< < |
| ||||||||||||
> > |
| ||||||||||||
Return: $url URL, e.g. "http://example.com:80/cgi-bin/view.pl/Main/WebNotify" | |||||||||||||
Line: 90 to 93 | |||||||||||||
Since: TWiki::Plugins::VERSION 1.000 (7 Dec 2002) | |||||||||||||
Changed: | |||||||||||||
< < | getOopsUrl( $web, $topic, $template, $param1, $param2, $param3, $param4 ) -> $urlCompose fully qualified 'oops' dialog URL
$url URL, e.g. "http://example.com:80/cgi-bin/oops.pl/ Main/WebNotify?template=oopslocked¶m1=joe" | ||||||||||||
> > | getPubUrlPath( ) -> $path | ||||||||||||
Changed: | |||||||||||||
< < | This might be used like this:
my $url = TWiki::Func::getOopsUrl($web, $topic, 'oopsmistake', 'I made a boo-boo'); TWiki::Func::redirectCgiQuery( undef, $url ); return 0; | ||||||||||||
> > | Get pub URL path | ||||||||||||
Changed: | |||||||||||||
< < | Since: TWiki::Plugins::VERSION 1.000 (7 Dec 2002) | ||||||||||||
> > | Return: $path URL path of pub directory, e.g. "/pub" | ||||||||||||
Changed: | |||||||||||||
< < | Since TWiki::Plugins::VERSION 1.1, the recommended approach is to throw an oops exception.
use Error qw( :try ); | ||||||||||||
> > | Since: TWiki::Plugins::VERSION 1.000 (14 Jul 2001) | ||||||||||||
Deleted: | |||||||||||||
< < | throw TWiki::OopsException($web, $topic, undef, 0, [ 'I made a boo-boo' ]); and let TWiki handle the cleanup. | ||||||||||||
Added: | |||||||||||||
> > | getExternalResource( $url ) -> $response | ||||||||||||
Changed: | |||||||||||||
< < | getPubUrlPath( ) -> $path | ||||||||||||
> > | Get whatever is at the other end of a URL (using an HTTP GET request). Will
only work for encrypted protocols such as https if the LWP CPAN module is
installed.
Note that the $url may have an optional user and password, as specified by
the relevant RFC. Any proxy set in configure is honoured.
The $response is an object that is known to implement the following subset of
the methods of LWP::Response . It may in fact be an LWP::Response object,
but it may also not be if LWP is not available, so callers may only assume
the following subset of methods is available:
is_error() will return
true, code() will return a valid HTTP status code
as specified in RFC 2616 and RFC 2518, and message() will return the
message that was received from
the server. In the event of a client-side error (e.g. an unparseable URL)
then is_error() will return true and message() will return an explanatory
message. code() will return 400 (BAD REQUEST). | ||||||||||||
Changed: | |||||||||||||
< < | Get pub URL path | ||||||||||||
> > | Note: Callers can easily check the availability of other HTTP::Response methods as follows: | ||||||||||||
Changed: | |||||||||||||
< < | Return: $path URL path of pub directory, e.g. "/pub" | ||||||||||||
> > | my $response = TWiki::Func::getExternalResource($url); if (!$response->is_error() && $response->isa('HTTP::Response')) { ... other methods of HTTP::Response may be called } else { ... only the methods listed above may be called } | ||||||||||||
Changed: | |||||||||||||
< < | Since: TWiki::Plugins::VERSION 1.000 (14 Jul 2001) | ||||||||||||
> > | Since: TWiki::Plugins::VERSION 1.2 | ||||||||||||
getCgiQuery( ) -> $query | |||||||||||||
Line: 135 to 159 | |||||||||||||
Since: TWiki::Plugins::VERSION 1.000 (7 Dec 2002) | |||||||||||||
Added: | |||||||||||||
> > | @keys
Get a list of all the names of session variables. The list is unsorted.
Session keys are stored and retrieved using | ||||||||||||
getSessionValue( $key ) -> $valueGet a session value from the client session module | |||||||||||||
Line: 175 to 208 | |||||||||||||
identifier - the view script has 'view', the edit script has 'edit' etc. So you can easily tell what 'type' of script your Plugin is being called within. The core context identifiers are listed | |||||||||||||
Changed: | |||||||||||||
< < | in the TWikiTemplates topic. Please be careful not to | ||||||||||||
> > | in the TWikiTemplates topic. Please be careful not to | ||||||||||||
overwrite any of these identifiers! Context identifiers can be used to communicate between Plugins, and between | |||||||||||||
Line: 210 to 243 | |||||||||||||
Since: TWiki::Plugins::VERSION 1.1 | |||||||||||||
Added: | |||||||||||||
> > | pushTopicContext($web, $topic)
$web.$topic
from now on. All the preferences will be reset to those of the new topic.
Note that if the new topic is not readable by the logged in user due to
access control considerations, there will not be an exception. It is the
duty of the caller to check access permissions before changing the topic.
It is the duty of the caller to restore the original context by calling
popTopicContext .
Note that this call does not re-initialise plugins, so if you have used
global variables to remember the web and topic in initPlugin , then those
values will be unchanged.
Since: TWiki::Plugins::VERSION 1.2
popTopicContext()Returns the TWiki context to the state it was in before thepushTopicContext was called.
Since: TWiki::Plugins::VERSION 1.2 | ||||||||||||
Preferences | |||||||||||||
Line: 281 to 341 | |||||||||||||
preferences set in the plugin topic will be ignored. | |||||||||||||
Added: | |||||||||||||
> > | setPreferencesValue($name, $val)Set the preferences value so that future calls to getPreferencesValue will return this value, and%$name% will expand to the preference when used in
future variable expansions.
The preference only persists for the rest of this request. Finalised
preferences cannot be redefined using this function.
Returns 1 if the preference was defined, and 0 otherwise. | ||||||||||||
getWikiToolName( ) -> $nameGet toolname as defined in TWiki.cfg | |||||||||||||
Line: 319 to 389 | |||||||||||||
Since: TWiki::Plugins::VERSION 1.000 (7 Dec 2002) | |||||||||||||
Changed: | |||||||||||||
< < | getWikiName( ) -> $wikiName | ||||||||||||
> > | getCanonicalUserID( $user ) -> $cUIDReturn the cUID of the specified user. A cUID is a unique identifier which is assigned by TWiki for each user. BEWARE: While the default TWikiUserMapping uses a cUID that looks like a user's LoginName, some characters are modified to make them compatible with rcs. Additionally, other usermappings will use other conventions - the JoomlauserMapping for example, has cUIDs like 'JoomlaeUserMapping_1234'. If $user is undefined Get the cUID of logged in user, and will generally be 'BaseUserMapping_666'
$cUID an internal unique and transportable escaped identifier for
registered users (they can be autogenerated for an authenticated but unregistered
user) | ||||||||||||
Changed: | |||||||||||||
< < | Get Wiki name of logged in user | ||||||||||||
> > | Since: TWiki::Plugins::VERSION 1.2
getWikiName( $user ) -> $wikiNamereturn the WikiName of the specified user if $user is undefined Get Wiki name of logged in user
| ||||||||||||
Return: $wikiName Wiki Name, e.g. 'JohnDoe'
Since: TWiki::Plugins::VERSION 1.000 (7 Dec 2002) | |||||||||||||
Changed: | |||||||||||||
< < | getWikiUserName( ) -> $wikiName | ||||||||||||
> > | getWikiUserName( $user ) -> $wikiNamereturn the userWeb.WikiName of the specified user if $user is undefined Get Wiki name of logged in user | ||||||||||||
Changed: | |||||||||||||
< < | Get Wiki name of logged in user with web prefix | ||||||||||||
> > |
| ||||||||||||
Return: $wikiName Wiki Name, e.g. "Main.JohnDoe" | |||||||||||||
Line: 338 to 434 | |||||||||||||
wikiToUserName( $wikiName ) -> $loginName | |||||||||||||
Changed: | |||||||||||||
< < | Translate a Wiki name to a login name based on Main.TWikiUsers topic | ||||||||||||
> > | Translate a Wiki name (or login name or cUID, if it can) to a login name. | ||||||||||||
| |||||||||||||
Changed: | |||||||||||||
< < | Return: $loginName Login name of user, e.g. 'jdoe' | ||||||||||||
> > | Return: $loginName Login name of user, e.g. 'jdoe' , or undef if not
matched.
Note that it is possible for several login names to map to the same wikiname.
This function will only return the first login name that maps to the
wikiname.
returns undef if the WikiName is not found. | ||||||||||||
Since: TWiki::Plugins::VERSION 1.000 (7 Dec 2002)
userToWikiName( $loginName, $dontAddWeb ) -> $wikiName | |||||||||||||
Changed: | |||||||||||||
< < | Translate a login name to a Wiki name based on Main.TWikiUsers topic | ||||||||||||
> > | Translate a login name to a Wiki name | ||||||||||||
$wikiName Wiki name of user, e.g. 'Main.JohnDoe' or 'JohnDoe' | |||||||||||||
Added: | |||||||||||||
> > | userToWikiName will always return a name, if the user does not exist in the mapping, the $loginName parameter is returned. (backward compatibility) | ||||||||||||
Since: TWiki::Plugins::VERSION 1.000 (7 Dec 2002) | |||||||||||||
Added: | |||||||||||||
> > | emailToWikiNames( $email, $dontAddWeb ) -> @wikiNames
wikiNameToEmails( $wikiname ) -> @emails
| ||||||||||||
isGuest( ) -> $booleanTest if logged in user is a guest (TWikiGuest) | |||||||||||||
Line: 363 to 485 | |||||||||||||
Since: TWiki::Plugins::VERSION 1.000 (7 Dec 2002) | |||||||||||||
Changed: | |||||||||||||
< < | permissionsSet( $web ) -> $boolean | ||||||||||||
> > | isAnAdmin( $login ) -> $boolean | ||||||||||||
Changed: | |||||||||||||
< < | Test if any access restrictions are set for this web, ignoring settings on individual pages
| ||||||||||||
> > | Find out if the user is an admin or not. If the user is not given,
the currently logged-in user is assumed.
| ||||||||||||
Changed: | |||||||||||||
< < | Since: TWiki::Plugins::VERSION 1.000 (27 Feb 2001) | ||||||||||||
> > | Since: TWiki::Plugins::VERSION 1.2
isGroupMember( $group, $login ) -> $booleanFind out if $login is in the named group. e.g.if( TWiki::Func::isGroupMember( "HesperionXXGroup", "jordi" )) { ... }If $user is undef , it defaults to the currently logged-in user.
eachUser() -> $iteratorGet an iterator over the list of all the registered users not including groups. The iterator will return each wiki name in turn (e.g. 'FredBloggs'). Use it as follows:my $iterator = TWiki::Func::eachUser(); while ($it->hasNext()) { my $user = $it->next(); # $user is a wikiname }WARNING on large sites, this could be a long list! Since: TWiki::Plugins::VERSION 1.2 eachMembership($wikiname) -> $iteratorGet an iterator over the names of all groups that the user is a member of. If$wikiname is undef , defaults to the currently logged-in user.
Since: TWiki::Plugins::VERSION 1.2
eachGroup() -> $iteratorGet an iterator over all groups. Use it as follows:my $iterator = TWiki::Func::eachGroup(); while ($it->hasNext()) { my $group = $it->next(); # $group is a group name e.g. TWikiAdminGroup }WARNING on large sites, this could be a long list! Since: TWiki::Plugins::VERSION 1.2 isGroup( $group ) -> $booleanChecks if$group is the name of a group known to TWiki.
eachGroupMember($group) -> $iteratorGet an iterator over all the members of the named group. Returns undef if $group is not a valid group. Use it as follows:my $iterator = TWiki::Func::eachGroupMember('RadioheadGroup'); while ($it->hasNext()) { my $user = $it->next(); # $user is a wiki name e.g. 'TomYorke', 'PhilSelway' }WARNING on large sites, this could be a long list! Since: TWiki::Plugins::VERSION 1.2 | ||||||||||||
checkAccessPermission( $type, $wikiName, $text, $topic, $web, $meta ) -> $booleanCheck access permission for a topic based on the | |||||||||||||
Changed: | |||||||||||||
< < | TWiki.TWikiAccessControl rules | ||||||||||||
> > | TWiki.TWikiAccessControl rules | ||||||||||||
| |||||||||||||
Line: 492 to 695 | |||||||||||||
Since: TWiki::Plugins::VERSION 1.1 | |||||||||||||
Added: | |||||||||||||
> > | eachChangeSince($web, $time) -> $iteratorGet an iterator over the list of all the changes in the given web between$time and now. $time is a time in seconds since 1st Jan 1970, and is not
guaranteed to return any changes that occurred before (now -
{Store}{RememberChangesFor}). {Store}{RememberChangesFor}) is a
setting in configure . Changes are returned in most-recent-first
order.
Use it as follows:
my $iterator = TWiki::Func::eachChangeSince( $web, time() - 7 * 24 * 60 * 60); # the last 7 days while ($it->hasNext()) { my $change = $it->next(); # $change is a perl hash that contains the following fields: # topic => topic name # user => wikiname - wikiname of user who made the change # time => time of the change # revision => revision number *after* the change # more => more info about the change (e.g. 'minor') } | ||||||||||||
@topics
Get list of all topics in a web | |||||||||||||
Line: 506 to 734 | |||||||||||||
Test if topic exists
| |||||||||||||
Added: | |||||||||||||
> > | |||||||||||||
$web and $topic are parsed as described in the documentation for normalizeWebTopicName . | |||||||||||||
Added: | |||||||||||||
> > | Specifically, the Main is used if $web is not specified and $topic has no web specifier. To get an expected behaviour it is recommened to specify the current web for $web; don't leave it empty. | ||||||||||||
Since: TWiki::Plugins::VERSION 1.000 (14 Jul 2001) | |||||||||||||
Line: 526 to 757 | |||||||||||||
| |||||||||||||
Changed: | |||||||||||||
< < |
| ||||||||||||
> > |
| ||||||||||||
Takes out a "lease" on the topic. The lease doesn't prevent anyone from editing and changing the topic, but it does redirect them | |||||||||||||
Line: 643 to 874 | |||||||||||||
NOTE: if you are trying to get revision info for a topic, use
$meta->getRevisionInfo instead if you can - it is significantly | |||||||||||||
Changed: | |||||||||||||
< < | more efficient, and returns a user object that contains other user information. NOTE: prior versions of TWiki may under some circumstances have returned the login name of the user rather than the wiki name; the code documentation was totally unclear, and we have been unable to establish the intent. However the wikiname is obviously more useful, so that is what is returned. | ||||||||||||
> > | more efficient. | ||||||||||||
Since: TWiki::Plugins::VERSION 1.000 (29 Jul 2001) | |||||||||||||
Line: 692 to 917 | |||||||||||||
$text Topic text with embedded meta data; an oops URL for calling redirectCgiQuery() is returned in case of an error | |||||||||||||
Changed: | |||||||||||||
< < | This method is more efficient than readTopic , but returns meta-data embedded in the text. Plugins authors must be very careful to avoid damaging meta-data. You are recommended to use readTopic instead, which is a lot safer.. | ||||||||||||
> > | This method is more efficient than readTopic , but returns meta-data embedded in the text. Plugins authors must be very careful to avoid damaging meta-data. You are recommended to use readTopic instead, which is a lot safer. | ||||||||||||
Since: TWiki::Plugins::VERSION 1.010 (31 Dec 2002) | |||||||||||||
Line: 815 to 1040 | |||||||||||||
readTemplate( $name, $skin ) -> $text | |||||||||||||
Changed: | |||||||||||||
< < | Read a template or skin. Embedded template directives get expanded | ||||||||||||
> > | Read a template or skin. Embedded template directives get expanded | ||||||||||||
$text Template text | |||||||||||||
Line: 855 to 1080 | |||||||||||||
writeHeader( $query, $contentLength )Prints a basic content-type HTML header for text/html to standard out | |||||||||||||
Changed: | |||||||||||||
< < |
| ||||||||||||
> > |
| ||||||||||||
Return: none Since: TWiki::Plugins::VERSION 1.000 (7 Dec 2002) | |||||||||||||
Line: 879 to 1104 | |||||||||||||
same TWiki installation. If $passthru is set to a true value, then TWiki
will save the current URL parameters, and then try to restore them on the
other side of the redirect. Parameters are stored on the server in a cache | |||||||||||||
Changed: | |||||||||||||
< < | file (see {PassthroughDir} in =configure ). | ||||||||||||
> > | file. | ||||||||||||
Note that if $passthru is set, then any parameters in $url will be lost
when the old parameters are restored. if you want to change any parameter | |||||||||||||
Line: 916 to 1141 | |||||||||||||
Changed: | |||||||||||||
< < | expandCommonVariables( $text, $topic, $web ) -> $text | ||||||||||||
> > | expandCommonVariables( $text, $topic, $web, $meta ) -> $text | ||||||||||||
Expand all common %VARIABLES%
| |||||||||||||
Added: | |||||||||||||
> > |
| ||||||||||||
Return: $text Expanded text, e.g. 'Current user is TWikiGuest'
Since: TWiki::Plugins::VERSION 1.000 (7 Dec 2002) | |||||||||||||
Line: 931 to 1157 | |||||||||||||
renderText( $text, $web ) -> $text | |||||||||||||
Changed: | |||||||||||||
< < | Render text from TWiki markup into XHTML as defined in TWiki.TextFormattingRules | ||||||||||||
> > | Render text from TWiki markup into XHTML as defined in TWiki.TextFormattingRules | ||||||||||||
$text XHTML text, e.g. '<b>bold</b> and <code>fixed font</code>' | |||||||||||||
Line: 1111 to 1337 | |||||||||||||
(ie, with the name of the function instead of the alias) will not work. | |||||||||||||
Added: | |||||||||||||
> > | decodeFormatTokens($str) -> $unencodedStringTWiki has an informal standard set of tokens used informat
parameters that are used to block evaluation of paramater strings.
For example, if you were to write
%MYTAG{format="%WURBLE%"}%
then %WURBLE would be expanded before %MYTAG is evaluated. To avoid
this TWiki uses escapes in the format string. For example:
%MYTAG{format="$percntWURBLE$percnt"}%
This lets you enter arbitrary strings into parameters without worrying that
TWiki will expand them before your plugin gets a chance to deal with them
properly. Once you have processed your tag, you will want to expand these
tokens to their proper value. That's what this function does.
| ||||||||||||
Searching | |||||||||||||
Line: 1250 to 1507 | |||||||||||||
Note that hierarchical web names (SubWeb) are only available if hierarchical webs are enabled in configure . | |||||||||||||
Changed: | |||||||||||||
< < | The symbols %USERSWEB%, %SYSTEMWEB%, %DOCWEB%, %MAINWEB% and %TWIKIWEB% can be used in the input to represent the web names set in $cfg{UsersWebName} and $cfg{SystemWebName}. For example: | ||||||||||||
> > | The symbols %USERSWEB%, %SYSTEMWEB% and %DOCWEB% can be used in the input to represent the web names set in $cfg{UsersWebName} and $cfg{SystemWebName}. For example: | ||||||||||||
| |||||||||||||
Added: | |||||||||||||
> > | StaticMethod *sanitizeAttachmentName ($fname) -> ($fileName,$origName)Given a file namer, sanitise it according to the rules for transforming attachment names. Returns the sanitised name together with the basename before sanitisation. Sanitation includes filtering illegal characters and mapping client file names to legal server names. Since: TWiki::Plugins::VERSION 1.2spaceOutWikiWord( $word, $sep ) -> $textSpaces out a wiki word by inserting a string (default: one space) between each word component. With parameter $sep any string may be used as separator between the word components; if $sep is undefined it defaults to a space. Since: TWiki::Plugins::VERSION 1.2 | ||||||||||||
writeWarning( $text )Log Warning that may require admin intervention to data/warning.txt | |||||||||||||
Line: 1287 to 1565 | |||||||||||||
Since: TWiki::Plugins::VERSION 1.020 (26 Feb 2004) | |||||||||||||
Added: | |||||||||||||
> > | isTrue( $value, $default ) -> $booleanReturns 1 if$value is true, and 0 otherwise. "true" means set to
something with a Perl true value, with the special cases that "off",
"false" and "no" (case insensitive) are forced to false. Leading and
trailing spaces in $value are ignored.
If the value is undef, then $default is returned. If $default is
not specified it is taken as 0.
Since: $TWiki::Plugins::VERSION 1.2 | ||||||||||||
isValidWikiWord ( $text ) -> $booleanCheck for a valid WikiWord or WikiName | |||||||||||||
Line: 1365 to 1656 | |||||||||||||
Since: TWiki::Plugins::VERSION 1.000 (7 Dec 2002) | |||||||||||||
Added: | |||||||||||||
> > | getOopsUrl( $web, $topic, $template, $param1, $param2, $param3, $param4 ) -> $urlCompose fully qualified 'oops' dialog URL
$url URL, e.g. "http://example.com:80/cgi-bin/oops.pl/ Main/WebNotify?template=oopslocked¶m1=joe"
DEPRECATED since 1.1, the recommended approach is to throw an oops exception.
use Error qw( :try ); throw TWiki::OopsException( 'toestuckerror', web => $web, topic => $topic, params => [ 'I got my toe stuck' ]);(this example will use the oopstoestuckerror template.)
If this is not possible (e.g. in a REST handler that does not trap the exception)
then you can use getScriptUrl instead:
my $url = TWiki::Func::getScriptUrl($web, $topic, 'oops', template => 'oopstoestuckerror', param1 => 'I got my toe stuck'); TWiki::Func::redirectCgiQuery( undef, $url ); return 0;Since: TWiki::Plugins::VERSION 1.000 (7 Dec 2002) permissionsSet( $web ) -> $booleanTest if any access restrictions are set for this web, ignoring settings on individual pages
getPreferencesValue instead to determine
what permissions are set on the web, for example:
foreach my $type qw( ALLOW DENY ) { foreach my $action qw( CHANGE VIEW ) { my $pref = $type . 'WEB' . $action; my $val = getPreferencesValue( $pref, $web ) || ''; if( $val =~ /\S/ ) { print "$pref is set to $val on $web\n"; } } } | ||||||||||||
@webs
DEPRECATED since 1.1 - use |