...
Package =TWikiTWiki 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.Public Data members
On this page:
StaticMethod getTWikiLibDir () -> $pathReturns the full path of the directory containing TWiki.pmObjectMethod *UTF82SiteCharSet ($utf8) -> $asciiAuto-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.
ObjectMethod *generateHTTPHeaders ($pageType,$contentType,$contentLength) -> $headerAll parameters are optional.
Content-length header.
StaticMethod isRedirectSafe ($redirect)=>$oktests if the $redirect is an external URL, returning false if AllowRedirectUrl is deniedObjectMethod redirect ($url,$passthrough,$action_redirectto)
$url , unless
ObjectMethod cacheQuery () -> $queryStringCaches the current query in the params cache, and returns a rewritten query string for the cache to be picked up again on the other side of a redirect. We can't encode post params into a redirect, because they may exceed the size of the GET request. So we cache the params, and reload them when the redirect target is reached.StaticMethod *isValidWikiWord ($name) -> $booleanCheck for a valid WikiWord or WikiNameStaticMethod *isValidTopicName ($name) -> $booleanCheck for a valid topic nameStaticMethod isValidAbbrev ($name) -> $booleanCheck for a valid ABBREV (acronym)StaticMethod isValidWebName ($name,$system) -> $booleanSTATIC 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 If $TWiki::cfg{EnableHierarchicalWebs} is off, it will also return false when a nested web name is passed to it.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:
ObjectMethod getSkin () -> $stringGet the currently requested skin pathObjectMethod getScriptUrl ($absolute,$script,$web,$topic,...) -> $scriptURLReturns 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".
ObjectMethod getPubUrl ($absolute,$web,$topic,$attachment) -> $urlComposes 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 cacheIconData ($action)Cache icon data based on action:
ObjectMethod formatIcon ($iconName,$format,$default) -> $iconFormat an icon based on name and format parameter. The format parameter handles these variables (with example):
ObjectMethod *normalizeWebTopicName ($theWeb,$theTopic) -> ($theWeb,$theTopic)Normalize a Web.TopicName See TWikiFuncDotPm for a full specification of the expansion (not duplicated here) WARNING if there is no web specification (in the web or topic parameters) the web defaults to $TWiki::cfg{UsersWebName}. If there is no topic specification, or the topic is '0', the topic defaults to the web home topic name.ClassMethod new ($loginName,$query,\%initialContext)Constructs a new TWiki object. Parameters are taken from the query object.
ObjectMethod renderer ()Get a reference to the renderer object. Done lazily because not everyone needs the renderer.ObjectMethod attach ()Get a reference to the attach object. Done lazily because not everyone needs the attach.ObjectMethod templates ()Get a reference to the templates object. Done lazily because not everyone needs the templates.ObjectMethod i18n ()Get a reference to the i18n object. Done lazily because not everyone needs the i18ner.ObjectMethod search ()Get a reference to the search object. Done lazily because not everyone needs the searcher.ObjectMethod security ()Get a reference to the security object. Done lazily because not everyone needs the security.ObjectMethod net ()Get a reference to the net object. Done lazily because not everyone needs the net.ObjectMethod finish ()Break circular references.ObjectMethod writeLog ($action,$webTopic,$extra,$user)
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) -> $textApply a pattern on included text to extract a subsetObjectMethod inlineAlert ($template,$def,...) -> $stringFormat 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%StaticMethod parseSections ($text) -> ($string,$sectionlistref)Generic parser for sections within a topic. Sections are delimited by STARTSECTION and ENDSECTION, which may be nested, overlapped or otherwise abused. The parser builds an array of sections, which is ordered by the order of the STARTSECTION within the topic. It also removes all the SECTION tags from the text, and returns the text and the array of sections. Each section is aTWiki::Attrs object, which contains the attributes
{type, name, start, end}
where start and end are character offsets in the
string after all section tags have been removed. All sections
are required to be uniquely named; if a section is unnamed, it
will be given a generated name. Sections may overlap or nest.
See test/unit/Fn_SECTION.pm for detailed testcases that
round out the spec.
ObjectMethod *expandVariablesOnTopicCreation ($text,$user,$web,$topic) -> $text
| |||||||||||||||||
Added: | |||||||||||||||||
> > |
| ||||||||||||||||
Expand limited set of variables during topic creation. These are variables expected in templates that must be statically expanded in new content. | |||||||||||||||||
Deleted: | |||||||||||||||||
< < |
| ||||||||||||||||
# SMELL: no plugin handler
StaticMethod entityEncode ($text,$extras) -> $encodedTextEscape 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 ". Other entities exist for special characters that cannot easily be entered with some keyboards..." This method encodes HTML special and any non-printable ascii characters (except for \n and \r) using numeric entities. FURTHER this method also encodes characters that are special in TWiki meta-language. $extras is an optional param that may be used to include additional characters in the set of encoded characters. It should be a string containing the additional chars.StaticMethod entityDecode ($encodedText) -> $textDecodes all numeric entities (e.g. {). Does not decode named entities such as & (use HTML::Entities for that)StaticMethod *urlEncodeAttachment ($text)For attachments, URL-encode specially to 'freeze' any characters >127 in the site charset (e.g. ISO-8859-1 or KOI8-R), by doing URL encoding into native charset ($siteCharset) - used when generating attachment URLs, to enable the web server to serve attachments, including images, directly. This encoding is required to handle the cases of: - browsers that generate UTF-8 URLs automatically from site charset URLs - now quite common - web servers that directly serve attachments, using the site charset for filenames, and cannot convert UTF-8 URLs into site charset filenames The aim is to prevent the browser from converting a site charset URL in the web page to a UTF-8 URL, which is the default. Hence we 'freeze' the URL into the site character set through URL encoding. In two cases, no URL encoding is needed: For EBCDIC mainframes, we assume that site charset URLs will be translated (outbound and inbound) by the web server to/from an EBCDIC character set. For sites running in UTF-8, there's no need for TWiki to do anything since all URLs and attachment filenames are already in UTF-8.StaticMethod urlEncode ($string) -> encodedstringEncode by converting characters that are illegal in URLs to their %NN equivalents. This method is used for encoding strings that must be embedded verbatim in URLs; it cannot be applied to URLs themselves, as it escapes reserved characters such as = and ?. RFC 1738, Dec. '94:...Only alphanumerics [0-9a-zA-Z], the special characters $-_.+!*'(), and reserved characters used for their reserved purposes may be used unencoded within a URL.Reserved characters are $&+,/:;=?@ - these are also encoded by this method. This URL-encoding handles all character encodings including ISO-8859-*, KOI8-R, EUC-* and UTF-8. This may not handle EBCDIC properly, as it generates an EBCDIC URL-encoded URL, but mainframe web servers seem to translate this outbound before it hits browser - see CGI::Util::escape for another approach. StaticMethod urlDecode ($string) -> decodedstringReverses the encoding done in urlEncode.StaticMethod 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.
StaticMethod *spaceOutWikiWord ($word,$sep) -> $stringSpaces 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.ObjectMethod expandAllTags (\$text,$topic,$web,$meta)Expands variables by replacing the variables with their values. Some example variables: %TOPIC%, %SCRIPTURL%, %WIKINAME%, etc. $web and $incs are passed in for recursive include expansion. They can safely be undef. The rules for tag expansion are:
ObjectMethod enterContext ($id,$val)Add the context id $id into the set of active contexts. The $val can be anything you like, but should always evaluate to boolean TRUE. An example of the use of contexts is in the use of tag expansion. The commonTagsHandler in plugins is called every time tags need to be expanded, and the context of that expansion is signalled by the expanding module using a context id. So the forms module adds the context id "form" before invoking common tags expansion. Contexts are not just useful for tag expansion; they are also relevant when rendering. Contexts are intended for use mainly by plugins. Core modules can use $session->inContext( $id ) to determine if a context is active.ObjectMethod leaveContext ($id)Remove the context id $id from the set of active contexts. (seeenterContext for more information on contexts)
ObjectMethod inContext ($id)Return the value for the given context id (seeenterContext for more information on contexts)
StaticMethod *registerTagHandler ($tag,$fnref)STATIC Add a tag handler to the function tag handlers.
StaticMethod *registerRESTHandler ($subject,$verb,\&fn)Adds a function to the dispatch table of the REST interface for a given subject. See TWikiScripts#rest for more info.
sub handler(\%session,$subject,$verb) -> $textwhere:
ObjectMethod *handleCommonTags ($text,$web,$topic,$meta) -> $textProcesses %VARIABLE%, and %TOC% syntax; also includes 'commonTagsHandler' plugin hook. Returns the text of the topic, after file inclusion, variable substitution, table-of-contents generation, and any plugin changes from commonTagsHandler. $meta may be undef when, for example, expanding templates, or one-off strings at a time when meta isn't available.ObjectMethod ADDTOHEAD ($args)Add$html to the HEAD tag of the page currently being generated.
Note that TWiki variables may be used in the HEAD. They will be expanded
according to normal variable expansion rules.
You can write == in a topic or template. This variable accepts the following parameters: |
Escape: | Expands To:<-- --> |
---|---|
$percnt |
Percent sign (% ) |
$n or $n() |
New line. Use $n() if followed by alphanumeric character, e.g. write Foo$n()Bar instead of Foo$nBar |
$lt |
Less than sign (< ) |
$nop or $nop() |
Is a "no operation". |
$gt |
Greater than sign (> ) |
$quot |
Double quote (" ) |
$dollar |
Dollar sign ($ ) |