Merge "Clean up Language::markNoConversion()."
authorNikerabbit <niklas.laxstrom@gmail.com>
Fri, 23 Nov 2012 13:01:08 +0000 (13:01 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Fri, 23 Nov 2012 13:01:08 +0000 (13:01 +0000)
includes/parser/Parser.php
languages/Language.php
languages/classes/LanguageGan.php
languages/classes/LanguageIu.php
languages/classes/LanguageKk.php
languages/classes/LanguageKu.php
languages/classes/LanguageShi.php
languages/classes/LanguageSr.php
languages/classes/LanguageZh.php
tests/parser/parserTests.txt

index 36b682e..f664e49 100644 (file)
@@ -1314,7 +1314,8 @@ class Parser {
                if ( $text === false ) {
                        # Not an image, make a link
                        $text = Linker::makeExternalLink( $url,
-                               $this->getConverterLanguage()->markNoConversion($url), true, 'free',
+                               $this->getConverterLanguage()->markNoConversion( $url, true ),
+                               true, 'free',
                                $this->getExternalLinkAttribs( $url ) );
                        # Register it in the output object...
                        # Replace unnecessary URL escape codes with their equivalent characters
index 437d3c4..7475d2f 100644 (file)
@@ -3704,15 +3704,24 @@ class Language {
        }
 
        /**
-        * Enclose a string with the "no conversion" tag. This is used by
-        * various functions in the Parser
+        * Prepare external link text for conversion. When the text is
+        * a URL, it shouldn't be converted, and it'll be wrapped in
+        * the "raw" tag (-{R| }-) to prevent conversion.
         *
-        * @param $text String: text to be tagged for no conversion
-        * @param $noParse bool
+        * This function is called "markNoConversion" for historical
+        * reasons.
+        *
+        * @param $text String: text to be used for external link
+        * @param $noParse bool: wrap it without confirming it's a real URL first
         * @return string the tagged text
         */
        public function markNoConversion( $text, $noParse = false ) {
-               return $this->mConverter->markNoConversion( $text, $noParse );
+               // Excluding protocal-relative URLs may avoid many false positives.
+               if ( $noParse || preg_match( '/^(?:' . wfUrlProtocolsWithoutProtRel() . ')/', $text ) ) {
+                       return $this->mConverter->markNoConversion( $text );
+               } else {
+                       return $text;
+               }
        }
 
        /**
index 6482070..0d652d4 100644 (file)
@@ -66,20 +66,6 @@ class GanConverter extends LanguageConverter {
                );
        }
 
-       /**
-        * there shouldn't be any latin text in Chinese conversion, so no need
-        * to mark anything.
-        * $noParse is there for compatibility with LanguageConvert::markNoConversion
-        *
-        * @param $text string
-        * @param $noParse bool
-        *
-        * @return string
-        */
-       function markNoConversion( $text, $noParse = false ) {
-               return $text;
-       }
-
        /**
         * @param $key string
         * @return String
index 79e5582..fe5cdf8 100644 (file)
@@ -157,21 +157,6 @@ class IuConverter extends LanguageConverter {
                        $link = $oldlink;
        }
 
-       /**
-        * We want our external link captions to be converted in variants,
-        * so we return the original text instead -{$text}-, except for URLs
-        *
-        * @param $text string
-        * @param $noParse bool
-        *
-        * @return string
-        */
-       function markNoConversion( $text, $noParse = false ) {
-               if ( $noParse || preg_match( "/^https?:\/\/|ftp:\/\/|irc:\/\//", $text ) )
-                       return parent::markNoConversion( $text );
-               return $text;
-       }
-
        /**
         * An ugly function wrapper for parsing Image titles
         * (to prevent image name conversion)
index bdaf2f4..6dd6959 100644 (file)
@@ -390,21 +390,6 @@ class KkConverter extends LanguageConverter {
                }
        }
 
-       /**
-        * We want our external link captions to be converted in variants,
-        * so we return the original text instead -{$text}-, except for URLs
-        *
-        * @param $text string
-        * @param $noParse string|bool
-        *
-        * @return string
-        */
-       function markNoConversion( $text, $noParse = false ) {
-               if ( $noParse || preg_match( "/^https?:\/\/|ftp:\/\/|irc:\/\//", $text ) )
-                       return parent::markNoConversion( $text );
-               return $text;
-       }
-
        /**
         * @param $key string
         * @return String
index 0eac439..30d98ba 100644 (file)
@@ -177,21 +177,6 @@ class KuConverter extends LanguageConverter {
                        $link = $oldlink;
        }
 
-       /**
-        * We want our external link captions to be converted in variants,
-        * so we return the original text instead -{$text}-, except for URLs
-        *
-        * @param $text string
-        * @param $noParse bool
-        *
-        * @return string
-        */
-       function markNoConversion( $text, $noParse = false ) {
-               if ( $noParse || preg_match( "/^https?:\/\/|ftp:\/\/|irc:\/\//", $text ) )
-                   return parent::markNoConversion( $text );
-               return $text;
-       }
-
        /**
         * An ugly function wrapper for parsing Image titles
         * (to prevent image name conversion)
index 4833d1c..5ddcfde 100644 (file)
@@ -136,21 +136,6 @@ class ShiConverter extends LanguageConverter {
                        $link = $oldlink;
        }
 
-       /**
-        * We want our external link captions to be converted in variants,
-        * so we return the original text instead -{$text}-, except for URLs
-        *
-        * @param $text string
-        * @param $noParse bool
-        *
-        * @return string
-        */
-       function markNoConversion( $text, $noParse = false ) {
-               if ( $noParse || preg_match( "/^https?:\/\/|ftp:\/\/|irc:\/\//", $text ) )
-                       return parent::markNoConversion( $text );
-               return $text;
-       }
-
        /**
         * An ugly function wrapper for parsing Image titles
         * (to prevent image name conversion)
index b472743..3610c1e 100644 (file)
@@ -128,21 +128,6 @@ class SrConverter extends LanguageConverter {
                        $link = $oldlink;
        }
 
-       /**
-        * We want our external link captions to be converted in variants,
-        * so we return the original text instead -{$text}-, except for URLs
-        *
-        * @param $text string
-        * @param $noParse bool
-        *
-        * @return string
-        */
-       function markNoConversion( $text, $noParse = false ) {
-               if ( $noParse || preg_match( "/^https?:\/\/|ftp:\/\/|irc:\/\//", $text ) )
-                       return parent::markNoConversion( $text );
-               return $text;
-       }
-
        /**
         * An ugly function wrapper for parsing Image titles
         * (to prevent image name conversion)
index 8bf66a3..04767f2 100644 (file)
@@ -87,20 +87,6 @@ class ZhConverter extends LanguageConverter {
                $this->mTables['zh-tw']->merge( $this->mTables['zh-hant'] );
        }
 
-       /**
-        * there shouldn't be any latin text in Chinese conversion, so no need
-        * to mark anything.
-        * $noParse is there for compatibility with LanguageConvert::markNoConversion
-        *
-        * @param $text string
-        * @param $noParse bool
-        *
-        * @return string
-        */
-       function markNoConversion( $text, $noParse = false ) {
-               return $text;
-       }
-
        /**
         * @param $key string
         * @return String
index 03a184b..0384434 100644 (file)
@@ -10623,6 +10623,29 @@ Nested: -{zh-hans:Hi -{zh-cn:China;zh-sg:Singapore;}-;zh-hant:Hello -{zh-tw:Taiw
 </p>
 !! end
 
+!! test
+Proper conversion of text in external links
+!! options
+language=sr variant=sr-ec
+!! input
+http://www.google.com
+gopher://www.google.com
+[http://www.google.com http://www.google.com]
+[gopher://www.google.com gopher://www.google.com]
+[https://www.google.com irc://www.google.com]
+[ftp://www.google.com www.google.com/ftp://dir]
+[//www.google.com www.google.com]
+!! result
+<p><a rel="nofollow" class="external free" href="http://www.google.com">http://www.google.com</a>
+<a rel="nofollow" class="external free" href="gopher://www.google.com">gopher://www.google.com</a>
+<a rel="nofollow" class="external free" href="http://www.google.com">http://www.google.com</a>
+<a rel="nofollow" class="external free" href="gopher://www.google.com">gopher://www.google.com</a>
+<a rel="nofollow" class="external text" href="https://www.google.com">irc://www.google.com</a>
+<a rel="nofollow" class="external text" href="ftp://www.google.com">www.гоогле.цом/фтп://дир</a>
+<a rel="nofollow" class="external text" href="//www.google.com">www.гоогле.цом</a>
+</p>
+!! end
+
 !! test
 Do not convert roman numbers to language variants
 !! options