962dbdfc33e687525b02463689817d21b9829003
[atutor.git] / mods / wiki / plugins / pluginloader.php
1 <?php
2 /*
3    dynamic plugin loading
4    ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
5    Will load plugins on demand, so they must not be included() one by one
6    together with the core script. This is what commonly the "plugin idea"
7    suggests, and only has minimal disadvantages.
8    - This loader currently only handles "page" and "action" plugins,
9      many other extensions must be activated as before (the other ones
10      are real functionality enhancements and behaviour tweaks, so this
11      approach really made no sense for them).
12    - There is no security risk with this plugin loader extension, because
13      it allows you to set which of the available plugins CAN be loaded
14      on demand (all others must/can be included() as usual elsewhere).
15    - This however requires administration of this plugins` configuration
16      array, but that is not much more effort than maintaining a bunch of
17      include() statements.
18    - Is a small degree faster then including multiple plugin script files
19      one by one. Alternatively you could also merge (cat, mkhuge) all
20      wanted plugins into one script file so you get a speed improvement
21      against multiple include() calls.
22    - Use tools/mkpluginmap to create the initial plugin list.
23    
24    NOTE: not yet updated to take advantage of new plugin *.meta files
25    and cache.
26 */
27
28
29 global $ewiki_plugins;
30 $ewiki_plugins["dl"]["action"] = array(
31         "view" => array("", "", 0),
32         "links" => array("", "", 0),
33         "info" => array("", "", 0),
34 #       "edit" => array("spellcheck.php", "", 0),
35         "raw" => array("action/raw.php", "ewiki_action_raw", 0),
36         "diff" => array("action/diff.php", "ewiki_page_stupid_diff", 0),
37 #       "diff" => array("action/diff_gnu.php", "ewiki_page_gnu_diff", 0),
38         "like" => array("action/like_pages.php", "ewiki_page_like", 0),
39 #       "verdiff" => array("action/verdiff.php", "ewiki_action_verdiff", 0),
40 #       "extodo" => array("action/extract.php", "ewiki_extract", 0),
41 #       "control" => array("admin/control.php", "ewiki_action_control_page", 0),
42 #       "imageappend" => array("aview/imgappend.php", "ewiki_action_image_append", 0),
43 #       "addpost" => array("aview/posts.php", "ewiki_add_post", 0),
44 #       "addthread" => array("aview/threads.php", "ewiki_add_thread", 0),
45 #       "updformatheader" => array("markup/update_format.php", "ewiki_header_format_swap", 0),
46 #       "calendar" => array("module/calendar.php", "ewiki_page_calendar", 0),
47 #       "binary" => array("module/downloads.php", "ewiki_binary", 0),
48 #       "attachments" => array("module/downloads.php", "ewiki_action_attachments", 0),
49 #       "tour" => array("module/tour.php", "ewiki_tour", 0),
50         "search" => array("page/powersearch.php", "ewiki_action_powersearch", 0),
51 );
52
53 $ewiki_plugins["dl"]["page"] = array(
54 #       "SearchAndReplace" => array("admin/page_searchandreplace.php", "ewiki_page_searchandreplace", 0),
55 #       "SearchCache" => array("admin/page_searchcache.php", "ewiki_cache_generated_pages", 0),
56 #       "ImageGallery" => array("aview/aedit_pageimage.php", "ewiki_page_image_gallery", 0),
57 #       "MainGallery" => array("aview/aedit_pageimage.php", "ewiki_page_image_gallery", 0),
58         "LinkDatabase" => array("linking/linkdatabase.php", "ewiki_linkdatabase", 0),
59 #       "PageCalendar" => array("module/calendar.php", "ewiki_page_calendar", 0),
60 #       "PageYearCalendar" => array("module/calendar.php", "ewiki_page_year_calendar", 0),
61 #       "FileUpload" => array("module/downloads.php", "ewiki_page_fileupload", 0),
62 #       "FileDownload" => array("module/downloads.php", "ewiki_page_filedownload", 0),
63         "README" => array("page/README.php", "ewiki_page_README", 0),
64 #       "README.de" => array("page/README.php", "ewiki_page_README", 0),
65 #       "plugins/auth/README.auth" => array("page/README.php", "ewiki_page_README", 0),
66 #       "AboutPlugins" => array("page/aboutplugins.php", "ewiki_page_aboutplugins", 0),
67 #       "EWikiLog" => array("page/ewikilog.php", "ewiki_page_ewikilog", 0),
68 #       "Fortune" => array("page/fortune.php", "ewiki_page_fortune", 0),
69         "HitCounter" => array("page/hitcounter.php", "ewiki_page_hitcounter", 0),
70         "InterWikiMap" => array("page/interwikimap.php", "ewiki_page_interwikimap", 0),
71         "OrphanedPages" => array("page/orphanedpages.php", "ewiki_page_orphanedpages", 0),
72 #       "PageIndex" => array("page/pageindex.php", "ewiki_page_index", 0),
73 #       "PhpInfo" => array("page/phpinfo.php", "ewiki_page_phpinfo", 0),
74         "PowerSearch" => array("page/powersearch.php", "ewiki_page_powersearch", 0),
75         "RandomPage" => array("page/randompage.php", "ewiki_page_random", 0),
76 #       "ScanDisk" => array("page/scandisk.php", "ewiki_page_scandisk", 0),
77 #       "SinceUpdatedPages" => array("page/since_updates.php", "ewiki_page_since_updates", 0),
78 #       "TextUpload" => array("page/textupload.php", "ewiki_page_textupload", 0),
79         "WantedPages" => array("page/wantedpages.php", "ewiki_page_wantedpages", 0),
80 #       "WikiDump" => array("page/wikidump.php", "ewiki_page_wiki_dump_tarball", 0),
81 #       "WikiNews" => array("page/wikinews.php", "ewiki_page_wikinews", 0),
82 #       "WikiUserLogin" => array("page/wikiuserlogin.php", "ewiki_page_wikiuserlogin", 0),
83         "WordIndex" => array("page/wordindex.php", "ewiki_page_wordindex", 0),
84 #       "AddNewPage" => array("page/addnewpage.php", "ewiki_addpage", 0),
85 #       "CreatePage" => array("page/addnewpage.php", "ewiki_addpage", 0),
86 #       "EineSeiteHinzufügen" => array("page/addnewpage.php", "ewiki_addpage", 0),
87 #       "CreateNewPage" => array("page/createnewpage.php", "ewiki_createpage", 0),
88         "RecentChanges" => array("page/recentchanges.php", "ewiki_page_recentchanges", 0),
89 #       "ExAllTodo" => array("page/extractall.php", "ewiki_page_exall", 0),
90 );
91
92 global $ewiki_config;
93 $ewiki_config["dl"]["action_links"]["view"]["raw"] = "raw";
94 $ewiki_config["dl"]["action_links"]["view"]["verdiff"] = "verdiff";
95 $ewiki_config["dl"]["action_links"]["view"]["extodo"] = "EXTTODO";
96 $ewiki_config["dl"]["action_links"]["view"]["control"] = "page control";
97 $ewiki_config["dl"]["action_links"]["view"]["addpost"] = "Add a post";
98 $ewiki_config["dl"]["action_links"]["view"]["updformatheader"] = "UPDHEADERFORMAT";
99 $ewiki_config["dl"]["action_links"]["view"]["calendar"] = "PageCalendar";
100 $ewiki_config["dl"]["action_links"]["view"]["attachments"] = "Attachments";
101 $ewiki_config["dl"]["action_links"]["view"]["tour"] = "PageTour";
102 $ewiki_config["dl"]["action_links"]["view"]["pdf"] = "pdf";
103 $ewiki_config["dl"]["action_links"]["info"]["raw"] = "raw";
104 $ewiki_config["dl"]["action_links"]["info"]["diff"] = "diff";
105 $ewiki_config["dl"]["action_links"]["extodo"]["raw"] = "raw";
106 $ewiki_config["dl"]["action_links"]["extodo"]["verdiff"] = "verdiff";
107 $ewiki_config["dl"]["action_links"]["extodo"]["view"] = "VIEWCOMPL";
108 $ewiki_config["dl"]["action_links"]["tour"]["view"] = "ViewFullPage";
109 $ewiki_config["dl"]["action_links"]["tour"]["links"] = "BACKLINKS";
110 $ewiki_config["dl"]["action_links"]["tour"]["info"] = "PAGEHISTORY";
111
112
113
114
115
116 ##############################################################################
117
118
119
120 #-- plugin glue
121 $ewiki_plugins["view_init"][] = "ewiki_dynamic_plugin_loader";
122
123
124 function ewiki_dynamic_plugin_loader(&$id, &$data, &$action) {
125
126    global $ewiki_plugins, $ewiki_id, $ewiki_title, $ewiki_t,
127           $ewiki_ring, $ewiki_author, $ewiki_config, $ewiki_auth_user,
128           $ewiki_action;
129
130    #-- check for entry
131    if (empty($ewiki_plugins["page"][$id])) {
132       $load = $ewiki_plugins["dl"]["page"][$id];
133    }
134    elseif (empty($ewiki_plugins["action"][$action])) {
135       $load = $ewiki_plugins["dl"]["action"][$action];
136    }
137
138    #-- load plugin
139    if ($load) {
140       if (!is_array($load)) {
141          $load = array($load, "");
142       }
143       if (!($pf=$load[1]) || !function_exists($pf)) {
144          include_once(dirname(__FILE__)."/".$load[0]);
145       }
146    }
147
148    #-- fake static pages
149    foreach ($ewiki_plugins["dl"]["page"] as $name) {
150       if (empty($ewiki_plugins["page"][$name])) {
151          $ewiki_plugins["page"][$name] = "ewiki_dynamic_plugin_loader";
152       }
153    }
154
155    #-- show action links
156    foreach ($ewiki_plugins["dl"]["action"] as $action=>$uu) {
157       foreach ($ewiki_config["dl"]["action_links"] as $where) {
158          if ($title = $ewiki_config["dl"]["action_links"][$where][$action]) {
159             $ewiki_config["action_links"][$where][$action] = $title;
160          }
161       }
162    }
163
164    return(NULL);
165 }
166
167
168 ?>