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
}
/**
- * 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;
+ }
}
/**
);
}
- /**
- * 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
$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)
}
}
- /**
- * 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
$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)
$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)
$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)
$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
</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