Line: 390 to 390 | ||||||||
---|---|---|---|---|---|---|---|---|
getCanonicalUserID( $user ) -> $cUID | ||||||||
Added: | ||||||||
> > |
| |||||||
Return 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. | ||||||||
Changed: | ||||||||
< < | Additionally, other usermappings will use other conventions - the JoomlauserMapping? | |||||||
> > | Other usermappings may use other conventions - the JoomlaUserMapping | |||||||
for example, has cUIDs like 'JoomlaeUserMapping_1234'. | ||||||||
Changed: | ||||||||
< < | If $user is undefined Get the cUID of logged in user, and will generally be 'BaseUserMapping_666' | |||||||
> > | If $user is undefined, it assumes the currently logged-in user. | |||||||
Changed: | ||||||||
< < |
$cUID an internal unique and transportable escaped identifier for
registered users (they can be autogenerated for an authenticated but unregistered
user) | |||||||
> > | Return: $cUID , an internal unique and portable escaped identifier for
registered users. This may be autogenerated for an authenticated but
unregistered user. | |||||||
Since: TWiki::Plugins::VERSION 1.2 | ||||||||
Line: 433 to 431 | ||||||||
Since: TWiki::Plugins::VERSION 1.000 (7 Dec 2002) | ||||||||
Changed: | ||||||||
< < | wikiToUserName( $wikiName ) -> $loginNameTranslate a Wiki name (or login name or cUID, if it can) to a login name.
| |||||||
> > | wikiToUserName( $id ) -> $loginNameTranslate a Wiki name to a login name.
| |||||||
Return: $loginName Login name of user, e.g. 'jdoe' , or undef if not
matched. | ||||||||
Line: 450 to 452 | ||||||||
userToWikiName( $loginName, $dontAddWeb ) -> $wikiNameTranslate a login name to a Wiki name | ||||||||
Changed: | ||||||||
< < |
| |||||||
> > |
| |||||||
$wikiName Wiki name of user, e.g. 'Main.JohnDoe' or 'JohnDoe' | ||||||||
Changed: | ||||||||
< < | userToWikiName will always return a name, if the user does not | |||||||
> > | 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) | ||||||||
Line: 470 to 474 | ||||||||
Since: TWiki::Plugins::VERSION 1.2 | ||||||||
Changed: | ||||||||
< < | wikiNameToEmails( $wikiname ) -> @emails
| |||||||
> > | wikinameToEmails( $user ) -> @emails
| |||||||
undef, returns the registered email addresses for the logged-in user. | ||||||||
Added: | ||||||||
> > | Since TWiki 4.2.1, $user may also be a login name, or the name of a group. | |||||||
Since: TWiki::Plugins::VERSION 1.2 | ||||||||
Line: 485 to 491 | ||||||||
Since: TWiki::Plugins::VERSION 1.000 (7 Dec 2002) | ||||||||
Changed: | ||||||||
< < | isAnAdmin( $login ) -> $boolean | |||||||
> > | isAnAdmin( $id ) -> $boolean | |||||||
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.2 | ||||||||
Changed: | ||||||||
< < | isGroupMember( $group, $login ) -> $boolean | |||||||
> > | isGroupMember( $group, $id ) -> $boolean | |||||||
Changed: | ||||||||
< < | Find out if $login is in the named group. e.g. | |||||||
> > | Find out if $id is in the named group. e.g. | |||||||
if( TWiki::Func::isGroupMember( "HesperionXXGroup", "jordi" )) { ... | ||||||||
Line: 504 to 510 | ||||||||
If $user is undef , it defaults to the currently logged-in user. | ||||||||
Changed: | ||||||||
< < |
| |||||||
> > |
| |||||||
Since: TWiki::Plugins::VERSION 1.2 | ||||||||
Line: 527 to 533 | ||||||||
Since: TWiki::Plugins::VERSION 1.2 | ||||||||
Changed: | ||||||||
< < | eachMembership($wikiname) -> $iterator | |||||||
> > | eachMembership($id) -> $iterator
| |||||||
Get an iterator over the names of all groups that the user is a member of. | ||||||||
Deleted: | ||||||||
< < | If $wikiname is undef , defaults to the currently logged-in user. | |||||||
Since: TWiki::Plugins::VERSION 1.2 | ||||||||
Line: 574 to 581 | ||||||||
Since: TWiki::Plugins::VERSION 1.2 | ||||||||
Changed: | ||||||||
< < | checkAccessPermission( $type, $wikiName, $text, $topic, $web, $meta ) -> $boolean | |||||||
> > | checkAccessPermission( $type, $id, $text, $topic, $web, $meta ) -> $boolean | |||||||
Check access permission for a topic based on the
TWiki.TWikiAccessControl rules
| ||||||||
Changed: | ||||||||
< < |
| |||||||
> > |
| |||||||
| ||||||||
Line: 598 to 606 | ||||||||
Settings in $meta override Set settings in $text.
A perl true result indicates that access is permitted. | ||||||||
Changed: | ||||||||
< < | Note the wierd parameter order is due to compatibility constraints with | |||||||
> > | Note the weird parameter order is due to compatibility constraints with | |||||||
earlier TWiki releases. Tip if you want, you can use this method to check your own access control types. For example, if you: | ||||||||
Line: 708 to 716 | ||||||||
my $iterator = TWiki::Func::eachChangeSince( $web, time() - 7 * 24 * 60 * 60); # the last 7 days | ||||||||
Changed: | ||||||||
< < | while ($it->hasNext()) { my $change = $it->next(); | |||||||
> > | while ($iterator->hasNext()) { my $change = $iterator->next(); | |||||||
# $change is a perl hash that contains the following fields: # topic => topic name # user => wikiname - wikiname of user who made the change | ||||||||
Line: 779 to 787 | ||||||||
| ||||||||
Changed: | ||||||||
< < |
| |||||||
> > |
| |||||||
| ||||||||
Line: 789 to 797 | ||||||||
my( $meta, $text ) = TWiki::Func::readTopic( $web, $topic ) $text =~ s/APPLE/ORANGE/g; | ||||||||
Changed: | ||||||||
< < | TWiki::Func::saveTopic( $web, $topic, $meta, $text, { comment => 'refruited' } ); | |||||||
> > | TWiki::Func::saveTopic( $web, $topic, $meta, $text, { forcenewrevision => 1 } ); | |||||||
Note: Plugins handlers ( e.g. beforeSaveHandler ) will be called as | ||||||||
Line: 903 to 911 | ||||||||
fully documented in the source code documentation shipped with the
release, or can be inspected in the lib/TWiki/Meta.pm file. | ||||||||
Changed: | ||||||||
< < | This method ignores topic access permissions. You should be careful to use checkAccessPermissions to ensure the current user has read access to the topic. | |||||||
> > | This method ignores topic access permissions. You should be careful to use
checkAccessPermissions to ensure the current user has read access to the
topic. | |||||||
Since: TWiki::Plugins::VERSION 1.000 (7 Dec 2002) | ||||||||
Line: 1209 to 1219 | ||||||||
wikiToEmail( $wikiName ) -> $email | ||||||||
Changed: | ||||||||
< < |
| |||||||
> > |
| |||||||
Get the e-mail address(es) of the named user. If the user has multiple e-mail addresses (for example, the user is a group), then the list will be comma-separated. Since: TWiki::Plugins::VERSION 1.1 | ||||||||
Added: | ||||||||
> > | Deprecated in favour of wikinameToEmails, because this function only returns a single email address, where a user may in fact have several. Since TWiki 4.2.1, $wikiName may also be a login name. | |||||||
Creating New Topics |
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 1.2. 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):
| ||||||||||||
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: | |||||||||||||
> > | getSessionKeys() -> @keysGet a list of all the names of session variables. The list is unsorted. Session keys are stored and retrieved usingsetSessionValue and
getSessionValue .
Since: TWiki::Plugins::VERSION 1.2 | ||||||||||||
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') } | ||||||||||||
getTopicList( $web ) -> @topicsGet 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"; } } } | ||||||||||||
getPublicWebList( ) -> @websDEPRECATED since 1.1 - usegetListOfWebs instead. |
Line: 371 to 371 | ||||||||
---|---|---|---|---|---|---|---|---|
Since: TWiki::Plugins::VERSION 1.000 (27 Feb 2001) | ||||||||
Changed: | ||||||||
< < | checkAccessPermission( $type, $wikiName, $text, $topic, $web ) -> $boolean | |||||||
> > | checkAccessPermission( $type, $wikiName, $text, $topic, $web, $meta ) -> $boolean | |||||||
Changed: | ||||||||
< < | Check access permission for a topic based on the TWiki.TWikiAccessControl rules
| |||||||
> > | Check access permission for a topic based on the
TWiki.TWikiAccessControl rules
| |||||||
| ||||||||
Added: | ||||||||
> > |
| |||||||
A perl true result indicates that access is permitted. | ||||||||
Added: | ||||||||
> > | Note the wierd parameter order is due to compatibility constraints with
earlier TWiki releases.
Tip if you want, you can use this method to check your own access control types. For example, if you:
ThatWeb.ThisTopic , then a call to checkAccessPermissions('SPIN', 'IncyWincy', undef, 'ThisTopic', 'ThatWeb', undef) will return true . | |||||||
Since: TWiki::Plugins::VERSION 1.000 (27 Feb 2001) |
Line: 1173 to 1173 | ||||||||
---|---|---|---|---|---|---|---|---|
Since: TWiki::Plugins::VERSION 1.020 (9 Feb 2004) Note: TWiki internally precompiles several regular expressions to | ||||||||
Changed: | ||||||||
< < | represent various string entities in an I18N? -compatible manner. Plugins | |||||||
> > | represent various string entities in an I18N-compatible manner. Plugins | |||||||
authors are encouraged to use these in matching where appropriate. The following are guaranteed to be present. Others may exist, but their use is unsupported and they may be removed in future TWiki versions. |
Line: 73 to 73 | |||||||||
---|---|---|---|---|---|---|---|---|---|
| |||||||||
Added: | |||||||||
> > |
| ||||||||
Return: $url URL, e.g. "http://example.com:80/cgi-bin/view.pl/Main/WebNotify"
Since: TWiki::Plugins::VERSION 1.000 (7 Dec 2002) | |||||||||
Line: 144 to 146 | |||||||||
setSessionValue( $key, $value ) -> $boolean | |||||||||
Changed: | |||||||||
< < | Set a session value via the client session module | ||||||||
> > | Set a session value. | ||||||||
| |||||||||
Line: 154 to 156 | |||||||||
clearSessionValue( $key ) -> $boolean | |||||||||
Changed: | |||||||||
< < | Clear a session value via the client session module
| ||||||||
> > | Clear a session value that was set using setSessionValue .
| ||||||||
Since: TWiki::Plugins::VERSION 1.1 | |||||||||
Line: 227 to 231 | |||||||||
| |||||||||
Added: | |||||||||
> > | NOTE: As of TWiki4.1, if $NO_PREFS_IN_TOPIC is enabled in the plugin, then
preferences set in the plugin topic will be ignored. | ||||||||
getPluginPreferencesValue( $key ) -> $value | |||||||||
Line: 238 to 245 | |||||||||
Since: TWiki::Plugins::VERSION 1.021 (27 Mar 2004) | |||||||||
Added: | |||||||||
> > | NOTE: As of TWiki4.1, if $NO_PREFS_IN_TOPIC is enabled in the plugin, then
preferences set in the plugin topic will be ignored. | ||||||||
getPreferencesFlag( $key, $web ) -> $value | |||||||||
Line: 253 to 263 | |||||||||
| |||||||||
Added: | |||||||||
> > | NOTE: As of TWiki4.1, if $NO_PREFS_IN_TOPIC is enabled in the plugin, then
preferences set in the plugin topic will be ignored. | ||||||||
getPluginPreferencesFlag( $key ) -> $boolean | |||||||||
Line: 264 to 277 | |||||||||
Since: TWiki::Plugins::VERSION 1.021 (27 Mar 2004) | |||||||||
Added: | |||||||||
> > | NOTE: As of TWiki4.1, if $NO_PREFS_IN_TOPIC is enabled in the plugin, then
preferences set in the plugin topic will be ignored. | ||||||||
getWikiToolName( ) -> $name | |||||||||
Line: 473 to 490 | |||||||||
Since: TWiki::Plugins::VERSION 1.000 (14 Jul 2001) | |||||||||
Changed: | |||||||||
< < | checkTopicEditLock( $web, $topic ) -> ( $oopsUrl, $loginName, $unlockTime ) | ||||||||
> > | checkTopicEditLock( $web, $topic, $script ) -> ( $oopsUrl, $loginName, $unlockTime ) | ||||||||
Check if a lease has been taken by some other user.
( $oopsUrl, $loginName, $unlockTime ) - The $oopsUrl for calling redirectCgiQuery(), user's $loginName , and estimated $unlockTime in minutes, or ( '', '', 0 ) if no lease exists. | |||||||||
Added: | |||||||||
> > |
| ||||||||
Since: TWiki::Plugins::VERSION 1.010 (31 Dec 2002) | |||||||||
Line: 814 to 841 | |||||||||
Since: TWiki::Plugins::VERSION 1.000 (7 Dec 2002) | |||||||||
Changed: | |||||||||
< < | redirectCgiQuery( $query, $url ) | ||||||||
> > | redirectCgiQuery( $query, $url, $passthru ) | ||||||||
Redirect to URL
| |||||||||
Changed: | |||||||||
< < | Return: none, never returns | ||||||||
> > |
$passthru parameter allows you to pass the parameters that were passed
to the current query on to the target URL, as long as it is another URL on the
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
file (see {PassthroughDir} in =configure ).
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
values, you will need to do that in the current CGI query before redirecting
e.g.
my $query = TWiki::Func::getCgiQuery(); $query->param(-name => 'text', -value => 'Different text'); TWiki::Func::redirectCgiQuery( undef, TWiki::Func::getScriptUrl($web, $topic, 'edit'), 1); $passthru does nothing if $url does not point to a script in the current
TWiki installation. | ||||||||
Since: TWiki::Plugins::VERSION 1.000 (7 Dec 2002) | |||||||||
Line: 984 to 1042 | |||||||||
would let you do this:
%EXEC{"ps -Af" silent="on"}% | |||||||||
Added: | |||||||||
> > | Registered tags differ from tags implemented using the old TWiki approach (text substitution in commonTagsHandler ) in the following ways:
| ||||||||
registerRESTHandler( $alias, \&fn, ) | |||||||||
Added: | |||||||||
> > | |||||||||
Should only be called from initPlugin. Adds a function to the dispatch table of the REST interface | |||||||||
Line: 1147 to 1213 | |||||||||
Parse a web and topic name, supplying defaults as appropriate.
| |||||||||
Changed: | |||||||||
< < | Return: the parsed Web/Topic pai | ||||||||
> > | Return: the parsed Web/Topic pair | ||||||||
Since: TWiki::Plugins::VERSION 1.1 | |||||||||
Line: 1156 to 1222 | |||||||||
| |||||||||
Added: | |||||||||
> > |
| ||||||||
| |||||||||
Added: | |||||||||
> > |
| ||||||||
| |||||||||
Changed: | |||||||||
< < |
Main and TWiki are the web names set in $cfg{UsersWebName} and $cfg{SystemWebName} respectively. | ||||||||
> > |
Note that hierarchical web names (SubWeb? ) are only available if hierarchical webs are enabled in configure .
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:
| ||||||||
writeWarning( $text ) | |||||||||
Line: 1296 to 1369 | |||||||||
getDataDir( ) -> $dir | |||||||||
Changed: | |||||||||
< < | DEPRECATED since 1.1 - use the content handling functions to manipulate topics instead | ||||||||
> > | DEPRECATED since 1.1 - use the "Webs, Topics and Attachments" functions to manipulate topics instead | ||||||||
Get data directory (topic file root) | |||||||||
Line: 1309 to 1382 | |||||||||
getPubDir( ) -> $dir | |||||||||
Changed: | |||||||||
< < | DEPRECATED since 1.1 - use the content handling functions to manipulateattachments instead | ||||||||
> > | DEPRECATED since 1.1 - use the "Webs, Topics and Attachments" functions to manipulateattachments instead | ||||||||
Get pub directory (file attachment root). Attachments are in $dir/Web/TopicName |
Line: 359 to 359 | ||||||||
---|---|---|---|---|---|---|---|---|
Check access permission for a topic based on the TWiki.TWikiAccessControl rules
| ||||||||
Changed: | ||||||||
< < |
| |||||||
> > |
| |||||||
| ||||||||
Added: | ||||||||
> > | A perl true result indicates that access is permitted. | |||||||
Since: TWiki::Plugins::VERSION 1.000 (27 Feb 2001) |
Line: 271 to 271 | ||||||||
---|---|---|---|---|---|---|---|---|
Return: $name Name of tool, e.g. 'TWiki' | ||||||||
Deleted: | ||||||||
< < | Synonymous with TWiki::Func::getPreferencesValue('WIKITOOLNAME'); | |||||||
Since: TWiki::Plugins::VERSION 1.000 (27 Feb 2001) | ||||||||
Line: 282 to 280 | ||||||||
Return: $name Name, e.g. 'Main' | ||||||||
Deleted: | ||||||||
< < | Synonymous with TWiki::Func::getPreferencesValue('MAINWEB'); | |||||||
Since: TWiki::Plugins::VERSION 1.000 (27 Feb 2001) | ||||||||
Line: 293 to 289 | ||||||||
Return: $name Name, e.g. 'TWiki' | ||||||||
Deleted: | ||||||||
< < | Synonymous with TWiki::Func::getPreferencesValue('TWIKIWEB'); | |||||||
Since: TWiki::Plugins::VERSION 1.000 (27 Feb 2001) | ||||||||
Line: 674 to 668 | ||||||||
| ||||||||
Changed: | ||||||||
< < | Read an attachment from the store for a topic, and return it as a string. The names of attachments on a topic can be recovered from the meta-data returned by readTopic . If the attachment does not exist, or cannot be read, undef will be returned. | |||||||
> > | Read an attachment from the store for a topic, and return it as a string. The
names of attachments on a topic can be recovered from the meta-data returned
by readTopic . If the attachment does not exist, or cannot be read, undef
will be returned. If the revision is not specified, the latest version will
be returned. | |||||||
View permission on the topic is required for the read to be successful. Access control violations are flagged by a | ||||||||
Changed: | ||||||||
< < | TWiki::AccessControlException. Permissions are checked for the user passed in. | |||||||
> > | TWiki::AccessControlException. Permissions are checked for the current user. | |||||||
my( $meta, $text ) = TWiki::Func::readTopic( $web, $topic ); my @attachments = $meta->find( 'FILEATTACHMENT' ); foreach my $a ( @attachments ) { try { | ||||||||
Changed: | ||||||||
< < | my $data = TWiki::Func::readAttachment( $meta, $a->{name} ); | |||||||
> > | my $data = TWiki::Func::readAttachment( $web, $topic, $a->{name} ); | |||||||
... } catch TWiki::AccessControlException with { }; |
Line: 1 to 1 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Added: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
> > | Package
|
dontlog | don't log this change in twiki log |
comment | comment for save |
minor | True if this is a minor change, and is not to be notified |
my( $meta, $text ) = TWiki::Func::readTopic( $web, $topic ) $text =~ s/APPLE/ORANGE/g; TWiki::Func::saveTopic( $web, $topic, $meta, $text, { comment => 'refruited' } );Note: Plugins handlers ( e.g.
beforeSaveHandler
) will be called as
appropriate.
$web
- Web name, e.g. 'Main'
, or empty
$topic
- Topic name, e.g. 'MyTopic'
, or "Main.MyTopic"
$text
- Topic text to save, assumed to include meta data
$ignorePermissions
- Set to "1"
if checkAccessPermission() is already performed and OK
$dontNotify
- Set to "1"
if not to notify users of the change
$oopsUrl
Empty string if OK; the $oopsUrl
for calling redirectCgiQuery() in case of error
This method is a lot less efficient and much more dangerous than saveTopic
.
Since: TWiki::Plugins::VERSION 1.010 (31 Dec 2002)
my $text = TWiki::Func::readTopicText( $web, $topic ); # check for oops URL in case of error: if( $text =~ /^http.*?\/oops/ ) { TWiki::Func::redirectCgiQuery( $query, $text ); return; } # do topic text manipulation like: $text =~ s/old/new/g; # do meta data manipulation like: $text =~ s/(META\:FIELD.*?name\=\"TopicClassification\".*?value\=\")[^\"]*/$1BugResolved/; $oopsUrl = TWiki::Func::saveTopicText( $web, $topic, $text ); # save topic text
$web
source web - required
$topic
source topic - required
$newWeb
dest web
$newTopic
dest topic
use Error qw( :try ); try { moveTopic( "Work", "TokyoOffice", "Trash", "ClosedOffice" ); } catch Error::Simple with { my $e = shift; # see documentation on Error::Simple } catch TWiki::AccessControlException with { my $e = shift; # see documentation on TWiki::AccessControlException } otherwise { ... };
$web
- Web name, optional, e.g. 'Main'
$topic
- Topic name, required, e.g. 'TokyoOffice'
$rev
- revsion number, or tag name (can be in the format 1.2, or just the minor number)
$attachment
-attachment filename
( $date, $user, $rev, $comment )
List with: ( last update date, login name of last user, minor part of top revision number ), e.g. ( 1234561, 'phoeny', "5" )
$date | in epochSec |
$user | Wiki name of the author (not login name) |
$rev | actual rev number |
$comment | WHAT COMMENT? |
$meta->getRevisionInfo
instead if you can - it is significantly
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.
Since: TWiki::Plugins::VERSION 1.000 (29 Jul 2001)
$web
- web for topic
$topic
- topic
$time
- time (in epoch secs) for the rev
$web
- Web name, required, e.g. 'Main'
$topic
- Topic name, required, e.g. 'TokyoOffice'
$rev
- revision to read (default latest)
( $meta, $text )
Meta data object and topic text
$meta
is a perl 'object' of class TWiki::Meta
. This class is
fully documented in the source code documentation shipped with the
release, or can be inspected in the lib/TWiki/Meta.pm
file.
This method ignores topic access permissions. You should be careful to use checkAccessPermissions
to ensure the current user has read access to the topic.
Since: TWiki::Plugins::VERSION 1.000 (7 Dec 2002)
$web
- Web name, e.g. 'Main'
, or empty
$topic
- Topic name, e.g. 'MyTopic'
, or "Main.MyTopic"
$rev
- Topic revision to read, optional. Specify the minor part of the revision, e.g. "5"
, not "1.5"
; the top revision is returned if omitted or empty.
$ignorePermissions
- Set to "1"
if checkAccessPermission() is already performed and OK; an oops URL is returned if user has no permission
$text
Topic text with embedded meta data; an oops URL for calling redirectCgiQuery() is returned in case of an error
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)
$web
- Web name, optional, e.g. Main
.
$topic
- Topic name, required, e.g. TokyoOffice
, or Main.TokyoOffice
$attachment
- attachment name, e.g.=logo.gif=
normalizeWebTopicName
.
Since: TWiki::Plugins::VERSION 1.1
$web
- web for topic
$topic
- topic
$name
- attachment name
$rev
- revision to read (default latest)
readTopic
. If the attachment does not exist, or cannot be read, undef will be returned.
View permission on the topic is required for the
read to be successful. Access control violations are flagged by a
TWiki::AccessControlException. Permissions are checked for the user
passed in.
my( $meta, $text ) = TWiki::Func::readTopic( $web, $topic ); my @attachments = $meta->find( 'FILEATTACHMENT' ); foreach my $a ( @attachments ) { try { my $data = TWiki::Func::readAttachment( $meta, $a->{name} ); ... } catch TWiki::AccessControlException with { }; }Since: TWiki::Plugins::VERSION 1.1
$web
- web for topic
$topic
- topic to atach to
$attachment
- name of the attachment
$opts
- Ref to hash of options
$opts
may include:
dontlog |
don't log this change in twiki log |
comment |
comment for save |
hide |
if the attachment is to be hidden in normal topic view |
stream |
Stream of file to upload |
file |
Name of a file to use for the attachment data. ignored if stream is set. Local file on the server. |
filepath |
Client path to file |
filesize |
Size of uploaded data |
filedate |
Date |
try { TWiki::Func::saveAttachment( $web, $topic, 'image.gif', { file => 'image.gif', comment => 'Picture of Health', hide => 1 } ); } catch Error::Simple with { # see documentation on Error } otherwise { ... };Since: TWiki::Plugins::VERSION 1.1
$web
source web - required
$topic
source topic - required
$attachment
source attachment - required
$newWeb
dest web
$newTopic
dest topic
$newAttachment
dest attachment
use Error qw( :try ); try { # move attachment between topics moveAttachment( "Countries", "Germany", "AlsaceLorraine.dat", "Countries", "France" ); # Note destination attachment name is defaulted to the same as source } catch TWiki::AccessControlException with { my $e = shift; # see documentation on TWiki::AccessControlException } catch Error::Simple with { my $e = shift; # see documentation on Error::Simple };Since: TWiki::Plugins::VERSION 1.1
$name
- Template name, e.g. 'view'
$skin
- Comma-separated list of skin names, optional, e.g. 'print'
$text
Template text
Since: TWiki::Plugins::VERSION 1.000 (7 Dec 2002)
$name
- template file name
$skin
- comma-separated list of skins to use (default: current skin)
$web
- the web to look in for topics that contain templates (default: current web)
$def
- template name
$query
- CGI query object. If not given, the default CGI query will be used. In most cases you should not pass this parameter.
$contentLength
- Length of content
$query
- CGI query object. Ignored, only there for compatibility. The session CGI query object is used instead.
$url
- URL to redirect to
$header
to the HTML header (the tag).
This is useful for Plugins that want to include some javascript custom css. $id
- Unique ID to prevent the same HTML from being duplicated. Plugins should use a prefix to prevent name clashes (e.g EDITTABLEPLUGIN_JSCALENDAR)
$header
- the HTML to be added to the section. The HTML must be valid in a HEAD tag - no checks are performed.
$header
will be expanded before being inserted into the
section.
Note that this is not the same as the HTTP header, which is modified through the Plugins modifyHeaderHandler
.
Since: TWiki::Plugins::VERSION 1.1
example:
TWiki::Func::addToHEAD('PATTERN_STYLE','<link id="twikiLayoutCss" rel="stylesheet" type="text/css" href="%PUBURL%/TWiki/PatternSkin/layout.css" media="all" />')
%VARIABLES%
$text
- Text with variables to expand, e.g. 'Current user is %WIKIUSER%'
$topic
- Current topic name, e.g. 'WebNotify'
$web
- Web name, optional, e.g. 'Main'
. The current web is taken if missing
$text
Expanded text, e.g. 'Current user is TWikiGuest'
Since: TWiki::Plugins::VERSION 1.000 (7 Dec 2002)
See also: expandVariablesOnTopicCreation
$text
- Text to render, e.g. '*bold* text and =fixed font='
$web
- Web name, optional, e.g. 'Main'
. The current web is taken if missing
$text
XHTML text, e.g. '<b>bold</b> and <code>fixed font</code>'
Since: TWiki::Plugins::VERSION 1.000 (7 Dec 2002)
renderText()
$pre
- Text occuring before the TWiki link syntax, optional
$web
- Web name, required, e.g. 'Main'
$topic
- Topic name to link to, required, e.g. 'WebNotify'
$label
- Link label, required. Usually the same as $topic
, e.g. 'notify'
$anchor
- Anchor, optional, e.g. '#Jump'
$createLink
- Set to '1'
to add question linked mark after topic name if topic does not exist;'0'
to suppress link for non-existing topics
$text
XHTML anchor, e.g. '<a href='/cgi-bin/view/Main/WebNotify#Jump'>notify</a>'
Since: TWiki::Plugins::VERSION 1.000 (7 Dec 2002)
$text
- text of the mail, including MIME headers
$retries
- number of times to retry the send (default 1)
To: liz@windsor.gov.uk From: serf@hovel.net CC: george@whitehouse.gov Subject: Revolution Dear Liz, Please abolish the monarchy (with King George's permission, of course) Thanks, A. PeasantLeave a blank line between the last header field and the message body. Since: TWiki::Plugins::VERSION 1.1
$wikiName
- wiki name of the user
$text
- the text to process
%DATE%
Signature-format date
%SERVERTIME%
See TWikiVariables
%GMTIME%
See TWikiVariables
%USERNAME%
Base login name
%WIKINAME%
Wiki name
%WIKIUSERNAME%
Wiki name with prepended web
%URLPARAM{...}%
- Parameters to the current CGI query
%NOP%
No-op
commonTagsHandler
. $var
- The name of the variable, i.e. the 'MYVAR' part of %MYVAR%. The variable name must match /^[A-Z][A-Z0-9_]*$/ or it won't work.
\&fn
- Reference to the handler function.
$syntax
can be 'classic' (the default) or 'context-free'. 'classic' syntax is appropriate where you want the variable to support classic TWiki syntax i.e. to accept the standard %MYVAR{ "unnamed" param1="value1" param2="value2" }%
syntax, as well as an unquoted default parameter, such as %MYVAR{unquoted parameter}%
. If your variable will only use named parameters, you can use 'context-free' syntax, which supports a more relaxed syntax. For example, %MYVAR{param1=value1, value 2, param3="value 3", param4='value 5"}%
sub handler(\%session, \%params, $topic, $web)where:
\%session
- a reference to the TWiki session object (may be ignored)
\%params
- a reference to a TWiki::Attrs object containing parameters. This can be used as a simple hash that maps parameter names to values, with _DEFAULT being the name for the default parameter.
$topic
- name of the topic in the query
$web
- name of the web in the query
sub initPlugin{ TWiki::Func::registerTagHandler('EXEC', \&boo); } sub boo { my( $session, $params, $topic, $web ) = @_; my $cmd = $params->{_DEFAULT}; return "NO COMMAND SPECIFIED" unless $cmd; my $result = `$cmd 2>&1`; return $params->{silent} ? '' : $result; } }would let you do this:
%EXEC{"ps -Af" silent="on"}%
$alias
- The name .
\&fn
- Reference to the function.
sub handler(\%session)where:
\%session
- a reference to the TWiki session object (may be ignored)
TWiki::Func::registerRESTHandler('example', \&restExample);This adds the
restExample
function to the REST dispatch table
for the EmptyPlugin under the 'example' alias, and allows it
to be invoked using the URL
http://server:port/bin/rest/EmptyPlugin/example
note that the URL
http://server:port/bin/rest/EmptyPlugin/restExample
(ie, with the name of the function instead of the alias) will not work.
$searchString
- the search string, in egrep format
$web
- The web to search in
\@topics
- reference to a list of topics to search
\%option
- reference to an options hash
\%options
hash may contain the following options: type
- if regex
will perform a egrep-syntax RE search (default '')
casesensitive
- false to ignore case (defaulkt true)
files_without_match
- true to return files only (default false). If files_without_match
is specified, it will return on the first match in each topic (i.e. it will return only one match per topic, and will not return matching lines).
my $result = TWiki::Func::searchInWebContent( "Slimy Toad", $web, \@topics, { casesensitive => 0, files_without_match => 0 } ); foreach my $topic (keys %$result ) { foreach my $matching_line ( @{$result->{$topic}} ) { ...etcSince: TWiki::Plugins::VERSION 1.1
$filename
- Full path name of file
$text
Content of file, empty if not found
NOTE: Use this function only for the Plugin workarea, not for topics and attachments. Use the appropriate functions to manipulate topics and attachments.
Since: TWiki::Plugins::VERSION 1.000 (07 Dec 2002)
$filename
- Full path name of file
$text
- Text to save
$name
- Name of the expression to retrieve. See notes below
my $upper = TWiki::Func::getRegularExpression('upperAlpha'); my $alpha = TWiki::Func::getRegularExpression('mixedAlpha'); my $capitalized = qr/[$upper][$alpha]+/;Those expressions marked type 'RE' are precompiled regular expressions that can be used outside square brackets. For example:
my $webRE = TWiki::Func::getRegularExpression('webNameRegex'); my $isWebName = ( $s =~ m/$webRE/ );
Name | Matches | Type |
---|---|---|
upperAlpha | Upper case characters | String |
upperAlphaNum | Upper case characters and digits | String |
lowerAlpha | Lower case characters | String |
lowerAlphaNum | Lower case characters and digits | String |
numeric | Digits | String |
mixedAlpha | Alphabetic characters | String |
mixedAlphaNum | Alphanumeric characters | String |
wikiWordRegex | WikiWords | RE |
webNameRegex | User web names | RE |
anchorRegex | #AnchorNames | RE |
abbrevRegex | Abbreviations e.g. GOV, IRS | RE |
emailAddrRegex | email@address.com | RE |
tagNameRegex | Standard variable names e.g. %THIS_BIT% (THIS_BIT only) | RE |
$web
- Web name, identifying variable, or empty string
$topic
- Topic name, may be a web.topic string, required.
Input<-- --> ![]() |
Return |
---|---|
( '', '' ) | ( 'Main', 'WebHome' ) |
( '', 'Topic' ) | ( 'Main', 'Topic' ) |
( '', 'Web.Topic' ) | ( 'Web', 'Topic' ) |
( '', 'Web/Topic' ) | ( 'Web', 'Topic' ) |
( 'Main', 'Topic' ) | ( 'Main', 'Topic' ) |
( 'TWiki', 'Topic' ) | ( 'TWiki', 'Topic' ) |
( 'Web', 'Topic' ) | ( 'Web', 'Topic' ) |
( 'Web1', 'Web2.Topic' ) | ( 'Web2', 'Topic' ) |
Main
and TWiki
are the web names set in $cfg{UsersWebName} and $cfg{SystemWebName} respectively.
$text
- Text to write; timestamp gets added
$text
- Text to write; timestamp gets added
$time
- Time in epoc seconds
$format
- Format type, optional. Default e.g. '31 Dec 2002 - 19:30'
. Can be '$iso'
(e.g. '2002-12-31T19:30Z'
), '$rcs'
(e.g. '2001/12/31 23:59:59'
, '$http'
for HTTP header format (e.g. 'Thu, 23 Jul 1998 07:21:56 GMT'
), or any string with tokens '$seconds, $minutes, $hours, $day, $wday, $month, $mo, $year, $ye, $tz'
for seconds, minutes, hours, day of month, day of week, 3 letter month, 2 digit month, 4 digit year, 2 digit year, timezone string, respectively
$timezone
- either not defined (uses the displaytime setting), 'gmtime', or 'servertime'
$text
Formatted time string
Note: | if you used the removed formatGmTime, add a third parameter 'gmtime' |
$text
- Word to test
$attr
- Attribute string
%params
Hash containing all parameters. The nameless parameter is stored in key _DEFAULT
Since: TWiki::Plugins::VERSION 1.025 (26 Aug 2004)
%TEST{ 'nameless' name1="val1" name2="val2" }%
{...}
to get: 'nameless' name1="val1" name2="val2"
%params
hash contains now: _DEFAULT => 'nameless'
name1 => "val1"
name2 => "val2"
$attr
- Attribute string
$name
- Name, optional
$value
Extracted value
Since: TWiki::Plugins::VERSION 1.000 (7 Dec 2002)
%TEST{ 'nameless' name1="val1" name2="val2" }%
{...}
to get: 'nameless' name1="val1" name2="val2"
my $noname = TWiki::Func::extractNameValuePair( $text );
my $val1 = TWiki::Func::extractNameValuePair( $text, "name1" );
my $val2 = TWiki::Func::extractNameValuePair( $text, "name2" );
TWiki::Plugins
version in which the handler was first deprecated. For example, if we need to define the endRenderingHandler
for compatibility with TWiki::Plugins
versions before 1.1, we would add this to the plugin:
package TWiki::Plugins::SinkPlugin; use vars qw( %TWikiCompatibility ); $TWikiCompatibility{endRenderingHandler} = 1.1;If the currently-running TWiki version is 1.1 or later, then the handler will not be called and the warning will not be issued. TWiki with versions of
TWiki::Plugins
before 1.1 will still call the handler as required.
The following functions are retained for compatibility only. You should
stop using them as soon as possible.
getScriptUrl
instead.
Return: $path
URL path of TWiki scripts, e.g. "/cgi-bin"
WARNING: you are strongly recommended not to use this function, as the
{ScriptUrlPaths} URL rewriting rules will not apply to urls generated
using it.
Since: TWiki::Plugins::VERSION 1.000 (7 Dec 2002)
getListOfWebs
instead.
Get list of all public webs, e.g. all webs that do not have the NOSEARCHALL
flag set in the WebPreferences
Return: @webs
List of all public webs, e.g. ( 'Main', 'Know', 'TWiki' )
Since: TWiki::Plugins::VERSION 1.000 (07 Dec 2002)
formatTime
instead.
Format the time to GM time $time
- Time in epoc seconds
$format
- Format type, optional. Default e.g. '31 Dec 2002 - 19:30'
, can be 'iso'
(e.g. '2002-12-31T19:30Z'
), 'rcs'
(e.g. '2001/12/31 23:59:59'
, 'http'
for HTTP header format (e.g. 'Thu, 23 Jul 1998 07:21:56 GMT'
)
$text
Formatted time string
Since: TWiki::Plugins::VERSION 1.000 (7 Dec 2002)
$dir
Data directory, e.g. '/twiki/data'
This function violates store encapsulation and is therefore deprecated.
Since: TWiki::Plugins::VERSION 1.000 (07 Dec 2002)
$dir/Web/TopicName
Return: $dir
Pub directory, e.g. '/htdocs/twiki/pub'
This function violates store encapsulation and is therefore deprecated.
Use readAttachment
and saveAttachment
instead.
Since: TWiki::Plugins::VERSION 1.000 (07 Dec 2002)