From: Brion Vibber
Date: Tue, 31 May 2005 08:49:03 +0000 (+0000)
Subject: * (bug 2271) Use faster text-only link replacement in image alt text
X-Git-Tag: 1.5.0alpha2~25
X-Git-Url: https://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/banques/ajouter.php?a=commitdiff_plain;h=1c537909667afe69069e171ff7b2313668fffc57;p=lhc%2Fweb%2Fwiklou.git
* (bug 2271) Use faster text-only link replacement in image alt text
instead of rerunning expensive link lookup and HTML generation.
---
diff --git a/RELEASE-NOTES b/RELEASE-NOTES
index bfe233f519..bbbb56aa7a 100644
--- a/RELEASE-NOTES
+++ b/RELEASE-NOTES
@@ -225,7 +225,8 @@ Various bugfixes, small features, and a few experimental things:
* (bug 2267) Don't generate thumbnail at the same size as the source image.
* Fix rebuildtextindex.inc for new schema
* Remove linkscc table code, no longer used.
-
+* (bug 2271) Use faster text-only link replacement in image alt text
+ instead of rerunning expensive link lookup and HTML generation.
=== Caveats ===
diff --git a/includes/Parser.php b/includes/Parser.php
index 7d657ccdb0..d532f89f4b 100644
--- a/includes/Parser.php
+++ b/includes/Parser.php
@@ -3000,10 +3000,52 @@ class Parser
$text );
wfProfileOut( $fname.'-interwiki' );
}
-
+
wfProfileOut( $fname );
return $colours;
}
+
+ /**
+ * Replace link placeholders with plain text of links
+ * (not HTML-formatted).
+ * @param string $text
+ * @return string
+ */
+ function replaceLinkHoldersText( $text ) {
+ global $wgUser, $wgLinkCache;
+ global $wgOutputReplace;
+
+ $fname = 'Parser::replaceLinkHoldersText';
+ wfProfileIn( $fname );
+
+ $text = preg_replace_callback(
+ '//',
+ array( &$this, 'replaceLinkHoldersTextCallback' ),
+ $text );
+
+ wfProfileOut( $fname );
+ return $text;
+ }
+
+ /**
+ * @param array $matches
+ * @return string
+ * @access private
+ */
+ function replaceLinkHoldersTextCallback( $matches ) {
+ $type = $matches[1];
+ $key = $matches[2];
+ if( $type == 'LINK' ) {
+ if( isset( $this->mLinkHolders['texts'][$key] ) ) {
+ return $this->mLinkHolders['texts'][$key];
+ }
+ } elseif( $type == 'IWLINK' ) {
+ if( isset( $this->mInterwikiLinkHolders[$key][1] ) ) {
+ return $this->mInterwikiLinkHolders[$key][1];
+ }
+ }
+ return $matches[0];
+ }
/**
* Renders an image gallery from a text with one line per image.
@@ -3125,8 +3167,7 @@ class Parser
}
}
# Strip bad stuff out of the alt text
- $alt = $caption;
- $this->replaceLinkHolders( $alt );
+ $alt = $this->replaceLinkHoldersText( $caption );
$alt = Sanitizer::stripAllTags( $alt );
# Linker does the rest
diff --git a/maintenance/parserTests.txt b/maintenance/parserTests.txt
index c321b37a35..16b1e36b79 100644
--- a/maintenance/parserTests.txt
+++ b/maintenance/parserTests.txt
@@ -1728,6 +1728,33 @@ BUG 648: Frameless image caption with a link
!! end
+!! test
+BUG 648: Frameless image caption with a link (suffix)
+!! input
+[[Image:foobar.jpg|text with a [[link]]foo in it]]
+!! result
+
+
+!! end
+
+!! test
+BUG 648: Frameless image caption with an interwiki link
+!! input
+[[Image:foobar.jpg|text with a [[MeatBall:Link]] in it]]
+!! result
+
+
+!! end
+
+!! test
+BUG 648: Frameless image caption with a piped interwiki link
+!! input
+[[Image:foobar.jpg|text with a [[MeatBall:Link|link]] in it]]
+!! result
+
+
+!! end
+
!! test
Escape HTML special chars in image alt text
!! input