---+ Package =TWiki=
TWiki operates by creating a singleton object (known as the Session
object) that acts as a point of reference for all the different
modules in the system. This package is the class for this singleton,
and also contains the vast bulk of the basic constants and the per-
site configuration mechanisms.
Global variables are avoided wherever possible to avoid problems
with CGI accelerators such as mod_perl.
%TOC%
---++ StaticMethod *getTWikiLibDir* () -> $path
STATIC method.
Returns the full path of the directory containing TWiki.pm
---++ ObjectMethod *UTF82SiteCharSet* ($utf8) -> $ascii
Auto-detect UTF-8 vs. site charset in string, and convert UTF-8 into site
charset.
---++ ObjectMethod *writeCompletePage* ($text,$pageType,$contentType)
Write a complete HTML page with basic header to the browser.
$text is the HTML of the page body (<html> to </html>)
This method removes noautolink and nop tags before outputting the page.
---++ ObjectMethod *writePageHeader* ($query,$pageType,$contentType,$contentLength)
All parameters are optional.
* =$query= CGI query object | Session CGI query (there is no good reason to set this)
* =$pageType= - May be "edit", which will cause headers to be generated that force caching for 24 hours, to prevent Codev.BackFromPreviewLosesText bug, which caused data loss with IE5 and IE6.
* =$contentType= - page content type | text/html
* =$contentLength= - content-length | no content-length will be set if this is undefined, as required by HTTP1.1
Implements the post-Dec2001 release plugin API, which requires the
writeHeaderHandler in plugin to return a string of HTTP headers, CR/LF
delimited. Filters any illegal headers. Plugin headers will override
core settings.
---++ ObjectMethod *redirect* ($url,...)
Generate a CGI redirect to $url unless (1) $session->{cgiQuery} is undef or
(2) $query->param('noredirect') is set to a true value. Thus a redirect is
only generated when in a CGI context.
The ... parameters are concatenated to the message written when printing
to STDOUT, and are ignored for a redirect.
Redirects the request to $url, via the CGI module object $query unless
overridden by a plugin declaring a =redirectCgiQueryHandler=.
---++ StaticMethod *isValidWikiWord* ($name) -> $boolean
Check for a valid WikiWord or WikiName
---++ StaticMethod *isValidTopicName* ($name) -> $boolean
Check for a valid topic name
---++ StaticMethod *isValidAbbrev* ($name) -> $boolean
Check for a valid ABBREV (acronym)
---++ StaticMethod *isValidWebName* ($name,$system) -> $boolean
STATIC Check for a valid web name. If $system is true, then
system web names are considered valid (names starting with _)
otherwise only user web names are valid
---++ ObjectMethod *readOnlyMirrorWeb* ($theWeb) -> ($mirrorSiteName,$mirrorViewURL,$mirrorLink,$mirrorNote)
If this is a mirrored web, return information about the mirror. The info
is returned in a quadruple:
| site name | URL | link | note |
---++ ObjectMethod *getSkin* () -> $string
Get the currently requested skin path
---++ ObjectMethod *getScriptUrl* ($absolute,$script,$web,$topic,...) -> $scriptURL
Returns the URL to a TWiki script, providing the web and topic as
"path info" parameters. The result looks something like this:
"http://host/twiki/bin/$script/$web/$topic".
* =...= - an arbitrary number of name,value parameter pairs that will be url-encoded and added to the url. The special parameter name '#' is reserved for specifying an anchor. e.g. getScriptUrl('x','y','view','#'=>'XXX',a=>1,b=>2) will give .../view/x/y#XXX?a=1&b=2
If $absolute is set, generates an absolute URL. $absolute is advisory only;
TWiki can decide to generate absolute URLs (for example when run from the
command-line) even when relative URLs have been requested.
The default script url is taken from {ScriptUrlPath}, unless there is
an exception defined for the given script in {ScriptUrlPaths}. Both
{ScriptUrlPath} and {ScriptUrlPaths} may be absolute or relative URIs. If
they are absolute, then they will always generate absolute URLs. if they
are relative, then they will be converted to absolute when required (e.g.
when running from the command line, or when generating rss). If
$script is not given, absolute URLs will always be generated.
If either the web or the topic is defined, will generate a full url (including web and topic). Otherwise will generate only up to the script name. An undefined web will default to the main web name.
---++ ObjectMethod *getPubUrl* ($absolute,$web,$topic,$attachment) -> $url
Composes a pub url. If $absolute is set, returns an absolute URL.
If $absolute is set, generates an absolute URL. $absolute is advisory only;
TWiki can decide to generate absolute URLs (for example when run from the
command-line) even when relative URLs have been requested.
$web, $topic and $attachment are optional. A partial URL path will be
generated if one or all is not given.
---++ ObjectMethod *getIconUrl* ($absolute,$iconName) -> $iconURL
Map an icon name to a URL path.
---++ ObjectMethod *mapToIconFileName* ($fileName,$default) -> $fileName
Maps from a filename (or just the extension) to the name of the
file that contains the image for that file type.
---++ ObjectMethod *getOopsUrl* ($template,@options) -> $absoluteOopsURL
Composes a URL for an "oops" error page. The @options consists of a list
of key => value pairs. The following keys are used:
* =-web= - web name
* =-topic= - topic name
* =-def= - optional template def within the main template file
* =-params= - a single parameter, or a reference to an array of parameters These are passed in the URL as '¶m1=' etc.
Do _not_ include the "oops" part in front of the template name.
Alternatively you can pass a reference to an OopsException in place of the template. All other parameters will be ignored.
The returned URL ends up looking something like this:
"http://host/twiki/bin/oops/$web/$topic?template=$template¶m1=$scriptParams[0]..."
---++ ObjectMethod *normalizeWebTopicName* ($theWeb,$theTopic) -> ($theWeb,$theTopic)
Normalize a Web
Input: Return:
( 'Web', 'Topic' ) ( 'Web', 'Topic' )
( '', 'Topic' ) ( 'Main', 'Topic' )
( '', '' ) ( 'Main', 'WebHome' )
( '', 'Web/Topic' ) ( 'Web', 'Topic' )
( '', 'Web.Topic' ) ( 'Web', 'Topic' )
( 'Web1', 'Web2.Topic' ) ( 'Web2', 'Topic' )
( '%MAINWEB%', 'Web2.Topic' ) ( 'Main', 'Topic' )
( '%TWIKIWEB%', 'Web2.Topic' ) ( 'TWiki', 'Topic' )
Note: Function renamed from getWebTopic
SMELL: WARNING: this function defaults the web and topic names.
Be very careful where you use it!
---++ ClassMethod *new* ($remoteUser,$query)
Constructs a new TWiki object. Parameters are taken from the query object.
* =$remoteUser= the logged-in user (login name)
* =$query= the query
---++ ObjectMethod *finish*
Complete processing after the client's HTTP request has been responded
to. Right now this only entails one activity: calling TWiki::Client to
flushing the user's
session (if any) to disk.
---++ ObjectMethod *writeLog* ($action,$webTopic,$extra,$user)
* =$action= - what happened, e.g. view, save, rename
* =$wbTopic= - what it happened to
* =$extra= - extra info, such as minor flag
* =$user= - user who did the saving (user object or string user name)
Write the log for an event to the logfile
---++ ObjectMethod *writeWarning* ($text)
Prints date, time, and contents $text to $TWiki::cfg{WarningFileName}, typically
'warnings.txt'. Use for warnings and errors that may require admin
intervention. Use this for defensive programming warnings (e.g. assertions).
---++ ObjectMethod *writeDebug* ($text)
Prints date, time, and contents of $text to $TWiki::cfg{DebugFileName}, typically
'debug.txt'. Use for debugging messages.
---++ StaticMethod *applyPatternToIncludedText* ($text,$pattern) -> $text
Apply a pattern on included text to extract a subset
---++ ObjectMethod *inlineAlert* ($template,$def,...) -> $string
Format an error for inline inclusion in rendered output. The message string
is obtained from the template 'oops'.$template, and the DEF $def is
selected. The parameters (...) are used to populate %PARAM1%..%PARAMn%
---++ ObjectMethod *expandVariablesOnTopicCreation* ($text,$user) -> $text
* =$text= - text to expand
* =$user= - reference to user object. This is the user expanded in e.g. %USERNAME. Optional, defaults to logged-in user.
Expand limited set of variables during topic creation. These are variables
expected in templates that must be statically expanded in new content.
# SMELL: no plugin handler
---++ StaticMethod *entityEncode* ($text,$extras) -> $encodedText
Escape special characters to HTML numeric entities. This is *not* a generic
encoding, it is tuned specifically for use in TWiki.
HTML4.0 spec:
"Certain characters in HTML are reserved for use as markup and must be
escaped to appear literally. The "<" character may be represented with
an entity, <. Similarly, ">"
is escaped as >, and "&" is escaped
as &. If an attribute value contains a
double quotation mark and is delimited by double quotation marks, then the
quote should be escaped as ".