Maintenance for SpamBlacklist extension.

* Replace deprecated methods. MediaWiki 1.19 required.
* Replace <tt> with <code>.
* Update documentation.
* Use WikiPage instead of Article for doEdit().
* Use __DIR__ instead of dirname( __FILE__ ).
* Remove superfluous newlines.

Change-Id: I3a0e42ca404638f7c7934c316735ad11cbc99d42
This commit is contained in:
Siebrand Mazeland 2012-09-02 17:41:39 +02:00
parent c3afe284ba
commit e9874344aa
6 changed files with 21 additions and 27 deletions

View file

@ -4,7 +4,6 @@
* Base class for different kinds of blacklists
*/
abstract class BaseBlacklist {
/**
* Array of blacklist sources
*
@ -369,5 +368,4 @@ abstract class BaseBlacklist {
public function getRegexEnd( $batchSize ) {
return ($batchSize > 0 ) ? '/Sim' : '/im';
}
}

View file

@ -15,7 +15,7 @@ $wgExtensionCredits['antispam'][] = array(
'descriptionmsg' => 'spam-blacklist-desc',
);
$dir = dirname(__FILE__) . '/';
$dir = __DIR__ . '/';
$wgExtensionMessagesFiles['SpamBlackList'] = $dir . 'SpamBlacklist.i18n.php';
/**
@ -45,6 +45,3 @@ $wgAutoloadClasses['EmailBlacklist'] = $dir . 'EmailBlacklist.php';
$wgAutoloadClasses['SpamBlacklistHooks'] = $dir . 'SpamBlacklistHooks.php';
$wgAutoloadClasses['SpamBlacklist'] = $dir . 'SpamBlacklist_body.php';
$wgAutoloadClasses['SpamRegexBatch'] = $dir . 'SpamRegexBatch.php';

View file

@ -4,7 +4,6 @@
* Hooks for the spam blacklist extension
*/
class SpamBlacklistHooks {
/**
* Hook function for EditFilterMerged
*
@ -26,12 +25,7 @@ class SpamBlacklistHooks {
$title = $editPage->mArticle->getTitle();
$ret = $spamObj->filter( $title, $text, '', $editSummary, $editPage );
if ( $ret !== false ) {
// spamPageWithContent() method was added in MW 1.17
if ( method_exists( $editPage, 'spamPageWithContent' ) ) {
$editPage->spamPageWithContent( $ret );
} else {
$editPage->spamPage( $ret );
}
$editPage->spamPageWithContent( $ret );
}
// Return convention for hooks is the inverse of $wgFilterCallback
return ( $ret === false );
@ -124,13 +118,13 @@ class SpamBlacklistHooks {
wfDebugLog( 'SpamBlacklist', "Spam blacklist validator: [[$thisPageName]] given invalid input lines: " .
implode( ', ', $badLines ) . "\n" );
$badList = "*<tt>" .
implode( "</tt>\n*<tt>",
$badList = "*<code>" .
implode( "</code>\n*<code>",
array_map( 'wfEscapeWikiText', $badLines ) ) .
"</tt>\n";
"</code>\n";
$hookError =
"<div class='errorbox'>" .
wfMsgExt( 'spam-invalid-lines', array( 'parsemag' ), count( $badLines ) ) . "<br />" .
wfMessage( 'spam-invalid-lines' )->numParams( $badLines )->text() . "<br />" .
$badList .
"</div>\n" .
"<br clear='all' />\n";

View file

@ -21,7 +21,7 @@ class SpamBlacklist extends BaseBlacklist {
* @param Title $title
* @param string $text Text of section, or entire text if $editPage!=false
* @param string $section Section number or name
* @param EditSummary $editSummary Edit summary if one exists, some people use urls there too
* @param string $editsummary Edit summary if one exists, some people use urls there too
* @param EditPage $editPage EditPage if EditFilterMerged was called, null otherwise
* @return Array Matched text(s) if the edit should not be allowed, false otherwise
*/
@ -95,7 +95,8 @@ class SpamBlacklist extends BaseBlacklist {
wfRestoreWarnings();
if( $check ) {
wfDebugLog( 'SpamBlacklist', "Match!\n" );
$ip = wfGetIP();
global $wgRequest;
$ip = $wgRequest->getIP();
$imploded = implode( ' ', $matches[0] );
wfDebugLog( 'SpamBlacklistHit', "$ip caught submitting spam: $imploded\n" );
if( $retVal === false ){

View file

@ -9,6 +9,7 @@ class SpamRegexBatch {
* Returns an empty list if the input list is empty.
*
* @param array $lines list of fragments which will match in URLs
* @param BaseBlacklist $blacklist
* @param int $batchSize largest allowed batch regex;
* if 0, will produce one regex per line
* @return array
@ -87,7 +88,8 @@ class SpamRegexBatch {
* Do a sanity check on the batch regex.
*
* @param $lines string unsanitized input lines
* @param $fileName string optional for debug reporting
* @param $blacklist BaseBlacklist
* @param $fileName bool|string optional for debug reporting
* @return array of regexes
*/
static function buildSafeRegexes( $lines, BaseBlacklist $blacklist, $fileName=false ) {
@ -110,6 +112,7 @@ class SpamRegexBatch {
* Returns an array of invalid lines
*
* @param array $lines
* @param $blacklist BaseBlacklist
* @return array of input lines which produce invalid input, or empty array if no problems
*/
static function getBadLines( $lines, BaseBlacklist $blacklist ) {
@ -144,6 +147,7 @@ class SpamRegexBatch {
* with empty lines and comments stripped.
*
* @param $source string
* @param $blacklist BaseBlacklist
* @param $fileName bool|string optional, for reporting of bad files
* @return array of regular expressions, potentially empty
*/
@ -157,15 +161,15 @@ class SpamRegexBatch {
* 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 = wfMsgForContent( $message );
if( $source && !wfEmptyMsg( $message, $source ) ) {
return SpamRegexBatch::regexesFromText( $source, $blacklist );
$source = wfMessage( $message )->inContentLanguage();
if( !$source->isDisabled() ) {
return SpamRegexBatch::regexesFromText( $source->plain(), $blacklist );
} else {
return array();
}
}
}

View file

@ -12,7 +12,7 @@ require_once( 'SpamBlacklist_body.php' );
/**
* Find the latest revision of the article that does not contain spam and revert to it
*/
function cleanupArticle( $rev, $regexes, $match ) {
function cleanupArticle( Revision $rev, $regexes, $match ) {
$title = $rev->getTitle();
$revId = $rev->getId();
while ( $rev ) {
@ -51,8 +51,8 @@ function cleanupArticle( $rev, $regexes, $match ) {
$text = $rev->getText();
$comment = "Cleaning up links to $match";
}
$article = new Article( $title );
$article->doEdit( $text, $comment );
$wikiPage = new WikiPage( $title );
$wikiPage->doEdit( $text, $comment );
$dbw->commit();
}