From: Wil Mahan Date: Tue, 5 Oct 2004 00:17:25 +0000 (+0000) Subject: Move length check to secureAndSplit(), so it is always used. X-Git-Tag: 1.5.0alpha1~1657 X-Git-Url: http://git.cyclocoop.org/%24action?a=commitdiff_plain;h=da2c08db84828628ac56fc4cf7c8a15119db8b0b;p=lhc%2Fweb%2Fwiklou.git Move length check to secureAndSplit(), so it is always used. Also, don't query the DB for the max length, but use a hardcoded 255. --- diff --git a/includes/Parser.php b/includes/Parser.php index f1fc4b56f9..df6f4b3e4a 100644 --- a/includes/Parser.php +++ b/includes/Parser.php @@ -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; } diff --git a/includes/SpecialMovepage.php b/includes/SpecialMovepage.php index 4f0c48d580..ebbd79db2a 100644 --- a/includes/SpecialMovepage.php +++ b/includes/SpecialMovepage.php @@ -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; }