PageRenderTime 64ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/mod/wiki/ewiki/ewiki.php

https://bitbucket.org/ceu/moodle_demo
PHP | 3601 lines | 2564 code | 528 blank | 509 comment | 523 complexity | 041bba9355e5008a8f65a120363ffb96 MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.0, LGPL-2.1

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. @define("EWIKI_VERSION", "R1.01d");
  3. /*
  4. ErfurtWiki - an embedable, fast and user-friendly wiki engine
  5. ---------
  6. This is Public Domain (no license, no warranty); but feel free
  7. to redistribute it under GPL or anything else you like.
  8. http://erfurtwiki.sourceforge.net/
  9. Mario Salzer <mario*erphesfurt·de> and many others(tm)
  10. Use it from inside yoursite.php like that:
  11. <html><body>...
  12. <?php
  13. include("ewiki.php");
  14. echo ewiki_page();
  15. ?>
  16. */
  17. #-- you could also establish a mysql connection in here, of course:
  18. // mysql_connect(":/var/run/mysqld/mysqld.sock", "user", "pw")
  19. // and mysql_query("USE mydatabase");
  20. #-------------------------------------------------------- config ---
  21. #-- I'm sorry for that, but all the @ annoy me
  22. error_reporting(0x0000377 & error_reporting());
  23. # error_reporting(E_ALL^E_NOTICE);
  24. #-- the position of your ewiki-wrapper script
  25. define("EWIKI_SCRIPT", "?id="); # relative/absolute to docroot
  26. # define("EWIKI_SCRIPT_URL", "http://...?id="); # absolute URL
  27. #-- change to your needs (site lang)
  28. define("EWIKI_NAME", "ErfurtWiki");
  29. define("EWIKI_PAGE_INDEX", "ErfurtWiki");
  30. define("EWIKI_PAGE_NEWEST", "NewestPages");
  31. define("EWIKI_PAGE_SEARCH", "SearchPages");
  32. define("EWIKI_PAGE_HITS", "MostVisitedPages");
  33. define("EWIKI_PAGE_VERSIONS", "MostOftenChangedPages");
  34. define("EWIKI_PAGE_UPDATES", "UpdatedPages");
  35. #-- default settings are good settings - most often ;)
  36. #- look & feel
  37. define("EWIKI_PRINT_TITLE", 1); # <h2>WikiPageName</h2> on top
  38. define("EWIKI_SPLIT_TITLE", 0); # <h2>Wiki Page Name</h2>
  39. define("EWIKI_CONTROL_LINE", 1); # EditThisPage-link at bottom
  40. define("EWIKI_LIST_LIMIT", 20); # listing limit
  41. #- behaviour
  42. define("EWIKI_AUTO_EDIT", 1); # edit box for non-existent pages
  43. define("EWIKI_EDIT_REDIRECT", 1); # redirect after edit save
  44. define("EWIKI_DEFAULT_ACTION", "view"); # (keep!)
  45. define("EWIKI_CASE_INSENSITIVE", 1); # wikilink case sensitivity
  46. define("EWIKI_HIT_COUNTING", 1);
  47. define("UNIX_MILLENNIUM", 1000000000);
  48. #- rendering
  49. define("EWIKI_ALLOW_HTML", 0); # often a very bad idea
  50. define("EWIKI_HTML_CHARS", 1); # allows for &#200;
  51. define("EWIKI_ESCAPE_AT", 1); # "@" -> "&#x40;"
  52. #- http/urls
  53. define("EWIKI_HTTP_HEADERS", 1); # most often a good thing
  54. define("EWIKI_NO_CACHE", 1); # browser+proxy shall not cache
  55. define("EWIKI_URLENCODE", 1); # disable when _USE_PATH_INFO
  56. define("EWIKI_URLDECODE", 1);
  57. define("EWIKI_USE_PATH_INFO", 1 &&!strstr($_SERVER["SERVER_SOFTWARE"],"Apache"));
  58. define("EWIKI_USE_ACTION_PARAM", 1);
  59. define("EWIKI_ACTION_SEP_CHAR", "/");
  60. define("EWIKI_UP_PAGENUM", "n"); # _UP_ means "url parameter"
  61. define("EWIKI_UP_PAGEEND", "e");
  62. define("EWIKI_UP_BINARY", "binary");
  63. define("EWIKI_UP_UPLOAD", "upload");
  64. #- other stuff
  65. define("EWIKI_DEFAULT_LANG", "en");
  66. define("EWIKI_CHARSET", "UTF-8");
  67. #- user permissions
  68. define("EWIKI_PROTECTED_MODE", 0); # disable funcs + require auth
  69. define("EWIKI_PROTECTED_MODE_HIDING", 0); # hides disallowed actions
  70. define("EWIKI_AUTH_DEFAULT_RING", 3); # 0=root 1=priv 2=user 3=view
  71. define("EWIKI_AUTO_LOGIN", 1); # [auth_query] on startup
  72. #-- allowed WikiPageNameCharacters
  73. #### BEGIN MOODLE CHANGES - to remove auto-camelcase linking.
  74. global $moodle_disable_camel_case;
  75. if ($moodle_disable_camel_case) {
  76. define("EWIKI_CHARS_L", "");
  77. define("EWIKI_CHARS_U", "");
  78. }
  79. else {
  80. #### END MOODLE CHANGES
  81. define("EWIKI_CHARS_L", "a-z_µ¤$\337-\377");
  82. define("EWIKI_CHARS_U", "A-Z0-9\300-\336");
  83. #### BEGIN MOODLE CHANGES
  84. }
  85. #### END MOODLE CHANGES
  86. define("EWIKI_CHARS", EWIKI_CHARS_L.EWIKI_CHARS_U);
  87. #-- database
  88. define("EWIKI_DB_TABLE_NAME", "ewiki"); # MySQL / ADOdb
  89. define("EWIKI_DBFILES_DIRECTORY", "/tmp"); # see "db_flat_files.php"
  90. define("EWIKI_DBA", "/tmp/ewiki.dba"); # see "db_dba.php"
  91. define("EWIKI_DBQUERY_BUFFER", 512*1024); # 512K
  92. define("EWIKI_INIT_PAGES", "./init-pages"); # for initialization
  93. define("EWIKI_DB_F_TEXT", 1<<0);
  94. define("EWIKI_DB_F_BINARY", 1<<1);
  95. define("EWIKI_DB_F_DISABLED", 1<<2);
  96. define("EWIKI_DB_F_HTML", 1<<3);
  97. define("EWIKI_DB_F_READONLY", 1<<4);
  98. define("EWIKI_DB_F_WRITEABLE", 1<<5);
  99. define("EWIKI_DB_F_APPENDONLY", 1<<6); #nyi
  100. define("EWIKI_DB_F_SYSTEM", 1<<7);
  101. define("EWIKI_DB_F_PART", 1<<8);
  102. define("EWIKI_DB_F_TYPE", EWIKI_DB_F_TEXT | EWIKI_DB_F_BINARY | EWIKI_DB_F_DISABLED | EWIKI_DB_F_SYSTEM | EWIKI_DB_F_PART);
  103. define("EWIKI_DB_F_ACCESS", EWIKI_DB_F_READONLY | EWIKI_DB_F_WRITEABLE | EWIKI_DB_F_APPENDONLY);
  104. define("EWIKI_DB_F_COPYMASK", EWIKI_DB_F_TYPE | EWIKI_DB_F_ACCESS);
  105. define("EWIKI_DBFILES_NLR", '\\n');
  106. define("EWIKI_DBFILES_ENCODE", 0 || (DIRECTORY_SEPARATOR != "/"));
  107. define("EWIKI_DBFILES_GZLEVEL", "2");
  108. #-- internal
  109. define("EWIKI_ADDPARAMDELIM", (strstr(EWIKI_SCRIPT,"?") ? "&" : "?"));
  110. #-- binary content (images)
  111. define("EWIKI_SCRIPT_BINARY", /*"/binary.php?binary="*/ ltrim(strtok(" ".EWIKI_SCRIPT,"?"))."?".EWIKI_UP_BINARY."=" );
  112. define("EWIKI_CACHE_IMAGES", 1 &&!headers_sent());
  113. define("EWIKI_IMAGE_MAXSIZE", 64 *1024);
  114. define("EWIKI_IMAGE_MAXWIDTH", 3072);
  115. define("EWIKI_IMAGE_MAXHEIGHT", 2048);
  116. define("EWIKI_IMAGE_MAXALLOC", 1<<19);
  117. define("EWIKI_IMAGE_RESIZE", 1);
  118. define("EWIKI_IMAGE_ACCEPT", "image/jpeg,image/png,image/gif,application/x-shockwave-flash");
  119. define("EWIKI_IDF_INTERNAL", "internal://");
  120. define("EWIKI_ACCEPT_BINARY", 0); # for arbitrary binary data files
  121. #-- misc
  122. define("EWIKI_TMP", $_SERVER["TEMP"] ? $_SERVER["TEMP"] : "/tmp");
  123. define("EWIKI_LOGLEVEL", -1); # 0=error 1=warn 2=info 3=debug
  124. define("EWIKI_LOGFILE", "/tmp/ewiki.log");
  125. #-- plugins (tasks mapped to function names)
  126. $ewiki_plugins["database"][] = "ewiki_database_mysql";
  127. $ewiki_plugins["edit_preview"][] = "ewiki_page_edit_preview";
  128. $ewiki_plugins["render"][] = "ewiki_format";
  129. $ewiki_plugins["init"][-5] = "ewiki_localization";
  130. $ewiki_plugins["init"][-1] = "ewiki_binary";
  131. $ewiki_plugins["handler"][-105] = "ewiki_eventually_initialize";
  132. $ewiki_plugins["handler"][] = "ewiki_intermap_walking";
  133. $ewiki_plugins["view_append"][-1] = "ewiki_control_links";
  134. $ewiki_plugins["view_final"][-1] = "ewiki_add_title";
  135. $ewiki_plugins["page_final"][] = "ewiki_http_headers";
  136. $ewiki_plugins["page_final"][99115115] = "ewiki_page_css_container";
  137. $ewiki_plugins["edit_form_final"][] = "ewiki_page_edit_form_final_imgupload";
  138. $ewiki_plugins["format_block"]["pre"][] = "ewiki_format_pre";
  139. $ewiki_plugins["format_block"]["code"][] = "ewiki_format_pre";
  140. $ewiki_plugins["format_block"]["htm"][] = "ewiki_format_html";
  141. $ewiki_plugins["format_block"]["html"][] = "ewiki_format_html";
  142. $ewiki_plugins["format_block"]["comment"][] = "ewiki_format_comment";
  143. #-- internal pages
  144. $ewiki_plugins["page"][EWIKI_PAGE_NEWEST] = "ewiki_page_newest";
  145. $ewiki_plugins["page"][EWIKI_PAGE_SEARCH] = "ewiki_page_search";
  146. if (EWIKI_HIT_COUNTING) $ewiki_plugins["page"][EWIKI_PAGE_HITS] = "ewiki_page_hits";
  147. $ewiki_plugins["page"][EWIKI_PAGE_VERSIONS] = "ewiki_page_versions";
  148. $ewiki_plugins["page"][EWIKI_PAGE_UPDATES] = "ewiki_page_updates";
  149. #-- page actions
  150. $ewiki_plugins["action"]["edit"] = "ewiki_page_edit";
  151. $ewiki_plugins["action_always"]["links"] = "ewiki_page_links";
  152. $ewiki_plugins["action"]["info"] = "ewiki_page_info";
  153. $ewiki_plugins["action"]["view"] = "ewiki_page_view";
  154. #-- helper vars ---------------------------------------------------
  155. $ewiki_config["idf"]["url"] = array("http://", "mailto:", "internal://", "ftp://", "https://", "irc://", "telnet://", "news://", "chrome://", "file://", "gopher://", "httpz://");
  156. $ewiki_config["idf"]["img"] = array(".jpeg", ".png", ".jpg", ".gif", ".j2k");
  157. $ewiki_config["idf"]["obj"] = array(".swf", ".svg");
  158. #-- entitle actions
  159. $ewiki_config["action_links"]["view"] = @array_merge(array(
  160. "edit" => "EDITTHISPAGE", # ewiki_t() is called on these
  161. "links" => "BACKLINKS",
  162. "info" => "PAGEHISTORY",
  163. "like" => "LIKEPAGES",
  164. ), @$ewiki_config["action_links"]["view"]
  165. );
  166. $ewiki_config["action_links"]["info"] = @array_merge(array(
  167. "view" => "browse",
  168. "edit" => "fetchback",
  169. ), @$ewiki_config["action_links"]["info"]
  170. );
  171. #-- variable configuration settings (go into '$ewiki_config')
  172. $ewiki_config_DEFAULTSTMP = array(
  173. "edit_thank_you" => 1,
  174. "edit_box_size" => "70x15",
  175. "print_title" => EWIKI_PRINT_TITLE,
  176. "split_title" => EWIKI_SPLIT_TITLE,
  177. "control_line" => EWIKI_CONTROL_LINE,
  178. "list_limit" => EWIKI_LIST_LIMIT,
  179. "script" => EWIKI_SCRIPT,
  180. "script_url" => (defined("EWIKI_SCRIPT_URL")?EWIKI_SCRIPT_URL:NULL),
  181. "script_binary" => EWIKI_SCRIPT_BINARY,
  182. #-- heart of the wiki -- don't try to read this! ;)
  183. "wiki_pre_scan_regex" => '/
  184. (?<![~!])
  185. ((?:(?:\w+:)*['.EWIKI_CHARS_U.']+['.EWIKI_CHARS_L.']+){2,}[\w\d]*)
  186. |\^([-'.EWIKI_CHARS_L.EWIKI_CHARS_U.']{3,})
  187. |\[ (?:"[^\]\"]+" | \s+ | [^:\]#]+\|)* ([^\|\"\[\]\#]+) (?:\s+ | "[^\]\"]+")* [\]\#]
  188. |(\w{3,9}:\/\/[^?#\s\[\]\'\"\)\,<]+) /x',
  189. "wiki_link_regex" => "\007 [!~]?(
  190. \#?\[[^<>\[\]\n]+\] |
  191. \^[-".EWIKI_CHARS_U.EWIKI_CHARS_L."]{3,} |
  192. \b([\w]{3,}:)*([".EWIKI_CHARS_U."]+[".EWIKI_CHARS_L."]+){2,}\#?[\w\d]* |
  193. ([a-z]{2,9}://|mailto:)[^\s\[\]\'\"\)\,<]+ |
  194. \w[-_.+\w]+@(\w[-_\w]+[.])+\w{2,} ) \007x",
  195. #-- rendering ruleset
  196. "wm_indent" => '',
  197. "wm_table_defaults" => 'cellpadding="2" border="1" cellspacing="0"',
  198. "wm_whole_line" => array(),
  199. "htmlentities" => array(
  200. "&" => "&amp;",
  201. ">" => "&gt;",
  202. "<" => "&lt;",
  203. ),
  204. "wm_source" => array(
  205. "%%%" => "<br />",
  206. "\t" => " ",
  207. "\n;:" => "\n ", # workaround, replaces the old ;:
  208. ),
  209. "wm_list" => array(
  210. "-" => array('ul type="square"', "", "li"),
  211. "*" => array('ul type="circle"', "", "li"),
  212. "#" => array("ol", "", "li"),
  213. ":" => array("dl", "dt", "dd"),
  214. #<out># ";" => array("dl", "dt", "dd"),
  215. ),
  216. "wm_style" => array(
  217. "'''''" => array("<b><i>", "</i></b>"),
  218. "'''" => array("<b>", "</b>"),
  219. "___" => array("<i><b>", "</b></i>"),
  220. "''" => array("<em>", "</em>"),
  221. "__" => array("<strong>", "</strong>"),
  222. "^^" => array("<sup>", "</sup>"),
  223. "==" => array("<tt>", "</tt>"),
  224. #<off># "***" => array("<b><i>", "</i></b>"),
  225. #<off># "###" => array("<big><b>", "</b></big>"),
  226. "**" => array("<b>", "</b>"),
  227. "##" => array("<big>", "</big>"),
  228. "µµ" => array("<small>", "</small>"),
  229. ),
  230. "wm_start_end" => array(
  231. ),
  232. #-- rendering plugins
  233. "format_block" => array(
  234. "html" => array("&lt;html&gt;", "&lt;/html&gt;", "html", 0x0000),
  235. "htm" => array("&lt;htm&gt;", "&lt;/htm&gt;", "html", 0x0003),
  236. "code" => array("&lt;code&gt;", "&lt;/code&gt;", false, 0x0000),
  237. "pre" => array("&lt;pre&gt;", "&lt;/pre&gt;", false, 0x003F),
  238. "comment" => array("\n&lt;!--", "--&gt;", false, 0x0030),
  239. # "verbatim" => array("&lt;verbatim&gt;", "&lt;/verbatim&gt;", false, 0x0000),
  240. ),
  241. "format_params" => array(
  242. "scan_links" => 1,
  243. "html" => EWIKI_ALLOW_HTML,
  244. "mpi" => 1,
  245. ),
  246. );
  247. foreach ($ewiki_config_DEFAULTSTMP as $set => $val) {
  248. if (!isset($ewiki_config[$set])) {
  249. $ewiki_config[$set] = $val;
  250. }
  251. elseif (is_array($val)) foreach ($val as $vali=>$valv) {
  252. if (is_int($vali)) {
  253. $ewiki_config[$set][] = $valv;
  254. }
  255. elseif (!isset($ewiki_config[$set][$vali])) {
  256. $ewiki_config[$set][$vali] = $valv;
  257. }
  258. }
  259. }
  260. $ewiki_config_DEFAULTSTMP = $valv = $vali = $val = NULL;
  261. #-- init stuff, autostarted parts
  262. ksort($ewiki_plugins["init"]);
  263. if ($pf_a = $ewiki_plugins["init"]) foreach ($pf_a as $pf) {
  264. // Binary Handling starts here
  265. #### MOODLE CHANGE TO BE COMPATIBLE WITH PHP 4.1
  266. #if(headers_sent($file,$line)) {
  267. # error("Headers already sent: $file:$line");
  268. if(headers_sent()) {
  269. error("Headers already sent.");
  270. }
  271. $pf($GLOBALS);
  272. }
  273. unset($ewiki_plugins["init"]);
  274. #-- text (never remove the "C" or "en" sections!)
  275. #
  276. $ewiki_t["C"] = @array_merge(@$ewiki_t["C"], array(
  277. "DATE" => "%a, %d %b %G %T %Z",
  278. "EDIT_TEXTAREA_RESIZE_JS" => '<a href="javascript:ewiki_enlarge()" style="text-decoration:none">+</a><script type="text/javascript"><!--'."\n".'function ewiki_enlarge() {var ta=document.getElementById("ewiki_content");ta.style.width=((ta.cols*=1.1)*10).toString()+"px";ta.style.height=((ta.rows*=1.1)*30).toString()+"px";}'."\n".'//--></script>',
  279. ));
  280. #
  281. $ewiki_t["en"] = @array_merge(@$ewiki_t["en"], array(
  282. "EDITTHISPAGE" => "EditThisPage",
  283. "APPENDTOPAGE" => "Add to",
  284. "BACKLINKS" => "BackLinks",
  285. "PAGESLINKINGTO" => "Pages linking to \$title",
  286. "PAGEHISTORY" => "PageInfo",
  287. "INFOABOUTPAGE" => "Information about page",
  288. "LIKEPAGES" => "Pages like this",
  289. "NEWESTPAGES" => "Newest Pages",
  290. "LASTCHANGED" => "last changed on %c",
  291. "DOESNOTEXIST" => "This page does not yet exist, please click on EditThisPage if you'd like to create it.",
  292. "DISABLEDPAGE" => "This page is currently not available.",
  293. "ERRVERSIONSAVE" => "Sorry, while you edited this page someone else
  294. did already save a changed version. Please go back to the
  295. previous screen and copy your changes to your computers
  296. clipboard to insert it again after you reload the edit
  297. screen.",
  298. "ERRORSAVING" => "An error occoured while saving your changes. Please try again.",
  299. "THANKSFORCONTRIBUTION" => "Thank you for your contribution!",
  300. "CANNOTCHANGEPAGE" => "This page cannot be changed.",
  301. "OLDVERCOMEBACK" => "Make this old version come back to replace the current one",
  302. "PREVIEW" => "Preview",
  303. "SAVE" => "Save",
  304. "CANCEL_EDIT" => "CancelEditing",
  305. "UPLOAD_PICTURE_BUTTON" => "upload picture &gt;&gt;&gt;",
  306. "EDIT_FORM_1" => "<a href=\"".EWIKI_SCRIPT."GoodStyle\">GoodStyle</a> is to
  307. write what comes to your mind. Don't care about how it
  308. looks too much now. You can add <a href=\"".EWIKI_SCRIPT."WikiMarkup\">WikiMarkup</a>
  309. also later if you think it is necessary.<br />",
  310. "EDIT_FORM_2" => "<br />Please do not write things, which may make other
  311. people angry. And please keep in mind that you are not all that
  312. anonymous in the internet (find out more about your computers
  313. '<a href=\"http://google.com/search?q=my+computers+IP+address\">IP address</a>' at Google).",
  314. "BIN_IMGTOOLARGE" => "Image file is too large!",
  315. "BIN_NOIMG" => "This is no image file (inacceptable file format)!",
  316. "FORBIDDEN" => "You are not authorized to access this page.",
  317. ));
  318. #
  319. $ewiki_t["es"] = @array_merge(@$ewiki_t["es"], array(
  320. "EDITTHISPAGE" => "EditarEstaPágina",
  321. "BACKLINKS" => "EnlacesInversos",
  322. "PAGESLINKINGTO" => "Páginas enlazando \$title",
  323. "PAGEHISTORY" => "InfoPágina",
  324. "INFOABOUTPAGE" => "Información sobre la página",
  325. "LIKEPAGES" => "Páginas como esta",
  326. "NEWESTPAGES" => "Páginas más nuevas",
  327. "LASTCHANGED" => "última modificación %d/%m/%Y a las %H:%M",
  328. "DOESNOTEXIST" => "Esta página aún no existe, por favor eliga EditarEstaPágina si desea crearla.",
  329. "DISABLEDPAGE" => "Esta página no está disponible en este momento.",
  330. "ERRVERSIONSAVE" => "Disculpe, mientras editaba esta página alguién más
  331. salvó una versión modificada. Por favor regrese a
  332. a la pantalla anterior y copie sus cambios a su computador
  333. para insertalos nuevamente después de que cargue
  334. la pantalla de edición.",
  335. "ERRORSAVING" => "Ocurrió un error mientras se salvavan sus cambios. Por favor intente de nuevo.",
  336. "THANKSFORCONTRIBUTION" => "Gracias por su contribución!",
  337. "CANNOTCHANGEPAGE" => "Esta página no puede ser modificada.",
  338. "OLDVERCOMEBACK" => "Hacer que esta versión antigua regrese a remplazar la actual",
  339. "PREVIEW" => "Previsualizar",
  340. "SAVE" => "Salvar",
  341. "CANCEL_EDIT" => "CancelarEdición",
  342. "UPLOAD_PICTURE_BUTTON" => "subir gráfica &gt;&gt;&gt;",
  343. "EDIT_FORM_1" => "<a href=\"".EWIKI_SCRIPT."BuenEstilo\">BuenEstilo</a> es
  344. escribir lo que viene a su mente. No se preocupe mucho
  345. por la apariencia. También puede agregar <a href=\"".EWIKI_SCRIPT."ReglasDeMarcadoWiki\">ReglasDeMarcadoWiki</a>
  346. más adelante si piensa que es necesario.<br />",
  347. "EDIT_FORM_2" => "<br />Por favor no escriba cosas, que puedan
  348. enfadar a otras personas. Y por favor tenga en mente que
  349. usted no es del todo anónimo en Internet
  350. (encuentre más sobre
  351. '<a href=\"http://google.com/search?q=my+computers+IP+address\">IP address</a>' de su computador con Google).",
  352. "BIN_IMGTOOLARGE" => "¡La gráfica es demasiado grande!",
  353. "BIN_NOIMG" => "¡No es un archivo con una gráfica (formato de archivo inaceptable)!",
  354. "FORBIDDEN" => "No está autorizado para acceder a esta página.",
  355. ));
  356. #
  357. $ewiki_t["de"] = @array_merge(@$ewiki_t["de"], array(
  358. "EDITTHISPAGE" => "DieseSeiteÄndern",
  359. "APPENDTOPAGE" => "Ergänze",
  360. "BACKLINKS" => "ZurückLinks",
  361. "PAGESLINKINGTO" => "Verweise zur Seite \$title",
  362. "PAGEHISTORY" => "SeitenInfo",
  363. "INFOABOUTPAGE" => "Informationen über Seite",
  364. "LIKEPAGES" => "Ähnliche Seiten",
  365. "NEWESTPAGES" => "Neueste Seiten",
  366. "LASTCHANGED" => "zuletzt geändert am %d.%m.%Y um %H:%M",
  367. "DISABLEDPAGE" => "Diese Seite kann momentan nicht angezeigt werden.",
  368. "ERRVERSIONSAVE" => "Entschuldige, aber während Du an der Seite
  369. gearbeitet hast, hat bereits jemand anders eine geänderte
  370. Fassung gespeichert. Damit nichts verloren geht, browse bitte
  371. zurück und speichere Deine Änderungen in der Zwischenablage
  372. (Bearbeiten->Kopieren) um sie dann wieder an der richtigen
  373. Stelle einzufügen, nachdem du die EditBoxSeite nocheinmal
  374. geladen hast.<br />
  375. Vielen Dank für Deine Mühe.",
  376. "ERRORSAVING" => "Beim Abspeichern ist ein Fehler aufgetreten. Bitte versuche es erneut.",
  377. "THANKSFORCONTRIBUTION" => "Vielen Dank für Deinen Beitrag!",
  378. "CANNOTCHANGEPAGE" => "Diese Seite kann nicht geändert werden.",
  379. "OLDVERCOMEBACK" => "Diese alte Version der Seite wieder zur Aktuellen machen",
  380. "PREVIEW" => "Vorschau",
  381. "SAVE" => "Speichern",
  382. "CANCEL_EDIT" => "ÄnderungenVerwerfen",
  383. "UPLOAD_PICTURE_BUTTON" => "Bild hochladen &gt;&gt;&gt;",
  384. "EDIT_FORM_1" => "<a href=\"".EWIKI_SCRIPT."GuterStil\">GuterStil</a> ist es,
  385. ganz einfach das zu schreiben, was einem gerade in den
  386. Sinn kommt. Du solltest dich jetzt noch nicht so sehr
  387. darum kümmern, wie die Seite aussieht. Du kannst später
  388. immernoch zurückkommen und den Text mit <a href=\"".EWIKI_SCRIPT."FormatierungsRegeln\">WikiTextFormatierungsRegeln</a>
  389. aufputschen.<br />",
  390. "EDIT_FORM_2" => "<br />Bitte schreib keine Dinge, die andere Leute
  391. verärgern könnten. Und bedenke auch, daß es schnell auf
  392. dich zurückfallen kann wenn du verschiedene andere Dinge sagst (mehr Informationen zur
  393. '<a href=\"http://google.de/search?q=computer+IP+adresse\">IP Adresse</a>'
  394. deines Computers findest du bei Google).",
  395. ));
  396. #-- InterWiki:Links
  397. $ewiki_config["interwiki"] = @array_merge(
  398. @$ewiki_config["interwiki"],
  399. array(
  400. "javascript" => "", # this actually protects from javascript: links
  401. "url" => "",
  402. # "self" => "this",
  403. "this" => EWIKI_SCRIPT, # better was absolute _URL to ewiki wrapper
  404. "jump" => ""
  405. ));
  406. // BEGIN MOODLE CHANGES - disable interwiki liks by default
  407. // can be enabled with $CFG->wiki_allow_interwiki = true . MDL-19460
  408. global $CFG;
  409. if (!empty($CFG->wiki_allow_interwiki)) {
  410. $ewiki_config["interwiki"] = @array_merge(
  411. $ewiki_config["interwiki"],
  412. array (
  413. "ErfurtWiki" => "http://erfurtwiki.sourceforge.net/?id=",
  414. "InterWiki" => "InterWikiSearch",
  415. "InterWikiSearch" => "http://sunir.org/apps/meta.pl?",
  416. "Wiki" => "WardsWiki",
  417. "WardsWiki" => "http://www.c2.com/cgi/wiki?",
  418. "WikiFind" => "http://c2.com/cgi/wiki?FindPage&amp;value=",
  419. "WikiPedia" => "http://www.wikipedia.com/wiki.cgi?",
  420. "MeatBall" => "MeatballWiki",
  421. "MeatballWiki" => "http://www.usemod.com/cgi-bin/mb.pl?",
  422. "UseMod" => "http://www.usemod.com/cgi-bin/wiki.pl?",
  423. "PhpWiki" => "http://phpwiki.sourceforge.net/phpwiki/index.php3?",
  424. "LinuxWiki" => "http://linuxwiki.de/",
  425. "OpenWiki" => "http://openwiki.com/?",
  426. "Tavi" => "http://andstuff.org/tavi/",
  427. "TWiki" => "http://twiki.sourceforge.net/cgi-bin/view/",
  428. "MoinMoin" => "http://www.purl.net/wiki/moin/",
  429. "Google" => "http://google.com/search?q=",
  430. "ISBN" => "http://www.amazon.com/exec/obidos/ISBN=",
  431. "icq" => "http://www.icq.com/"
  432. ));
  433. }
  434. // END MOODLE CHANGES
  435. #-------------------------------------------------------------------- main ---
  436. /* this is the main function, which you should preferrably call to
  437. integrate the ewiki into your web site; it chains to most other
  438. parts and plugins (including the edit box);
  439. if you do not supply the requested pages "$id" we will fetch it
  440. from the pre-defined possible URL parameters.
  441. */
  442. function ewiki_page($id=false) {
  443. global $ewiki_links, $ewiki_plugins, $ewiki_ring, $ewiki_t, $ewiki_errmsg;
  444. #-- output var
  445. $o = "";
  446. #-- selected page
  447. if (!isset($_REQUEST)) {
  448. $_REQUEST = @array_merge($_GET, $_POST);
  449. }
  450. if (!strlen($id)) {
  451. $id = ewiki_id();
  452. }
  453. $id = format_string($id,true);
  454. #-- page action
  455. $action = EWIKI_DEFAULT_ACTION;
  456. if ($delim = strpos($id, EWIKI_ACTION_SEP_CHAR)) {
  457. $action = substr($id, 0, $delim);
  458. $id = substr($id, $delim + 1);
  459. }
  460. elseif (EWIKI_USE_ACTION_PARAM && isset($_REQUEST["action"])) {
  461. $action = $_REQUEST["action"];
  462. }
  463. $GLOBALS["ewiki_id"] = $id;
  464. $GLOBALS["ewiki_title"] = ewiki_split_title($id);
  465. $GLOBALS["ewiki_action"] = $action;
  466. #-- fetch from db
  467. $dquery = array(
  468. "id" => $id
  469. );
  470. if (!isset($_REQUEST["content"]) && ($dquery["version"] = @$_REQUEST["version"])) {
  471. $dquery["forced_version"] = $dquery["version"];
  472. }
  473. $data = @array_merge($dquery, ewiki_database("GET", $dquery));
  474. #-- stop here if page is not marked as _TEXT,
  475. # perform authentication then, and let only administrators proceed
  476. if (!empty($data["flags"]) && (($data["flags"] & EWIKI_DB_F_TYPE) != EWIKI_DB_F_TEXT)) {
  477. if (($data["flags"] & EWIKI_DB_F_BINARY) && ($pf = $ewiki_plugins["handler_binary"][0])) {
  478. return($pf($id, $data, $action)); //_BINARY entries handled separately
  479. }
  480. elseif (!EWIKI_PROTECTED_MODE || !ewiki_auth($id, $data, $action, 0, 1) && ($ewiki_ring!=0)) {
  481. return(ewiki_t("DISABLEDPAGE"));
  482. }
  483. }
  484. #-- pre-check if actions exist
  485. $pf_page = ewiki_array($ewiki_plugins["page"], $id);
  486. #-- edit <form> for non-existent pages
  487. if (($action==EWIKI_DEFAULT_ACTION) && empty($data["content"]) && empty($pf_page)) {
  488. if (EWIKI_AUTO_EDIT) {
  489. $action = "edit";
  490. }
  491. else {
  492. $data["content"] = ewiki_t("DOESNOTEXIST");
  493. }
  494. }
  495. #-- more initialization
  496. if ($pf_a = @$ewiki_plugins["page_init"]) {
  497. ksort($pf_a);
  498. foreach ($pf_a as $pf) {
  499. $o .= $pf($id, $data, $action);
  500. }
  501. unset($ewiki_plugins["page_init"]);
  502. }
  503. $pf_page = ewiki_array($ewiki_plugins["page"], $id);
  504. #-- require auth
  505. if (EWIKI_PROTECTED_MODE) {
  506. if (!ewiki_auth($id, $data, $action, $ring=false, $force=EWIKI_AUTO_LOGIN)) {
  507. return($o.=$ewiki_errmsg);
  508. }
  509. }
  510. #-- handlers
  511. $handler_o = "";
  512. if ($pf_a = @$ewiki_plugins["handler"]) {
  513. ksort($pf_a);
  514. foreach ($pf_a as $pf) {
  515. if ($handler_o = $pf($id, $data, $action)) { break; }
  516. } }
  517. #-- finished by handler
  518. if ($handler_o) {
  519. $o .= $handler_o;
  520. }
  521. #-- actions that also work for static and internal pages
  522. elseif (($pf = @$ewiki_plugins["action_always"][$action]) && function_exists($pf)) {
  523. $o .= $pf($id, $data, $action);
  524. }
  525. #-- internal pages
  526. elseif ($pf_page && function_exists($pf_page)) {
  527. $o .= $pf_page($id, $data, $action);
  528. }
  529. #-- page actions
  530. else {
  531. $pf = @$ewiki_plugins["action"][$action];
  532. #-- fallback to "view" action
  533. if (empty($pf) || !function_exists($pf)) {
  534. $pf = "ewiki_page_view";
  535. $action = "view"; // we could also allow different (this is a
  536. // catch-all) view variants, but this would lead to some problems
  537. }
  538. $o .= $pf($id, $data, $action);
  539. }
  540. #-- error instead of page?
  541. if (empty($o) && $ewiki_errmsg) {
  542. $o = $ewiki_errmsg;
  543. }
  544. #-- html post processing
  545. if ($pf_a = $ewiki_plugins["page_final"]) {
  546. ksort($pf_a);
  547. foreach ($pf_a as $pf) {
  548. if ($action == 'edit' and $pf == 'ewiki_html_tag_balancer') {
  549. continue; // balancer breaks htmlarea buttons
  550. }
  551. $pf($o, $id, $data, $action);
  552. }
  553. }
  554. (EWIKI_ESCAPE_AT) && ($o = str_replace("@", "&#x40;", $o));
  555. return($o);
  556. }
  557. #-- HTTP meta headers
  558. function ewiki_http_headers(&$o, $id, &$data, $action) {
  559. global $ewiki_t;
  560. if (EWIKI_HTTP_HEADERS && !headers_sent()) {
  561. if (!empty($data)) {
  562. if ($uu = @$data["id"]) @header('Content-Disposition: inline; filename="' . urlencode($uu) . '.html"');
  563. if ($uu = @$data["version"]) @header('Content-Version: ' . $uu);
  564. if ($uu = @$data["lastmodified"]) @header('Last-Modified: ' . gmstrftime($ewiki_t["C"]["DATE"], $uu));
  565. }
  566. if (EWIKI_NO_CACHE) {
  567. header('Expires: ' . gmstrftime($ewiki_t["C"]["DATE"], UNIX_MILLENNIUM));
  568. header('Pragma: no-cache');
  569. header('Cache-Control: no-cache, private, must-revalidate');
  570. # change to "C-C: cache, must-revalidate" ??
  571. # private only for authenticated users / _PROT_MODE
  572. }
  573. #-- ETag
  574. if ($data["version"] && ($etag=ewiki_etag($data)) || ($etag=md5($o))) {
  575. $weak = "W/" . urlencode($id) . "." . $data["version"];
  576. header("ETag: \"$etag\""); ###, \"$weak\"");
  577. }
  578. }
  579. }
  580. function ewiki_etag(&$data) {
  581. return( urlencode($data["id"]) . ":" . dechex($data["version"]) . ":ewiki:" .
  582. dechex(crc32($data["content"]) & 0x7FFFBFFF) );
  583. }
  584. #-- encloses whole page output with a descriptive <div>
  585. function ewiki_page_css_container(&$o, &$id, &$data, &$action) {
  586. $o = "<div class=\"wiki $action "
  587. . strtr($id, ' ./ --_!"§$%&()=?²³{[]}`+#*;:,<>| @µöäüÖÄÜߤ^°«»\'\\',
  588. '- -----------------------------------------------')
  589. . "\">\n"
  590. . $o . "\n</div>\n";
  591. }
  592. function ewiki_split_title ($id='', $split=EWIKI_SPLIT_TITLE, $entities=1) {
  593. strlen($id) or ($id = $GLOBALS["ewiki_id"]);
  594. if ($split) {
  595. $id = preg_replace("/([".EWIKI_CHARS_L."])([".EWIKI_CHARS_U."]+)/", "$1 $2", $id);
  596. }
  597. return($entities ? s($id) : $id);
  598. }
  599. function ewiki_add_title(&$html, $id, &$data, $action, $go_action="links") {
  600. $html = ewiki_make_title($id, '', 1, $action, $go_action) . $html;
  601. }
  602. function ewiki_make_title($id='', $title='', $class=3, $action="view", $go_action="links", $may_split=1) {
  603. global $ewiki_config, $ewiki_plugins, $ewiki_title, $ewiki_id;
  604. #-- advanced handler
  605. if ($pf = @$ewiki_plugins["make_title"][0]) {
  606. return($pf($title, $class, $action, $go_action, $may_split));
  607. }
  608. #-- disabled
  609. elseif (!$ewiki_config["print_title"]) {
  610. return("");
  611. }
  612. #-- get id
  613. if (empty($id)) {
  614. $id = $ewiki_id;
  615. }
  616. #-- get title
  617. if (!strlen($title)) {
  618. $title = $ewiki_title; // already in &html; format
  619. }
  620. elseif ($ewiki_config["split_title"] && $may_split) {
  621. $title = ewiki_split_title($title, $ewiki_config["split_title"], 0&($title!=$ewiki_title));
  622. }
  623. else {
  624. $title = s($title);
  625. }
  626. #-- title mangling
  627. if ($pf_a = @$ewiki_plugins["title_transform"]) {
  628. foreach ($pf_a as $pf) { $pf($id, $title, $go_action); }
  629. }
  630. #-- clickable link or simple headline
  631. if ($class <= $ewiki_config["print_title"]) {
  632. if ($uu = @$ewiki_config["link_title_action"][$action]) {
  633. $go_action = $uu;
  634. }
  635. if ($uu = @$ewiki_config["link_title_url"]) {
  636. $href = $uu;
  637. unset($ewiki_config["link_title_url"]);
  638. }
  639. else {
  640. $href = ewiki_script($go_action, $id);
  641. }
  642. $o = '<a href="' . $href . '">' . ($title) . '</a>';
  643. }
  644. else {
  645. $o = $title;
  646. }
  647. return('<h2 class="page title">' . $o . '</h2>'."\n");
  648. }
  649. function ewiki_page_view($id, &$data, $action, $all=1) {
  650. global $ewiki_plugins, $ewiki_config;
  651. $o = "";
  652. #-- render requested wiki page <-- goal !!!
  653. $render_args = array(
  654. "scan_links" => 1,
  655. "html" => (EWIKI_ALLOW_HTML||(@$data["flags"]&EWIKI_DB_F_HTML)),
  656. );
  657. $o .= $ewiki_plugins["render"][0] ($data["content"], $render_args);
  658. if (!$all) {
  659. return($o);
  660. }
  661. #### MOODLE CHANGE
  662. /// Add Moodle filters to text porion of wiki.
  663. global $moodle_format; // from wiki/view.php
  664. $o = format_text($o, $moodle_format);
  665. $o.= "<br /><br />";
  666. #-- control line + other per-page info stuff
  667. if ($pf_a = $ewiki_plugins["view_append"]) {
  668. ksort($pf_a);
  669. foreach ($pf_a as $n => $pf) { $o .= $pf($id, $data, $action); }
  670. }
  671. if ($pf_a = $ewiki_plugins["view_final"]) {
  672. ksort($pf_a);
  673. foreach ($pf_a as $n => $pf) { $pf($o, $id, $data, $action); }
  674. }
  675. if (!empty($_REQUEST["thankyou"]) && $ewiki_config["edit_thank_you"]) {
  676. $o = ewiki_t("THANKSFORCONTRIBUTION") . $o;
  677. }
  678. if (EWIKI_HIT_COUNTING) {
  679. ewiki_database("HIT", $data);
  680. }
  681. return($o);
  682. }
  683. #-------------------------------------------------------------------- util ---
  684. /* retrieves "$id/$action" string from URL / QueryString / PathInfo,
  685. change this in conjunction with ewiki_script() to customize your URLs
  686. further whenever desired
  687. */
  688. function ewiki_id() {
  689. ($id = @$_REQUEST["id"]) or
  690. ($id = @$_REQUEST["name"]) or
  691. ($id = @$_REQUEST["page"]) or
  692. ($id = @$_REQUEST["file"]) or
  693. (EWIKI_USE_PATH_INFO) and ($id = ltrim(@$_SERVER["PATH_INFO"], "/")) or
  694. (!isset($_REQUEST["id"])) and ($id = trim(strtok($_SERVER["QUERY_STRING"], "&")));
  695. if (!strlen($id) || ($id=="id=")) {
  696. $id = EWIKI_PAGE_INDEX;
  697. }
  698. (EWIKI_URLDECODE) && ($id = urldecode($id));
  699. return($id);
  700. }
  701. /* replaces EWIKI_SCRIPT, works more sophisticated, and
  702. bypasses various design flaws
  703. - if only the first parameter is used (old style), it can contain
  704. a complete "action/WikiPage" - but this is ambigutious
  705. - else $asid is the action, and $id contains the WikiPageName
  706. - $ewiki_config["script"] will now be used in favour of the constant
  707. - needs more work on _BINARY, should be a separate function
  708. */
  709. ## MOODLE-CHANGE: $asid="", Knows the devil why....
  710. function ewiki_script($asid="", $id=false, $params="", $bin=0, $html=1, $script=NULL) {
  711. global $ewiki_config, $ewiki_plugins;
  712. #-- get base script url from config vars
  713. if (empty($script)) {
  714. $script = &$ewiki_config[!$bin?"script":"script_binary"];
  715. }
  716. #-- separate $action and $id for old style requests
  717. if ($id === false) {
  718. if (strpos($asid, EWIKI_ACTION_SEP_CHAR) !== false) {
  719. $asid = strtok($asid, EWIKI_ACTION_SEP_CHAR);
  720. $id = strtok("\000");
  721. }
  722. else {
  723. $id = $asid;
  724. $asid = "";
  725. }
  726. }
  727. #-- prepare params
  728. if (is_array($params)) {
  729. $uu = $params;
  730. $params = "";
  731. if ($uu) foreach ($uu as $k=>$v) {
  732. $params .= (strlen($params)?"&":"") . rawurlencode($k) . "=" . rawurlencode($v);
  733. }
  734. }
  735. #-- action= parameter
  736. if (EWIKI_USE_ACTION_PARAM >= 2) {
  737. $params = "action=$asid" . (strlen($params)?"&":"") . $params;
  738. $asid = "";
  739. }
  740. #-- workaround slashes in $id
  741. if (empty($asid) && (strpos($id, EWIKI_ACTION_SEP_CHAR) !== false) && !$bin) {
  742. $asid = "view";
  743. }
  744. /*paranoia*/ $asid = trim($asid, EWIKI_ACTION_SEP_CHAR);
  745. #-- make url
  746. if (EWIKI_URLENCODE) {
  747. $id = urlencode($id);
  748. $asid = urlencode($asid);
  749. }
  750. else {
  751. # only urlencode &, %, ? for example
  752. }
  753. $url = $script;
  754. if ($asid) {
  755. $id = $asid . EWIKI_ACTION_SEP_CHAR . $id; #= "action/PageName"
  756. }
  757. if (strpos($url, "%s") !== false) {
  758. $url = str_replace("%s", $id, $url);
  759. }
  760. else {
  761. $url .= $id;
  762. }
  763. #-- add url params
  764. if (strlen($params)) {
  765. $url .= (strpos($url,"?")!==false ? "&":"?") . $params;
  766. }
  767. #-- fin
  768. if ($html) {
  769. //Don't replace & if it's part of encoded character (bug 2209)
  770. $url = preg_replace("/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,5};)/","&amp;", $url);
  771. } else {
  772. //This is going to be used in some header or meta redirect, so It cannot use &amp; (bug 2620)
  773. $url = preg_replace('/&amp;/', '&', $url);
  774. }
  775. return($url);
  776. }
  777. /* this ewiki_script() wrapper is used to generate URLs to binary
  778. content in the ewiki database
  779. */
  780. function ewiki_script_binary($asid, $id=false, $params=array(), $upload=0) {
  781. $upload |= is_string($params) && strlen($params) || count($params);
  782. #-- generate URL directly to the plainly saved data file,
  783. # see also plugins/binary_store
  784. if (defined("EWIKI_DB_STORE_URL") && !$upload) {
  785. $url = EWIKI_DB_STORE_URL . rawurlencode($id);
  786. }
  787. #-- else get standard URL (thru ewiki.php) from ewiki_script()
  788. else {
  789. $url = ewiki_script($asid, $id, $params, "_BINARY=1");
  790. }
  791. return($url);
  792. }
  793. /* this function returns the absolute ewiki_script url, if EWIKI_SCRIPT_URL
  794. is set, else it guesses the value
  795. */
  796. function ewiki_script_url() {
  797. global $ewiki_action, $ewiki_id, $ewiki_config;
  798. $scr_template = $ewiki_config["script"];
  799. $scr_current = ewiki_script($ewiki_action, $ewiki_id);
  800. $req_uri = $_SERVER["REQUEST_URI"];
  801. if ($url = $ewiki_config["script_url"]) {
  802. return($url);
  803. }
  804. elseif (strpos($req_uri, $scr_current) !== false) {
  805. $url = str_replace($req_uri, $scr_current, $scr_template);
  806. }
  807. elseif (strpos($req_uri, "?") && (strpos($scr_template, "?") !== false)) {
  808. $url = substr($req_uri, 0, strpos($req_uri, "?"))
  809. . substr($scr_template, strpos($scr_template, "?"));
  810. }
  811. elseif (strpos($req_uri, $sn = $_SERVER["SCRIPT_NAME"])) {
  812. $url = $sn . "?id=";
  813. }
  814. else {
  815. return(NULL); #-- could not guess it
  816. }
  817. #$url = "http://" . $_SERVER["SERVER_NAME"] . $url;
  818. return($url);
  819. }
  820. #------------------------------------------------------------ page plugins ---
  821. function ewiki_page_links($id, &$data, $action) {
  822. $o = ewiki_make_title($id, ewiki_t("PAGESLINKINGTO", array("title"=>$id)), 1, $action, "", "_MAY_SPLIT=1");
  823. if ($pages = ewiki_get_backlinks($id)) {
  824. $o .= ewiki_list_pages($pages);
  825. } else {
  826. $o .= ewiki_t("This page isn't linked from anywhere else.");
  827. }
  828. return($o);
  829. }
  830. function ewiki_get_backlinks($id) {
  831. $result = ewiki_database("SEARCH", array("refs" => $id));
  832. $pages = array();
  833. while ($row = $result->get(0, 0x0020)) {
  834. if ( strpos($row["refs"], "\n$id\n") !== false) {
  835. $pages[] = $row["id"];
  836. }
  837. }
  838. return($pages);
  839. }
  840. function ewiki_get_links($id) {
  841. if ($data = ewiki_database("GET", array("id"=>$id))) {
  842. $refs = explode("\n", trim($data["refs"]));
  843. $r = array();
  844. foreach (ewiki_database("FIND", $refs) as $id=>$exists) {
  845. if ($exists) {
  846. $r[] = $id;
  847. }
  848. }
  849. return($r);
  850. }
  851. }
  852. function ewiki_list_pages($pages=array(), $limit=EWIKI_LIST_LIMIT,
  853. $value_as_title=0, $pf_list=false)
  854. {
  855. global $ewiki_plugins;
  856. $o = "";
  857. $is_num = !empty($pages[0]);
  858. $lines = array();
  859. $n = 0;
  860. foreach ($pages as $id=>$add_text) {
  861. $title = $id;
  862. $params = "";
  863. if (is_array($add_text)) {
  864. list($id, $params, $title, $add_text) = $add_text;
  865. }
  866. elseif ($is_num) {
  867. $id = $title = $add_text;
  868. $add_text = "";
  869. }
  870. elseif ($value_as_title) {
  871. $title = $add_text;
  872. $add_text = "";
  873. }
  874. $lines[] = '<a href="' . ewiki_script("", $id, $params) . '">' . s($title) . '</a> ' . $add_text;
  875. if (($limit > 0) && ($n++ >= $limit)) {
  876. break;
  877. }
  878. }
  879. if ($pf_a = @$ewiki_plugins["list_transform"])
  880. foreach ($pf_a as $pf_transform) {
  881. $pf_transform($lines);
  882. }
  883. if (($pf_list) || ($pf_list = @$ewiki_plugins["list_pages"][0])) {
  884. $o = $pf_list($lines);
  885. }
  886. elseif($lines) {
  887. $o = "&middot; " . implode("<br />\n&middot; ", $lines) . "<br />\n";
  888. }
  889. return($o);
  890. }
  891. function ewiki_page_ordered_list($orderby="created", $asc=0, $print, $title) {
  892. $o = ewiki_make_title("", $title, 2, ".list", "links", 0);
  893. $sorted = array();
  894. $result = ewiki_database("GETALL", array($orderby));
  895. while ($row = $result->get()) {
  896. $row = ewiki_database("GET", array(
  897. "id" => $row["id"],
  898. ($asc >= 0 ? "version" : "uu") => 1 // version 1 is most accurate for {hits}
  899. ));
  900. #-- text page?
  901. if (EWIKI_DB_F_TEXT == ($row["flags"] & EWIKI_DB_F_TYPE)) {
  902. #-- viewing allowed?
  903. if (!EWIKI_PROTECTED_MODE || !EWIKI_PROTECTED_MODE_HIDING || ewiki_auth($row["id"], $row, "view")) {
  904. $sorted[$row["id"]] = $row[$orderby];
  905. }
  906. }
  907. }
  908. if ($asc != 0) { arsort($sorted); }
  909. else { asort($sorted); }
  910. foreach ($sorted as $name => $value) {
  911. if (empty($value)) { $value = "0"; }
  912. ##### BEGIN MOODLE ADDITION #####
  913. #$sorted[$name] = strftime(str_replace('%n', $value, $print), $value);
  914. if($print=="LASTCHANGED") {
  915. $value=strftime("%c",$value);
  916. }
  917. $sorted[$name] = get_string(strtolower($print),"wiki",$value);
  918. ##### BEGIN MOODLE ADDITION #####
  919. }
  920. $o .= ewiki_list_pages($sorted);
  921. return($o);
  922. }
  923. function ewiki_page_newest($id=0, $data=0) {
  924. return( ewiki_page_ordered_list("created", 1, "LASTCHANGED", ewiki_t(EWIKI_PAGE_NEWEST)) );
  925. }
  926. function ewiki_page_updates($id=0, $data=0) {
  927. return( ewiki_page_ordered_list("lastmodified", -1, "LASTCHANGED", ewiki_t(EWIKI_PAGE_UPDATES)) );
  928. }
  929. function ewiki_page_hits($id=0, $data=0) {
  930. ##### BEGIN MOODLE ADDITION #####
  931. return( ewiki_page_ordered_list("hits", 1, "hits", ewiki_t(EWIKI_PAGE_HITS)) );
  932. }
  933. function ewiki_page_versions($id=0, $data=0) {
  934. return( ewiki_page_ordered_list("version", -1, "changes", ewiki_t(EWIKI_PAGE_VERSIONS)) );
  935. ##### END MOODLE ADDITION #####
  936. }
  937. function ewiki_page_search($id, &$data, $action) {
  938. global $CFG;
  939. $o = ewiki_make_title($id, $id, 2, $action);
  940. if (! ($q = @$_REQUEST["q"])) {
  941. $o .= '<form action="' . ewiki_script("", $id) . '" method="post">';
  942. $o .= '<fieldset class="invisiblefieldset">';
  943. $o .= '<input name="q" size="30" /><br /><br />';
  944. $o .= '<input type="submit" value="'.$id.'" />';
  945. $o .= '</fieldset>';
  946. $o .= '</form>';
  947. }
  948. else {
  949. $found = array();
  950. if ($CFG->unicodedb) {
  951. $q = preg_replace('/\s*[\W]+\s*/u', ' ', $q);
  952. } else {
  953. $q = preg_replace('/\s*[^\w]+\s*/', ' ', $q);
  954. }
  955. foreach (explode(" ", $q) as $search) {
  956. if (empty($search)) { continue; }
  957. $result = ewiki_database("SEARCH", array("content" => $search));
  958. while ($row = $result->get()) {
  959. #-- show this entry in page listings?
  960. if (EWIKI_PROTECTED_MODE && EWIKI_PROTECTED_MODE_HIDING && !ewiki_auth($row["id"], $row, "view")) {
  961. continue;
  962. }
  963. $found[] = $row["id"];
  964. }
  965. }
  966. $o .= ewiki_list_pages($found);
  967. }
  968. return($o);
  969. }
  970. function ewiki_page_info($id, &$data, $action) {
  971. global $ewiki_plugins, $ewiki_config, $ewiki_links;
  972. global $CFG, $course; // MOODLE HACK
  973. $o = ewiki_make_title($id, ewiki_t("INFOABOUTPAGE")." '{$id}'", 2, $action,"", "_MAY_SPLIT=1");
  974. $flagnames = array(
  975. "TEXT", "BIN", "DISABLED", "HTML", "READONLY", "WRITEABLE",
  976. "APPENDONLY", "SYSTEM",
  977. );
  978. $show = array(
  979. "version", "author", "userid", "created",
  980. "lastmodified", "refs",
  981. "flags", "meta", "content"
  982. );
  983. #-- versions to show
  984. $v_start = $data["version"];
  985. if ( ($uu=@$_REQUEST[EWIKI_UP_PAGENUM]) && ($uu<=$v_start) ) {
  986. $v_start = $uu;
  987. }
  988. $v_end = $v_start - $ewiki_config["list_limit"] + 1;
  989. if ( ($uu=@$_REQUEST[EWIKI_UP_PAGEEND]) && ($uu<=$v_start) ) {
  990. $v_end = $uu;
  991. }
  992. $v_end = max($v_end, 1);
  993. #-- go
  994. # the very ($first) entry is rendered more verbosely than the others
  995. for ($v=$v_start,$first=1; ($v>=$v_end); $v--,$first=0) {
  996. $current = ewiki_database("GET", array("id"=>$id, "version"=>$v));
  997. if (!strlen(trim($current["id"])) || !$current["version"] || !strlen(trim($current["content"]))) {
  998. continue;
  999. }
  1000. $o .= '<table class="version-info" cellpadding="2" cellspacing="1">' . "\n";
  1001. #-- additional info-actions
  1002. $commands = '';
  1003. foreach ($ewiki_config["action_links"]["info"] as $thisaction=>$title)
  1004. if (@$ewiki_plugins["action"][$thisaction] || @$ewiki_plugins["action_always"][$thisaction]) {
  1005. ##### BEGIN MOODLE ADDITION #####
  1006. if ($commands) {
  1007. $commands .= '&nbsp;&nbsp;';
  1008. }
  1009. $commands .= '<a href="' .
  1010. ewiki_script($thisaction, $id, array("version"=>$current["version"])) .
  1011. '">' . get_string($title,"wiki") . '</a>';
  1012. ##### END MOODLE ADDITION #####
  1013. }
  1014. #-- print page database entry
  1015. foreach($show as $i) {
  1016. $value = @$current[$i];
  1017. #-- show database {fields} differently
  1018. if ($i == "meta") {
  1019. continue; // MOODLE DOESN'T USE IT
  1020. $str = "";
  1021. if ($first && $value) { foreach ($value as $n=>$d) {
  1022. $str .= s("$n: $d") . "<br />\n";
  1023. } }
  1024. $value = $str;
  1025. }
  1026. elseif ($value >= UNIX_MILLENNIUM) { #-- {lastmodified}, {created}
  1027. #### BEGIN MOODLE CHANGE
  1028. $value=userdate($value);
  1029. #$value = strftime("%c", $value);
  1030. #### END MOODLE CHANGE
  1031. }
  1032. elseif ($i == "content") {
  1033. continue; // MOODLE DOESN'T CARE
  1034. $value = strlen(trim($value)) . " bytes";
  1035. $i = "content size";
  1036. }
  1037. elseif ($first && ($i == "refs") && !(EWIKI_PROTECTED_MODE && (EWIKI_PROTECTED_MODE_HIDING>=2))) {
  1038. $a = explode("\n", trim($value));
  1039. $ewiki_links = ewiki_database("FIND", $a);
  1040. ewiki_merge_links($ewiki_links);
  1041. foreach ($a as $n=>$link) {
  1042. $a[$n] = ewiki_link_regex_callback(array("$link"), "force_noimg");
  1043. }
  1044. $value = trim(implode(", ", $a));
  1045. if (!$value) {
  1046. continue;
  1047. }
  1048. }
  1049. elseif (strpos($value, "\n") !== false) { #-- also for {refs}
  1050. $value = str_replace("\n", ", ", trim($value));
  1051. if (!$value) {
  1052. continue;
  1053. }
  1054. }
  1055. elseif ($i == "version") {
  1056. $value = '<a href="' .
  1057. ewiki_script("", $id, array("version"=>$value)) . '">' .
  1058. $value . '</a> '."($commands)";
  1059. }
  1060. elseif ($i == "flags") {
  1061. continue; // MOODLE DOESN'T USE IT
  1062. $fstr = "";
  1063. for ($n = 0; $n < 32; $n++) {
  1064. if ($value & (1 << $n)) {
  1065. if (! ($s=$flagnames[$n])) { $s = "UU$n"; }
  1066. $fstr .= $s . " ";
  1067. }
  1068. }
  1069. $value = $fstr;
  1070. }
  1071. elseif ($i == "author") {
  1072. continue;
  1073. $ewiki_links=1;
  1074. $value = preg_replace_callback("/((\w+:)?([".EWIKI_CHARS_U."]+[".EWIKI_CHARS_L."]+){2,}[\w\d]*)/", "ewiki_link_regex_callback", $value);
  1075. }
  1076. elseif ($i == "userid") {
  1077. $i = 'author';
  1078. if ($user = get_record('user', 'id', (int)$value)) {
  1079. if (!isset($course->id)) {
  1080. $course->id = 1;
  1081. }
  1082. $picture = print_user_picture($user->id, $course->id, $user->picture, false, true, true);
  1083. $value = $picture." <a href=\"$CFG->wwwroot/user/view.php?id=$user->id&amp;course=$course->id\">".fullname($user)."</a>";
  1084. } else {
  1085. continue;
  1086. //$value = @$current['author'];
  1087. }
  1088. }
  1089. ##### BEGIN MOODLE ADDITION #####
  1090. $o .= '<tr class="page-'.$i.'"><td style="vertical-align:top;text-align:right;white-space: nowrap;"><b>' .ewiki_t($i). ':</b></td>' .
  1091. '<td>' . $value . "</td></tr>\n";
  1092. ##### END MOODLE ADDITION #####
  1093. }
  1094. $o .= "</table><br /><br />\n";
  1095. }
  1096. #-- page result split
  1097. if ($v >= 1) {
  1098. $o .= "<br />\n".get_string('showversions','wiki').' '.ewiki_chunked_page($action, $id, -1, $v, 1, 0, 0) . "\n <br />";
  1099. }
  1100. return($o);
  1101. }
  1102. function ewiki_chunked_page($action, $id, $dir=-1, $start=10, $end=1, $limit=0, $overlap=0.25, $collapse_last=0.67) {
  1103. global $ewiki_config;
  1104. if (empty($limit)) {
  1105. $limit = $ewiki_config["list_limit"];
  1106. }
  1107. if ($overlap < 1) {
  1108. $overlap = (int) ($limit * $overlap);
  1109. }
  1110. $p = "";
  1111. $n = $start;
  1112. while ($n) {
  1113. $n -= $dir * $overlap;
  1114. $e = $n + $dir * ($limit + $overlap) + 1;
  1115. if ($dir<0) {
  1116. $e = max(1, $e);
  1117. if ($e <= $collapse_last * $limit) {
  1118. $e = 1;
  1119. }
  1120. }
  1121. else {
  1122. $e = min($end, $e);
  1123. if ($e >= $collapse_last * $limit) {
  1124. $e = $end;
  1125. }
  1126. }
  1127. $o .= ($o?" &middot; ":"")
  1128. . '<a href="'.ewiki_script($action, $id, array(EWIKI_UP_PAGENUM=>$n, EWIKI_UP_PAGEEND=>$e))
  1129. . '">'. "$n-$e" . '</a>';
  1130. if (($n=$e-1) < $end) {
  1131. $n = false;
  1132. }
  1133. }
  1134. return('<span class="chunked-result">'. $o .'</span>');
  1135. }
  1136. function ewiki_page_edit($id, $data, $action) {
  1137. global $ewiki_links, $ewiki_author, $ewiki_plugins, $ewiki_ring, $ewiki_errmsg;
  1138. $hidden_postdata = array();
  1139. #-- previous version come back
  1140. if (@$data["forced_version"]) {
  1141. $current = ewiki_database("GET", array("id"=>$id));
  1142. $data["version"] = $current["version"];
  1143. unset($current);
  1144. unset($_REQUEST["content"]);
  1145. unset($_REQUEST["version"]);
  1146. }
  1147. #-- edit hacks
  1148. if ($pf_a = @$ewiki_plugins["edit_hook"]) foreach ($pf_a as $pf) {
  1149. if ($output = $pf($id, $data, $hidden_postdata)) {
  1150. return($output);
  1151. }
  1152. }
  1153. #-- permission checks
  1154. if (isset($ewiki_ring)) {

Large files files are truncated, but you can click here to view the full file