* Fixed loop detection in LST
authorTim Starling <tstarling@users.mediawiki.org>
Mon, 14 Jan 2008 06:59:20 +0000 (06:59 +0000)
committerTim Starling <tstarling@users.mediawiki.org>
Mon, 14 Jan 2008 06:59:20 +0000 (06:59 +0000)
* Renamed some LST parser tests
* Fixed <gallery> caption behaviour .It should not generate <pre> when there are spaces at the start. Used recursiveTagParse() instead of parse(), to avoid generation of a limit report, among other things.
* Refactored template loop check
* Updated a couple of parser tests

includes/Parser.php
maintenance/parserTests.txt

index 06007e9..226cc2e 100644 (file)
@@ -3371,7 +3371,7 @@ class Parser
                                        $wgContLang->findVariantLink($part1, $title);
                                }
                                # Do infinite loop check
-                               if ( isset( $frame->loopCheckHash[$titleText] ) ) {
+                               if ( !$frame->loopCheck( $title ) ) {
                                        $found = true;
                                        $text = "<span class=\"error\">Template loop detected: [[$titleText]]</span>";
                                        wfDebug( __METHOD__.": template loop broken at '$titleText'\n" );
@@ -3440,8 +3440,6 @@ class Parser
                if ( $isDOM ) {
                        # Clean up argument array
                        $newFrame = $frame->newChild( $args, $title );
-                       # Add a new element to the templace loop detection hashtable
-                       $newFrame->loopCheckHash[$titleText] = true;
 
                        if ( $titleText !== false && $newFrame->isEmpty() ) {
                                # Expansion is eligible for the empty-frame cache
@@ -4806,13 +4804,7 @@ class Parser
                                $label = '';
                        }
 
-                       $pout = $this->parse( $label,
-                               $this->mTitle,
-                               $this->mOptions,
-                               false, // Strip whitespace...?
-                               false  // Don't clear state!
-                       );
-                       $html = $pout->getText();
+                       $html = $this->recursiveTagParse( trim( $label ) );
 
                        $ig->add( $nt, $html );
 
@@ -5621,6 +5613,13 @@ class PPFrame {
        function getArgument( $name ) {
                return false;
        }
+
+       /**
+        * Returns true if the infinite loop check is OK, false if a loop is detected
+        */
+       function loopCheck( $title ) {
+               return !isset( $this->loopCheckHash[$title->getPrefixedDBkey()] );
+       }
 }
 
 /**
@@ -5636,9 +5635,13 @@ class PPTemplateFrame extends PPFrame {
                $this->numberedArgs = $numberedArgs;
                $this->namedArgs = $namedArgs;
                $this->title = $title;
+               $pdbk = $title ? $title->getPrefixedDBkey() : false;
                $this->titleCache = $parent->titleCache;
-               $this->titleCache[] = $title ? $title->getPrefixedDBkey() : false;
+               $this->titleCache[] = $pdbk;
                $this->loopCheckHash = /*clone*/ $parent->loopCheckHash;
+               if ( $pdbk !== false ) {
+                       $this->loopCheckHash[$pdbk] = true;
+               }
                $this->depth = $parent->depth + 1;
                $this->numberedExpansionCache = $this->namedExpansionCache = array();
        }
index 28f3023..c6af74f 100644 (file)
@@ -2410,7 +2410,7 @@ Template infinite loop
 !! input
 {{loop1}}
 !! result
-<p><a href="/index.php?title=Loop1&amp;action=edit" class="new" title="Loop1">loop1</a><!-- WARNING: template loop detected -->
+<p><span class="error">Template loop detected: <a href="/wiki/Template:Loop1" title="Template:Loop1">Template:Loop1</a></span>
 </p>
 !! end
 
@@ -5972,8 +5972,8 @@ image4    |300px| centre
                <td><div class="gallerybox" style="width: 155px;">
                        <div style="height: 152px;">Image5.svg</div>
                        <div class="gallerytext">
-<pre><a href="http://///////" class="external free" title="http://///////" rel="nofollow">http://///////</a>
-</pre>
+<p><a href="http://///////" class="external free" title="http://///////" rel="nofollow">http://///////</a>
+</p>
                        </div>
                </div></td>
                <td><div class="gallerybox" style="width: 155px;">