diff --git a/TitleBlacklist.list.php b/TitleBlacklist.list.php index 9772679f..9f99366f 100755 --- a/TitleBlacklist.list.php +++ b/TitleBlacklist.list.php @@ -357,26 +357,40 @@ class TitleBlacklistEntry { } /** - * Check whether a user can perform the specified action - * on the specified Title + * Check whether a user can perform the specified action on the specified Title * - * @param $title string to check - * @param $action %Action to check + * @param string $title Title to check + * @param string $action Action to check * @return bool TRUE if the the regex matches the title, and is not overridden * else false if it doesn't match (or was overridden) */ public function matches( $title, $action ) { - if ( !$title ) { + if ( $title == '' ) { return false; } - if( $action == 'new-account' && !$this->filtersNewAccounts() ) { + if ( $action === 'new-account' && !$this->filtersNewAccounts() ) { return false; } - if ( isset( $this->mParams['antispoof'] ) && is_callable( 'AntiSpoof::checkUnicodeString' ) ) { - list( $ok, $norm ) = AntiSpoof::checkUnicodeString( $title ); - if ( $ok == "OK" ) { + if ( isset( $this->mParams['antispoof'] ) + && is_callable( 'AntiSpoof::checkUnicodeString' ) + ) { + if ( $action === 'edit' ) { + // Use process cache for frequently edited pages + $cache = ObjectCache::getMainWANInstance(); + list( $ok, $norm ) = $cache->getWithSetCallback( + $cache->makeKey( 'titleblacklist', 'normalized-unicode', md5( $title ) ), + $cache::TTL_MONTH, + function () use ( $title ) { + return AntiSpoof::checkUnicodeString( $title ); + } + ); + } else { + list( $ok, $norm ) = AntiSpoof::checkUnicodeString( $title ); + } + + if ( $ok === "OK" ) { list( $ver, $title ) = explode( ':', $norm, 2 ); } else { wfDebugLog( 'TitleBlacklist', 'AntiSpoof could not normalize "' . $title . '".' ); @@ -384,7 +398,10 @@ class TitleBlacklistEntry { } wfSuppressWarnings(); - $match = preg_match( "/^(?:{$this->mRegex})$/us" . ( isset( $this->mParams['casesensitive'] ) ? '' : 'i' ), $title ); + $match = preg_match( + "/^(?:{$this->mRegex})$/us" . ( isset( $this->mParams['casesensitive'] ) ? '' : 'i' ), + $title + ); wfRestoreWarnings(); if ( $match ) { @@ -403,6 +420,7 @@ class TitleBlacklistEntry { } return true; } + return false; }