e6d24f74351e08bbb3be9fa2ccd2aeb95c0df340
[atutor.git] / mods / wiki / plugins / edit / limitlinks.php
1 <?php
2 //@FIX: make it an revoverably error, include captcha to allow
3 //      proceeding the save - else this becomes too cumbersome
4 /*
5   This is an anti-spam plugin, which simply disallows adding more than
6   a given number of external links to pages. It will hurt you, if you
7   use your Wiki for creation of a link directory, otherwise it is a
8   good way to fight bored link spammers (because it makes you a less
9   interesting target if they cannot add hundreds of links at once
10   anymore).
11   Raise or lower the allowed number as you see fit (but 15 or 20 is
12   advised as maximum).
13 */
14
15 define("EWIKI_LIMIT_LINKS", 5);
16 $ewiki_plugins["edit_save"][] = "ewiki_edit_save_limit_adding_external_links";
17
18 $ewiki_t["en"]["LINK_ADDING_LIMITED"] = "Sorry, but adding links to this page is restricted to a certain amount. You reached it, and therefore page saving was cancelled.<br><br>If you're a bored link spammer, this is message is for you:<br>*hehe*, *laugh*<br>Happy Death!";
19
20
21 function ewiki_edit_save_limit_adding_external_links(&$save, &$old) {
22    global $ewiki_errmsg;
23
24    #-- count
25    preg_match_all('°(http://[^\s*<>"\'\[\]\#]+)°', $old["content"], $old_urls);
26    preg_match_all('°(http://[^\s*<>"\'\[\]\#]+)°', $save["content"], $save_urls);
27    $added_urls = array_diff($save_urls[1], $old_urls[1]);
28
29    #-- engage trap
30    if (count($added_urls) > EWIKI_LIMIT_LINKS) {
31
32       #-- abort saving with an error message
33       $save = array();
34       $ewiki_errmsg = ewiki_t("LINK_ADDING_LIMITED");
35       return(false);
36    }
37 }
38
39 ?>