r99060 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r99059‎ | r99060 | r99061 >
Date:23:39, 5 October 2011
Author:aaron
Status:ok (Comments)
Tags:
Comment:
MFT r99059
Modified paths:
  • /branches/wmf/1.18wmf1/extensions/AbuseFilter/AbuseFilter.parser.php (modified) (history)

Diff [purge]

Index: branches/wmf/1.18wmf1/extensions/AbuseFilter/AbuseFilter.parser.php
@@ -216,12 +216,13 @@
217217 $pattern .= 'i';
218218 }
219219
 220+ $handler = new AFPRegexErrorHandler( $pattern, $pos );
220221 try {
221 - set_error_handler( array( 'AbuseFilterParser', 'regexErrorHandler' ) );
 222+ $handler->install();
222223 $result = preg_match( $pattern, $str );
223 - restore_error_handler();
 224+ $handler->restore();
224225 } catch ( Exception $e ) {
225 - restore_error_handler();
 226+ $handler->restore();
226227 throw $e;
227228 }
228229 return new AFPData( self::DBool, (bool)$result );
@@ -381,6 +382,32 @@
382383 }
383384 }
384385
 386+class AFPRegexErrorHandler {
 387+ function __construct( $regex, $pos ) {
 388+ $this->regex = $regex;
 389+ $this->pos = $pos;
 390+ }
 391+
 392+ function handleError( $errno, $errstr, $errfile, $errline, $context ) {
 393+ if ( error_reporting() == 0 ) {
 394+ return true;
 395+ }
 396+ throw new AFPUserVisibleException(
 397+ 'regexfailure',
 398+ $this->pos,
 399+ array( $errstr, $this->regex )
 400+ );
 401+ }
 402+
 403+ function install() {
 404+ set_error_handler( array( $this, 'handleError' ) );
 405+ }
 406+
 407+ function restore() {
 408+ restore_error_handler();
 409+ }
 410+}
 411+
385412 class AbuseFilterParser {
386413 var $mParams, $mVars, $mCode, $mTokens, $mPos, $mCur, $mShortCircuit, $mAllowShort;
387414
@@ -1453,12 +1480,13 @@
14541481
14551482 $matches = array();
14561483
 1484+ $handler = new AFPRegexErrorHandler( $needle, $this->mCur->pos );
14571485 try {
1458 - set_error_handler( array( 'AbuseFilterParser', 'regexErrorHandler' ) );
 1486+ $handler->install();
14591487 $count = preg_match_all( $needle, $haystack, $matches );
1460 - restore_error_handler();
 1488+ $handler->restore();
14611489 } catch ( Exception $e ) {
1462 - restore_error_handler();
 1490+ $handler->restore();
14631491 throw $e;
14641492 }
14651493 }
@@ -1742,17 +1770,6 @@
17431771
17441772 return AFPData::castTypes( $val, AFPData::DBool );
17451773 }
1746 -
1747 - public static function regexErrorHandler( $errno, $errstr, $errfile, $errline, $context ) {
1748 - if ( error_reporting() == 0 ) {
1749 - return true;
1750 - }
1751 - throw new AFPUserVisibleException(
1752 - 'regexfailure',
1753 - $context['pos'],
1754 - array( $errstr, $context['regex'] )
1755 - );
1756 - }
17571774 }
17581775
17591776 # Taken from http://au2.php.net/manual/en/function.fnmatch.php#71725

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r99059(bug 31379) Don't use the $errcontext parameter of a PHP error handler to get...tstarling23:31, 5 October 2011

Comments

#Comment by Krinkle (talk | contribs)   00:48, 6 October 2011

Hi, do you mind mentioning the target branch in the commit message of future MFT's ?

Makes the workflow a bit smoother on pages like these. Thanks!

Status & tagging log