1)); if (isset($_POST['text']) && $BlocklistActions[$action]) { Blocklist($pagename, $_POST['text']); if (!$EnablePost) { unset($_POST['post']); unset($_POST['postattr']); unset($_POST['postedit']); } } } ## If $EnableBlocklist is set to 10 or higher, then arrange to ## periodically download the "chongqed" and "moinmaster" blacklists. if ($EnableBlocklist >= 10) { SDVA($BlocklistDownload['SiteAdmin.Blocklist-Chongqed'], array( 'url' => 'http://blacklist.chongqed.org/', 'format' => 'regex')); SDVA($BlocklistDownload['SiteAdmin.Blocklist-MoinMaster'], array( 'url' => 'http://moinmaster.wikiwikiweb.de/BadContent?action=raw', 'format' => 'regex')); } ## CheckBlocklist is inserted into $EditFunctions, to automatically ## check for blocks on anything being posted through the normal ## "update a page cycle" array_unshift($EditFunctions, 'CheckBlocklist'); function CheckBlocklist($pagename, &$page, &$new) { StopWatch("CheckBlocklist: begin $pagename"); $ptext = implode('', @$_POST); if (@$ptext) Blocklist($pagename, $ptext); StopWatch("CheckBlocklist: end $pagename"); } ## Blocklist is the function that does all of the work of ## checking for reasons to block a posting. It reads ## the available blocklist pages ($BlocklistPages) and ## builds an array of strings and regular expressiongs to ## be checked against the page; if any are found, then ## posting is blocked (via $EnablePost=0). The function ## also checks the REMOTE_ADDR against any blocked IP addresses. function Blocklist($pagename, $text) { global $BlocklistPages, $BlockedMessagesFmt, $BlocklistDownload, $BlocklistDownloadRefresh, $Now, $EnablePost, $WhyBlockedFmt, $MessagesFmt, $BlocklistMessageFmt, $EnableWhyBlocked, $IsBlocked; StopWatch("Blocklist: begin $pagename"); $BlocklistDownload = (array)@$BlocklistDownload; SDV($BlocklistPages, array_merge(array('$SiteAdminGroup.Blocklist', '$SiteAdminGroup.Blocklist-Farm'), array_keys($BlocklistDownload))); SDV($BlocklistMessageFmt, "

$[This post has been blocked by the administrator]

"); SDVA($BlockedMessagesFmt, array( 'ip' => '$[Address blocked from posting]: ', 'text' => '$[Text blocked from posting]: ')); SDV($BlocklistDownloadRefresh, 86400); ## Loop over all blocklist pages foreach((array)$BlocklistPages as $b) { ## load the current blocklist page $pn = FmtPageName($b, $pagename); $page = ReadPage($pn, READPAGE_CURRENT); if (!$page) continue; ## if the page being checked is a blocklist page, stop blocking if ($pagename == $pn) return; ## If the blocklist page is managed by automatic download, ## schedule any new downloads here if (@$BlocklistDownload[$pn]) { $bd = &$BlocklistDownload[$pn]; SDVA($bd, array( 'refresh' => $BlocklistDownloadRefresh, 'url' => "http://www.pmwiki.org/blocklists/$pn" )); if (!@$page['text'] || $page['time'] < $Now - $bd['refresh']) register_shutdown_function('BlocklistDownload', $pn, getcwd()); } ## If the blocklist is simply a list of regexes to be matched, load ## them into $terms['block'] and continue to the next blocklist page. ## Some regexes from remote sites aren't well-formed, so we have ## to escape any slashes that aren't already escaped. if (strpos($page['text'], 'blocklist-format: regex') !==false) { if (preg_match_all('/^([^\\s#].+)/m', $page['text'], $match)) foreach($match[0] as $m) { $m = preg_replace('#(?$why\n"; } StopWatch("Blocklist: end $pagename"); } ## BlocklistDownload() handles retrieving blocklists from ## external sources into PmWiki pages. If it's able to ## download an updated list, it uses that; otherwise it leaves ## any existing list alone. function BlocklistDownload($pagename, $dir = '') { global $BlocklistDownloadFmt, $BlocklistDownload, $FmtV; if ($dir) { flush(); chdir($dir); } SDV($BlocklistDownloadFmt, " [@ ## blocklist-note: NOTE: This page is automatically generated by blocklist.php ## blocklist-note: NOTE: Any edits to this page may be lost! ## blocklist-url: \$BlocklistDownloadUrl ## blocklist-when: \$CurrentTimeISO # blocklist-format: \$BlocklistFormat \$BlocklistData @] "); ## get the existing blocklist page $bd = &$BlocklistDownload[$pagename]; $page = ReadPage($pagename, READPAGE_CURRENT); ## try to retrieve the remote data $blocklistdata = @file($bd['url']); ## if we didn't get it, and we don't already have text, save a ## note in the page so we know what happened if (!$blocklistdata && !@$page['text']) { $auf = ini_get('allow_url_fopen'); $blocklistdata = "#### Unable to download blocklist (allow_url_fopen=$auf)"; } ## if we have some new text to save, let's format it and save it if ($blocklistdata) { $blocklistdata = implode('', (array)$blocklistdata); $blocklistdata = preg_replace('/^##blocklist.*/m', '', $blocklistdata); $FmtV['$BlocklistData'] = $blocklistdata; $FmtV['$BlocklistDownloadUrl'] = $bd['url']; $FmtV['$BlocklistFormat'] = $bd['format']; $page['text'] = FmtPageName($BlocklistDownloadFmt, $pagename); SDV($page['passwdread'], '@lock'); } ## save our updated(?) blocklist page WritePage($pagename, $page); }