Minor fix to primeFileCache() comment
[lhc/web/wiklou.git] / includes / MagicWord.php
index 7476fcf..424735e 100644 (file)
@@ -652,7 +652,7 @@ class MagicWord {
         * This method uses the php feature to do several replacements at the same time,
         * thereby gaining some efficiency. The result is placed in the out variable
         * $result. The return value is true if something was replaced.
-        * @todo Should this be static? It doesn't seem to be used at all
+        * @deprecated since 1.25, unused
         *
         * @param array $magicarr
         * @param string $subject
@@ -661,6 +661,7 @@ class MagicWord {
         * @return bool
         */
        function replaceMultiple( $magicarr, $subject, &$result ) {
+               wfDeprecated( __METHOD__, '1.25' );
                $search = array();
                $replace = array();
                foreach ( $magicarr as $id => $replacement ) {
@@ -717,9 +718,6 @@ class MagicWordArray {
 
        private $regex;
 
-       /** @todo Unused? */
-       private $matches;
-
        /**
         * @param array $names
         */
@@ -943,6 +941,7 @@ class MagicWordArray {
         *
         * @param string $text
         *
+        * @throws Exception
         * @return array
         */
        public function matchAndRemove( &$text ) {
@@ -952,12 +951,23 @@ class MagicWordArray {
                        if ( $regex === '' ) {
                                continue;
                        }
-                       preg_match_all( $regex, $text, $matches, PREG_SET_ORDER );
-                       foreach ( $matches as $m ) {
-                               list( $name, $param ) = $this->parseMatch( $m );
-                               $found[$name] = $param;
+                       $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 ) {
+                               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' );
                        }
-                       $text = preg_replace( $regex, '', $text );
                }
                return $found;
        }