/** * Hook function for EditFilter * Confirm that a local blacklist page being saved is valid, * and toss back a warning to the user if it isn't. * * @param $editPage EditPage * @param $text string * @param $section string * @param $hookError string * @return bool */ static function validate( $editPage, $text, $section, &$hookError ) { $thisPageName = $editPage->mTitle->getPrefixedDBkey(); if( !BaseBlacklist::isLocalSource( $editPage->mTitle ) ) { wfDebugLog( 'SpamBlacklist', "Spam blacklist validator: [[$thisPageName]] not a local blacklist\n" ); return true; } $lines = explode( "\n", $text ); $badLines = SpamRegexBatch::getBadLines( $lines ); if( $badLines ) { wfDebugLog( 'SpamBlacklist', "Spam blacklist validator: [[$thisPageName]] given invalid input lines: " . implode( ', ', $badLines ) . "\n" ); $badList = "*<tt>" . implode( "</tt>\n*<tt>", array_map( 'wfEscapeWikiText', $badLines ) ) . "</tt>\n"; $hookError = "<div class='errorbox'>" . wfMsgExt( 'spam-invalid-lines', array( 'parsemag' ), count( $badLines ) ) . "<br />" . $badList . "</div>\n" . "<br clear='all' />\n"; return true; } else { wfDebugLog( 'SpamBlacklist', "Spam blacklist validator: [[$thisPageName]] ok or empty blacklist\n" ); return true; } }
function buildSharedBlacklists() { $regexes = array(); $listType = $this->getBlacklistType(); # Load lists wfDebugLog( 'SpamBlacklist', "Constructing $listType blacklist\n" ); foreach ( $this->files as $fileName ) { $matches = array(); if ( preg_match( '/^DB: ([\w-]*) (.*)$/', $fileName, $matches ) ) { $text = $this->getArticleText( $matches[1], $matches[2] ); } elseif ( preg_match( '/^http:\/\//', $fileName ) ) { $text = $this->getHttpText( $fileName ); } else { $text = file_get_contents( $fileName ); wfDebugLog( 'SpamBlacklist', "got from file $fileName\n" ); } // Build a separate batch of regexes from each source. // While in theory we could squeeze a little efficiency // out of combining multiple sources in one regex, if // there's a bad line in one of them we'll gain more // from only having to break that set into smaller pieces. $regexes = array_merge( $regexes, SpamRegexBatch::regexesFromText( $text, $fileName ) ); } return $regexes; }
/** * Build a set of regular expressions from a MediaWiki message. * Will be correctly empty if the message isn't present. * * @param $message string * @return array of regular expressions, potentially empty */ static function regexesFromMessage( $message ) { $source = wfMsgForContent( $message ); if( $source && !wfEmptyMsg( $message, $source ) ) { return SpamRegexBatch::regexesFromText( $source ); } else { return array(); } }
/** * Hook function for EditFilter * Confirm that a local blacklist page being saved is valid, * and toss back a warning to the user if it isn't. * * @param $editPage EditPage * @param $text string * @param $section string * @param $hookError string * @return bool */ static function validate($editPage, $text, $section, &$hookError) { $thisPageName = $editPage->mTitle->getPrefixedDBkey(); if (!BaseBlacklist::isLocalSource($editPage->mTitle)) { wfDebugLog('SpamBlacklist', "Spam blacklist validator: [[{$thisPageName}]] not a local blacklist\n"); return true; } $type = BaseBlacklist::getTypeFromTitle($editPage->mTitle); if ($type === false) { return true; } $lines = explode("\n", $text); $badLines = SpamRegexBatch::getBadLines($lines, BaseBlacklist::getInstance($type)); if ($badLines) { wfDebugLog('SpamBlacklist', "Spam blacklist validator: [[{$thisPageName}]] given invalid input lines: " . implode(', ', $badLines) . "\n"); $badList = "*<code>" . implode("</code>\n*<code>", array_map('wfEscapeWikiText', $badLines)) . "</code>\n"; $hookError = "<div class='errorbox'>" . wfMessage('spam-invalid-lines')->numParams($badLines)->text() . "<br />" . $badList . "</div>\n" . "<br clear='all' />\n"; } else { wfDebugLog('SpamBlacklist', "Spam blacklist validator: [[{$thisPageName}]] ok or empty blacklist\n"); } return true; }
/** * Build a set of regular expressions from a MediaWiki message. * Will be correctly empty if the message isn't present. * * @param $message string * @param $blacklist BaseBlacklist * @return array of regular expressions, potentially empty */ static function regexesFromMessage($message, BaseBlacklist $blacklist) { $source = wfMessage($message)->inContentLanguage(); if (!$source->isDisabled()) { return SpamRegexBatch::regexesFromText($source->plain(), $blacklist); } else { return array(); } }