1 # <a name="Package <code>TWiki="></a> Package =TWiki
3 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.
5 Global variables are avoided wherever possible to avoid problems with CGI accelerators such as mod\_perl.
9 <li><a href="#Package =TWiki="> Package TWiki</a><ul>
10 <li><a href="#StaticMethod <strong>get_TWikiLibDir</strong> ("> StaticMethod getTWikiLibDir <tt>() -> $path</tt></a></li>
11 <li><a href="#ObjectMethod *_UTF82SiteCharSet*"> ObjectMethod UTF82SiteCharSet <tt>($utf8) -> $ascii</tt></a></li>
12 <li><a href="#ObjectMethod *write_CompletePage"> ObjectMethod writeCompletePage <tt>($text,$pageType,$contentType)</tt></a></li>
13 <li><a href="#ObjectMethod *write_PageHeader*"> ObjectMethod writePageHeader <tt>($query,$pageType,$contentType,$contentLength)</tt></a></li>
14 <li><a href="#ObjectMethod <strong>redirect</strong> ($url,$p"> ObjectMethod redirect <tt>($url,$passthrough)</tt></a></li>
15 <li><a href="#ObjectMethod <strong>cacheQuery</strong> () ->"> ObjectMethod cacheQuery <tt>() -> $queryString</tt></a></li>
16 <li><a href="#StaticMethod *is_ValidWikiWord*"> StaticMethod isValidWikiWord <tt>($name) -> $boolean</tt></a></li>
17 <li><a href="#StaticMethod *is_ValidTopicName*"> StaticMethod isValidTopicName <tt>($name) -> $boolean</tt></a></li>
18 <li><a href="#StaticMethod <strong>is_ValidAbbrev</strong> ($"> StaticMethod isValidAbbrev <tt>($name) -> $boolean</tt></a></li>
19 <li><a href="#StaticMethod <strong>is_ValidWebName</strong> ("> StaticMethod isValidWebName <tt>($name,$system) -> $boolean</tt></a></li>
20 <li><a href="#ObjectMethod *read_OnlyMirrorWeb"> ObjectMethod readOnlyMirrorWeb <tt>($theWeb) -> ($mirrorSiteName,$mirrorViewURL,$mirrorLink,$mirrorNote)</tt></a></li>
21 <li><a href="#ObjectMethod <strong>getSkin</strong> () -> $st"> ObjectMethod getSkin <tt>() -> $string</tt></a></li>
22 <li><a href="#ObjectMethod <strong>get_ScriptUrl</strong> ($a"> ObjectMethod getScriptUrl <tt>($absolute,$script,$web,$topic,...) -> $scriptURL</tt></a></li>
23 <li><a href="#ObjectMethod <strong>get_PubUrl</strong> ($abso"> ObjectMethod getPubUrl <tt>($absolute,$web,$topic,$attachment) -> $url</tt></a></li>
24 <li><a href="#ObjectMethod <strong>get_IconUrl</strong> ($abs"> ObjectMethod getIconUrl <tt>($absolute,$iconName) -> $iconURL</tt></a></li>
25 <li><a href="#ObjectMethod *map_ToIconFileName"> ObjectMethod mapToIconFileName <tt>($fileName,$default) -> $fileName</tt></a></li>
26 <li><a href="#ObjectMethod <strong>get_OopsUrl</strong> ($tem"> ObjectMethod getOopsUrl <tt>($template,@options) -> $absoluteOopsURL</tt></a></li>
27 <li><a href="#ObjectMethod *normalize_WebTopic"> ObjectMethod normalizeWebTopicName <tt>($theWeb,$theTopic) -> ($theWeb,$theTopic)</tt></a></li>
28 <li><a href="#ClassMethod <strong>new</strong> ($loginName,$q"> ClassMethod new <tt>($loginName,$query,\%initialContext)</tt></a></li>
29 <li><a href="#ObjectMethod *finish*"> ObjectMethod finish <tt></tt></a></li>
30 <li><a href="#ObjectMethod <strong>writeLog</strong> ($action"> ObjectMethod writeLog <tt>($action,$webTopic,$extra,$user)</tt></a></li>
31 <li><a href="#ObjectMethod <strong>writeWarning</strong> ($te"> ObjectMethod writeWarning <tt>($text)</tt></a></li>
32 <li><a href="#ObjectMethod <strong>writeDebug</strong> ($text"> ObjectMethod writeDebug <tt>($text)</tt></a></li>
33 <li><a href="#StaticMethod *apply_PatternToInc"> StaticMethod applyPatternToIncludedText <tt>($text,$pattern) -> $text</tt></a></li>
34 <li><a href="#ObjectMethod <strong>inlineAlert</strong> ($tem"> ObjectMethod inlineAlert <tt>($template,$def,...) -> $string</tt></a></li>
35 <li><a href="#StaticMethod <strong>parseSections</strong> ($t"> StaticMethod parseSections <tt>($text) -> ($string,$sectionlistref)</tt></a></li>
36 <li><a href="#ObjectMethod *expand_VariablesOn"> ObjectMethod expandVariablesOnTopicCreation <tt>($text,$user) -> $text</tt></a></li>
37 <li><a href="#StaticMethod <strong>entityEncode</strong> ($te"> StaticMethod entityEncode <tt>($text,$extras) -> $encodedText</tt></a></li>
38 <li><a href="#StaticMethod <strong>entityDecode</strong> ($en"> StaticMethod entityDecode <tt>($encodedText) -> $text</tt></a></li>
39 <li><a href="#StaticMethod <strong>urlEncode</strong> ($strin"> StaticMethod urlEncode <tt>($string) -> encodedstring</tt></a></li>
40 <li><a href="#StaticMethod <strong>urlDecode</strong> ($strin"> StaticMethod urlDecode <tt>($string) -> decodedstring</tt></a></li>
41 <li><a href="#StaticMethod <strong>isTrue</strong> ($value,$d"> StaticMethod isTrue <tt>($value,$default) -> $boolean</tt></a></li>
42 <li><a href="#StaticMethod *space_OutWikiWord*"> StaticMethod spaceOutWikiWord <tt>($word,$sep) -> $string</tt></a></li>
43 <li><a href="#ObjectMethod <strong>enterContext</strong> ($id"> ObjectMethod enterContext <tt>($id,$val)</tt></a></li>
44 <li><a href="#ObjectMethod <strong>leaveContext</strong> ($id"> ObjectMethod leaveContext <tt>($id)</tt></a></li>
45 <li><a href="#ObjectMethod <strong>inContext</strong> ($id)"> ObjectMethod inContext <tt>($id)</tt></a></li>
46 <li><a href="#StaticMethod *register_TagHandle"> StaticMethod registerTagHandler <tt>($tag,$fnref)</tt></a></li>
47 <li><a href="#StaticMethod *registerRESTHandle"> StaticMethod registerRESTHandler <tt>($subject,$verb,\&fn)</tt></a></li>
48 <li><a href="#StaticMethod <strong>restDispatch</strong> ($su"> StaticMethod restDispatch <tt>($subject,$verb)=>\&fn</tt></a></li>
49 <li><a href="#ObjectMethod *handle_CommonTags*"> ObjectMethod handleCommonTags <tt>($text,$web,$topic) -> $text</tt></a></li>
50 <li><a href="#ObjectMethod <strong>add_ToHEAD</strong> ($id,$"> ObjectMethod addToHEAD <tt>($id,$html)</tt></a></li>
51 <li><a href="#StaticMethod <strong>initialize</strong> ($path"> StaticMethod initialize <tt>($pathInfo,$remoteUser,$topic,$url,$query) -> ($topicName,$webName,$scriptUrlPath,$userName,$dataDir)</tt></a></li>
52 <li><a href="#StaticMethod <strong>readFile</strong> ($filena"> StaticMethod readFile <tt>($filename) -> $text</tt></a></li>
53 <li><a href="#StaticMethod *expand_StandardEsc"> StaticMethod expandStandardEscapes <tt>($str) -> $unescapedStr</tt></a></li>
59 ## <a name="StaticMethod <strong>get_TWikiLibDir</strong> ("></a> [[StaticMethod]] **getTWikiLibDir** `() -> $path`
63 Returns the full path of the directory containing TWiki.pm
65 ## <a name="ObjectMethod <strong>_UTF82SiteCharSet*"></a> [[ObjectMethod]] \*UTF82SiteCharSet `($utf8) -> $ascii`
67 Auto-detect UTF-8 vs. site charset in string, and convert UTF-8 into site charset.
69 ## <a name="ObjectMethod <strong>write_CompletePage"></a> [[ObjectMethod]] \*writeCompletePage `($text,$pageType,$contentType)`
71 Write a complete HTML page with basic header to the browser.
73 - `$text` is the text of the page body (<html> to </html> if it's HTML)
74 - `$pageType` - May be "edit", which will cause headers to be generated that force caching for 24 hours, to prevent [[BackFromPreviewLosesText]] bug, which caused data loss with IE5 and IE6.
75 - `$contentType` - page content type | text/html
77 This method removes noautolink and nop tags before outputting the page unless $contentType is text/plain.
79 ## <a name="ObjectMethod <strong>write_PageHeader*"></a><a name="ObjectMethod *write_PageHeader</strong> "></a> [[ObjectMethod]] **writePageHeader** `($query,$pageType,$contentType,$contentLength)`
81 All parameters are optional.
83 - `$query` CGI query object | Session CGI query (there is no good reason to set this)
84 - `$pageType` - May be "edit", which will cause headers to be generated that force caching for 24 hours, to prevent [[BackFromPreviewLosesText]] bug, which caused data loss with IE5 and IE6.
85 - `$contentType` - page content type | text/html
86 - `$contentLength` - content-length | no content-length will be set if this is undefined, as required by HTTP1.1
88 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.
90 ## <a name="ObjectMethod <strong>redirect</strong> ($url,$p"></a> [[ObjectMethod]] **redirect** `($url,$passthrough)`
92 Redirects the request to `$url`, **unless**
94 1. It is overridden by a plugin declaring a `redirectCgiQueryHandler`.
95 2. `$session->{cgiQuery}` is `undef` or
96 3. $query->param('noredirect') is set to a true value.
98 Thus a redirect is only generated when in a CGI context.
100 Normally this method will ignore parameters to the current query. If $passthrough is set, then it will pass all parameters that were passed to the current query on to the redirect target. If the request\_method was GET, then all parameters can be passed in the URL. If the request\_method was POST then it caches the form data and passes over a cache reference in the redirect GET.
102 Passthrough is only meaningful if the redirect target is on the same server.
104 ## <a name="ObjectMethod <strong>cacheQuery</strong> () - $"></a> [[ObjectMethod]] **cacheQuery** `() -> $queryString`
106 Caches 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.
108 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.
110 ## <a name="StaticMethod <strong>is_ValidWikiWord*"></a><a name="StaticMethod *is_ValidWikiWord</strong> "></a> [[StaticMethod]] **isValidWikiWord** `($name) -> $boolean`
112 Check for a valid [[WikiWord]] or [[WikiName]]
114 ## <a name="StaticMethod <strong>is_ValidTopicName*"></a> [[StaticMethod]] \*isValidTopicName `($name) -> $boolean`
116 Check for a valid topic name
118 ## <a name="StaticMethod <strong>is_ValidAbbrev</strong> ($"></a> [[StaticMethod]] **isValidAbbrev** `($name) -> $boolean`
120 Check for a valid ABBREV (acronym)
122 ## <a name="StaticMethod <strong>is_ValidWebName</strong> ("></a> [[StaticMethod]] **isValidWebName** `($name,$system) -> $boolean`
124 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
126 ## <a name="ObjectMethod <strong>read_OnlyMirrorWeb"></a> [[ObjectMethod]] \*readOnlyMirrorWeb `($theWeb) -> ($mirrorSiteName,$mirrorViewURL,$mirrorLink,$mirrorNote)`
128 If this is a mirrored web, return information about the mirror. The info is returned in a quadruple:
130 <table border="1" cellpadding="0" cellspacing="0">
139 ## <a name="ObjectMethod <strong>getSkin</strong> () - $str"></a> [[ObjectMethod]] **getSkin** `() -> $string`
141 Get the currently requested skin path
143 ## <a name="ObjectMethod <strong>get_ScriptUrl</strong> ($a"></a> [[ObjectMethod]] **getScriptUrl** `($absolute,$script,$web,$topic,...) -> $scriptURL`
145 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".
147 - `...` - 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?a=1&b=2#XXX`
149 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.
151 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.
153 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.
155 ## <a name="ObjectMethod <strong>get_PubUrl</strong> ($abso"></a> [[ObjectMethod]] **getPubUrl** `($absolute,$web,$topic,$attachment) -> $url`
157 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.
159 $web, $topic and $attachment are optional. A partial URL path will be generated if one or all is not given.
161 ## <a name="ObjectMethod <strong>get_IconUrl</strong> ($abs"></a> [[ObjectMethod]] **getIconUrl** `($absolute,$iconName) -> $iconURL`
163 Map an icon name to a URL path.
165 ## <a name="ObjectMethod <strong>map_ToIconFileName"></a> [[ObjectMethod]] \*mapToIconFileName `($fileName,$default) -> $fileName`
167 Maps from a filename (or just the extension) to the name of the file that contains the image for that file type.
169 ## <a name="ObjectMethod <strong>get_OopsUrl</strong> ($tem"></a> [[ObjectMethod]] **getOopsUrl** `($template,@options) -> $absoluteOopsURL`
171 Composes a URL for an "oops" error page. The @options consists of a list of key => value pairs. The following keys are used:
174 - `-topic` - topic name
175 - `-def` - optional template def within the main template file
176 - `-params` - a single parameter, or a reference to an array of parameters These are passed in the URL as '&param1=' etc.
178 Do _not_ include the "oops" part in front of the template name.
180 Alternatively you can pass a reference to an [[OopsException]] in place of the template. All other parameters will be ignored.
182 The returned URL ends up looking something like this: "http://host/twiki/bin/oops/$web/$topic?template=$template&param1=$scriptParams[0]..."
184 Note: if \{keep\} is true in the params, then they will also be pushed into the current query.
186 ## <a name="ObjectMethod <strong>normalize_WebTopic"></a> [[ObjectMethod]] \*normalizeWebTopicName `($theWeb,$theTopic) -> ($theWeb,$theTopic)`
188 Normalize a Web.TopicName
190 See [[TWikiFuncDotPm]] for a full specification of the expansion (not duplicated here)
192 **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.
194 ## <a name="ClassMethod <strong>new</strong> ($loginName,$q"></a> [[ClassMethod]] **new** `($loginName,$query,\%initialContext)`
196 Constructs a new TWiki object. Parameters are taken from the query object.
198 - `$loginName` is the username of the user you want to be logged-in if none is available from a session or browser. Used mainly for side scripts and debugging.
199 - `$query` the CGI query (may be undef, in which case an empty query is used)
200 - `\%initialContext` - reference to a hash containing context name=value pairs to be pre-installed in the context hash
202 ## <a name="ObjectMethod <strong>finish*"></a><a name="ObjectMethod *finish</strong> "></a> [[ObjectMethod]] **finish** ``
204 Complete processing after the client's HTTP request has been responded to. Right now this does two things:
206 1. calling TWiki::Client to flushing the user's session (if any) to disk,
207 2. breaking circular references to allow garbage collection in persistent environments
209 ## <a name="ObjectMethod <strong>writeLog</strong> ($action"></a> [[ObjectMethod]] **writeLog** `($action,$webTopic,$extra,$user)`
211 - `$action` - what happened, e.g. view, save, rename
212 - `$wbTopic` - what it happened to
213 - `$extra` - extra info, such as minor flag
214 - `$user` - user who did the saving (user object or string user name)
216 Write the log for an event to the logfile
218 ## <a name="ObjectMethod <strong>writeWarning</strong> ($te"></a> [[ObjectMethod]] **writeWarning** `($text)`
220 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).
222 ## <a name="ObjectMethod <strong>writeDebug</strong> ($text"></a> [[ObjectMethod]] **writeDebug** `($text)`
224 Prints date, time, and contents of $text to $TWiki::cfg\{DebugFileName\}, typically 'debug.txt'. Use for debugging messages.
226 ## <a name="StaticMethod <strong>apply_PatternToInc"></a> [[StaticMethod]] \*applyPatternToIncludedText `($text,$pattern) -> $text`
228 Apply a pattern on included text to extract a subset
230 ## <a name="ObjectMethod <strong>inlineAlert</strong> ($tem"></a> [[ObjectMethod]] **inlineAlert** `($template,$def,...) -> $string`
232 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%
234 ## <a name="StaticMethod <strong>parseSections</strong> ($t"></a> [[StaticMethod]] **parseSections** `($text) -> ($string,$sectionlistref)`
236 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.
238 Each section is a `TWiki::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.
240 See test/unit/Fn\_SECTION.pm for detailed testcases that round out the spec.
242 ## <a name="ObjectMethod <strong>expand_VariablesOn"></a> [[ObjectMethod]] \*expandVariablesOnTopicCreation `($text,$user) -> $text`
244 - `$text` - text to expand
245 - `$user` - reference to user object. This is the user expanded in e.g. %USERNAME. Optional, defaults to logged-in user.
247 Expand limited set of variables during topic creation. These are variables expected in templates that must be statically expanded in new content.
249 # SMELL: no plugin handler
251 ## <a name="StaticMethod <strong>entityEncode</strong> ($te"></a> [[StaticMethod]] **entityEncode** `($text,$extras) -> $encodedText`
253 Escape special characters to HTML numeric entities. This is **not** a generic encoding, it is tuned specifically for use in TWiki.
255 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_, **&lt;**. Similarly, ">" is escaped as **&gt;**, and "&" is escaped as **&amp;**. If an attribute value contains a double quotation mark and is delimited by double quotation marks, then the quote should be escaped as **&quot;**.
257 Other entities exist for special characters that cannot easily be entered with some keyboards..."
259 This method encodes HTML special and any non-printable ascii characters (except for \\n and \\r) using numeric entities.
261 FURTHER this method also encodes characters that are special in TWiki meta-language.
263 $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.
265 ## <a name="StaticMethod <strong>entityDecode</strong> ($en"></a> [[StaticMethod]] **entityDecode** `($encodedText) -> $text`
267 Decodes all numeric entities (e.g. &#123;). _Does not_ decode named entities such as &amp; (use HTML::Entities for that)
269 ## <a name="StaticMethod <strong>urlEncode</strong> ($strin"></a> [[StaticMethod]] **urlEncode** `($string) -> encodedstring`
271 Encode 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 ?.
276 ...Only alphanumerics [0-9a-zA-Z], the special
277 characters $-_.+!*'(), and reserved characters used for their
278 reserved purposes may be used unencoded within a URL.
280 Reserved characters are $&+,/:;=?@ - these are _also_ encoded by this method.
282 SMELL: For non-ISO-8859-1 $TWiki::cfg\{Site\}\{CharSet\}, need to convert to UTF-8 before URL encoding. This encoding only supports 8-bit character codes.
284 ## <a name="StaticMethod <strong>urlDecode</strong> ($strin"></a> [[StaticMethod]] **urlDecode** `($string) -> decodedstring`
286 Reverses the encoding done in urlEncode.
288 ## <a name="StaticMethod <strong>isTrue</strong> ($value,$d"></a> [[StaticMethod]] **isTrue** `($value,$default) -> $boolean`
290 Returns 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.
292 If the value is undef, then `$default` is returned. If `$default` is not specified it is taken as 0.
294 ## <a name="StaticMethod <strong>space_OutWikiWord*"></a> [[StaticMethod]] \*spaceOutWikiWord `($word,$sep) -> $string`
296 Spaces 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.
298 ## <a name="ObjectMethod <strong>enterContext</strong> ($id"></a> [[ObjectMethod]] **enterContext** `($id,$val)`
300 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.
302 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.
304 Contexts are not just useful for tag expansion; they are also relevant when rendering.
306 Contexts are intended for use mainly by plugins. Core modules can use $session->inContext( $id ) to determine if a context is active.
308 ## <a name="ObjectMethod <strong>leaveContext</strong> ($id"></a> [[ObjectMethod]] **leaveContext** `($id)`
310 Remove the context id $id from the set of active contexts. (see `enterContext` for more information on contexts)
312 ## <a name="ObjectMethod <strong>inContext</strong> ($id)"></a> [[ObjectMethod]] **inContext** `($id)`
314 Return the value for the given context id (see `enterContext` for more information on contexts)
316 ## <a name="StaticMethod <strong>register_TagHandle"></a> [[StaticMethod]] \*registerTagHandler `($tag,$fnref)`
318 STATIC Add a tag handler to the function tag handlers.
320 - `$tag` name of the tag e.g. MYTAG
321 - `$fnref` Function to execute. Will be passed ($session, \\%params, $web, $topic )
323 ## <a name="StaticMethod <strong>registerRESTHandle"></a> [[StaticMethod]] \*registerRESTHandler `($subject,$verb,\&fn)`
325 Adds a function to the dispatch table of the REST interface for a given subject. See [[TWikiScripts#rest]] for more info.
327 - `$subject` - The subject under which the function will be registered.
328 - `$verb` - The verb under which the function will be registered.
329 - `\&fn` - Reference to the function.
331 The handler function must be of the form:
333 sub handler(\%session,$subject,$verb) -> $text
337 - `\%session` - a reference to the TWiki session object (may be ignored)
338 - `$subject` - The invoked subject (may be ignored)
339 - `$verb` - The invoked verb (may be ignored)
341 **Since:** TWiki::Plugins::VERSION 1.1
343 ## <a name="StaticMethod <strong>restDispatch</strong> ($su"></a> [[StaticMethod]] **restDispatch** `($subject,$verb)=>\&fn`
345 Returns the handler function associated to the given $subject and $werb, or undef if none is found.
347 **Since:** TWiki::Plugins::VERSION 1.1
349 ## <a name="ObjectMethod <strong>handle_CommonTags*"></a> [[ObjectMethod]] \*handleCommonTags `($text,$web,$topic) -> $text`
351 Processes %VARIABLE%, and %TOC% syntax; also includes 'commonTagsHandler' plugin hook.
353 Returns the text of the topic, after file inclusion, variable substitution, table-of-contents generation, and any plugin changes from commonTagsHandler.
355 ## <a name="ObjectMethod <strong>add_ToHEAD</strong> ($id,$"></a> [[ObjectMethod]] **addToHEAD** `($id,$html)`
357 Add `$html` to the HEAD tag of the page currently being generated.
359 Note that TWiki variables may be used in the HEAD. They will be expanded according to normal variable expansion rules.
361 The 'id' is used to ensure that multiple adds of the same block of HTML don't result in it being added many times.
363 ## <a name="StaticMethod <strong>initialize</strong> ($path"></a> [[StaticMethod]] **initialize** `($pathInfo,$remoteUser,$topic,$url,$query) -> ($topicName,$webName,$scriptUrlPath,$userName,$dataDir)`
365 Return value: ( $topicName, $webName, $TWiki::cfg\{ScriptUrlPath\}, $userName, $TWiki::cfg\{DataDir\} )
367 Static method to construct a new singleton session instance. It creates a new TWiki and sets the Plugins $SESSION variable to point to it, so that TWiki::Func methods will work.
369 This method is **DEPRECATED** but is maintained for script compatibility.
371 Note that $theUrl, if specified, must be identical to $query->url()
373 ## <a name="StaticMethod <strong>readFile</strong> ($filena"></a> [[StaticMethod]] **readFile** `($filename) -> $text`
375 Returns the entire contents of the given file, which can be specified in any format acceptable to the Perl open() function. Fast, but inherently unsafe.
377 WARNING: Never, ever use this for accessing topics or attachments! Use the Store API for that. This is for global control files only, and should be used **only** if there is **absolutely no alternative**.
379 ## <a name="StaticMethod <strong>expand_StandardEsc"></a> [[StaticMethod]] \*expandStandardEscapes `($str) -> $unescapedStr`
381 Expands standard escapes used in parameter values to block evaluation. The following escapes are handled:
383 <table border="1" cellpadding="0" cellspacing="0">
385 <th bgcolor="#99CCCC"><strong> Escape: </strong></th>
386 <th bgcolor="#99CCCC"><strong> Expands To: </strong></th>
389 <td><code>$n</code> or <code>$n()</code></td>
390 <td> New line. Use <code>$n()</code> if followed by alphanumeric character, e.g. write <code>Foo$n()Bar</code> instead of <code>Foo$nBar</code></td>
393 <td><code>$nop</code> or <code>$nop()</code></td>
394 <td> Is a "no operation". </td>
397 <td><code>$quot</code></td>
398 <td> Double quote (<code>"</code>) </td>
401 <td><code>$percnt</code></td>
402 <td> Percent sign (<code>%</code>) </td>
405 <td><code>$dollar</code></td>
406 <td> Dollar sign (<code>$</code>) </td>