https://www.mediawiki.org/wiki/Special:Code/MediaWiki/114929
Revision: 114929
Author: reedy
Date: 2012-04-16 19:29:48 +0000 (Mon, 16 Apr 2012)
Log Message:
-----------
Fix register_globals
Update code, remove unused globals
Fix wfProfileOut() calls
Remove other unused variables
Modified Paths:
--------------
trunk/extensions/AkismetKlik/AkismetKlik.php
Modified: trunk/extensions/AkismetKlik/AkismetKlik.php
===================================================================
--- trunk/extensions/AkismetKlik/AkismetKlik.php 2012-04-16 19:05:24 UTC
(rev 114928)
+++ trunk/extensions/AkismetKlik/AkismetKlik.php 2012-04-16 19:29:48 UTC
(rev 114929)
@@ -3,9 +3,7 @@
exit;
}
-#
# Include PHP5 Akismet class from http://www.achingbrain.net/stuff/akismet
(GPL)
-#
require_once('Akismet.class.php');
#Extension credits
@@ -13,42 +11,30 @@
'name' => 'AkismetKlik',
'author' => 'Carl Austin Bennett',
'url' => 'http://www.mediawiki.org/wiki/Extension:AkismetKlik',
- 'description' => 'Rejects edits from suspected comment spammers on
Akismet\'s blacklist.',
+ 'description' => "Rejects edits from suspected comment spammers on
Akismet's blacklist.",
);
# Set site-specific configuration values
-#$wgAKkey='867-5309';
-#$siteURL='http://wiki.example.org';
+$wgAKkey = '';
+$wgAKSiteUrl = '';
#
# MediaWiki hooks
#
# Loader for spam blacklist feature
# Include this from LocalSettings.php
+$wgHooks['EditFilterMerged'][] = 'wfAkismetFilterMerged';
-global $wgAkismetFilterCallback, $wgPreAkismetFilterCallback, $wgUser;
-$wgPreAkismetFilterCallback = false;
-
-if ( defined( 'MW_SUPPORTS_EDITFILTERMERGED' ) ) {
- $wgHooks['EditFilterMerged'][] = 'wfAkismetFilterMerged';
-} else {
- if ( $wgFilterCallback ) {
- $wgPreAkismetFilterCallback = $wgFilterCallback;
- }
- $wgFilterCallback = 'wfAkismetFilter';
-}
-
-#$wgHooks['EditFilter'][] = 'wfAkismetFilter';
-
/**
* Get an instance of AkismetKlik and do some first-call initialisation.
* All actual functionality is implemented in that object
+ * @return AkismetKlik
*/
function wfAkismetKlikObject() {
global $wgSpamBlacklistSettings, $wgPreSpamFilterCallback;
static $spamObj;
if ( !$spamObj ) {
- $spamObj = new AkismetKlik ( $wgSpamBlacklistSettings );
+ $spamObj = new AkismetKlik( $wgSpamBlacklistSettings );
$spamObj->previousFilter = $wgPreSpamFilterCallback;
}
return $spamObj;
@@ -56,6 +42,10 @@
/**
* Hook function for $wgFilterCallback
+ * @param $title Title
+ * @param $text string
+ * @param $section
+ * @return bool
*/
function wfAkismetFilter( &$title, $text, $section ) {
$spamObj = wfAkismetKlikObject();
@@ -64,11 +54,13 @@
/**
* Hook function for EditFilterMerged, replaces wfAkismetFilter
+ * @param $editPage EditPage
+ * @param $text string
+ * @return bool
*/
function wfAkismetFilterMerged( $editPage, $text ) {
$spamObj = new AkismetKlik();
- $ret = $spamObj->filter( $editPage->mArticle->getTitle(), $text, '',
$editPage );
- // Return convention for hooks is the inverse of
$wgAkismetFilterCallback
+ $ret = $spamObj->filter( $editPage->getArticle()->getTitle(), $text,
'', $editPage );
return !$ret;
}
@@ -77,10 +69,12 @@
#
class AkismetKlik {
- function AkismetKlik( $settings = array() ) {
+ /**
+ * @param $settings array
+ */
+ function __construct( $settings = array() ) {
foreach ( $settings as $name => $value ) {
$this->$name = $value;
- echo $value;
}
}
@@ -88,34 +82,28 @@
* @param Title $title
* @param string $text Text of section, or entire text if
$editPage!=false
* @param string $section Section number or name
- * @param EditPage $editPage EditPage if EditFilterMerged was called,
false otherwise
- * @return True if the edit should not be allowed, false otherwise
+ * @param EditPage|bool $editPage EditPage if EditFilterMerged was
called, false otherwise
+ * @throws MWException
+ * @return bool True if the edit should not be allowed, false otherwise
* If the return value is true, an error will have been sent to $wgOut
*/
function filter( &$title, $text, $section, $editPage = false ) {
- global $wgArticle, $wgVersion, $wgOut, $wgParser, $wgUser;
- global $siteURL, $wgAKkey;
+ global $wgParser, $wgUser, $wgAKSiteUrl, $wgAKkey, $IP;
- $fname = 'wfAkismetKlikFilter';
- wfProfileIn( $fname );
-
- # Call the rest of the hook chain first
- if ( $this->previousFilter ) {
- $f = $this->previousFilter;
- if ( $f( $title, $text, $section ) ) {
- wfProfileOut( $fname );
- return true;
- }
+ if ( strlen( $wgAKkey ) == 0 ) {
+ throw new MWException( "Set $wgAKkey" );
}
+ if ( strlen( $wgAKkey ) == 0 ) {
+ throw new MWException( "Set $wgAKkey" );
+ }
- $this->title = $title;
- $this->text = $text;
- $this->section = $section;
+ wfProfileIn( __METHOD__ );
+
$text = str_replace( '.', '.', $text );
# Run parser to strip SGML comments and such out of the markup
if ( $editPage ) {
- $editInfo = $editPage->mArticle->prepareTextForEdit(
$text );
+ $editInfo =
$editPage->getArticle()->prepareTextForEdit( $text );
$out = $editInfo->output;
$pgtitle = $title;
} else {
@@ -124,28 +112,28 @@
$out = $wgParser->parse( $text, $title, $options );
$pgtitle = "";
}
- $links = implode( "\n", array_keys( $out->getExternalLinks()));
+ $links = implode( "\n", array_keys( $out->getExternalLinks() )
);
# Do the match
- if ($wgUser->mName == "") $user = $IP;
- else $user = $wgUser->mName;
- $akismet = new Akismet($siteURL, $wgAKkey);
- $akismet->setCommentAuthor($user);
- $akismet->setCommentAuthorEmail($wgUser->mEmail);
- $akismet->setCommentAuthorURL($links);
- $akismet->setCommentContent($text);
- $akismet->setCommentType("wiki");
- $akismet->setPermalink($siteURL . '/wiki/' . $pgtitle);
- if($akismet->isCommentSpam()&&!$wgUser->isAllowed(
'bypassakismet' ))
- {
+ if ( $wgUser->mName == "" ) {
+ $user = $IP;
+ } else {
+ $user = $wgUser->mName;
+ }
+ $akismet = new Akismet( $wgAKSiteUrl, $wgAKkey );
+ $akismet->setCommentAuthor( $user );
+ $akismet->setCommentAuthorEmail( $wgUser->mEmail );
+ $akismet->setCommentAuthorURL( $links );
+ $akismet->setCommentContent( $text );
+ $akismet->setCommentType( "wiki" );
+ $akismet->setPermalink( $wgAKSiteUrl . '/wiki/' . $pgtitle );
+ if( $akismet->isCommentSpam() && !$wgUser->isAllowed(
'bypassakismet' ) ) {
wfDebugLog( 'AkismetKlik', "Match!\n" );
- if ( $editPage ) {
- $editPage->spamPage( "http://akismet.com
blacklist error" );
- } else {
- EditPage::spamPage( "http://akismet.com
blacklist error" );
- }
+ EditPage::spamPage( "http://akismet.com blacklist
error" );
+ wfProfileOut( __METHOD__ );
return true;
}
+ wfProfileOut( __METHOD__ );
return false;
}
}
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs