Http::getProxy() method to get proxy configuration
[lhc/web/wiklou.git] / includes / MagicWord.php
index 424735e..80e60d2 100644 (file)
@@ -23,6 +23,8 @@
  * @ingroup Parser
  */
 
+use MediaWiki\Logger\LoggerFactory;
+
 /**
  * This class encapsulates "magic words" such as "#redirect", __NOTOC__, etc.
  *
@@ -941,7 +943,6 @@ class MagicWordArray {
         *
         * @param string $text
         *
-        * @throws Exception
         * @return array
         */
        public function matchAndRemove( &$text ) {
@@ -952,22 +953,28 @@ class MagicWordArray {
                                continue;
                        }
                        $matches = array();
-                       $matched = preg_match_all( $regex, $text, $matches, PREG_SET_ORDER );
-                       if ( $matched === false ) {
-                               throw new Exception( __METHOD__ . ': preg_match_all returned false' );
-                       }
-                       if ( $matched ) {
+                       $res = preg_match_all( $regex, $text, $matches, PREG_SET_ORDER );
+                       if ( $res === false ) {
+                               LoggerFactory::getInstance( 'parser' )->warning( 'preg_match_all returned false', array(
+                                       'code' => preg_last_error(),
+                                       'regex' => $regex,
+                                       'text' => $text,
+                               ) );
+                       } elseif ( $res ) {
                                foreach ( $matches as $m ) {
                                        list( $name, $param ) = $this->parseMatch( $m );
                                        $found[$name] = $param;
                                }
                        }
-                       $replaced = preg_replace( $regex, '', $text );
-                       if ( $replaced !== null ) {
-                               $text = $replaced;
-                       } else {
-                               throw new Exception( __METHOD__ . ': preg_replace returned null' );
+                       $res = preg_replace( $regex, '', $text );
+                       if ( $res === null ) {
+                               LoggerFactory::getInstance( 'parser' )->warning( 'preg_replace returned null', array(
+                                       'code' => preg_last_error(),
+                                       'regex' => $regex,
+                                       'text' => $text,
+                               ) );
                        }
+                       $text = $res;
                }
                return $found;
        }