r114929 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r114928‎ | r114929 | r114930 >
Date:19:29, 16 April 2012
Author:reedy
Status:new
Tags:
Comment:
Fix register_globals

Update code, remove unused globals

Fix wfProfileOut() calls

Remove other unused variables
Modified paths:
  • /trunk/extensions/AkismetKlik/AkismetKlik.php (modified) (history)

Diff [purge]

Index: trunk/extensions/AkismetKlik/AkismetKlik.php
@@ -3,9 +3,7 @@
44 exit;
55 }
66
7 -#
87 # Include PHP5 Akismet class from http://www.achingbrain.net/stuff/akismet (GPL)
9 -#
108 require_once('Akismet.class.php');
119
1210 #Extension credits
@@ -13,42 +11,30 @@
1412 'name' => 'AkismetKlik',
1513 'author' => 'Carl Austin Bennett',
1614 'url' => 'http://www.mediawiki.org/wiki/Extension:AkismetKlik',
17 - 'description' => 'Rejects edits from suspected comment spammers on Akismet\'s blacklist.',
 15+ 'description' => "Rejects edits from suspected comment spammers on Akismet's blacklist.",
1816 );
1917
2018 # Set site-specific configuration values
21 -#$wgAKkey='867-5309';
22 -#$siteURL='http://wiki.example.org';
 19+$wgAKkey = '';
 20+$wgAKSiteUrl = '';
2321
2422 #
2523 # MediaWiki hooks
2624 #
2725 # Loader for spam blacklist feature
2826 # Include this from LocalSettings.php
 27+$wgHooks['EditFilterMerged'][] = 'wfAkismetFilterMerged';
2928
30 -global $wgAkismetFilterCallback, $wgPreAkismetFilterCallback, $wgUser;
31 -$wgPreAkismetFilterCallback = false;
32 -
33 -if ( defined( 'MW_SUPPORTS_EDITFILTERMERGED' ) ) {
34 - $wgHooks['EditFilterMerged'][] = 'wfAkismetFilterMerged';
35 -} else {
36 - if ( $wgFilterCallback ) {
37 - $wgPreAkismetFilterCallback = $wgFilterCallback;
38 - }
39 - $wgFilterCallback = 'wfAkismetFilter';
40 -}
41 -
42 -#$wgHooks['EditFilter'][] = 'wfAkismetFilter';
43 -
4429 /**
4530 * Get an instance of AkismetKlik and do some first-call initialisation.
4631 * All actual functionality is implemented in that object
 32+ * @return AkismetKlik
4733 */
4834 function wfAkismetKlikObject() {
4935 global $wgSpamBlacklistSettings, $wgPreSpamFilterCallback;
5036 static $spamObj;
5137 if ( !$spamObj ) {
52 - $spamObj = new AkismetKlik ( $wgSpamBlacklistSettings );
 38+ $spamObj = new AkismetKlik( $wgSpamBlacklistSettings );
5339 $spamObj->previousFilter = $wgPreSpamFilterCallback;
5440 }
5541 return $spamObj;
@@ -56,6 +42,10 @@
5743
5844 /**
5945 * Hook function for $wgFilterCallback
 46+ * @param $title Title
 47+ * @param $text string
 48+ * @param $section
 49+ * @return bool
6050 */
6151 function wfAkismetFilter( &$title, $text, $section ) {
6252 $spamObj = wfAkismetKlikObject();
@@ -64,11 +54,13 @@
6555
6656 /**
6757 * Hook function for EditFilterMerged, replaces wfAkismetFilter
 58+ * @param $editPage EditPage
 59+ * @param $text string
 60+ * @return bool
6861 */
6962 function wfAkismetFilterMerged( $editPage, $text ) {
7063 $spamObj = new AkismetKlik();
71 - $ret = $spamObj->filter( $editPage->mArticle->getTitle(), $text, '', $editPage );
72 - // Return convention for hooks is the inverse of $wgAkismetFilterCallback
 64+ $ret = $spamObj->filter( $editPage->getArticle()->getTitle(), $text, '', $editPage );
7365 return !$ret;
7466 }
7567
@@ -77,10 +69,12 @@
7870 #
7971 class AkismetKlik {
8072
81 - function AkismetKlik( $settings = array() ) {
 73+ /**
 74+ * @param $settings array
 75+ */
 76+ function __construct( $settings = array() ) {
8277 foreach ( $settings as $name => $value ) {
8378 $this->$name = $value;
84 - echo $value;
8579 }
8680 }
8781
@@ -88,34 +82,28 @@
8983 * @param Title $title
9084 * @param string $text Text of section, or entire text if $editPage!=false
9185 * @param string $section Section number or name
92 - * @param EditPage $editPage EditPage if EditFilterMerged was called, false otherwise
93 - * @return True if the edit should not be allowed, false otherwise
 86+ * @param EditPage|bool $editPage EditPage if EditFilterMerged was called, false otherwise
 87+ * @throws MWException
 88+ * @return bool True if the edit should not be allowed, false otherwise
9489 * If the return value is true, an error will have been sent to $wgOut
9590 */
9691 function filter( &$title, $text, $section, $editPage = false ) {
97 - global $wgArticle, $wgVersion, $wgOut, $wgParser, $wgUser;
98 - global $siteURL, $wgAKkey;
 92+ global $wgParser, $wgUser, $wgAKSiteUrl, $wgAKkey, $IP;
9993
100 - $fname = 'wfAkismetKlikFilter';
101 - wfProfileIn( $fname );
102 -
103 - # Call the rest of the hook chain first
104 - if ( $this->previousFilter ) {
105 - $f = $this->previousFilter;
106 - if ( $f( $title, $text, $section ) ) {
107 - wfProfileOut( $fname );
108 - return true;
109 - }
 94+ if ( strlen( $wgAKkey ) == 0 ) {
 95+ throw new MWException( "Set $wgAKkey" );
11096 }
 97+ if ( strlen( $wgAKkey ) == 0 ) {
 98+ throw new MWException( "Set $wgAKkey" );
 99+ }
111100
112 - $this->title = $title;
113 - $this->text = $text;
114 - $this->section = $section;
 101+ wfProfileIn( __METHOD__ );
 102+
115103 $text = str_replace( '.', '.', $text );
116104
117105 # Run parser to strip SGML comments and such out of the markup
118106 if ( $editPage ) {
119 - $editInfo = $editPage->mArticle->prepareTextForEdit( $text );
 107+ $editInfo = $editPage->getArticle()->prepareTextForEdit( $text );
120108 $out = $editInfo->output;
121109 $pgtitle = $title;
122110 } else {
@@ -124,28 +112,28 @@
125113 $out = $wgParser->parse( $text, $title, $options );
126114 $pgtitle = "";
127115 }
128 - $links = implode( "\n", array_keys( $out->getExternalLinks()));
 116+ $links = implode( "\n", array_keys( $out->getExternalLinks() ) );
129117
130118 # Do the match
131 - if ($wgUser->mName == "") $user = $IP;
132 - else $user = $wgUser->mName;
133 - $akismet = new Akismet($siteURL, $wgAKkey);
134 - $akismet->setCommentAuthor($user);
135 - $akismet->setCommentAuthorEmail($wgUser->mEmail);
136 - $akismet->setCommentAuthorURL($links);
137 - $akismet->setCommentContent($text);
138 - $akismet->setCommentType("wiki");
139 - $akismet->setPermalink($siteURL . '/wiki/' . $pgtitle);
140 - if($akismet->isCommentSpam()&&!$wgUser->isAllowed( 'bypassakismet' ))
141 - {
 119+ if ( $wgUser->mName == "" ) {
 120+ $user = $IP;
 121+ } else {
 122+ $user = $wgUser->mName;
 123+ }
 124+ $akismet = new Akismet( $wgAKSiteUrl, $wgAKkey );
 125+ $akismet->setCommentAuthor( $user );
 126+ $akismet->setCommentAuthorEmail( $wgUser->mEmail );
 127+ $akismet->setCommentAuthorURL( $links );
 128+ $akismet->setCommentContent( $text );
 129+ $akismet->setCommentType( "wiki" );
 130+ $akismet->setPermalink( $wgAKSiteUrl . '/wiki/' . $pgtitle );
 131+ if( $akismet->isCommentSpam() && !$wgUser->isAllowed( 'bypassakismet' ) ) {
142132 wfDebugLog( 'AkismetKlik', "Match!\n" );
143 - if ( $editPage ) {
144 - $editPage->spamPage( "http://akismet.com blacklist error" );
145 - } else {
146 - EditPage::spamPage( "http://akismet.com blacklist error" );
147 - }
 133+ EditPage::spamPage( "http://akismet.com blacklist error" );
 134+ wfProfileOut( __METHOD__ );
148135 return true;
149136 }
 137+ wfProfileOut( __METHOD__ );
150138 return false;
151139 }
152140 }