Merge "(Bug 38439) Attempt on fixing the suicidal LangObjCache"
[lhc/web/wiklou.git] / languages / Language.php
index cc763d0..1de65fe 100644 (file)
@@ -282,7 +282,7 @@ class Language {
                        throw new MWException( __METHOD__ . " must be passed a string, $type given$addmsg" );
                }
 
-               return preg_match( '/^[a-z0-9-]+$/i', $code );
+               return (bool)preg_match( '/^[a-z0-9-]+$/i', $code );
        }
 
        /**
@@ -3709,15 +3709,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;
+               }
        }
 
        /**