Fixed spacing
[lhc/web/wiklou.git] / includes / parser / Preprocessor_DOM.php
index c9e16b3..3138f48 100644 (file)
@@ -183,21 +183,21 @@ class Preprocessor_DOM implements Preprocessor {
                        $xml = UtfNormal::cleanUp( $xml );
                        // 1 << 19 == XML_PARSE_HUGE, needed so newer versions of libxml2 don't barf when the XML is >256 levels deep
                        $result = $dom->loadXML( $xml, 1 << 19 );
-                       if ( !$result ) {
-                               wfProfileOut( __METHOD__ . '-loadXML' );
-                               if ( $cacheable ) {
-                                       wfProfileOut( __METHOD__ . '-cacheable' );
-                               }
-                               wfProfileOut( __METHOD__ );
-                               throw new MWException( __METHOD__ . ' generated invalid XML' );
-                       }
                }
-               $obj = new PPNode_DOM( $dom->documentElement );
+               if ( $result ) {
+                       $obj = new PPNode_DOM( $dom->documentElement );
+               }
                wfProfileOut( __METHOD__ . '-loadXML' );
+
                if ( $cacheable ) {
                        wfProfileOut( __METHOD__ . '-cacheable' );
                }
+
                wfProfileOut( __METHOD__ );
+
+               if ( !$result ) {
+                       throw new MWException( __METHOD__ . ' generated invalid XML' );
+               }
                return $obj;
        }
 
@@ -376,11 +376,11 @@ class Preprocessor_DOM implements Preprocessor {
                                                $i = $lengthText;
                                        } else {
                                                // Search backwards for leading whitespace
-                                               $wsStart = $i ? ( $i - strspn( $revText, ' ', $lengthText - $i ) ) : 0;
+                                               $wsStart = $i ? ( $i - strspn( $revText, " \t", $lengthText - $i ) ) : 0;
 
                                                // Search forwards for trailing whitespace
                                                // $wsEnd will be the position of the last space (or the '>' if there's none)
-                                               $wsEnd = $endPos + 2 + strspn( $text, ' ', $endPos + 3 );
+                                               $wsEnd = $endPos + 2 + strspn( $text, " \t", $endPos + 3 );
 
                                                // Keep looking forward as long as we're finding more
                                                // comments.
@@ -390,7 +390,7 @@ class Preprocessor_DOM implements Preprocessor {
                                                        if ( $c === false ) {
                                                                break;
                                                        }
-                                                       $c = $c + 2 + strspn( $text, ' ', $c + 3 );
+                                                       $c = $c + 2 + strspn( $text, " \t", $c + 3 );
                                                        $comments[] = array( $wsEnd + 1, $c );
                                                        $wsEnd = $c;
                                                }
@@ -405,7 +405,9 @@ class Preprocessor_DOM implements Preprocessor {
                                                        // Remove leading whitespace from the end of the accumulator
                                                        // Sanity check first though
                                                        $wsLength = $i - $wsStart;
-                                                       if ( $wsLength > 0 && substr( $accum, -$wsLength ) === str_repeat( ' ', $wsLength ) ) {
+                                                       if ( $wsLength > 0
+                                                               && strspn( $accum, " \t", -$wsLength ) === $wsLength )
+                                                       {
                                                                $accum = substr( $accum, 0, -$wsLength );
                                                        }
 
@@ -413,10 +415,10 @@ class Preprocessor_DOM implements Preprocessor {
                                                        foreach ( $comments as $j => $com ) {
                                                                $startPos = $com[0];
                                                                $endPos = $com[1] + 1;
-                                                               if ( $j == ( count( $comments ) - 1) ) {
+                                                               if ( $j == ( count( $comments ) - 1 ) ) {
                                                                        break;
                                                                }
-                                                               $inner = substr( $text, $startPos, $endPos - $startPos);
+                                                               $inner = substr( $text, $startPos, $endPos - $startPos );
                                                                $accum .= '<comment>' . htmlspecialchars( $inner ) . '</comment>';
                                                        }