Move length check to secureAndSplit(), so it is always used.
authorWil Mahan <wmahan@users.mediawiki.org>
Tue, 5 Oct 2004 00:17:25 +0000 (00:17 +0000)
committerWil Mahan <wmahan@users.mediawiki.org>
Tue, 5 Oct 2004 00:17:25 +0000 (00:17 +0000)
Also, don't query the DB for the max length, but use a
hardcoded 255.

includes/Parser.php
includes/SpecialMovepage.php

index f1fc4b5..df6f4b3 100644 (file)
@@ -669,8 +669,6 @@ class Parser
                }
                $text = $this->doAllQuotes( $text );
                $text = $this->replaceInternalLinks ( $text );
-               # Another call to replace links and images inside captions of images
-               $text = $this->replaceInternalLinks ( $text );
                $text = $this->replaceExternalLinks( $text );
                $text = $this->doMagicLinks( $text );
                $text = $this->doTableStuff( $text );
@@ -1105,8 +1103,9 @@ class Parser
 
                wfProfileOut( $fname.'-setup' );
 
-               # start procedeeding each line
-               foreach ( $a as $line ) {
+               # Loop for each link
+               for ($k = 0; isset( $a[$k] ); $k++) {
+                       $line = $a[$k];
                        wfProfileIn( $fname.'-prefixhandling' );
                        if ( $useLinkPrefixExtension ) {
                                if ( preg_match( $e2, $s, $m ) ) {
@@ -1123,14 +1122,56 @@ class Parser
                        }
                        wfProfileOut( $fname.'-prefixhandling' );
 
+                       $nt = false;
                        if ( preg_match( $e1, $line, $m ) ) { # page with normal text or alt
                                $text = $m[2];
                                # fix up urlencoded title texts
                                if(preg_match('/%/', $m[1] )) $m[1] = urldecode($m[1]);
                                $trail = $m[3];
-                       } else { # Invalid form; output directly
-                               $s .= $prefix . '[[' . $line ;
-                               continue;
+                       }
+                       else {
+                               # Image captions are a special case: they
+                               # may contain other links, so check for them
+                               # and replace links inside them if necessary.
+                               # If the image caption contains a link,
+                               # it will be cut short, so fix it first.
+                               $orig_line = $line;
+                               $found = false;
+                               if (strpos( $line, ']]' ) === false ) {
+                                       # Keep adding to $line until we find the matching ']]'
+                                       while (isset ($a[$k+1]) ) {
+                                               $line .=  '[[' . array_shift(array_splice( $a, $k + 1, 1) );
+                                               if ( substr_count( $line, '[[' ) === substr_count( $line, ']]' ) - 1 )
+                                               {
+                                                       $found = true;
+                                                       break;
+                                               }
+                                       }
+                               }
+
+                               if ($found) {
+                                       # Recursively do links inside [[Image:...]].
+                                       # In theory, we only need to do this for the
+                                       # image caption, but including the other options
+                                       # is simpler and shouldn't hurt anything.
+                                       $found = preg_match( $e1, $line, $m );
+                                       echo "wtm: line $line\n";
+                               }
+
+                               if ($found) {
+                                       $text = $m[2];
+                                       $trail = $m[3];
+                               }
+
+                               if ( $found ) {
+                                       $nt = Title::newFromText( $m[1] );
+                                       $found = !is_null($nt);
+                               }
+                               if (!$found || $nt->getNamespace() != NS_IMAGE ) {
+                                       # Invalid form; output directly
+                                       $s .= $prefix . '[[' . $orig_line ;
+                                       continue;
+                               }
                        }
 
                        # Don't allow internal links to pages containing
@@ -1153,7 +1194,9 @@ class Parser
                        $wasblank = ( '' == $text );
                        if( $wasblank ) $text = $link;
 
-                       $nt = Title::newFromText( $link );
+                       if (!$nt) {
+                               $nt = Title::newFromText( $link );
+                       }
                        if( !$nt ) {
                                $s .= $prefix . '[[' . $line;
                                continue;
@@ -1197,7 +1240,7 @@ class Parser
                                }
                                
                                if ( $ns == NS_IMAGE ) {
-                                       $s .= $prefix . $sk->makeImageLinkObj( $nt, $text ) . $trail;
+                                       $s .= $prefix . $this->insertStripItem( $sk->makeImageLinkObj( $nt, $text ), $this->mStripState ) . $trail;
                                        $wgLinkCache->addImageLinkObj( $nt );
                                        continue;
                                }
index 4f0c48d..ebbd79d 100644 (file)
@@ -130,7 +130,7 @@ class MovePageForm {
                $nt = Title::newFromText( $this->newTitle );
 
                # don't allow moving to pages with # in
-               if ( $nt->getFragment() != '' ) {
+               if ( !$nt || $nt->getFragment() != '' ) {
                        $this->showForm( wfMsg( "badtitletext" ) );
                        return;
                }