public static function parseExternalLinks( $text ) {
		static $urlProtocols = false;
		static $counter = 0;
		// @codeCoverageIgnoreStart
		if ( !$urlProtocols ) {
			if ( function_exists( 'wfUrlProtocols' ) ) {
				// Allow custom protocols
				$urlProtocols = wfUrlProtocols();
			} else {
				$urlProtocols = 'https?:\/\/|ftp:\/\/';
			}
		}
		// @codeCoverageIgnoreEnd

		$extLinkBracketedRegex = '/(?:(<[^>]*)|' .
			'\[(((?i)' . $urlProtocols . ')' .
				self::EXT_LINK_URL_CLASS .
				'+)\p{Zs}*([^\]\\x00-\\x08\\x0a-\\x1F]*?)\]|' .
			'(((?i)' . $urlProtocols . ')' .
				self::EXT_LINK_URL_CLASS .
				'+))/Su';

		return preg_replace_callback(
			$extLinkBracketedRegex,
			function ( array $bits ) use ( &$counter ) {
				// @codeCoverageIgnoreStart
				if ( $bits[1] != '' ) {
					return $bits[1];
				}
				// @codeCoverageIgnoreEnd

				if ( isset( $bits[4] ) && $bits[4] != '' ) {
					return '<a href="' . $bits[2] . '">' . $bits[4] . '</a>';
				} elseif ( isset( $bits[5] ) ) {
					return '<a href="' . $bits[5] . '">' . $bits[5] . '</a>';
				} else {
					return '<a href="' . $bits[2] . '">[' . ++$counter . ']</a>';
				}
			},
			$text
		);
	}