Changeset 1041 for trunk/core/lib/Foswiki/Func.pm
- Timestamp:
- 11/28/08 13:33:03 (3 years ago)
- File:
-
- 1 edited
-
trunk/core/lib/Foswiki/Func.pm (modified) (192 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/core/lib/Foswiki/Func.pm
r966 r1041 1 1 # See bottom of file for license and copyright information 2 2 3 = pod3 =begin TML 4 4 5 5 ---+ package Foswiki::Func 6 6 7 <!-- STARTINCLUDE required for huge CompleteDocumentation topic --> 8 %STARTINCLUDE% 9 10 _Official Foswiki interface for Plugin developers_ 11 12 This module defines the interfaces that [[%SYSTEMWEB%.Plugins][Plugins]] 7 _Interface for Foswiki extensions developers_ 8 9 This module defines the main interfaces that extensions 13 10 can use to interact with the Foswiki engine and content. 14 11 … … 16 13 and starter documentation on how to write a Plugin. 17 14 18 Plugins should *only* use functions described here. If you use 19 functions in other Foswiki libraries you might create a security hole and 15 Plugins should *only* call methods in packages documented in 16 System.DevelopingPlugins. If you use 17 functions in other Foswiki libraries you risk creating a security hole, and 20 18 you will probably need to change your plugin when you upgrade Foswiki. 21 19 22 Deprecated functions will still work in older code, though they should 20 %TOC% 21 22 API version $Date$ (revision $Rev$) 23 24 *Since* _date_ indicates where functions or parameters have been added since 25 the baseline of the API (TWiki release 4.2.3). The _date_ indicates the 26 earliest date of a Foswiki release that will support that function or 27 parameter. 28 29 *Deprecated* _date_ indicates where a function or parameters has been 30 [[http://en.wikipedia.org/wiki/Deprecation][deprecated]]. Deprecated 31 functions will still work, though they should 23 32 _not_ be called in new plugins and should be replaced in older plugins 24 as soon as possible. 25 26 The compatibility history of this module is given by the VERSION number 27 of the Foswiki::Plugins module. 28 29 Notes on use of =$Foswiki::Plugins::VERSION=: 30 * If the *major* version (e.g. =1.=) is the same then any plugin coded 31 to use any *earlier* revision of the =1.= API will still work. No 32 function has been removed from the interface, nor has any API published 33 in that version changed in such a way as to *require* plugins to be 34 recoded. 35 * If the *minor* version (e.g. =1.1.=) is incremented there may be changes 36 in the API that may help improve the coding of some plugins - for 37 example, new interfaces giving access to previously hidden core functions. 38 In addition, *deprecation* of functions in the interface trigger a minor 39 version increment. Note that deprecated functions are not _removed_, they 40 are merely frozen, and plugin authors are recommended to stop using them. 41 * Any additional digits in the version number relate to minor changes, such 42 as the addition of parameters to the existing functions, or addition of 43 utility functions that are unlikely to require significant changes to 44 existing plugins. 45 * =$Foswiki::Plugins::VERSION= also applies to the plugin handlers. The 46 handlers are documented in the !EmptyPlugin, and that module indicates 47 what version of =Foswiki::Plugins::VERSION= it relates to. 48 49 =cut 33 as soon as possible. Deprecated parameters are simply ignored in Foswiki 34 releases after _date_. 35 36 *Until* _date_ indicates where a function or parameter has been removed. 37 The _date_ indicates the latest date at which Foswiki releases still supported 38 the function or parameter. 39 40 =cut 41 42 # THIS PACKAGE IS PART OF THE PUBLISHED API USED BY EXTENSION AUTHORS. 43 # DO NOT CHANGE THE EXISTING APIS (well thought out extensions are OK) 44 # AND ENSURE ALL POD DOCUMENTATION IS COMPLETE AND ACCURATE. 45 # 46 # Deprecated functions should not be removed, but should be moved to to the 47 # deprecated functions section. 50 48 51 49 package Foswiki::Func; … … 58 56 require Foswiki::Plugins; 59 57 60 = pod58 =begin TML 61 59 62 60 ---++ Environment … … 64 62 =cut 65 63 66 = pod64 =begin TML 67 65 68 66 ---+++ getSkin( ) -> $skin … … 72 70 Return: =$skin= Comma-separated list of skins, e.g. ='gnu,tartan'=. Empty string if none. 73 71 74 *Since:* Foswiki::Plugins::VERSION 1.000 (29 Jul 2001)75 76 72 =cut 77 73 … … 82 78 } 83 79 84 = pod80 =begin TML 85 81 86 82 ---+++ getUrlHost( ) -> $host … … 90 86 Return: =$host= URL host, e.g. ="http://example.com:80"= 91 87 92 *Since:* Foswiki::Plugins::VERSION 1.000 (7 Dec 2002)93 94 88 =cut 95 89 … … 100 94 } 101 95 102 = pod96 =begin TML 103 97 104 98 ---+++ getScriptUrl( $web, $topic, $script, ... ) -> $url … … 112 106 Return: =$url= URL, e.g. ="http://example.com:80/cgi-bin/view.pl/Main/WebNotify"= 113 107 114 *Since:* Foswiki::Plugins::VERSION 1.000 (7 Dec 2002)115 116 108 =cut 117 109 … … 126 118 } 127 119 128 = pod120 =begin TML 129 121 130 122 ---+++ getViewUrl( $web, $topic ) -> $url … … 135 127 Return: =$url= URL, e.g. ="http://example.com:80/cgi-bin/view.pl/Main/WebNotify"= 136 128 137 *Since:* Foswiki::Plugins::VERSION 1.000 (7 Dec 2002)138 139 129 =cut 140 130 … … 147 137 } 148 138 149 = pod139 =begin TML 150 140 151 141 ---+++ getPubUrlPath( ) -> $path … … 154 144 155 145 Return: =$path= URL path of pub directory, e.g. ="/pub"= 156 157 *Since:* Foswiki::Plugins::VERSION 1.000 (14 Jul 2001)158 146 159 147 =cut … … 163 151 } 164 152 165 = pod153 =begin TML 166 154 167 155 ---+++ getExternalResource( $url ) -> $response … … 210 198 </verbatim> 211 199 212 *Since:* Foswiki::Plugins::VERSION 1.2213 214 200 =cut 215 201 … … 222 208 } 223 209 224 = pod210 =begin TML 225 211 226 212 ---+++ getCgiQuery( ) -> $query … … 230 216 Return: =$query= CGI query object; or 0 if script is called as a shell script 231 217 232 *Since:* Foswiki::Plugins::VERSION 1.000 (7 Dec 2002)233 234 218 =cut 235 219 … … 239 223 } 240 224 241 = pod225 =begin TML 242 226 243 227 ---+++ getSessionKeys() -> @keys … … 246 230 Session keys are stored and retrieved using =setSessionValue= and 247 231 =getSessionValue=. 248 249 *Since:* Foswiki::Plugins::VERSION 1.2250 232 251 233 =cut … … 258 240 } 259 241 260 = pod242 =begin TML 261 243 262 244 ---+++ getSessionValue( $key ) -> $value … … 266 248 Return: =$value= Value associated with key; empty string if not set 267 249 268 *Since:* Foswiki::Plugins::VERSION 1.000 (27 Feb 200)269 270 250 =cut 271 251 … … 279 259 } 280 260 281 = pod261 =begin TML 282 262 283 263 ---+++ setSessionValue( $key, $value ) -> $boolean … … 288 268 Return: true if function succeeded 289 269 290 *Since:* Foswiki::Plugins::VERSION 1.000 (17 Aug 2001)291 292 270 =cut 293 271 … … 300 278 } 301 279 302 = pod280 =begin TML 303 281 304 282 ---+++ clearSessionValue( $key ) -> $boolean … … 309 287 Return: true if the session value was cleared 310 288 311 *Since:* Foswiki::Plugins::VERSION 1.1312 313 289 =cut 314 290 … … 320 296 } 321 297 322 = pod298 =begin TML 323 299 324 300 ---+++ getContext() -> \%hash … … 365 341 working, the context ID 'FirstPlugin' will be set. 366 342 367 *Since:* Foswiki::Plugins::VERSION 1.1368 369 343 =cut 370 344 … … 374 348 } 375 349 376 = pod350 =begin TML 377 351 378 352 ---+++ pushTopicContext($web, $topic) … … 391 365 global variables to remember the web and topic in =initPlugin=, then those 392 366 values will be unchanged. 393 394 *Since:* Foswiki::Plugins::VERSION 1.2395 367 396 368 =cut … … 415 387 } 416 388 417 = pod389 =begin TML 418 390 419 391 ---+++ popTopicContext() … … 421 393 Returns the Foswiki context to the state it was in before the 422 394 =pushTopicContext= was called. 423 424 *Since:* Foswiki::Plugins::VERSION 1.2425 395 426 396 =cut … … 436 406 } 437 407 438 = pod408 =begin TML 439 409 440 410 ---++ Preferences … … 442 412 =cut 443 413 444 = pod414 =begin TML 445 415 446 416 ---+++ getPreferencesValue( $key, $web ) -> $value … … 450 420 * =$web= - Name of web, optional. Current web if not specified; does not apply to settings of Plugin topics 451 421 Return: =$value= Preferences value; empty string if not set 452 453 *Since:* Foswiki::Plugins::VERSION 1.000 (7 Dec 2002)454 422 455 423 * Example for Plugin setting: … … 479 447 } 480 448 481 = pod449 =begin TML 482 450 483 451 ---+++ getPluginPreferencesValue( $key ) -> $value … … 488 456 489 457 __Note__: This function will will *only* work when called from the Plugin.pm file itself. it *will not work* if called from a sub-package (e.g. Foswiki::Plugins::MyPlugin::MyModule) 490 491 *Since:* Foswiki::Plugins::VERSION 1.021 (27 Mar 2004)492 458 493 459 *NOTE:* If =$NO_PREFS_IN_TOPIC= is enabled in the plugin, then … … 505 471 } 506 472 507 = pod473 =begin TML 508 474 509 475 ---+++ getPreferencesFlag( $key, $web ) -> $value … … 514 480 Return: =$value= Preferences flag ='1'= (if set), or ="0"= (for preferences values ="off"=, ="no"= and ="0"=) 515 481 516 *Since:* Foswiki::Plugins::VERSION 1.000 (7 Dec 2002)517 518 482 * Example for Plugin setting: 519 483 * MyPlugin topic has: =* Set SHOWHELP = off= … … 533 497 } 534 498 535 = pod499 =begin TML 536 500 537 501 ---+++ getPluginPreferencesFlag( $key ) -> $boolean … … 542 506 543 507 __Note__: This function will will *only* work when called from the Plugin.pm file itself. it *will not work* if called from a sub-package (e.g. Foswiki::Plugins::MyPlugin::MyModule) 544 545 *Since:* Foswiki::Plugins::VERSION 1.021 (27 Mar 2004)546 508 547 509 *NOTE:* If =$NO_PREFS_IN_TOPIC= is enabled in the plugin, then … … 557 519 } 558 520 559 = pod521 =begin TML 560 522 561 523 ---+++ setPreferencesValue($name, $val) … … 576 538 } 577 539 578 = pod540 =begin TML 579 541 580 542 ---++ User Handling and Access Control … … 584 546 Return: =$loginName= Default user name, e.g. ='guest'= 585 547 586 *Since:* Foswiki::Plugins::VERSION 1.000 (7 Dec 2002)587 588 548 =cut 589 549 … … 592 552 } 593 553 594 = pod554 =begin TML 595 555 596 556 ---+++ getCanonicalUserID( $user ) -> $cUID … … 608 568 registered users. This may be autogenerated for an authenticated but 609 569 unregistered user. 610 611 *Since:* Foswiki::Plugins::VERSION 1.2612 570 613 571 =cut … … 633 591 } 634 592 635 = pod593 =begin TML 636 594 637 595 ---+++ getWikiName( $user ) -> $wikiName … … 643 601 644 602 Return: =$wikiName= Wiki Name, e.g. ='JohnDoe'= 645 646 *Since:* Foswiki::Plugins::VERSION 1.000 (7 Dec 2002)647 603 648 604 =cut … … 660 616 } 661 617 662 = pod618 =begin TML 663 619 664 620 ---+++ getWikiUserName( $user ) -> $wikiName … … 670 626 671 627 Return: =$wikiName= Wiki Name, e.g. ="Main.JohnDoe"= 672 673 *Since:* Foswiki::Plugins::VERSION 1.000 (7 Dec 2002)674 628 675 629 =cut … … 687 641 } 688 642 689 = pod643 =begin TML 690 644 691 645 ---+++ wikiToUserName( $id ) -> $loginName 692 646 Translate a Wiki name to a login name. 693 647 * =$id= - Wiki name, e.g. ='Main.JohnDoe'= or ='JohnDoe'=. 694 Since TWiki 4.2.1,$id may also be a login name. This will normally648 $id may also be a login name. This will normally 695 649 be transparent, but should be borne in mind if you have login names 696 650 that are also legal wiki names. … … 704 658 705 659 returns undef if the WikiName is not found. 706 707 *Since:* Foswiki::Plugins::VERSION 1.000 (7 Dec 2002)708 660 709 661 =cut … … 723 675 } 724 676 725 = pod677 =begin TML 726 678 727 679 ---+++ userToWikiName( $loginName, $dontAddWeb ) -> $wikiName … … 735 687 userToWikiName will always return a name. If the user does not 736 688 exist in the mapping, the $loginName parameter is returned. (backward compatibility) 737 738 *Since:* Foswiki::Plugins::VERSION 1.000 (7 Dec 2002)739 689 740 690 =cut … … 755 705 } 756 706 757 = pod707 =begin TML 758 708 759 709 ---+++ emailToWikiNames( $email, $dontAddWeb ) -> @wikiNames … … 763 713 registered address. Since several users could register with the same email 764 714 address, this returns a list of wikinames rather than a single wikiname. 765 766 *Since:* Foswiki::Plugins::VERSION 1.2767 715 768 716 =cut … … 789 737 } 790 738 791 = pod739 =begin TML 792 740 793 741 ---+++ wikinameToEmails( $user ) -> @emails … … 797 745 798 746 $user may also be a login name, or the name of a group. 799 800 *Since:* Foswiki::Plugins::VERSION 1.2801 747 802 748 =cut … … 825 771 } 826 772 827 = pod773 =begin TML 828 774 829 775 ---+++ isGuest( ) -> $boolean 830 776 831 777 Test if logged in user is a guest (WikiGuest) 832 833 *Since:* Foswiki::Plugins::VERSION 1.000 (7 Dec 2002)834 778 835 779 =cut … … 841 785 } 842 786 843 = pod787 =begin TML 844 788 845 789 ---+++ isAnAdmin( $id ) -> $boolean … … 848 792 the currently logged-in user is assumed. 849 793 * $id can be either a login name or a WikiName 850 851 *Since:* Foswiki::Plugins::VERSION 1.2852 794 853 795 =cut … … 859 801 } 860 802 861 = pod803 =begin TML 862 804 863 805 ---+++ isGroupMember( $group, $id ) -> $boolean … … 872 814 873 815 * $id can be a login name or a WikiName 874 875 *Since:* Foswiki::Plugins::VERSION 1.2876 816 877 817 =cut … … 894 834 } 895 835 896 = pod836 =begin TML 897 837 898 838 ---+++ eachUser() -> $iterator … … 910 850 911 851 *WARNING* on large sites, this could be a long list! 912 913 *Since:* Foswiki::Plugins::VERSION 1.2914 852 915 853 =cut … … 923 861 } 924 862 925 = pod863 =begin TML 926 864 927 865 ---+++ eachMembership($id) -> $iterator … … 929 867 If =$id= is =undef=, defaults to the currently logged-in user. 930 868 Get an iterator over the names of all groups that the user is a member of. 931 932 *Since:* Foswiki::Plugins::VERSION 1.2933 869 934 870 =cut … … 950 886 } 951 887 952 = pod888 =begin TML 953 889 954 890 ---+++ eachGroup() -> $iterator … … 966 902 *WARNING* on large sites, this could be a long list! 967 903 968 *Since:* Foswiki::Plugins::VERSION 1.2969 970 904 =cut 971 905 … … 976 910 } 977 911 978 = pod912 =begin TML 979 913 980 914 ---+++ isGroup( $group ) -> $boolean … … 990 924 } 991 925 992 = pod926 =begin TML 993 927 994 928 ---+++ eachGroupMember($group) -> $iterator … … 1006 940 1007 941 *WARNING* on large sites, this could be a long list! 1008 1009 *Since:* Foswiki::Plugins::VERSION 1.21010 942 1011 943 =cut … … 1023 955 } 1024 956 1025 = pod957 =begin TML 1026 958 1027 959 ---+++ checkAccessPermission( $type, $id, $text, $topic, $web, $meta ) -> $boolean … … 1057 989 in =ThatWeb.ThisTopic=, then a call to =checkAccessPermissions('SPIN', 'IncyWincy', undef, 'ThisTopic', 'ThatWeb', undef)= will return =true=. 1058 990 1059 *Since:* Foswiki::Plugins::VERSION 1.000 (27 Feb 2001)1060 1061 991 =cut 1062 992 … … 1072 1002 } 1073 1003 1074 = pod1004 =begin TML 1075 1005 1076 1006 ---++ Webs, Topics and Attachments … … 1078 1008 =cut 1079 1009 1080 = pod1010 =begin TML 1081 1011 1082 1012 ---+++ getListOfWebs( $filter [, $web] ) -> @webs … … 1098 1028 </verbatim> 1099 1029 1100 *Since:* Foswiki::Plugins::VERSION 1.11101 1102 1030 =cut 1103 1031 … … 1107 1035 } 1108 1036 1109 = pod1037 =begin TML 1110 1038 1111 1039 ---+++ webExists( $web ) -> $boolean … … 1114 1042 * =$web= - Web name, required, e.g. ='Sandbox'= 1115 1043 1116 *Since:* Foswiki::Plugins::VERSION 1.000 (14 Jul 2001)1117 1118 1044 =cut 1119 1045 … … 1125 1051 } 1126 1052 1127 = pod1053 =begin TML 1128 1054 1129 1055 ---+++ createWeb( $newWeb, $baseWeb, $opts ) … … 1151 1077 </verbatim> 1152 1078 1153 *Since:* Foswiki::Plugins::VERSION 1.11154 1155 1079 =cut 1156 1080 … … 1161 1085 } 1162 1086 1163 = pod1087 =begin TML 1164 1088 1165 1089 ---+++ moveWeb( $oldName, $newName ) … … 1189 1113 </verbatim> 1190 1114 1191 *Since:* Foswiki::Plugins::VERSION 1.11192 1193 1115 =cut 1194 1116 … … 1200 1122 } 1201 1123 1202 = pod1124 =begin TML 1203 1125 1204 1126 ---+++ eachChangeSince($web, $time) -> $iterator … … 1237 1159 } 1238 1160 1239 = pod1161 =begin TML 1240 1162 1241 1163 ---+++ getTopicList( $web ) -> @topics … … 1245 1167 Return: =@topics= Topic list, e.g. =( 'WebChanges', 'WebHome', 'WebIndex', 'WebNotify' )= 1246 1168 1247 *Since:* Foswiki::Plugins::VERSION 1.000 (7 Dec 2002)1248 1249 1169 =cut 1250 1170 … … 1256 1176 } 1257 1177 1258 = pod1178 =begin TML 1259 1179 1260 1180 ---+++ topicExists( $web, $topic ) -> $boolean … … 1268 1188 To get an expected behaviour it is recommened to specify the current web for $web; don't leave it empty. 1269 1189 1270 *Since:* Foswiki::Plugins::VERSION 1.000 (14 Jul 2001)1271 1272 1190 =cut 1273 1191 … … 1278 1196 } 1279 1197 1280 = pod1198 =begin TML 1281 1199 1282 1200 ---+++ checkTopicEditLock( $web, $topic, $script ) -> ( $oopsUrl, $loginName, $unlockTime ) … … 1287 1205 Return: =( $oopsUrl, $loginName, $unlockTime )= - The =$oopsUrl= for calling redirectCgiQuery(), user's =$loginName=, and estimated =$unlockTime= in minutes, or ( '', '', 0 ) if no lease exists. 1288 1206 * =$script= The script to invoke when continuing with the edit 1289 1290 *Since:* Foswiki::Plugins::VERSION 1.010 (31 Dec 2002)1291 1207 1292 1208 =cut … … 1327 1243 } 1328 1244 1329 = pod1245 =begin TML 1330 1246 1331 1247 ---+++ setTopicEditLock( $web, $topic, $lock ) … … 1342 1258 It is *impossible* to fully lock a topic. Concurrent changes will be 1343 1259 merged. 1344 1345 *Since:* Foswiki::Plugins::VERSION 1.010 (31 Dec 2002)1346 1260 1347 1261 =cut … … 1362 1276 } 1363 1277 1364 = pod1278 =begin TML 1365 1279 1366 1280 ---+++ saveTopic( $web, $topic, $meta, $text, $options ) -> $error … … 1377 1291 Return: error message or undef. 1378 1292 1379 *Since:* Foswiki::Plugins::VERSION 1.000 (29 Jul 2001)1380 1381 1293 For example, 1382 1294 <verbatim> … … 1401 1313 } 1402 1314 1403 = pod1315 =begin TML 1404 1316 1405 1317 ---+++ saveTopicText( $web, $topic, $text, $ignorePermissions, $dontNotify ) -> $oopsUrl … … 1414 1326 1415 1327 This method is a lot less efficient and much more dangerous than =saveTopic=. 1416 1417 *Since:* Foswiki::Plugins::VERSION 1.010 (31 Dec 2002)1418 1328 1419 1329 <verbatim> … … 1491 1401 } 1492 1402 1493 = pod1403 =begin TML 1494 1404 1495 1405 ---+++ moveTopic( $web, $topic, $newWeb, $newTopic ) … … 1506 1416 1507 1417 Rename a topic to the $Foswiki::cfg{TrashWebName} to delete it. 1508 1509 *Since:* Foswiki::Plugins::VERSION 1.11510 1418 1511 1419 <verbatim> … … 1539 1447 } 1540 1448 1541 = pod1449 =begin TML 1542 1450 1543 1451 ---+++ getRevisionInfo($web, $topic, $rev, $attachment ) -> ( $date, $user, $rev, $comment ) … … 1558 1466 more efficient. 1559 1467 1560 *Since:* Foswiki::Plugins::VERSION 1.000 (29 Jul 2001)1561 1562 1468 =cut 1563 1469 … … 1570 1476 } 1571 1477 1572 = pod1478 =begin TML 1573 1479 1574 1480 ---+++ getRevisionAtTime( $web, $topic, $time ) -> $rev … … 1581 1487 (either because the topic isn't that old, or there was a problem) 1582 1488 1583 *Since:* Foswiki::Plugins::VERSION 1.11584 1585 1489 =cut 1586 1490 … … 1590 1494 } 1591 1495 1592 = pod1496 =begin TML 1593 1497 1594 1498 ---+++ readTopic( $web, $topic, $rev ) -> ( $meta, $text ) … … 1608 1512 topic. 1609 1513 1610 *Since:* Foswiki::Plugins::VERSION 1.000 (7 Dec 2002)1611 1612 1514 =cut 1613 1515 … … 1620 1522 } 1621 1523 1622 = pod1524 =begin TML 1623 1525 1624 1526 ---+++ readTopicText( $web, $topic, $rev, $ignorePermissions ) -> $text … … 1632 1534 1633 1535 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. 1634 1635 *Since:* Foswiki::Plugins::VERSION 1.010 (31 Dec 2002)1636 1536 1637 1537 =cut … … 1665 1565 } 1666 1566 1667 = pod1567 =begin TML 1668 1568 1669 1569 ---+++ attachmentExists( $web, $topic, $attachment ) -> $boolean … … 1675 1575 $web and $topic are parsed as described in the documentation for =normalizeWebTopicName=. 1676 1576 1677 *Since:* Foswiki::Plugins::VERSION 1.11678 1679 1577 =cut 1680 1578 … … 1689 1587 } 1690 1588 1691 = pod1589 =begin TML 1692 1590 1693 1591 ---+++ readAttachment( $web, $topic, $name, $rev ) -> $data … … 1719 1617 </verbatim> 1720 1618 1721 *Since:* Foswiki::Plugins::VERSION 1.11722 1723 1619 =cut 1724 1620 … … 1737 1633 } 1738 1634 1739 = pod1635 =begin TML 1740 1636 1741 1637 ---+++ saveAttachment( $web, $topic, $attachment, \%opts ) … … 1770 1666 </verbatim> 1771 1667 1772 *Since:* Foswiki::Plugins::VERSION 1.11773 1774 1668 =cut 1775 1669 … … 1790 1684 } 1791 1685 1792 = pod1686 =begin TML 1793 1687 1794 1688 ---+++ moveAttachment( $web, $topic, $attachment, $newWeb, $newTopic, $newAttachment ) … … 1826 1720 </verbatim> 1827 1721 1828 *Since:* Foswiki::Plugins::VERSION 1.11829 1830 1722 =cut 1831 1723 … … 1847 1739 } 1848 1740 1849 = pod1741 =begin TML 1850 1742 1851 1743 ---++ Assembling Pages … … 1853 1745 =cut 1854 1746 1855 = pod1747 =begin TML 1856 1748 1857 1749 ---+++ readTemplate( $name, $skin ) -> $text … … 1862 1754 Return: =$text= Template text 1863 1755 1864 *Since:* Foswiki::Plugins::VERSION 1.000 (7 Dec 2002)1865 1866 1756 =cut 1867 1757 … … 1873 1763 } 1874 1764 1875 = pod1765 =begin TML 1876 1766 1877 1767 ---+++ loadTemplate ( $name, $skin, $web ) -> $text … … 1882 1772 Return: expanded template text (what's left after removal of all %TMPL:DEF% statements) 1883 1773 1884 *Since:* Foswiki::Plugins::VERSION 1.11885 1886 1774 Reads a template and extracts template definitions, adding them to the 1887 1775 list of loaded templates, overwriting any previous definition. … … 1898 1786 } 1899 1787 1900 = pod1788 =begin TML 1901 1789 1902 1790 ---+++ expandTemplate( $def ) -> $string … … 1906 1794 Return: the text of the expanded template 1907 1795 1908 *Since:* Foswiki::Plugins::VERSION 1.11909 1910 1796 A template is defined using a %TMPL:DEF% statement in a template 1911 1797 file. See the documentation on Foswiki templates for more information. … … 1918 1804 } 1919 1805 1920 = pod1806 =begin TML 1921 1807 1922 1808 ---+++ writeHeader() … … 1924 1810 Prints a basic content-type HTML header for text/html to standard out. 1925 1811 1926 *Since:* Foswiki::Plugins::VERSION 1.000 (7 Dec 2002)1927 1928 1812 =cut 1929 1813 … … 1933 1817 } 1934 1818 1935 = pod1819 =begin TML 1936 1820 1937 1821 ---+++ redirectCgiQuery( $query, $url, $passthru ) … … 1967 1851 Foswiki installation. 1968 1852 1969 *Since:* Foswiki::Plugins::VERSION 1.000 (7 Dec 2002)1970 1971 1853 =cut 1972 1854 … … 1977 1859 } 1978 1860 1979 = pod1861 =begin TML 1980 1862 1981 1863 ---+++ addToHEAD( $id, $header, $requires ) … … 1991 1873 Note that this is _not_ the same as the HTTP header, which is modified through the Plugins =modifyHeaderHandler=. 1992 1874 1993 *Since:* Foswiki::Plugins::VERSION 1.1 1994 1995 example: 1875 Example: 1996 1876 <verbatim> 1997 1877 Foswiki::Func::addToHEAD('PATTERN_STYLE','<link id="twikiLayoutCss" rel="stylesheet" type="text/css" href="%PUBURL%/Foswiki/PatternSkin/layout.css" media="all" />'); … … 2006 1886 } 2007 1887 2008 = pod1888 =begin TML 2009 1889 2010 1890 ---+++ expandCommonVariables( $text, $topic, $web, $meta ) -> $text … … 2014 1894 * =$topic= - Current topic name, e.g. ='WebNotify'= 2015 1895 * =$web= - Web name, optional, e.g. ='Main'=. The current web is taken if missing 2016 * =$meta= - topic meta-data to use while expanding (Since Foswiki::Plugins::VERSION 1.2)1896 * =$meta= - topic meta-data to use while expanding 2017 1897 Return: =$text= Expanded text, e.g. ='Current user is <nop>WikiGuest'= 2018 2019 *Since:* Foswiki::Plugins::VERSION 1.000 (7 Dec 2002)2020 1898 2021 1899 See also: expandVariablesOnTopicCreation … … 2032 1910 } 2033 1911 2034 = pod1912 =begin TML 2035 1913 2036 1914 ---+++ renderText( $text, $web ) -> $text … … 2041 1919 Return: =$text= XHTML text, e.g. ='<b>bold</b> and <code>fixed font</code>'= 2042 1920 2043 *Since:* Foswiki::Plugins::VERSION 1.000 (7 Dec 2002)2044 2045 1921 =cut 2046 1922 … … 2052 1928 } 2053 1929 2054 = pod1930 =begin TML 2055 1931 2056 1932 ---+++ internalLink( $pre, $web, $topic, $label, $anchor, $createLink ) -> $text … … 2065 1941 Return: =$text= XHTML anchor, e.g. ='<a href='/cgi-bin/view/Main/WebNotify#Jump'>notify</a>'= 2066 1942 2067 *Since:* Foswiki::Plugins::VERSION 1.000 (7 Dec 2002)2068 2069 1943 =cut 2070 1944 … … 2077 1951 } 2078 1952 2079 = pod1953 =begin TML 2080 1954 2081 1955 ---++ E-mail … … 2104 1978 Leave a blank line between the last header field and the message body. 2105 1979 2106 *Since:* Foswiki::Plugins::VERSION 1.12107 2108 1980 =cut 2109 1981 … … 2115 1987 } 2116 1988 2117 =pod 2118 2119 ---+++ wikiToEmail( $wikiName ) -> $email 2120 2121 * =$wikiname= - wiki name of the user 2122 Get the e-mail address(es) of the named user. If the user has multiple 2123 e-mail addresses (for example, the user is a group), then the list will 2124 be comma-separated. 2125 2126 *Since:* Foswiki::Plugins::VERSION 1.1 2127 2128 *Deprecated* in favour of wikinameToEmails, because this function only 2129 returns a single email address, where a user may in fact have several. 2130 2131 $wikiName may also be a login name. 2132 2133 =cut 2134 2135 sub wikiToEmail { 2136 my ($user) = @_; 2137 my @emails = wikinameToEmails($user); 2138 if ( scalar(@emails) ) { 2139 return $emails[0]; 2140 } 2141 return ''; 2142 } 2143 2144 =pod 1989 =begin TML 2145 1990 2146 1991 ---++ Creating New Topics … … 2148 1993 =cut 2149 1994 2150 = pod1995 =begin TML 2151 1996 2152 1997 ---+++ expandVariablesOnTopicCreation ( $text ) -> $text … … 2155 2000 * =$text= - the text to process 2156 2001 Return: text with variables expanded 2157 2158 *Since:* Foswiki::Plugins::VERSION 1.12159 2002 2160 2003 Expands only the variables expected in templates that must be statically … … 2181 2024 } 2182 2025 2183 = pod2026 =begin TML 2184 2027 2185 2028 ---++ Special handlers … … 2189 2032 =cut 2190 2033 2191 = pod=2034 =begin TML= 2192 2035 2193 2036 ---+++ registerTagHandler( $var, \&fn, $syntax ) … … 2199 2042 * =\&fn= - Reference to the handler function. 2200 2043 * =$syntax= can be 'classic' (the default) or 'context-free'. 'classic' syntax is appropriate where you want the variable to support classic syntax i.e. to accept the standard =%<nop>MYVAR{ "unnamed" param1="value1" param2="value2" }%= syntax, as well as an unquoted default parameter, such as =%<nop>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"}% 2201 2202 *Since:* Foswiki::Plugins::VERSION 1.12203 2044 2204 2045 The variable handler function must be of the form: … … 2258 2099 } 2259 2100 2260 = pod=2101 =begin TML= 2261 2102 2262 2103 ---+++ registerRESTHandler( $alias, \&fn, ) … … 2267 2108 * =$alias= - The name . 2268 2109 * =\&fn= - Reference to the function. 2269 2270 *Since:* Foswiki::Plugins::VERSION 1.12271 2110 2272 2111 The handler function must be of the form: … … 2322 2161 } 2323 2162 2324 = pod2163 =begin TML 2325 2164 2326 2165 ---+++ decodeFormatTokens($str) -> $unencodedString … … 2352 2191 alphanumeric characters*. You have been warned! 2353 2192 2354 *Since:* Foswiki::Plugins::VERSION 1.22355 2356 2193 =cut 2357 2194 … … 2360 2197 } 2361 2198 2362 = pod2199 =begin TML 2363 2200 2364 2201 ---++ Searching … … 2366 2203 =cut 2367 2204 2368 = pod2205 =begin TML 2369 2206 2370 2207 ---+++ searchInWebContent($searchString, $web, \@topics, \%options ) -> \%map … … 2393 2230 </verbatim> 2394 2231 2395 *Since:* Foswiki::Plugins::VERSION 1.12396 2397 2232 =cut 2398 2233 … … 2404 2239 } 2405 2240 2406 = pod2241 =begin TML 2407 2242 2408 2243 ---++ Plugin-specific file handling … … 2410 2245 =cut 2411 2246 2412 = pod2247 =begin TML 2413 2248 2414 2249 ---+++ getWorkArea( $pluginName ) -> $directorypath … … 2423 2258 to keep their areas tidy. 2424 2259 2425 *Since:* Foswiki::Plugins::VERSION 1.1 (Dec 2005)2426 2427 2260 =cut 2428 2261 … … 2433 2266 } 2434 2267 2435 = pod2268 =begin TML 2436 2269 2437 2270 ---+++ readFile( $filename ) -> $text … … 2442 2275 2443 2276 __NOTE:__ Use this function only for the Plugin workarea, *not* for topics and attachments. Use the appropriate functions to manipulate topics and attachments. 2444 2445 *Since:* Foswiki::Plugins::VERSION 1.000 (07 Dec 2002)2446 2277 2447 2278 =cut … … 2458 2289 } 2459 2290 2460 = pod2291 =begin TML 2461 2292 2462 2293 ---+++ saveFile( $filename, $text ) … … 2468 2299 2469 2300 __NOTE:__ Use this function only for the Plugin workarea, *not* for topics and attachments. Use the appropriate functions to manipulate topics and attachments. 2470 2471 *Since:* Foswiki::Plugins::VERSION 1.000 (07 Dec 2002)2472 2301 2473 2302 =cut … … 2483 2312 } 2484 2313 2485 = pod2314 =begin TML 2486 2315 2487 2316 ---++ General Utilities … … 2489 2318 =cut 2490 2319 2491 = pod2320 =begin TML 2492 2321 2493 2322 ---+++ getRegularExpression( $name ) -> $expr … … 2496 2325 * =$name= - Name of the expression to retrieve. See notes below 2497 2326 Return: String or precompiled regular expression matching as described below. 2498 2499 *Since:* Foswiki::Plugins::VERSION 1.020 (9 Feb 2004)2500 2327 2501 2328 __Note:__ Foswiki internally precompiles several regular expressions to … … 2541 2368 } 2542 2369 2543 = pod2370 =begin TML 2544 2371 2545 2372 ---+++ normalizeWebTopicName($web, $topic) -> ($web, $topic) … … 2549 2376 * =$topic= - Topic name, may be a web.topic string, required. 2550 2377 Return: the parsed Web/Topic pair 2551 2552 *Since:* Foswiki::Plugins::VERSION 1.12553 2378 2554 2379 | *Input* | *Return* | … … 2579 2404 } 2580 2405 2581 = pod2406 =begin TML 2582 2407 2583 2408 ---+++ StaticMethod sanitizeAttachmentName($fname) -> ($fileName, $origName) … … 2590 2415 file names to legal server names. 2591 2416 2592 *Since:* Foswiki::Plugins::VERSION 1.22593 2594 2417 =cut 2595 2418 … … 2599 2422 } 2600 2423 2601 = pod2424 =begin TML 2602 2425 2603 2426 ---+++ spaceOutWikiWord( $word, $sep ) -> $text … … 2606 2429 With parameter $sep any string may be used as separator between the word components; if $sep is undefined it defaults to a space. 2607 2430 2608 *Since:* Foswiki::Plugins::VERSION 1.22609 2610 2431 =cut 2611 2432 … … 2616 2437 } 2617 2438 2618 = pod2439 =begin TML 2619 2440 2620 2441 ---+++ writeWarning( $text ) … … 2624 2445 Return: none 2625 2446 2626 *Since:* Foswiki::Plugins::VERSION 1.020 (16 Feb 2004)2627 2628 2447 =cut 2629 2448 … … 2637 2456 } 2638 2457 2639 = pod2458 =begin TML 2640 2459 2641 2460 ---+++ writeDebug( $text ) … … 2645 2464 Return: none 2646 2465 2647 *Since:* Foswiki::Plugins::VERSION 1.020 (16 Feb 2004)2648 2649 2466 =cut 2650 2467 … … 2656 2473 } 2657 2474 2658 =pod 2659 2660 ---+++ formatTime( $time, $format, $timezone ) -> $text 2661 2662 Format the time in seconds into the desired time string 2663 * =$time= - Time in epoc seconds 2664 * =$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 2665 * =$timezone= - either not defined (uses the displaytime setting), 'gmtime', or 'servertime' 2666 Return: =$text= Formatted time string 2667 | Note: | if you used the removed formatGmTime, add a third parameter 'gmtime' | 2668 2669 *Since:* Foswiki::Plugins::VERSION 1.020 (26 Feb 2004) 2670 2671 =cut 2672 2673 sub formatTime { 2674 2675 # my ( $epSecs, $format, $timezone ) = @_; 2676 require Foswiki::Time; 2677 return Foswiki::Time::formatTime(@_); 2678 } 2679 2680 =pod 2475 =begin TML 2681 2476 2682 2477 ---+++ isTrue( $value, $default ) -> $boolean … … 2690 2485 not specified it is taken as 0. 2691 2486 2692 *Since:* $Foswiki::Plugins::VERSION 1.22693 2694 2487 =cut 2695 2488 … … 2701 2494 } 2702 2495 2703 = pod2496 =begin TML 2704 2497 2705 2498 ---+++ isValidWikiWord ( $text ) -> $boolean … … 2708 2501 * =$text= - Word to test 2709 2502 2710 *Since:* Foswiki::Plugins::VERSION 1.100 (Dec 2005)2711 2712 2503 =cut 2713 2504 … … 2716 2507 } 2717 2508 2718 = pod2509 =begin TML 2719 2510 2720 2511 ---+++ extractParameters($attr ) -> %params … … 2723 2514 * =$attr= - Attribute string 2724 2515 Return: =%params= Hash containing all parameters. The nameless parameter is stored in key =_DEFAULT= 2725 2726 *Since:* Foswiki::Plugins::VERSION 1.025 (26 Aug 2004)2727 2516 2728 2517 * Example: … … 2749 2538 } 2750 2539 2751 = pod2540 =begin TML 2752 2541 2753 2542 ---+++ extractNameValuePair( $attr, $name ) -> $value … … 2758 2547 * =$name= - Name, optional 2759 2548 Return: =$value= Extracted value 2760 2761 *Since:* Foswiki::Plugins::VERSION 1.000 (7 Dec 2002)2762 2549 2763 2550 * Example: … … 2776 2563 } 2777 2564 2778 = pod2565 =begin TML 2779 2566 2780 2567 ---++ Deprecated functions … … 2799 2586 Get script URL path 2800 2587 2801 *D EPRECATED* since 1.1- use =getScriptUrl= instead.2588 *Deprecated* 28 Nov 2008 - use =getScriptUrl= instead. 2802 2589 2803 2590 Return: =$path= URL path of bin scripts, e.g. ="/cgi-bin"= … … 2807 2594 using it. 2808 2595 2809 *Since:* Foswiki::Plugins::VERSION 1.000 (7 Dec 2002)2810 2811 2596 =cut 2812 2597 … … 2817 2602 2818 2603 2819 = pod2604 =begin TML 2820 2605 2821 2606 ---+++ getWikiToolName( ) -> $name 2822 2607 2823 *D EPRECATED*in Foswiki; use $Foswiki::cfg{WikiToolName} instead2608 *Deprecated* 28 Nov 2008 in Foswiki; use $Foswiki::cfg{WikiToolName} instead 2824 2609 2825 2610 =cut … … 2827 2612 sub getWikiToolName { return $Foswiki::cfg{WikiToolName}; } 2828 2613 2829 = pod2614 =begin TML 2830 2615 2831 2616 ---+++ getMainWebname( ) -> $name 2832 2617 2833 *D EPRECATED*in Foswiki; use $Foswiki::cfg{UsersWebName} instead2618 *Deprecated* 28 Nov 2008 in Foswiki; use $Foswiki::cfg{UsersWebName} instead 2834 2619 2835 2620 =cut … … 2837 2622 sub getMainWebname { return $Foswiki::cfg{UsersWebName}; } 2838 2623 2839 = pod2624 =begin TML 2840 2625 2841 2626 ---+++ getTwikiWebname( ) -> $name 2842 2627 2843 *D EPRECATED*in Foswiki; use $Foswiki::cfg{SystemWebName} instead2628 *Deprecated* 28 Nov 2008 in Foswiki; use $Foswiki::cfg{SystemWebName} instead 2844 2629 2845 2630 =cut … … 2847 2632 sub getTwikiWebname { return $Foswiki::cfg{SystemWebName}; } 2848 2633 2849 = pod2634 =begin TML 2850 2635 2851 2636 ---+++ getOopsUrl( $web, $topic, $template, $param1, $param2, $param3, $param4 ) -> $url … … 2858 2643 Return: =$url= URL, e.g. ="http://example.com:80/cgi-bin/oops.pl/ Main/WebNotify?template=oopslocked&param1=joe"= 2859 2644 2860 *D EPRECATED* since 1.1, the recommended approach is to throw an oops exception.2645 *Deprecated* 28 Nov 2008, the recommended approach is to throw an oops exception. 2861 2646 <verbatim> 2862 2647 use Error qw( :try ); … … 2879 2664 return 0; 2880 2665 </verbatim> 2881 2882 *Since:* Foswiki::Plugins::VERSION 1.000 (7 Dec 2002)2883 2666 2884 2667 =cut … … 2896 2679 } 2897 2680 2898 =pod 2681 =begin TML 2682 2683 ---+++ wikiToEmail( $wikiName ) -> $email 2684 2685 * =$wikiname= - wiki name of the user 2686 Get the e-mail address(es) of the named user. If the user has multiple 2687 e-mail addresses (for example, the user is a group), then the list will 2688 be comma-separated. 2689 2690 *Deprecated* 28 Nov 2008 in favour of wikinameToEmails, because this function only 2691 returns a single email address, where a user may in fact have several. 2692 2693 $wikiName may also be a login name. 2694 2695 =cut 2696 2697 sub wikiToEmail { 2698 my ($user) = @_; 2699 my @emails = wikinameToEmails($user); 2700 if ( scalar(@emails) ) { 2701 return $emails[0]; 2702 } 2703 return ''; 2704 } 2705 2706 =begin TML 2899 2707 2900 2708 ---+++ permissionsSet( $web ) -> $boolean … … 2904 2712 * =$web= - Web name, required, e.g. ='Sandbox'= 2905 2713 2906 *Since:* Foswiki::Plugins::VERSION 1.000 (27 Feb 2001) 2907 2908 *DEPRECATED* since 1.2 - use =getPreferencesValue= instead to determine 2714 *Deprecated* 28 Nov 2008 - use =getPreferencesValue= instead to determine 2909 2715 what permissions are set on the web, for example: 2910 2716 <verbatim> … … 2936 2742 } 2937 2743 2938 = pod2744 =begin TML 2939 2745 2940 2746 ---+++ getPublicWebList( ) -> @webs 2941 2747 2942 *D EPRECATED* since 1.1- use =getListOfWebs= instead.2748 *Deprecated* 28 Nov 2008 - use =getListOfWebs= instead. 2943 2749 2944 2750 Get list of all public webs, e.g. all webs *and subwebs* that do not have the =NOSEARCHALL= flag set in the WebPreferences … … 2946 2752 Return: =@webs= List of all public webs *and subwebs* 2947 2753 2948 *Since:* Foswiki::Plugins::VERSION 1.000 (07 Dec 2002)2949 2950 2754 =cut 2951 2755 … … 2955 2759 } 2956 2760 2957 =pod 2761 =begin TML 2762 2763 ---+++ formatTime( $time, $format, $timezone ) -> $text 2764 2765 *Deprecated* 28 Nov 2008 - use =Foswiki::Time::formatTime= instead (it has an identical interface). 2766 2767 Format the time in seconds into the desired time string 2768 * =$time= - Time in epoch seconds 2769 * =$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 2770 * =$timezone= - either not defined (uses the displaytime setting), 'gmtime', or 'servertime' 2771 Return: =$text= Formatted time string 2772 | Note: | if you used the removed formatGmTime, add a third parameter 'gmtime' | 2773 2774 =cut 2775 2776 sub formatTime { 2777 2778 # my ( $epSecs, $format, $timezone ) = @_; 2779 require Foswiki::Time; 2780 return Foswiki::Time::formatTime(@_); 2781 } 2782 2783 =begin TML 2958 2784 2959 2785 ---+++ formatGmTime( $time, $format ) -> $text 2960 2786 2961 *D EPRECATED* since 1.1 - use =formatTime= instead.2787 *Deprecated* 28 Nov 2008 - use =Foswiki::Time::formatTime= instead. 2962 2788 2963 2789 Format the time to GM time … … 2966 2792 Return: =$text= Formatted time string 2967 2793 2968 *Since:* Foswiki::Plugins::VERSION 1.000 (7 Dec 2002)2969 2970 2794 =cut 2971 2795 … … 2973 2797 2974 2798 # my ( $epSecs, $format ) = @_; 2975 2976 # FIXME: Write warning based on flag (disabled for now); indicate who is calling this function2977 ## writeWarning( 'deprecated use of Func::formatGmTime' );2978 2979 2799 require Foswiki::Time; 2980 2800 return Foswiki::Time::formatTime( @_, 'gmtime' ); 2981 2801 } 2982 2802 2983 = pod2803 =begin TML 2984 2804 2985 2805 ---+++ getDataDir( ) -> $dir 2986 2806 2987 *D EPRECATED* since 1.1- use the "Webs, Topics and Attachments" functions to manipulate topics instead2807 *Deprecated* 28 Nov 2008 - use the "Webs, Topics and Attachments" functions to manipulate topics instead 2988 2808 2989 2809 =cut … … 2993 2813 } 2994 2814 2995 = pod2815 =begin TML 2996 2816 2997 2817 ---+++ getPubDir( ) -> $dir 2998 2818 2999 *D EPRECATED* since 1.1- use the "Webs, Topics and Attachments" functions to manipulateattachments instead2819 *Deprecated* 28 Nov 2008 - use the "Webs, Topics and Attachments" functions to manipulateattachments instead 3000 2820 3001 2821 =cut
Note: See TracChangeset
for help on using the changeset viewer.
