Index: trunk/extensions/SpamRegex/SpamRegex.i18n.php |
— | — | @@ -15,7 +15,7 @@ |
16 | 16 | 'spamregex' => 'Spam regex', |
17 | 17 | 'spamregex-desc' => '[[Special:SpamRegex|Filter]] out unwanted phrases in edited pages, based on regular expressions', |
18 | 18 | 'spamregex-error-unblocking' => 'Error unblocking "$1". Probably there is no such pattern.', |
19 | | - 'spamregex-summary' => 'The text was found in the page\'s summary.', |
| 19 | + 'spamregex-summary' => "The text was found in the page's summary.", |
20 | 20 | 'spamregex-intro' => 'Use this form to effectively block expressions from saving into a page\'s text. |
21 | 21 | If the text contains the given expression, change would not be saved and an explanation will be displayed to user that tried to save the page. |
22 | 22 | Caution advised, expressions should not be too short or too common.', |
— | — | @@ -23,13 +23,13 @@ |
24 | 24 | 'spamregex-currently-blocked' => "'''Currently blocked phrases:'''", |
25 | 25 | 'spamregex-move' => 'The reason you entered contained a blocked phrase.', |
26 | 26 | 'spamregex-no-currently-blocked' => "'''There are no blocked phrases.'''", |
27 | | - 'spamregex-log' => '* \'\'\'$1\'\'\' $2 ([{{SERVER}}$3&text=$4 remove]) added by $5 on $6 at $7', |
| 27 | + 'spamregex-log' => "* '''$1''' $2 ([{{SERVER}}$3&text=$4 remove]) added by $5 on $6 at $7", |
28 | 28 | 'spamregex-page-title-1' => 'Block phrase using regular expressions', |
29 | 29 | 'spamregex-unblock-success' => 'Unblock succedeed', |
30 | | - 'spamregex-unblock-message' => 'Phrase \'\'\'$1\'\'\' has been unblocked from editing.', |
| 30 | + 'spamregex-unblock-message' => "Phrase '''$1''' has been unblocked from editing.", |
31 | 31 | 'spamregex-page-title-2' => 'Block phrases from saving using regular expressions', |
32 | 32 | 'spamregex-block-success' => 'Block succedeed', |
33 | | - 'spamregex-block-message' => 'Phrase \'\'\'$1\'\'\' has been blocked.', |
| 33 | + 'spamregex-block-message' => "Phrase '''$1''' has been blocked.", |
34 | 34 | 'spamregex-warning-1' => 'Give a phrase to block.', |
35 | 35 | 'spamregex-error-1' => 'Invalid regular expression.', |
36 | 36 | 'spamregex-warning-2' => 'Please check at least one blocking mode.', |
Index: trunk/extensions/SpamRegex/SpamRegex.php |
— | — | @@ -2,9 +2,12 @@ |
3 | 3 | /** |
4 | 4 | * SpamRegex - A special page with the interface for blocking, viewing and unblocking of unwanted phrases |
5 | 5 | * |
| 6 | + * @file |
6 | 7 | * @ingroup Extensions |
7 | | - * @author Bartek Łapiński |
8 | | - * @version 1.2 |
| 8 | + * @author Bartek Łapiński <bartek(at)wikia-inc.com> |
| 9 | + * @author Alexandre Emsenhuber |
| 10 | + * @author Jack Phoenix <jack@countervandalism.net> |
| 11 | + * @version 1.2.2 |
9 | 12 | * @link http://www.mediawiki.org/wiki/Extension:SpamRegex Documentation |
10 | 13 | * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later |
11 | 14 | */ |
— | — | @@ -13,8 +16,9 @@ |
14 | 17 | * Protect against register_globals vulnerabilities. |
15 | 18 | * This line must be present before any global variable is referenced. |
16 | 19 | */ |
17 | | -if ( !defined('MEDIAWIKI') ) |
18 | | - die(); |
| 20 | +if ( !defined( 'MEDIAWIKI' ) ){ |
| 21 | + die( "This is not a valid entry point.\n" ); |
| 22 | +} |
19 | 23 | |
20 | 24 | /* for memcached - expiration time */ |
21 | 25 | define('SPAMREGEX_EXPIRE', 0); |
— | — | @@ -26,8 +30,8 @@ |
27 | 31 | // Extension credits |
28 | 32 | $wgExtensionCredits['specialpage'][] = array( |
29 | 33 | 'name' => 'Regular Expression Spam Block', |
30 | | - 'version' => '1.2.1', |
31 | | - 'author' => 'Bartek Łapiński', |
| 34 | + 'version' => '1.2.2', |
| 35 | + 'author' => array( 'Bartek Łapiński', 'Alexandre Emsenhuber', 'Jack Phoenix' ), |
32 | 36 | 'url' => 'http://www.mediawiki.org/wiki/Extension:SpamRegex', |
33 | 37 | 'description' => 'Filters out unwanted phrases in edited pages, based on regular expressions', |
34 | 38 | 'descriptionmsg' => 'spamregex-desc', |
Index: trunk/extensions/SpamRegex/SpecialSpamRegex.php |
— | — | @@ -3,15 +3,16 @@ |
4 | 4 | * Protect against register_globals vulnerabilities. |
5 | 5 | * This line must be present before any global variable is referenced. |
6 | 6 | */ |
7 | | -if( !defined( 'MEDIAWIKI' ) ) |
8 | | - die(); |
| 7 | +if ( !defined( 'MEDIAWIKI' ) ){ |
| 8 | + die( "This is not a valid entry point.\n" ); |
| 9 | +} |
9 | 10 | |
10 | 11 | class SpamRegex extends SpecialPage { |
11 | 12 | |
12 | 13 | /** |
13 | | - * Constructor |
14 | | - */ |
15 | | - function __construct() { |
| 14 | + * Constructor |
| 15 | + */ |
| 16 | + public function __construct() { |
16 | 17 | parent::__construct( 'SpamRegex', 'spamregex' ); |
17 | 18 | wfLoadExtensionMessages( 'SpamRegex' ); |
18 | 19 | } |
— | — | @@ -21,17 +22,22 @@ |
22 | 23 | * |
23 | 24 | * @param $par Mixed: parameter passed to the page or null |
24 | 25 | */ |
25 | | - function execute( $par ) { |
| 26 | + public function execute( $par ) { |
26 | 27 | global $wgOut, $wgUser, $wgRequest; |
27 | 28 | |
| 29 | + # No access for blocked users |
28 | 30 | if ( $wgUser->isBlocked() ) { |
29 | 31 | $wgOut->blockedPage(); |
30 | 32 | return; |
31 | 33 | } |
| 34 | + |
| 35 | + # Can't use the special page if database is locked... |
32 | 36 | if ( wfReadOnly() ) { |
33 | 37 | $wgOut->readOnlyPage(); |
34 | 38 | return; |
35 | 39 | } |
| 40 | + |
| 41 | + # And we'll also be needing the correct user rights in order to proceed |
36 | 42 | if ( !$wgUser->isAllowed( 'spamregex' ) ) { |
37 | 43 | $this->displayRestrictionError(); |
38 | 44 | return; |
— | — | @@ -101,7 +107,7 @@ |
102 | 108 | global $wgOut, $wgRequest, $wgLang; |
103 | 109 | |
104 | 110 | /* on error, display error */ |
105 | | - if ( "" != $err ) { |
| 111 | + if ( '' != $err ) { |
106 | 112 | $wgOut->addHTML( "<p class='error'>{$err}</p>\n" ); |
107 | 113 | } |
108 | 114 | |
— | — | @@ -123,23 +129,23 @@ |
124 | 130 | while ( $row = $res->fetchObject() ) { |
125 | 131 | $date = $wgLang->date( wfTimestamp( TS_MW, $row->spam_timestamp ), true ); |
126 | 132 | $time = $wgLang->time( wfTimestamp( TS_MW, $row->spam_timestamp ), true ); |
127 | | - $ublock_ip = urlencode($row->spam_text); |
| 133 | + $ublock_ip = urlencode( $row->spam_text ); |
128 | 134 | $desc = ''; |
129 | 135 | if ( $row->spam_textbox == 1 ) { |
130 | 136 | $desc .= wfMsg( 'spamregex-text' ); |
131 | 137 | } |
132 | 138 | if ( $row->spam_summary == 1 ) { |
133 | 139 | if ( $row->spam_textbox == 1 ) { |
134 | | - $desc .= " "; |
| 140 | + $desc .= ' '; |
135 | 141 | } |
136 | 142 | $desc .= wfMsg( 'spamregex-summary-log' ); |
137 | 143 | } |
138 | | - $wgOut->addHTML( "<ul>" ); |
139 | | - $wgOut->addWikiText( wfMsg( 'spamregex-log', $row->spam_text, $desc, $action_unblock, $ublock_ip, $row->spam_user, $date, $time ) ); |
140 | | - $wgOut->addHTML( "</ul>" ); |
| 144 | + $wgOut->addHTML( '<ul>' ); |
| 145 | + $wgOut->addWikiMsg( 'spamregex-log', $row->spam_text, $desc, $action_unblock, $ublock_ip, $row->spam_user, $date, $time ); |
| 146 | + $wgOut->addHTML( '</ul>' ); |
141 | 147 | } |
142 | 148 | $res->free(); |
143 | | - $wgOut->addHTML( "</form>" ); |
| 149 | + $wgOut->addHTML( '</form>' ); |
144 | 150 | $this->showPrevNext( $wgOut ); |
145 | 151 | } |
146 | 152 | wfProfileOut( __METHOD__ ); |
— | — | @@ -148,7 +154,7 @@ |
149 | 155 | /* remove from list - without confirmation */ |
150 | 156 | function deleteFromList() { |
151 | 157 | wfProfileIn( __METHOD__ ); |
152 | | - global $wgOut, $wgRequest, $wgUser; |
| 158 | + global $wgOut, $wgRequest; |
153 | 159 | $text = urldecode( $wgRequest->getVal( 'text' ) ); |
154 | 160 | /* delete */ |
155 | 161 | $dbw = wfGetDB( DB_MASTER ); |
— | — | @@ -166,7 +172,7 @@ |
167 | 173 | } |
168 | 174 | |
169 | 175 | /** |
170 | | - * fetch number of all rows |
| 176 | + * Fetch number of all rows |
171 | 177 | * Use memcached if possible |
172 | 178 | */ |
173 | 179 | function fetchNumResults() { |
— | — | @@ -199,7 +205,7 @@ |
200 | 206 | static function validateRegex( $text ) { |
201 | 207 | try { |
202 | 208 | $test = @preg_match("/{$text}/", 'Whatever'); |
203 | | - if( !is_int($test) ) { |
| 209 | + if( !is_int( $test ) ) { |
204 | 210 | throw new Exception("error!"); |
205 | 211 | } |
206 | 212 | } |
— | — | @@ -232,12 +238,12 @@ |
233 | 239 | global $wgContLang, $wgRequest; |
234 | 240 | list( $limit, $offset ) = $wgRequest->getLimitOffset(); |
235 | 241 | $html = wfViewPrevNext( |
236 | | - $offset, |
237 | | - $limit, |
238 | | - $wgContLang->specialpage( 'SpamRegex' ), |
239 | | - '', |
240 | | - ($this->numResults - $offset) <= $limit |
241 | | - ); |
| 242 | + $offset, |
| 243 | + $limit, |
| 244 | + $wgContLang->specialpage( 'SpamRegex' ), |
| 245 | + '', |
| 246 | + ($this->numResults - $offset) <= $limit |
| 247 | + ); |
242 | 248 | $out->addHTML( '<p>' . $html . '</p>' ); |
243 | 249 | } |
244 | 250 | } |
— | — | @@ -264,7 +270,7 @@ |
265 | 271 | $titleObj = SpecialPage::getTitleFor( 'SpamRegex' ); |
266 | 272 | $action = $titleObj->escapeLocalURL( "action=submit&".spamRegexList::getListBits() ); |
267 | 273 | |
268 | | - if ( "" != $err ) { |
| 274 | + if ( '' != $err ) { |
269 | 275 | $wgOut->setSubtitle( wfMsgHtml( 'formerror' ) ); |
270 | 276 | $wgOut->addHTML( "<p class='error'>{$err}</p>\n" ); |
271 | 277 | } |
— | — | @@ -302,10 +308,10 @@ |
303 | 309 | addOnloadHook (SpamRegexEnhanceControls); |
304 | 310 | </script>" |
305 | 311 | ); |
306 | | - $phraseblock = wfMsgExt( 'spamregex-phrase-block', array( 'parseinline' ) ); |
307 | | - $phraseblocktext = wfMsgExt( 'spamregex-phrase-block-text', array( 'parseinline' ) ); |
308 | | - $phraseblocksummary = wfMsgExt( 'spamregex-phrase-block-summary', array( 'parseinline' ) ); |
309 | | - $blockphrase = wfMsgExt('spamregex-block-submit', array( 'escapenoentities' ) ); |
| 312 | + $phraseblock = wfMsgExt( 'spamregex-phrase-block', 'parseinline' ); |
| 313 | + $phraseblocktext = wfMsgExt( 'spamregex-phrase-block-text', 'parseinline' ); |
| 314 | + $phraseblocksummary = wfMsgExt( 'spamregex-phrase-block-summary', 'parseinline' ); |
| 315 | + $blockphrase = wfMsgExt( 'spamregex-block-submit', 'escapenoentities' ); |
310 | 316 | $wgOut->addHTML(" |
311 | 317 | <form name=\"spamregex\" method=\"post\" action=\"{$action}\"> |
312 | 318 | <table border=\"0\"> |
— | — | @@ -342,24 +348,24 @@ |
343 | 349 | |
344 | 350 | /* on success */ |
345 | 351 | function showSuccess() { |
346 | | - global $wgOut, $wgRequest; |
| 352 | + global $wgOut; |
347 | 353 | $wgOut->setPageTitle( wfMsg( 'spamregex-page-title-2' ) ); |
348 | 354 | $wgOut->setSubTitle( wfMsg( 'spamregex-block-success' ) ); |
349 | | - |
350 | | - $wgOut->addWikiMsg('spamregex-block-message', $this->mBlockedPhrase); |
| 355 | + $wgOut->addWikiMsg( 'spamregex-block-message', $this->mBlockedPhrase ); |
351 | 356 | } |
352 | 357 | |
353 | 358 | /* on submit */ |
354 | 359 | function doSubmit() { |
355 | 360 | wfProfileIn( __METHOD__ ); |
356 | | - global $wgOut, $wgUser, $wgMemc; |
| 361 | + global $wgOut, $wgUser; |
357 | 362 | |
358 | 363 | /* empty name */ |
359 | | - if ( strlen($this->mBlockedPhrase) == 0 ) { |
| 364 | + if ( strlen( $this->mBlockedPhrase ) == 0 ) { |
360 | 365 | $this->showForm( wfMsgHtml( 'spamregex-warning-1' ) ); |
361 | 366 | wfProfileOut( __METHOD__ ); |
362 | 367 | return; |
363 | 368 | } |
| 369 | + |
364 | 370 | /* validate expression */ |
365 | 371 | if ( !$simple_regex = spamRegexList::validateRegex( $this->mBlockedPhrase ) ) { |
366 | 372 | $this->showForm( wfMsgHtml( 'spamregex-error-1' ) ); |
Index: trunk/extensions/SpamRegex/SpamRegexCore.php |
— | — | @@ -64,8 +64,8 @@ |
65 | 65 | foreach( $s_phrases as $s_phrase ) { |
66 | 66 | if ( preg_match( $s_phrase, $reason, $s_matches ) ) { |
67 | 67 | wfLoadExtensionMessages( 'SpamRegex' ); |
68 | | - $error .= wfMsgExt( 'spamregex-move', array( 'parseinline' ) ) . wfMsg( 'word_separator' ); |
69 | | - $error .= wfMsgExt( 'spamprotectionmatch', array( 'parseinline' ), "<nowiki>{$s_matches[0]}</nowiki>" ); |
| 68 | + $error .= wfMsgExt( 'spamregex-move', 'parseinline' ) . wfMsg( 'word_separator' ); |
| 69 | + $error .= wfMsgExt( 'spamprotectionmatch', 'parseinline', "<nowiki>{$s_matches[0]}</nowiki>" ); |
70 | 70 | wfProfileOut( __METHOD__ ); |
71 | 71 | return false; |
72 | 72 | } |
— | — | @@ -91,7 +91,7 @@ |
92 | 92 | $res = $dbr->select( 'spam_regex', 'spam_text', array( $field => 1 ), __METHOD__ ); |
93 | 93 | while ( $row = $res->fetchObject() ) { |
94 | 94 | $concat = $row->spam_text; |
95 | | - $phrases [] = "/" . $concat . "/i" ; |
| 95 | + $phrases[] = "/" . $concat . "/i"; |
96 | 96 | } |
97 | 97 | $wgMemc->set( $key, $phrases, 0 ); |
98 | 98 | $res->free(); |