r48645 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r48644‎ | r48645 | r48646 >
Date:20:45, 20 March 2009
Author:ashley
Status:ok
Tags:
Comment:
spamRegex:
*minor cleanup
*remove unused globals
*mark visibility of some functions
*add myself & ialex to authors
*bump version number
Modified paths:
  • /trunk/extensions/SpamRegex/SpamRegex.i18n.php (modified) (history)
  • /trunk/extensions/SpamRegex/SpamRegex.php (modified) (history)
  • /trunk/extensions/SpamRegex/SpamRegexCore.php (modified) (history)
  • /trunk/extensions/SpamRegex/SpecialSpamRegex.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SpamRegex/SpamRegex.i18n.php
@@ -15,7 +15,7 @@
1616 'spamregex' => 'Spam regex',
1717 'spamregex-desc' => '[[Special:SpamRegex|Filter]] out unwanted phrases in edited pages, based on regular expressions',
1818 '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.",
2020 'spamregex-intro' => 'Use this form to effectively block expressions from saving into a page\'s text.
2121 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.
2222 Caution advised, expressions should not be too short or too common.',
@@ -23,13 +23,13 @@
2424 'spamregex-currently-blocked' => "'''Currently blocked phrases:'''",
2525 'spamregex-move' => 'The reason you entered contained a blocked phrase.',
2626 '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",
2828 'spamregex-page-title-1' => 'Block phrase using regular expressions',
2929 '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.",
3131 'spamregex-page-title-2' => 'Block phrases from saving using regular expressions',
3232 'spamregex-block-success' => 'Block succedeed',
33 - 'spamregex-block-message' => 'Phrase \'\'\'$1\'\'\' has been blocked.',
 33+ 'spamregex-block-message' => "Phrase '''$1''' has been blocked.",
3434 'spamregex-warning-1' => 'Give a phrase to block.',
3535 'spamregex-error-1' => 'Invalid regular expression.',
3636 'spamregex-warning-2' => 'Please check at least one blocking mode.',
Index: trunk/extensions/SpamRegex/SpamRegex.php
@@ -2,9 +2,12 @@
33 /**
44 * SpamRegex - A special page with the interface for blocking, viewing and unblocking of unwanted phrases
55 *
 6+ * @file
67 * @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
912 * @link http://www.mediawiki.org/wiki/Extension:SpamRegex Documentation
1013 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
1114 */
@@ -13,8 +16,9 @@
1417 * Protect against register_globals vulnerabilities.
1518 * This line must be present before any global variable is referenced.
1619 */
17 -if ( !defined('MEDIAWIKI') )
18 - die();
 20+if ( !defined( 'MEDIAWIKI' ) ){
 21+ die( "This is not a valid entry point.\n" );
 22+}
1923
2024 /* for memcached - expiration time */
2125 define('SPAMREGEX_EXPIRE', 0);
@@ -26,8 +30,8 @@
2731 // Extension credits
2832 $wgExtensionCredits['specialpage'][] = array(
2933 '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' ),
3236 'url' => 'http://www.mediawiki.org/wiki/Extension:SpamRegex',
3337 'description' => 'Filters out unwanted phrases in edited pages, based on regular expressions',
3438 'descriptionmsg' => 'spamregex-desc',
Index: trunk/extensions/SpamRegex/SpecialSpamRegex.php
@@ -3,15 +3,16 @@
44 * Protect against register_globals vulnerabilities.
55 * This line must be present before any global variable is referenced.
66 */
7 -if( !defined( 'MEDIAWIKI' ) )
8 - die();
 7+if ( !defined( 'MEDIAWIKI' ) ){
 8+ die( "This is not a valid entry point.\n" );
 9+}
910
1011 class SpamRegex extends SpecialPage {
1112
1213 /**
13 - * Constructor
14 - */
15 - function __construct() {
 14+ * Constructor
 15+ */
 16+ public function __construct() {
1617 parent::__construct( 'SpamRegex', 'spamregex' );
1718 wfLoadExtensionMessages( 'SpamRegex' );
1819 }
@@ -21,17 +22,22 @@
2223 *
2324 * @param $par Mixed: parameter passed to the page or null
2425 */
25 - function execute( $par ) {
 26+ public function execute( $par ) {
2627 global $wgOut, $wgUser, $wgRequest;
2728
 29+ # No access for blocked users
2830 if ( $wgUser->isBlocked() ) {
2931 $wgOut->blockedPage();
3032 return;
3133 }
 34+
 35+ # Can't use the special page if database is locked...
3236 if ( wfReadOnly() ) {
3337 $wgOut->readOnlyPage();
3438 return;
3539 }
 40+
 41+ # And we'll also be needing the correct user rights in order to proceed
3642 if ( !$wgUser->isAllowed( 'spamregex' ) ) {
3743 $this->displayRestrictionError();
3844 return;
@@ -101,7 +107,7 @@
102108 global $wgOut, $wgRequest, $wgLang;
103109
104110 /* on error, display error */
105 - if ( "" != $err ) {
 111+ if ( '' != $err ) {
106112 $wgOut->addHTML( "<p class='error'>{$err}</p>\n" );
107113 }
108114
@@ -123,23 +129,23 @@
124130 while ( $row = $res->fetchObject() ) {
125131 $date = $wgLang->date( wfTimestamp( TS_MW, $row->spam_timestamp ), true );
126132 $time = $wgLang->time( wfTimestamp( TS_MW, $row->spam_timestamp ), true );
127 - $ublock_ip = urlencode($row->spam_text);
 133+ $ublock_ip = urlencode( $row->spam_text );
128134 $desc = '';
129135 if ( $row->spam_textbox == 1 ) {
130136 $desc .= wfMsg( 'spamregex-text' );
131137 }
132138 if ( $row->spam_summary == 1 ) {
133139 if ( $row->spam_textbox == 1 ) {
134 - $desc .= " ";
 140+ $desc .= ' ';
135141 }
136142 $desc .= wfMsg( 'spamregex-summary-log' );
137143 }
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>' );
141147 }
142148 $res->free();
143 - $wgOut->addHTML( "</form>" );
 149+ $wgOut->addHTML( '</form>' );
144150 $this->showPrevNext( $wgOut );
145151 }
146152 wfProfileOut( __METHOD__ );
@@ -148,7 +154,7 @@
149155 /* remove from list - without confirmation */
150156 function deleteFromList() {
151157 wfProfileIn( __METHOD__ );
152 - global $wgOut, $wgRequest, $wgUser;
 158+ global $wgOut, $wgRequest;
153159 $text = urldecode( $wgRequest->getVal( 'text' ) );
154160 /* delete */
155161 $dbw = wfGetDB( DB_MASTER );
@@ -166,7 +172,7 @@
167173 }
168174
169175 /**
170 - * fetch number of all rows
 176+ * Fetch number of all rows
171177 * Use memcached if possible
172178 */
173179 function fetchNumResults() {
@@ -199,7 +205,7 @@
200206 static function validateRegex( $text ) {
201207 try {
202208 $test = @preg_match("/{$text}/", 'Whatever');
203 - if( !is_int($test) ) {
 209+ if( !is_int( $test ) ) {
204210 throw new Exception("error!");
205211 }
206212 }
@@ -232,12 +238,12 @@
233239 global $wgContLang, $wgRequest;
234240 list( $limit, $offset ) = $wgRequest->getLimitOffset();
235241 $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+ );
242248 $out->addHTML( '<p>' . $html . '</p>' );
243249 }
244250 }
@@ -264,7 +270,7 @@
265271 $titleObj = SpecialPage::getTitleFor( 'SpamRegex' );
266272 $action = $titleObj->escapeLocalURL( "action=submit&".spamRegexList::getListBits() );
267273
268 - if ( "" != $err ) {
 274+ if ( '' != $err ) {
269275 $wgOut->setSubtitle( wfMsgHtml( 'formerror' ) );
270276 $wgOut->addHTML( "<p class='error'>{$err}</p>\n" );
271277 }
@@ -302,10 +308,10 @@
303309 addOnloadHook (SpamRegexEnhanceControls);
304310 </script>"
305311 );
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' );
310316 $wgOut->addHTML("
311317 <form name=\"spamregex\" method=\"post\" action=\"{$action}\">
312318 <table border=\"0\">
@@ -342,24 +348,24 @@
343349
344350 /* on success */
345351 function showSuccess() {
346 - global $wgOut, $wgRequest;
 352+ global $wgOut;
347353 $wgOut->setPageTitle( wfMsg( 'spamregex-page-title-2' ) );
348354 $wgOut->setSubTitle( wfMsg( 'spamregex-block-success' ) );
349 -
350 - $wgOut->addWikiMsg('spamregex-block-message', $this->mBlockedPhrase);
 355+ $wgOut->addWikiMsg( 'spamregex-block-message', $this->mBlockedPhrase );
351356 }
352357
353358 /* on submit */
354359 function doSubmit() {
355360 wfProfileIn( __METHOD__ );
356 - global $wgOut, $wgUser, $wgMemc;
 361+ global $wgOut, $wgUser;
357362
358363 /* empty name */
359 - if ( strlen($this->mBlockedPhrase) == 0 ) {
 364+ if ( strlen( $this->mBlockedPhrase ) == 0 ) {
360365 $this->showForm( wfMsgHtml( 'spamregex-warning-1' ) );
361366 wfProfileOut( __METHOD__ );
362367 return;
363368 }
 369+
364370 /* validate expression */
365371 if ( !$simple_regex = spamRegexList::validateRegex( $this->mBlockedPhrase ) ) {
366372 $this->showForm( wfMsgHtml( 'spamregex-error-1' ) );
Index: trunk/extensions/SpamRegex/SpamRegexCore.php
@@ -64,8 +64,8 @@
6565 foreach( $s_phrases as $s_phrase ) {
6666 if ( preg_match( $s_phrase, $reason, $s_matches ) ) {
6767 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>" );
7070 wfProfileOut( __METHOD__ );
7171 return false;
7272 }
@@ -91,7 +91,7 @@
9292 $res = $dbr->select( 'spam_regex', 'spam_text', array( $field => 1 ), __METHOD__ );
9393 while ( $row = $res->fetchObject() ) {
9494 $concat = $row->spam_text;
95 - $phrases [] = "/" . $concat . "/i" ;
 95+ $phrases[] = "/" . $concat . "/i";
9696 }
9797 $wgMemc->set( $key, $phrases, 0 );
9898 $res->free();

Status & tagging log