/** * 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; } }
/** * 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; }