r64280 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r64279‎ | r64280 | r64281 >
Date:00:50, 28 March 2010
Author:soxred93
Status:deferred (Comments)
Tags:
Comment:
Adding irlike function: case-insensitive regex
Modified paths:
  • /trunk/extensions/AbuseFilter/AbuseFilter.class.php (modified) (history)
  • /trunk/extensions/AbuseFilter/AbuseFilter.i18n.php (modified) (history)
  • /trunk/extensions/AbuseFilter/AbuseFilter.parser.php (modified) (history)

Diff [purge]

Index: trunk/extensions/AbuseFilter/AbuseFilter.parser.php
@@ -198,12 +198,14 @@
199199 return new AFPData( self::DBool, (bool)$result );
200200 }
201201
202 - public static function keywordRegex( $str, $regex, $pos ) {
 202+ public static function keywordRegex( $str, $regex, $pos, $insensitive = false ) {
203203 $str = $str->toString();
204204 $pattern = $regex = $regex->toString();
205205
206206 $pattern = preg_replace( '!(\\\\\\\\)*(\\\\)?/!', '$1\/', $pattern );
207207 $pattern = "/$pattern/u";
 208+
 209+ if( $insensitive ) $pattern .= "i";
208210
209211 try {
210212 set_error_handler( array( 'AbuseFilterParser', 'regexErrorHandler' ) );
@@ -215,6 +217,10 @@
216218 }
217219 return new AFPData( self::DBool, (bool)$result );
218220 }
 221+
 222+ public static function keywordRegexInsensitive( $str, $regex, $pos ) {
 223+ return self::keywordRegex( $str, $regex, $pos, true );
 224+ }
219225
220226 public static function unaryMinus( $data ) {
221227 if ( $data->type == self::DInt ) {
@@ -403,7 +409,7 @@
404410 );
405411 static $mKeywords = array(
406412 'in', 'like', 'true', 'false', 'null', 'contains', 'matches',
407 - 'rlike', 'regex', 'if', 'then', 'else', 'end',
 413+ 'rlike', 'irlike', 'regex', 'if', 'then', 'else', 'end',
408414 );
409415
410416 static $parserCache = array();
@@ -837,6 +843,7 @@
838844 'matches' => 'keywordLike',
839845 'contains' => 'keywordContains',
840846 'rlike' => 'keywordRegex',
 847+ 'irlike' => 'keywordRegexInsensitive',
841848 'regex' => 'keywordRegex'
842849 );
843850 if ( $this->mCur->type == AFPToken::TKeyword && in_array( $keyword, array_keys( $specwords ) ) ) {
Index: trunk/extensions/AbuseFilter/AbuseFilter.class.php
@@ -49,6 +49,7 @@
5050 'like' => 'like',
5151 '""' => 'stringlit',
5252 'rlike' => 'rlike',
 53+ 'irlike' => 'irlike',
5354 'cond ? iftrue : iffalse' => 'tern',
5455 'if cond then iftrue else iffalse end' => 'cond',
5556 ),
Index: trunk/extensions/AbuseFilter/AbuseFilter.i18n.php
@@ -250,6 +250,7 @@
251251 'abusefilter-edit-builder-misc-in' => 'contained in string (in)',
252252 'abusefilter-edit-builder-misc-like' => 'Matches pattern (like)',
253253 'abusefilter-edit-builder-misc-rlike' => 'Matches regex (rlike)',
 254+ 'abusefilter-edit-builder-misc-rlike' => 'Matches regex, case insensitive (irlike)',
254255 'abusefilter-edit-builder-misc-contains' => 'Left string contains right string (contains)',
255256 'abusefilter-edit-builder-misc-stringlit' => 'String literal ("")',
256257 'abusefilter-edit-builder-misc-tern' => 'Ternary operator (X ? Y : Z)',

Follow-up revisions

RevisionCommit summaryAuthorDate
r64284Follow-up r64280: Fix message keyraymond07:00, 28 March 2010

Comments

#Comment by Werdna (talk | contribs)   00:53, 29 March 2010

Useless. You can just use /whatever/i in the regex function.

I'll revert this later on.

#Comment by X! (talk | contribs)   22:22, 2 April 2010

I tested this theory, it doesn't work.

Status & tagging log