Index: trunk/extensions/HashTables/HashTables.php |
— | — | @@ -340,7 +340,7 @@ |
341 | 341 | else { |
342 | 342 | // reset specific hash tables: |
343 | 343 | foreach( $args as $arg ) { |
344 | | - $hashId = trim( $frame->expand($arg) ); |
| 344 | + $hashId = trim( $frame->expand( $arg ) ); |
345 | 345 | $store->unsetHash( $hashId ); |
346 | 346 | |
347 | 347 | } |
— | — | @@ -783,14 +783,21 @@ |
784 | 784 | } |
785 | 785 | |
786 | 786 | /** |
787 | | - * Allows to unset a certain variable |
| 787 | + * Allows to unset a certain hash. Returns whether the hash existed or not. |
788 | 788 | * |
789 | 789 | * @since 0.8 |
790 | 790 | * |
791 | | - * @param type $varName |
| 791 | + * @param string $varName |
| 792 | + * |
| 793 | + * @return boolean |
792 | 794 | */ |
793 | 795 | public function unsetHash( $hashId ) { |
794 | | - unset( $this->mHashTables[ $hashId ] ); |
| 796 | + $hashId = trim( $hashId ); |
| 797 | + if( $this->hashExists( $hashId ) ) { |
| 798 | + unset( $this->mHashTables[ $hashId ] ); |
| 799 | + return true; |
| 800 | + } |
| 801 | + return false; |
795 | 802 | } |
796 | 803 | |
797 | 804 | /** |
— | — | @@ -801,7 +808,13 @@ |
802 | 809 | * @return boolean |
803 | 810 | */ |
804 | 811 | static function isValidRegEx( $pattern ) { |
805 | | - return preg_match( '/^([\\/\\|%]).*\\1[imsSuUx]*$/', $pattern ); |
| 812 | + if( ! preg_match( '/^([\\/\\|%]).*\\1[imsSuUx]*$/', $pattern ) ) { |
| 813 | + return false; |
| 814 | + } |
| 815 | + wfSuppressWarnings(); // instead of using the evil @ operator! |
| 816 | + $isValid = false !== preg_match( $pattern, ' ' ); // preg_match returns false on error |
| 817 | + wfRestoreWarnings(); |
| 818 | + return $isValid; |
806 | 819 | } |
807 | 820 | |
808 | 821 | } |