none
[openafs-wiki.git] / TWiki / TWikiDotPm.mdwn
1 # <a name="Package &lt;code&gt;TWiki="></a> Package =TWiki
2
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.
4
5 Global variables are avoided wherever possible to avoid problems with CGI accelerators such as mod\_perl.
6
7 <div>
8   <ul>
9     <li><a href="#Package =TWiki="> Package TWiki</a><ul>
10         <li><a href="#StaticMethod <strong>get_TWikiLibDir</strong> ("> StaticMethod getTWikiLibDir <tt>() -&gt; $path</tt></a></li>
11         <li><a href="#ObjectMethod *_UTF82SiteCharSet*"> ObjectMethod UTF82SiteCharSet <tt>($utf8) -&gt; $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>() -&gt; $queryString</tt></a></li>
16         <li><a href="#StaticMethod *is_ValidWikiWord*"> StaticMethod isValidWikiWord <tt>($name) -&gt; $boolean</tt></a></li>
17         <li><a href="#StaticMethod *is_ValidTopicName*"> StaticMethod isValidTopicName <tt>($name) -&gt; $boolean</tt></a></li>
18         <li><a href="#StaticMethod <strong>is_ValidAbbrev</strong> ($"> StaticMethod isValidAbbrev <tt>($name) -&gt; $boolean</tt></a></li>
19         <li><a href="#StaticMethod <strong>is_ValidWebName</strong> ("> StaticMethod isValidWebName <tt>($name,$system) -&gt; $boolean</tt></a></li>
20         <li><a href="#ObjectMethod *read_OnlyMirrorWeb"> ObjectMethod readOnlyMirrorWeb <tt>($theWeb) -&gt; ($mirrorSiteName,$mirrorViewURL,$mirrorLink,$mirrorNote)</tt></a></li>
21         <li><a href="#ObjectMethod <strong>getSkin</strong> () -> $st"> ObjectMethod getSkin <tt>() -&gt; $string</tt></a></li>
22         <li><a href="#ObjectMethod <strong>get_ScriptUrl</strong> ($a"> ObjectMethod getScriptUrl <tt>($absolute,$script,$web,$topic,...) -&gt; $scriptURL</tt></a></li>
23         <li><a href="#ObjectMethod <strong>get_PubUrl</strong> ($abso"> ObjectMethod getPubUrl <tt>($absolute,$web,$topic,$attachment) -&gt; $url</tt></a></li>
24         <li><a href="#ObjectMethod <strong>get_IconUrl</strong> ($abs"> ObjectMethod getIconUrl <tt>($absolute,$iconName) -&gt; $iconURL</tt></a></li>
25         <li><a href="#ObjectMethod *map_ToIconFileName"> ObjectMethod mapToIconFileName <tt>($fileName,$default) -&gt; $fileName</tt></a></li>
26         <li><a href="#ObjectMethod <strong>get_OopsUrl</strong> ($tem"> ObjectMethod getOopsUrl <tt>($template,@options) -&gt; $absoluteOopsURL</tt></a></li>
27         <li><a href="#ObjectMethod *normalize_WebTopic"> ObjectMethod normalizeWebTopicName <tt>($theWeb,$theTopic) -&gt; ($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) -&gt; $text</tt></a></li>
34         <li><a href="#ObjectMethod <strong>inlineAlert</strong> ($tem"> ObjectMethod inlineAlert <tt>($template,$def,...) -&gt; $string</tt></a></li>
35         <li><a href="#StaticMethod <strong>parseSections</strong> ($t"> StaticMethod parseSections <tt>($text) -&gt; ($string,$sectionlistref)</tt></a></li>
36         <li><a href="#ObjectMethod *expand_VariablesOn"> ObjectMethod expandVariablesOnTopicCreation <tt>($text,$user) -&gt; $text</tt></a></li>
37         <li><a href="#StaticMethod <strong>entityEncode</strong> ($te"> StaticMethod entityEncode <tt>($text,$extras) -&gt; $encodedText</tt></a></li>
38         <li><a href="#StaticMethod <strong>entityDecode</strong> ($en"> StaticMethod entityDecode <tt>($encodedText) -&gt; $text</tt></a></li>
39         <li><a href="#StaticMethod <strong>urlEncode</strong> ($strin"> StaticMethod urlEncode <tt>($string) -&gt; encodedstring</tt></a></li>
40         <li><a href="#StaticMethod <strong>urlDecode</strong> ($strin"> StaticMethod urlDecode <tt>($string) -&gt; decodedstring</tt></a></li>
41         <li><a href="#StaticMethod <strong>isTrue</strong> ($value,$d"> StaticMethod isTrue <tt>($value,$default) -&gt; $boolean</tt></a></li>
42         <li><a href="#StaticMethod *space_OutWikiWord*"> StaticMethod spaceOutWikiWord <tt>($word,$sep) -&gt; $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,\&amp;fn)</tt></a></li>
48         <li><a href="#StaticMethod <strong>restDispatch</strong> ($su"> StaticMethod restDispatch <tt>($subject,$verb)=&gt;\&amp;fn</tt></a></li>
49         <li><a href="#ObjectMethod *handle_CommonTags*"> ObjectMethod handleCommonTags <tt>($text,$web,$topic) -&gt; $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) -&gt; ($topicName,$webName,$scriptUrlPath,$userName,$dataDir)</tt></a></li>
52         <li><a href="#StaticMethod <strong>readFile</strong> ($filena"> StaticMethod readFile <tt>($filename) -&gt; $text</tt></a></li>
53         <li><a href="#StaticMethod *expand_StandardEsc"> StaticMethod expandStandardEscapes <tt>($str) -&gt; $unescapedStr</tt></a></li>
54       </ul>
55     </li>
56   </ul>
57 </div>
58
59 ## <a name="StaticMethod &lt;strong&gt;get_TWikiLibDir&lt;/strong&gt; ("></a> [[StaticMethod]] **getTWikiLibDir** `() -> $path`
60
61 STATIC method.
62
63 Returns the full path of the directory containing TWiki.pm
64
65 ## <a name="ObjectMethod &lt;strong&gt;_UTF82SiteCharSet*"></a> [[ObjectMethod]] \*UTF82SiteCharSet `($utf8) -> $ascii`
66
67 Auto-detect UTF-8 vs. site charset in string, and convert UTF-8 into site charset.
68
69 ## <a name="ObjectMethod &lt;strong&gt;write_CompletePage"></a> [[ObjectMethod]] \*writeCompletePage `($text,$pageType,$contentType)`
70
71 Write a complete HTML page with basic header to the browser.
72
73 - `$text` is the text of the page body (&lt;html&gt; to &lt;/html&gt; 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
76
77 This method removes noautolink and nop tags before outputting the page unless $contentType is text/plain.
78
79 ## <a name="ObjectMethod &lt;strong&gt;write_PageHeader*"></a><a name="ObjectMethod *write_PageHeader&lt;/strong&gt; "></a> [[ObjectMethod]] **writePageHeader** `($query,$pageType,$contentType,$contentLength)`
80
81 All parameters are optional.
82
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
87
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.
89
90 ## <a name="ObjectMethod &lt;strong&gt;redirect&lt;/strong&gt; ($url,$p"></a> [[ObjectMethod]] **redirect** `($url,$passthrough)`
91
92 Redirects the request to `$url`, **unless**
93
94 1. It is overridden by a plugin declaring a `redirectCgiQueryHandler`.
95 2. `$session->{cgiQuery}` is `undef` or
96 3. $query-&gt;param('noredirect') is set to a true value.
97
98 Thus a redirect is only generated when in a CGI context.
99
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.
101
102 Passthrough is only meaningful if the redirect target is on the same server.
103
104 ## <a name="ObjectMethod &lt;strong&gt;cacheQuery&lt;/strong&gt; () - $"></a> [[ObjectMethod]] **cacheQuery** `() -> $queryString`
105
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.
107
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.
109
110 ## <a name="StaticMethod &lt;strong&gt;is_ValidWikiWord*"></a><a name="StaticMethod *is_ValidWikiWord&lt;/strong&gt; "></a> [[StaticMethod]] **isValidWikiWord** `($name) -> $boolean`
111
112 Check for a valid [[WikiWord]] or [[WikiName]]
113
114 ## <a name="StaticMethod &lt;strong&gt;is_ValidTopicName*"></a> [[StaticMethod]] \*isValidTopicName `($name) -> $boolean`
115
116 Check for a valid topic name
117
118 ## <a name="StaticMethod &lt;strong&gt;is_ValidAbbrev&lt;/strong&gt; ($"></a> [[StaticMethod]] **isValidAbbrev** `($name) -> $boolean`
119
120 Check for a valid ABBREV (acronym)
121
122 ## <a name="StaticMethod &lt;strong&gt;is_ValidWebName&lt;/strong&gt; ("></a> [[StaticMethod]] **isValidWebName** `($name,$system) -> $boolean`
123
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
125
126 ## <a name="ObjectMethod &lt;strong&gt;read_OnlyMirrorWeb"></a> [[ObjectMethod]] \*readOnlyMirrorWeb `($theWeb) -> ($mirrorSiteName,$mirrorViewURL,$mirrorLink,$mirrorNote)`
127
128 If this is a mirrored web, return information about the mirror. The info is returned in a quadruple:
129
130 <table border="1" cellpadding="0" cellspacing="0">
131   <tr>
132     <td> site name </td>
133     <td> URL </td>
134     <td> link </td>
135     <td> note </td>
136   </tr>
137 </table>
138
139 ## <a name="ObjectMethod &lt;strong&gt;getSkin&lt;/strong&gt; () - $str"></a> [[ObjectMethod]] **getSkin** `() -> $string`
140
141 Get the currently requested skin path
142
143 ## <a name="ObjectMethod &lt;strong&gt;get_ScriptUrl&lt;/strong&gt; ($a"></a> [[ObjectMethod]] **getScriptUrl** `($absolute,$script,$web,$topic,...) -> $scriptURL`
144
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".
146
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`
148
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.
150
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.
152
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.
154
155 ## <a name="ObjectMethod &lt;strong&gt;get_PubUrl&lt;/strong&gt; ($abso"></a> [[ObjectMethod]] **getPubUrl** `($absolute,$web,$topic,$attachment) -> $url`
156
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.
158
159 $web, $topic and $attachment are optional. A partial URL path will be generated if one or all is not given.
160
161 ## <a name="ObjectMethod &lt;strong&gt;get_IconUrl&lt;/strong&gt; ($abs"></a> [[ObjectMethod]] **getIconUrl** `($absolute,$iconName) -> $iconURL`
162
163 Map an icon name to a URL path.
164
165 ## <a name="ObjectMethod &lt;strong&gt;map_ToIconFileName"></a> [[ObjectMethod]] \*mapToIconFileName `($fileName,$default) -> $fileName`
166
167 Maps from a filename (or just the extension) to the name of the file that contains the image for that file type.
168
169 ## <a name="ObjectMethod &lt;strong&gt;get_OopsUrl&lt;/strong&gt; ($tem"></a> [[ObjectMethod]] **getOopsUrl** `($template,@options) -> $absoluteOopsURL`
170
171 Composes a URL for an "oops" error page. The @options consists of a list of key =&gt; value pairs. The following keys are used:
172
173 - `-web` - web name
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 '&amp;param1=' etc.
177
178 Do _not_ include the "oops" part in front of the template name.
179
180 Alternatively you can pass a reference to an [[OopsException]] in place of the template. All other parameters will be ignored.
181
182 The returned URL ends up looking something like this: "http://host/twiki/bin/oops/$web/$topic?template=$template&amp;param1=$scriptParams[0]..."
183
184 Note: if \{keep\} is true in the params, then they will also be pushed into the current query.
185
186 ## <a name="ObjectMethod &lt;strong&gt;normalize_WebTopic"></a> [[ObjectMethod]] \*normalizeWebTopicName `($theWeb,$theTopic) -> ($theWeb,$theTopic)`
187
188 Normalize a Web.TopicName
189
190 See [[TWikiFuncDotPm]] for a full specification of the expansion (not duplicated here)
191
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.
193
194 ## <a name="ClassMethod &lt;strong&gt;new&lt;/strong&gt; ($loginName,$q"></a> [[ClassMethod]] **new** `($loginName,$query,\%initialContext)`
195
196 Constructs a new TWiki object. Parameters are taken from the query object.
197
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
201
202 ## <a name="ObjectMethod &lt;strong&gt;finish*"></a><a name="ObjectMethod *finish&lt;/strong&gt; "></a> [[ObjectMethod]] **finish** ``
203
204 Complete processing after the client's HTTP request has been responded to. Right now this does two things:
205
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
208
209 ## <a name="ObjectMethod &lt;strong&gt;writeLog&lt;/strong&gt; ($action"></a> [[ObjectMethod]] **writeLog** `($action,$webTopic,$extra,$user)`
210
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)
215
216 Write the log for an event to the logfile
217
218 ## <a name="ObjectMethod &lt;strong&gt;writeWarning&lt;/strong&gt; ($te"></a> [[ObjectMethod]] **writeWarning** `($text)`
219
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).
221
222 ## <a name="ObjectMethod &lt;strong&gt;writeDebug&lt;/strong&gt; ($text"></a> [[ObjectMethod]] **writeDebug** `($text)`
223
224 Prints date, time, and contents of $text to $TWiki::cfg\{DebugFileName\}, typically 'debug.txt'. Use for debugging messages.
225
226 ## <a name="StaticMethod &lt;strong&gt;apply_PatternToInc"></a> [[StaticMethod]] \*applyPatternToIncludedText `($text,$pattern) -> $text`
227
228 Apply a pattern on included text to extract a subset
229
230 ## <a name="ObjectMethod &lt;strong&gt;inlineAlert&lt;/strong&gt; ($tem"></a> [[ObjectMethod]] **inlineAlert** `($template,$def,...) -> $string`
231
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%
233
234 ## <a name="StaticMethod &lt;strong&gt;parseSections&lt;/strong&gt; ($t"></a> [[StaticMethod]] **parseSections** `($text) -> ($string,$sectionlistref)`
235
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.
237
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.
239
240 See test/unit/Fn\_SECTION.pm for detailed testcases that round out the spec.
241
242 ## <a name="ObjectMethod &lt;strong&gt;expand_VariablesOn"></a> [[ObjectMethod]] \*expandVariablesOnTopicCreation `($text,$user) -> $text`
243
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.
246
247 Expand limited set of variables during topic creation. These are variables expected in templates that must be statically expanded in new content.
248
249 # SMELL: no plugin handler
250
251 ## <a name="StaticMethod &lt;strong&gt;entityEncode&lt;/strong&gt; ($te"></a> [[StaticMethod]] **entityEncode** `($text,$extras) -> $encodedText`
252
253 Escape special characters to HTML numeric entities. This is **not** a generic encoding, it is tuned specifically for use in TWiki.
254
255 HTML4.0 spec: "Certain characters in HTML are reserved for use as markup and must be escaped to appear literally. The "&lt;" character may be represented with an _entity_, **&amp;lt;**. Similarly, "&gt;" is escaped as **&amp;gt;**, and "&amp;" is escaped as **&amp;amp;**. If an attribute value contains a double quotation mark and is delimited by double quotation marks, then the quote should be escaped as **&amp;quot;**.
256
257 Other entities exist for special characters that cannot easily be entered with some keyboards..."
258
259 This method encodes HTML special and any non-printable ascii characters (except for \\n and \\r) using numeric entities.
260
261 FURTHER this method also encodes characters that are special in TWiki meta-language.
262
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.
264
265 ## <a name="StaticMethod &lt;strong&gt;entityDecode&lt;/strong&gt; ($en"></a> [[StaticMethod]] **entityDecode** `($encodedText) -> $text`
266
267 Decodes all numeric entities (e.g. &amp;#123;). _Does not_ decode named entities such as &amp;amp; (use HTML::Entities for that)
268
269 ## <a name="StaticMethod &lt;strong&gt;urlEncode&lt;/strong&gt; ($strin"></a> [[StaticMethod]] **urlEncode** `($string) -> encodedstring`
270
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 ?.
272
273 RFC 1738, Dec. '94:
274
275     >
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.
279
280 Reserved characters are $&amp;+,/:;=?@ - these are _also_ encoded by this method.
281
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.
283
284 ## <a name="StaticMethod &lt;strong&gt;urlDecode&lt;/strong&gt; ($strin"></a> [[StaticMethod]] **urlDecode** `($string) -> decodedstring`
285
286 Reverses the encoding done in urlEncode.
287
288 ## <a name="StaticMethod &lt;strong&gt;isTrue&lt;/strong&gt; ($value,$d"></a> [[StaticMethod]] **isTrue** `($value,$default) -> $boolean`
289
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.
291
292 If the value is undef, then `$default` is returned. If `$default` is not specified it is taken as 0.
293
294 ## <a name="StaticMethod &lt;strong&gt;space_OutWikiWord*"></a> [[StaticMethod]] \*spaceOutWikiWord `($word,$sep) -> $string`
295
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.
297
298 ## <a name="ObjectMethod &lt;strong&gt;enterContext&lt;/strong&gt; ($id"></a> [[ObjectMethod]] **enterContext** `($id,$val)`
299
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.
301
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.
303
304 Contexts are not just useful for tag expansion; they are also relevant when rendering.
305
306 Contexts are intended for use mainly by plugins. Core modules can use $session-&gt;inContext( $id ) to determine if a context is active.
307
308 ## <a name="ObjectMethod &lt;strong&gt;leaveContext&lt;/strong&gt; ($id"></a> [[ObjectMethod]] **leaveContext** `($id)`
309
310 Remove the context id $id from the set of active contexts. (see `enterContext` for more information on contexts)
311
312 ## <a name="ObjectMethod &lt;strong&gt;inContext&lt;/strong&gt; ($id)"></a> [[ObjectMethod]] **inContext** `($id)`
313
314 Return the value for the given context id (see `enterContext` for more information on contexts)
315
316 ## <a name="StaticMethod &lt;strong&gt;register_TagHandle"></a> [[StaticMethod]] \*registerTagHandler `($tag,$fnref)`
317
318 STATIC Add a tag handler to the function tag handlers.
319
320 - `$tag` name of the tag e.g. MYTAG
321 - `$fnref` Function to execute. Will be passed ($session, \\%params, $web, $topic )
322
323 ## <a name="StaticMethod &lt;strong&gt;registerRESTHandle"></a> [[StaticMethod]] \*registerRESTHandler `($subject,$verb,\&fn)`
324
325 Adds a function to the dispatch table of the REST interface for a given subject. See [[TWikiScripts#rest]] for more info.
326
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.
330
331 The handler function must be of the form:
332
333     sub handler(\%session,$subject,$verb) -> $text
334
335 where:
336
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)
340
341 **Since:** TWiki::Plugins::VERSION 1.1
342
343 ## <a name="StaticMethod &lt;strong&gt;restDispatch&lt;/strong&gt; ($su"></a> [[StaticMethod]] **restDispatch** `($subject,$verb)=>\&fn`
344
345 Returns the handler function associated to the given $subject and $werb, or undef if none is found.
346
347 **Since:** TWiki::Plugins::VERSION 1.1
348
349 ## <a name="ObjectMethod &lt;strong&gt;handle_CommonTags*"></a> [[ObjectMethod]] \*handleCommonTags `($text,$web,$topic) -> $text`
350
351 Processes %VARIABLE%, and %TOC% syntax; also includes 'commonTagsHandler' plugin hook.
352
353 Returns the text of the topic, after file inclusion, variable substitution, table-of-contents generation, and any plugin changes from commonTagsHandler.
354
355 ## <a name="ObjectMethod &lt;strong&gt;add_ToHEAD&lt;/strong&gt; ($id,$"></a> [[ObjectMethod]] **addToHEAD** `($id,$html)`
356
357 Add `$html` to the HEAD tag of the page currently being generated.
358
359 Note that TWiki variables may be used in the HEAD. They will be expanded according to normal variable expansion rules.
360
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.
362
363 ## <a name="StaticMethod &lt;strong&gt;initialize&lt;/strong&gt; ($path"></a> [[StaticMethod]] **initialize** `($pathInfo,$remoteUser,$topic,$url,$query) -> ($topicName,$webName,$scriptUrlPath,$userName,$dataDir)`
364
365 Return value: ( $topicName, $webName, $TWiki::cfg\{ScriptUrlPath\}, $userName, $TWiki::cfg\{DataDir\} )
366
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.
368
369 This method is **DEPRECATED** but is maintained for script compatibility.
370
371 Note that $theUrl, if specified, must be identical to $query-&gt;url()
372
373 ## <a name="StaticMethod &lt;strong&gt;readFile&lt;/strong&gt; ($filena"></a> [[StaticMethod]] **readFile** `($filename) -> $text`
374
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.
376
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**.
378
379 ## <a name="StaticMethod &lt;strong&gt;expand_StandardEsc"></a> [[StaticMethod]] \*expandStandardEscapes `($str) -> $unescapedStr`
380
381 Expands standard escapes used in parameter values to block evaluation. The following escapes are handled:
382
383 <table border="1" cellpadding="0" cellspacing="0">
384   <tr>
385     <th bgcolor="#99CCCC"><strong> Escape: </strong></th>
386     <th bgcolor="#99CCCC"><strong> Expands To: </strong></th>
387   </tr>
388   <tr>
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>
391   </tr>
392   <tr>
393     <td><code>$nop</code> or <code>$nop()</code></td>
394     <td> Is a "no operation". </td>
395   </tr>
396   <tr>
397     <td><code>$quot</code></td>
398     <td> Double quote (<code>"</code>) </td>
399   </tr>
400   <tr>
401     <td><code>$percnt</code></td>
402     <td> Percent sign (<code>%</code>) </td>
403   </tr>
404   <tr>
405     <td><code>$dollar</code></td>
406     <td> Dollar sign (<code>$</code>) </td>
407   </tr>
408 </table>